The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.app; |
| 18 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 20 | import android.annotation.SdkConstant; |
| 21 | import android.annotation.SdkConstant.SdkConstantType; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 22 | import android.content.Context; |
| 23 | import android.content.Intent; |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 24 | import android.content.pm.ApplicationInfo; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 25 | import android.content.pm.PackageManager.NameNotFoundException; |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 26 | import android.content.res.ColorStateList; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 27 | import android.graphics.Bitmap; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 28 | import android.graphics.Canvas; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 29 | import android.graphics.PorterDuff; |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 30 | import android.graphics.drawable.Drawable; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 31 | import android.media.AudioAttributes; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 32 | import android.media.AudioManager; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 33 | import android.media.session.MediaSession; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 34 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 35 | import android.os.BadParcelableException; |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 36 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 37 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | import android.os.Parcel; |
| 39 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 40 | import android.os.SystemClock; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 41 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | import android.text.TextUtils; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 43 | import android.util.Log; |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 44 | import android.util.MathUtils; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 45 | import android.util.TypedValue; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 46 | import android.view.Gravity; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 47 | import android.view.View; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 48 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | import android.widget.RemoteViews; |
| 50 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 51 | import com.android.internal.R; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 52 | import com.android.internal.util.NotificationColorUtil; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 53 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 54 | import java.lang.annotation.Retention; |
| 55 | import java.lang.annotation.RetentionPolicy; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 56 | import java.lang.reflect.Constructor; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 57 | import java.text.NumberFormat; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 58 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 59 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 60 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 61 | import java.util.List; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 62 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | /** |
| 64 | * A class that represents how a persistent notification is to be presented to |
| 65 | * the user using the {@link android.app.NotificationManager}. |
| 66 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 67 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 68 | * easier to construct Notifications.</p> |
| 69 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 70 | * <div class="special reference"> |
| 71 | * <h3>Developer Guides</h3> |
| 72 | * <p>For a guide to creating notifications, read the |
| 73 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 74 | * developer guide.</p> |
| 75 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 76 | */ |
| 77 | public class Notification implements Parcelable |
| 78 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 79 | private static final String TAG = "Notification"; |
| 80 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 81 | /** |
Daniel Sandler | 01df1c6 | 2014-06-09 10:54:01 -0400 | [diff] [blame] | 82 | * An activity that provides a user interface for adjusting notification preferences for its |
| 83 | * containing application. Optional but recommended for apps that post |
| 84 | * {@link android.app.Notification Notifications}. |
| 85 | */ |
| 86 | @SdkConstant(SdkConstantType.INTENT_CATEGORY) |
| 87 | public static final String INTENT_CATEGORY_NOTIFICATION_PREFERENCES |
| 88 | = "android.intent.category.NOTIFICATION_PREFERENCES"; |
| 89 | |
| 90 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | * Use all default values (where applicable). |
| 92 | */ |
| 93 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 94 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | /** |
| 96 | * Use the default notification sound. This will ignore any given |
| 97 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 98 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 99 | * <p> |
| 100 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 101 | * </p> |
| 102 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 103 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 104 | */ |
| 105 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 106 | public static final int DEFAULT_SOUND = 1; |
| 107 | |
| 108 | /** |
| 109 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 110 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 111 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 112 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 113 | * <p> |
| 114 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 115 | * </p> |
| 116 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 118 | */ |
| 119 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 120 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 121 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 122 | /** |
| 123 | * Use the default notification lights. This will ignore the |
| 124 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 125 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 126 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 127 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 128 | */ |
| 129 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 130 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 131 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 132 | /** |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 133 | * Maximum length of CharSequences accepted by Builder and friends. |
| 134 | * |
| 135 | * <p> |
| 136 | * Avoids spamming the system with overly large strings such as full e-mails. |
| 137 | */ |
| 138 | private static final int MAX_CHARSEQUENCE_LENGTH = 5 * 1024; |
| 139 | |
| 140 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 141 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 142 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 143 | * Default value: {@link System#currentTimeMillis() Now}. |
| 144 | * |
| 145 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 146 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 147 | * 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] | 148 | * timestamped according to when the activity began. |
| 149 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 150 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 151 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 152 | * <ul> |
| 153 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 154 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 155 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 156 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 157 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 158 | * <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] | 159 | * </ul> |
| 160 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | */ |
| 162 | public long when; |
| 163 | |
| 164 | /** |
| 165 | * The resource id of a drawable to use as the icon in the status bar. |
Daniel Sandler | d952dae | 2011-02-07 16:33:36 -0500 | [diff] [blame] | 166 | * This is required; notifications with an invalid icon resource will not be shown. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 167 | */ |
| 168 | public int icon; |
| 169 | |
| 170 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 171 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 172 | * leave it at its default value of 0. |
| 173 | * |
| 174 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 175 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 176 | */ |
| 177 | public int iconLevel; |
| 178 | |
| 179 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 180 | * The number of events that this notification represents. For example, in a new mail |
| 181 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 182 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 183 | * The system may or may not use this field to modify the appearance of the notification. For |
| 184 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 185 | * superimposed over the icon in the status bar. Starting with |
| 186 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 187 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 188 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 189 | * If the number is 0 or negative, it is never shown. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | */ |
| 191 | public int number; |
| 192 | |
| 193 | /** |
| 194 | * The intent to execute when the expanded status entry is clicked. If |
| 195 | * this is an activity, it must include the |
| 196 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 197 | * that you take care of task management as described in the |
| 198 | * <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] | 199 | * Stack</a> document. In particular, make sure to read the notification section |
| 200 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 201 | * Notifications</a> for the correct ways to launch an application from a |
| 202 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 203 | */ |
| 204 | public PendingIntent contentIntent; |
| 205 | |
| 206 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 207 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 208 | * the "Clear All" button or by swiping it away individually. |
| 209 | * |
| 210 | * This probably shouldn't be launching an activity since several of those will be sent |
| 211 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | */ |
| 213 | public PendingIntent deleteIntent; |
| 214 | |
| 215 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 216 | * 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] | 217 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 218 | * <p> |
| 219 | * The system UI may choose to display a heads-up notification, instead of |
| 220 | * launching this intent, while the user is using the device. |
| 221 | * </p> |
| 222 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 223 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 224 | */ |
| 225 | public PendingIntent fullScreenIntent; |
| 226 | |
| 227 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 228 | * Text that summarizes this notification for accessibility services. |
| 229 | * |
| 230 | * As of the L release, this text is no longer shown on screen, but it is still useful to |
| 231 | * accessibility services (where it serves as an audible announcement of the notification's |
| 232 | * appearance). |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 233 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 234 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | */ |
| 236 | public CharSequence tickerText; |
| 237 | |
| 238 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 239 | * Formerly, a view showing the {@link #tickerText}. |
| 240 | * |
| 241 | * No longer displayed in the status bar as of API 21. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 242 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 243 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 244 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 245 | |
| 246 | /** |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 247 | * The view that will represent this notification in the expanded status bar. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 248 | */ |
| 249 | public RemoteViews contentView; |
| 250 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 251 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 252 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 253 | * opportunity to show more detail. The system UI may choose to show this |
| 254 | * instead of the normal content view at its discretion. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 255 | */ |
| 256 | public RemoteViews bigContentView; |
| 257 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 258 | |
| 259 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 260 | * A medium-format version of {@link #contentView}, providing the Notification an |
| 261 | * opportunity to add action buttons to contentView. At its discretion, the system UI may |
| 262 | * choose to show this as a heads-up notification, which will pop up so the user can see |
| 263 | * it without leaving their current activity. |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 264 | */ |
| 265 | public RemoteViews headsUpContentView; |
| 266 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 267 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 268 | * The bitmap that may escape the bounds of the panel and bar. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 269 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 270 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 271 | |
| 272 | /** |
| 273 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 274 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | * <p> |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 276 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 277 | * </p> |
| 278 | * |
| 279 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 280 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 281 | * </p> |
| 282 | */ |
| 283 | public Uri sound; |
| 284 | |
| 285 | /** |
| 286 | * Use this constant as the value for audioStreamType to request that |
| 287 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 288 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 289 | * |
| 290 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 291 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 292 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 293 | public static final int STREAM_DEFAULT = -1; |
| 294 | |
| 295 | /** |
| 296 | * The audio stream type to use when playing the sound. |
| 297 | * Should be one of the STREAM_ constants from |
| 298 | * {@link android.media.AudioManager}. |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 299 | * |
| 300 | * @deprecated Use {@link #audioAttributes} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 301 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 302 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 303 | public int audioStreamType = STREAM_DEFAULT; |
| 304 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 305 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 306 | * The default value of {@link #audioAttributes}. |
| 307 | */ |
| 308 | public static final AudioAttributes AUDIO_ATTRIBUTES_DEFAULT = new AudioAttributes.Builder() |
| 309 | .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) |
| 310 | .setUsage(AudioAttributes.USAGE_NOTIFICATION) |
| 311 | .build(); |
| 312 | |
| 313 | /** |
| 314 | * The {@link AudioAttributes audio attributes} to use when playing the sound. |
| 315 | */ |
| 316 | public AudioAttributes audioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
| 317 | |
| 318 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 319 | * The pattern with which to vibrate. |
| 320 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 321 | * <p> |
| 322 | * To vibrate the default pattern, see {@link #defaults}. |
| 323 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 324 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 325 | * <p> |
| 326 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 327 | * </p> |
| 328 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 329 | * @see android.os.Vibrator#vibrate(long[],int) |
| 330 | */ |
| 331 | public long[] vibrate; |
| 332 | |
| 333 | /** |
| 334 | * The color of the led. The hardware will do its best approximation. |
| 335 | * |
| 336 | * @see #FLAG_SHOW_LIGHTS |
| 337 | * @see #flags |
| 338 | */ |
| 339 | public int ledARGB; |
| 340 | |
| 341 | /** |
| 342 | * The number of milliseconds for the LED to be on while it's flashing. |
| 343 | * The hardware will do its best approximation. |
| 344 | * |
| 345 | * @see #FLAG_SHOW_LIGHTS |
| 346 | * @see #flags |
| 347 | */ |
| 348 | public int ledOnMS; |
| 349 | |
| 350 | /** |
| 351 | * The number of milliseconds for the LED to be off while it's flashing. |
| 352 | * The hardware will do its best approximation. |
| 353 | * |
| 354 | * @see #FLAG_SHOW_LIGHTS |
| 355 | * @see #flags |
| 356 | */ |
| 357 | public int ledOffMS; |
| 358 | |
| 359 | /** |
| 360 | * Specifies which values should be taken from the defaults. |
| 361 | * <p> |
| 362 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 363 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 364 | * values, use {@link #DEFAULT_ALL}. |
| 365 | * </p> |
| 366 | */ |
| 367 | public int defaults; |
| 368 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 369 | /** |
| 370 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 371 | * set if you want the LED on for this notification. |
| 372 | * <ul> |
| 373 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 374 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 375 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 376 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 377 | * be on and off to ledOnMS and ledOffMS.</li> |
| 378 | * </ul> |
| 379 | * <p> |
| 380 | * Since hardware varies, you are not guaranteed that any of the values |
| 381 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 382 | * because they will be set to values that work on any given hardware. |
| 383 | * <p> |
| 384 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 385 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | */ |
| 387 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 388 | |
| 389 | /** |
| 390 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 391 | * set if this notification is in reference to something that is ongoing, |
| 392 | * like a phone call. It should not be set if this notification is in |
| 393 | * reference to something that happened at a particular point in time, |
| 394 | * like a missed phone call. |
| 395 | */ |
| 396 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 397 | |
| 398 | /** |
| 399 | * 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] | 400 | * the audio will be repeated until the notification is |
| 401 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 402 | */ |
| 403 | public static final int FLAG_INSISTENT = 0x00000004; |
| 404 | |
| 405 | /** |
| 406 | * 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] | 407 | * set if you would only like the sound, vibrate and ticker to be played |
| 408 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 409 | */ |
| 410 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 411 | |
| 412 | /** |
| 413 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 414 | * 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] | 415 | * user. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 416 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 417 | */ |
| 418 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 419 | |
| 420 | /** |
| 421 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 422 | * set if the notification should not be canceled when the user clicks |
| 423 | * the Clear all button. |
| 424 | */ |
| 425 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 426 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 427 | /** |
| 428 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 429 | * set if this notification represents a currently running service. This |
| 430 | * will normally be set for you by {@link Service#startForeground}. |
| 431 | */ |
| 432 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 433 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 434 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 435 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 436 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 437 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 438 | */ |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 439 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 440 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 441 | /** |
| 442 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 443 | * set if this notification is relevant to the current device only |
| 444 | * and it is not recommended that it bridge to other devices. |
| 445 | */ |
| 446 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 447 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 448 | /** |
| 449 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 450 | * set if this notification is the group summary for a group of notifications. |
| 451 | * Grouped notifications may display in a cluster or stack on devices which |
| 452 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 453 | */ |
| 454 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 455 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 456 | public int flags; |
| 457 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 458 | /** @hide */ |
| 459 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 460 | @Retention(RetentionPolicy.SOURCE) |
| 461 | public @interface Priority {} |
| 462 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 463 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 464 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 465 | * notifications, use this value for all notifications. |
| 466 | */ |
| 467 | public static final int PRIORITY_DEFAULT = 0; |
| 468 | |
| 469 | /** |
| 470 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 471 | * items smaller, or at a different position in the list, compared with your app's |
| 472 | * {@link #PRIORITY_DEFAULT} items. |
| 473 | */ |
| 474 | public static final int PRIORITY_LOW = -1; |
| 475 | |
| 476 | /** |
| 477 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 478 | * circumstances, such as detailed notification logs. |
| 479 | */ |
| 480 | public static final int PRIORITY_MIN = -2; |
| 481 | |
| 482 | /** |
| 483 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 484 | * show these items larger, or at a different position in notification lists, compared with |
| 485 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 486 | */ |
| 487 | public static final int PRIORITY_HIGH = 1; |
| 488 | |
| 489 | /** |
| 490 | * Highest {@link #priority}, for your application's most important items that require the |
| 491 | * user's prompt attention or input. |
| 492 | */ |
| 493 | public static final int PRIORITY_MAX = 2; |
| 494 | |
| 495 | /** |
| 496 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 497 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 498 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 499 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 500 | * 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] | 501 | * system will make a determination about how to interpret this priority when presenting |
| 502 | * the notification. |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 503 | * |
| 504 | * <p> |
| 505 | * A notification that is at least {@link #PRIORITY_HIGH} is more likely to be presented |
| 506 | * as a heads-up notification. |
| 507 | * </p> |
| 508 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 509 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 510 | @Priority |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 511 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 512 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 513 | /** |
| 514 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 515 | * to be applied by the standard Style templates when presenting this notification. |
| 516 | * |
| 517 | * The current template design constructs a colorful header image by overlaying the |
| 518 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 519 | * ignored. |
| 520 | */ |
| 521 | public int color = COLOR_DEFAULT; |
| 522 | |
| 523 | /** |
| 524 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 525 | * any special color but instead use default colors when presenting this notification. |
| 526 | */ |
| 527 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 528 | |
| 529 | /** |
| 530 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 531 | * the notification's presence and contents in untrusted situations (namely, on the secure |
| 532 | * lockscreen). |
| 533 | * |
| 534 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 535 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 536 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 537 | * the appropriate user. |
| 538 | * |
| 539 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 540 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 541 | * To modify the public version of this notification—for example, to redact some portions—see |
| 542 | * {@link Builder#setPublicVersion(Notification)}. |
| 543 | * |
| 544 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 545 | * and ticker until the user has bypassed the lockscreen. |
| 546 | */ |
| 547 | public int visibility; |
| 548 | |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 549 | /** |
| 550 | * Notification visibility: Show this notification in its entirety on all lockscreens. |
| 551 | * |
| 552 | * {@see #visibility} |
| 553 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 554 | public static final int VISIBILITY_PUBLIC = 1; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 555 | |
| 556 | /** |
| 557 | * Notification visibility: Show this notification on all lockscreens, but conceal sensitive or |
| 558 | * private information on secure lockscreens. |
| 559 | * |
| 560 | * {@see #visibility} |
| 561 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 562 | public static final int VISIBILITY_PRIVATE = 0; |
Griff Hazen | fc3922d | 2014-08-20 11:56:44 -0700 | [diff] [blame] | 563 | |
| 564 | /** |
| 565 | * Notification visibility: Do not reveal any part of this notification on a secure lockscreen. |
| 566 | * |
| 567 | * {@see #visibility} |
| 568 | */ |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 569 | public static final int VISIBILITY_SECRET = -1; |
| 570 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 571 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 572 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 573 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 574 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 575 | |
| 576 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 577 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 578 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 579 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 580 | |
| 581 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 582 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 583 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 584 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 585 | |
| 586 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 587 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 588 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 589 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 590 | |
| 591 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 592 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 593 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 594 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 595 | |
| 596 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 597 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 598 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 599 | public static final String CATEGORY_ALARM = "alarm"; |
| 600 | |
| 601 | /** |
| 602 | * Notification category: progress of a long-running background operation. |
| 603 | */ |
| 604 | public static final String CATEGORY_PROGRESS = "progress"; |
| 605 | |
| 606 | /** |
| 607 | * Notification category: social network or sharing update. |
| 608 | */ |
| 609 | public static final String CATEGORY_SOCIAL = "social"; |
| 610 | |
| 611 | /** |
| 612 | * Notification category: error in background operation or authentication status. |
| 613 | */ |
| 614 | public static final String CATEGORY_ERROR = "err"; |
| 615 | |
| 616 | /** |
| 617 | * Notification category: media transport control for playback. |
| 618 | */ |
| 619 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 620 | |
| 621 | /** |
| 622 | * Notification category: system or device status update. Reserved for system use. |
| 623 | */ |
| 624 | public static final String CATEGORY_SYSTEM = "sys"; |
| 625 | |
| 626 | /** |
| 627 | * Notification category: indication of running background service. |
| 628 | */ |
| 629 | public static final String CATEGORY_SERVICE = "service"; |
| 630 | |
| 631 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 632 | * Notification category: a specific, timely recommendation for a single thing. |
| 633 | * For example, a news app might want to recommend a news story it believes the user will |
| 634 | * want to read next. |
| 635 | */ |
| 636 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 637 | |
| 638 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 639 | * Notification category: ongoing information about device or contextual status. |
| 640 | */ |
| 641 | public static final String CATEGORY_STATUS = "status"; |
| 642 | |
| 643 | /** |
| 644 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 645 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 646 | */ |
| 647 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 648 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 649 | private String mGroupKey; |
| 650 | |
| 651 | /** |
| 652 | * Get the key used to group this notification into a cluster or stack |
| 653 | * with other notifications on devices which support such rendering. |
| 654 | */ |
| 655 | public String getGroup() { |
| 656 | return mGroupKey; |
| 657 | } |
| 658 | |
| 659 | private String mSortKey; |
| 660 | |
| 661 | /** |
| 662 | * Get a sort key that orders this notification among other notifications from the |
| 663 | * same package. This can be useful if an external sort was already applied and an app |
| 664 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 665 | * value, although providing different priorities in addition to providing sort key may |
| 666 | * cause this value to be ignored. |
| 667 | * |
| 668 | * <p>This sort key can also be used to order members of a notification group. See |
| 669 | * {@link Builder#setGroup}. |
| 670 | * |
| 671 | * @see String#compareTo(String) |
| 672 | */ |
| 673 | public String getSortKey() { |
| 674 | return mSortKey; |
| 675 | } |
| 676 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 677 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 678 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 679 | * <p> |
| 680 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 681 | * APIs, and are intended to be used by |
| 682 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 683 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 684 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 685 | public Bundle extras = new Bundle(); |
| 686 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 687 | /** |
| 688 | * {@link #extras} key: this is the title of the notification, |
| 689 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 690 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 691 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 692 | |
| 693 | /** |
| 694 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 695 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 696 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 697 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 698 | |
| 699 | /** |
| 700 | * {@link #extras} key: this is the main text payload, as supplied to |
| 701 | * {@link Builder#setContentText(CharSequence)}. |
| 702 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 703 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 704 | |
| 705 | /** |
| 706 | * {@link #extras} key: this is a third line of text, as supplied to |
| 707 | * {@link Builder#setSubText(CharSequence)}. |
| 708 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 709 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 710 | |
| 711 | /** |
| 712 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 713 | * {@link Builder#setContentInfo(CharSequence)}. |
| 714 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 715 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 716 | |
| 717 | /** |
| 718 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 719 | * alongside expanded notifications, as supplied to (e.g.) |
| 720 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 721 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 722 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 723 | |
| 724 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 725 | * {@link #extras} key: this is the longer text shown in the big form of a |
| 726 | * {@link BigTextStyle} notification, as supplied to |
| 727 | * {@link BigTextStyle#bigText(CharSequence)}. |
| 728 | */ |
| 729 | public static final String EXTRA_BIG_TEXT = "android.bigText"; |
| 730 | |
| 731 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 732 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 733 | * supplied to {@link Builder#setSmallIcon(int)}. |
| 734 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 735 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 736 | |
| 737 | /** |
| 738 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 739 | * notification payload, as |
| 740 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
| 741 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 742 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 743 | |
| 744 | /** |
| 745 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 746 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 747 | * shown in its expanded form, as supplied to |
| 748 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 749 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 750 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 751 | |
| 752 | /** |
| 753 | * {@link #extras} key: this is the progress value supplied to |
| 754 | * {@link Builder#setProgress(int, int, boolean)}. |
| 755 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 756 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 757 | |
| 758 | /** |
| 759 | * {@link #extras} key: this is the maximum value supplied to |
| 760 | * {@link Builder#setProgress(int, int, boolean)}. |
| 761 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 762 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 763 | |
| 764 | /** |
| 765 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 766 | * {@link Builder#setProgress(int, int, boolean)}. |
| 767 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 768 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 769 | |
| 770 | /** |
| 771 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 772 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 773 | * {@link Builder#setUsesChronometer(boolean)}. |
| 774 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 775 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 776 | |
| 777 | /** |
| 778 | * {@link #extras} key: whether {@link #when} should be shown, |
| 779 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 780 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 781 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 782 | |
| 783 | /** |
| 784 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 785 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 786 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 787 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 788 | |
| 789 | /** |
| 790 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 791 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 792 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 793 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 794 | |
| 795 | /** |
| 796 | * {@link #extras} key: A string representing the name of the specific |
| 797 | * {@link android.app.Notification.Style} used to create this notification. |
| 798 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 799 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 800 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 801 | /** |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 802 | * {@link #extras} key: A String array containing the people that this notification relates to, |
| 803 | * each of which was supplied to {@link Builder#addPerson(String)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 804 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 805 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 806 | |
| 807 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 808 | * {@link #extras} key: used to provide hints about the appropriateness of |
| 809 | * displaying this notification as a heads-up notification. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 810 | * @hide |
| 811 | */ |
| 812 | public static final String EXTRA_AS_HEADS_UP = "headsup"; |
| 813 | |
| 814 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 815 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 816 | * Only available to notifications coming from the android package. |
| 817 | * @hide |
| 818 | */ |
| 819 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 820 | |
| 821 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 822 | * {@link #extras} key: A |
| 823 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 824 | * in the background when the notification is selected. The URI must point to an image stream |
| 825 | * suitable for passing into |
| 826 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 827 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 828 | * URI used for this purpose must require no permissions to read the image data. |
| 829 | */ |
| 830 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 831 | |
| 832 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 833 | * {@link #extras} key: A |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 834 | * {@link android.media.session.MediaSession.Token} associated with a |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 835 | * {@link android.app.Notification.MediaStyle} notification. |
| 836 | */ |
| 837 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 838 | |
| 839 | /** |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 840 | * {@link #extras} key: the indices of actions to be shown in the compact view, |
| 841 | * as supplied to (e.g.) {@link MediaStyle#setShowActionsInCompactView(int...)}. |
| 842 | */ |
| 843 | public static final String EXTRA_COMPACT_ACTIONS = "android.compactActions"; |
| 844 | |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 845 | /** |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 846 | * {@link #extras} key: the user that built the notification. |
| 847 | * |
| 848 | * @hide |
| 849 | */ |
| 850 | public static final String EXTRA_ORIGINATING_USERID = "android.originatingUserId"; |
| 851 | |
| 852 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 853 | * Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification should not be |
| 854 | * displayed in the heads up space. |
| 855 | * |
| 856 | * <p> |
| 857 | * If this notification has a {@link #fullScreenIntent}, then it will always launch the |
| 858 | * full-screen intent when posted. |
| 859 | * </p> |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 860 | * @hide |
| 861 | */ |
| 862 | public static final int HEADS_UP_NEVER = 0; |
| 863 | |
| 864 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 865 | * Default value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification may be |
| 866 | * displayed as a heads up. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 867 | * @hide |
| 868 | */ |
| 869 | public static final int HEADS_UP_ALLOWED = 1; |
| 870 | |
| 871 | /** |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 872 | * Value for {@link #EXTRA_AS_HEADS_UP} that indicates this notification is a |
| 873 | * good candidate for display as a heads up. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 874 | * @hide |
| 875 | */ |
| 876 | public static final int HEADS_UP_REQUESTED = 2; |
| 877 | |
| 878 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 879 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 880 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 881 | * selected by the user. |
| 882 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 883 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 884 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 885 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 886 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 887 | public static class Action implements Parcelable { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 888 | private final Bundle mExtras; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 889 | private final RemoteInput[] mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 890 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 891 | /** |
| 892 | * Small icon representing the action. |
| 893 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 894 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 895 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 896 | /** |
| 897 | * Title of the action. |
| 898 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 899 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 900 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 901 | /** |
| 902 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 903 | * may be rendered in a disabled presentation by the system UI. |
| 904 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 905 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 906 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 907 | private Action(Parcel in) { |
| 908 | icon = in.readInt(); |
| 909 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 910 | if (in.readInt() == 1) { |
| 911 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 912 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 913 | mExtras = in.readBundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 914 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 915 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 916 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 917 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 918 | * Use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 919 | */ |
| 920 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 921 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 922 | } |
| 923 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 924 | private Action(int icon, CharSequence title, PendingIntent intent, Bundle extras, |
| 925 | RemoteInput[] remoteInputs) { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 926 | this.icon = icon; |
| 927 | this.title = title; |
| 928 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 929 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 930 | this.mRemoteInputs = remoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | /** |
| 934 | * Get additional metadata carried around with this Action. |
| 935 | */ |
| 936 | public Bundle getExtras() { |
| 937 | return mExtras; |
| 938 | } |
| 939 | |
| 940 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 941 | * Get the list of inputs to be collected from the user when this action is sent. |
| 942 | * May return null if no remote inputs were added. |
| 943 | */ |
| 944 | public RemoteInput[] getRemoteInputs() { |
| 945 | return mRemoteInputs; |
| 946 | } |
| 947 | |
| 948 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 949 | * Builder class for {@link Action} objects. |
| 950 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 951 | public static final class Builder { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 952 | private final int mIcon; |
| 953 | private final CharSequence mTitle; |
| 954 | private final PendingIntent mIntent; |
| 955 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 956 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 957 | |
| 958 | /** |
| 959 | * Construct a new builder for {@link Action} object. |
| 960 | * @param icon icon to show for this action |
| 961 | * @param title the title of the action |
| 962 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 963 | */ |
| 964 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 965 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 966 | } |
| 967 | |
| 968 | /** |
| 969 | * Construct a new builder for {@link Action} object using the fields from an |
| 970 | * {@link Action}. |
| 971 | * @param action the action to read fields from. |
| 972 | */ |
| 973 | public Builder(Action action) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 974 | this(action.icon, action.title, action.actionIntent, new Bundle(action.mExtras), |
| 975 | action.getRemoteInputs()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 976 | } |
| 977 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 978 | private Builder(int icon, CharSequence title, PendingIntent intent, Bundle extras, |
| 979 | RemoteInput[] remoteInputs) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 980 | mIcon = icon; |
| 981 | mTitle = title; |
| 982 | mIntent = intent; |
| 983 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 984 | if (remoteInputs != null) { |
| 985 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 986 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 987 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 988 | } |
| 989 | |
| 990 | /** |
| 991 | * Merge additional metadata into this builder. |
| 992 | * |
| 993 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 994 | * |
| 995 | * @see Notification.Action#extras |
| 996 | */ |
| 997 | public Builder addExtras(Bundle extras) { |
| 998 | if (extras != null) { |
| 999 | mExtras.putAll(extras); |
| 1000 | } |
| 1001 | return this; |
| 1002 | } |
| 1003 | |
| 1004 | /** |
| 1005 | * Get the metadata Bundle used by this Builder. |
| 1006 | * |
| 1007 | * <p>The returned Bundle is shared with this Builder. |
| 1008 | */ |
| 1009 | public Bundle getExtras() { |
| 1010 | return mExtras; |
| 1011 | } |
| 1012 | |
| 1013 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1014 | * Add an input to be collected from the user when this action is sent. |
| 1015 | * Response values can be retrieved from the fired intent by using the |
| 1016 | * {@link RemoteInput#getResultsFromIntent} function. |
| 1017 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 1018 | * @return this object for method chaining |
| 1019 | */ |
| 1020 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 1021 | if (mRemoteInputs == null) { |
| 1022 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 1023 | } |
| 1024 | mRemoteInputs.add(remoteInput); |
| 1025 | return this; |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * Apply an extender to this action builder. Extenders may be used to add |
| 1030 | * metadata or change options on this builder. |
| 1031 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1032 | public Builder extend(Extender extender) { |
| 1033 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1034 | return this; |
| 1035 | } |
| 1036 | |
| 1037 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1038 | * Combine all of the options that have been set and return a new {@link Action} |
| 1039 | * object. |
| 1040 | * @return the built action |
| 1041 | */ |
| 1042 | public Action build() { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1043 | RemoteInput[] remoteInputs = mRemoteInputs != null |
| 1044 | ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null; |
| 1045 | return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1046 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1047 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1048 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1049 | @Override |
| 1050 | public Action clone() { |
| 1051 | return new Action( |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1052 | icon, |
| 1053 | title, |
| 1054 | actionIntent, // safe to alias |
| 1055 | new Bundle(mExtras), |
| 1056 | getRemoteInputs()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1057 | } |
| 1058 | @Override |
| 1059 | public int describeContents() { |
| 1060 | return 0; |
| 1061 | } |
| 1062 | @Override |
| 1063 | public void writeToParcel(Parcel out, int flags) { |
| 1064 | out.writeInt(icon); |
| 1065 | TextUtils.writeToParcel(title, out, flags); |
| 1066 | if (actionIntent != null) { |
| 1067 | out.writeInt(1); |
| 1068 | actionIntent.writeToParcel(out, flags); |
| 1069 | } else { |
| 1070 | out.writeInt(0); |
| 1071 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1072 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1073 | out.writeTypedArray(mRemoteInputs, flags); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1074 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1075 | public static final Parcelable.Creator<Action> CREATOR = |
| 1076 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1077 | public Action createFromParcel(Parcel in) { |
| 1078 | return new Action(in); |
| 1079 | } |
| 1080 | public Action[] newArray(int size) { |
| 1081 | return new Action[size]; |
| 1082 | } |
| 1083 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1084 | |
| 1085 | /** |
| 1086 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 1087 | * metadata or change options on an action builder. |
| 1088 | */ |
| 1089 | public interface Extender { |
| 1090 | /** |
| 1091 | * Apply this extender to a notification action builder. |
| 1092 | * @param builder the builder to be modified. |
| 1093 | * @return the build object for chaining. |
| 1094 | */ |
| 1095 | public Builder extend(Builder builder); |
| 1096 | } |
| 1097 | |
| 1098 | /** |
| 1099 | * Wearable extender for notification actions. To add extensions to an action, |
| 1100 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 1101 | * the {@code WearableExtender()} constructor and apply it to a |
| 1102 | * {@link android.app.Notification.Action.Builder} using |
| 1103 | * {@link android.app.Notification.Action.Builder#extend}. |
| 1104 | * |
| 1105 | * <pre class="prettyprint"> |
| 1106 | * Notification.Action action = new Notification.Action.Builder( |
| 1107 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1108 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1109 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 1110 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1111 | */ |
| 1112 | public static final class WearableExtender implements Extender { |
| 1113 | /** Notification action extra which contains wearable extensions */ |
| 1114 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 1115 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1116 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1117 | private static final String KEY_FLAGS = "flags"; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1118 | private static final String KEY_IN_PROGRESS_LABEL = "inProgressLabel"; |
| 1119 | private static final String KEY_CONFIRM_LABEL = "confirmLabel"; |
| 1120 | private static final String KEY_CANCEL_LABEL = "cancelLabel"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1121 | |
| 1122 | // Flags bitwise-ored to mFlags |
| 1123 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
| 1124 | |
| 1125 | // Default value for flags integer |
| 1126 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1127 | |
| 1128 | private int mFlags = DEFAULT_FLAGS; |
| 1129 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1130 | private CharSequence mInProgressLabel; |
| 1131 | private CharSequence mConfirmLabel; |
| 1132 | private CharSequence mCancelLabel; |
| 1133 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1134 | /** |
| 1135 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1136 | * options. |
| 1137 | */ |
| 1138 | public WearableExtender() { |
| 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1143 | * wearable options present in an existing notification action. |
| 1144 | * @param action the notification action to inspect. |
| 1145 | */ |
| 1146 | public WearableExtender(Action action) { |
| 1147 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1148 | if (wearableBundle != null) { |
| 1149 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1150 | mInProgressLabel = wearableBundle.getCharSequence(KEY_IN_PROGRESS_LABEL); |
| 1151 | mConfirmLabel = wearableBundle.getCharSequence(KEY_CONFIRM_LABEL); |
| 1152 | mCancelLabel = wearableBundle.getCharSequence(KEY_CANCEL_LABEL); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1153 | } |
| 1154 | } |
| 1155 | |
| 1156 | /** |
| 1157 | * Apply wearable extensions to a notification action that is being built. This is |
| 1158 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1159 | * method of {@link android.app.Notification.Action.Builder}. |
| 1160 | */ |
| 1161 | @Override |
| 1162 | public Action.Builder extend(Action.Builder builder) { |
| 1163 | Bundle wearableBundle = new Bundle(); |
| 1164 | |
| 1165 | if (mFlags != DEFAULT_FLAGS) { |
| 1166 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1167 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1168 | if (mInProgressLabel != null) { |
| 1169 | wearableBundle.putCharSequence(KEY_IN_PROGRESS_LABEL, mInProgressLabel); |
| 1170 | } |
| 1171 | if (mConfirmLabel != null) { |
| 1172 | wearableBundle.putCharSequence(KEY_CONFIRM_LABEL, mConfirmLabel); |
| 1173 | } |
| 1174 | if (mCancelLabel != null) { |
| 1175 | wearableBundle.putCharSequence(KEY_CANCEL_LABEL, mCancelLabel); |
| 1176 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1177 | |
| 1178 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1179 | return builder; |
| 1180 | } |
| 1181 | |
| 1182 | @Override |
| 1183 | public WearableExtender clone() { |
| 1184 | WearableExtender that = new WearableExtender(); |
| 1185 | that.mFlags = this.mFlags; |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1186 | that.mInProgressLabel = this.mInProgressLabel; |
| 1187 | that.mConfirmLabel = this.mConfirmLabel; |
| 1188 | that.mCancelLabel = this.mCancelLabel; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1189 | return that; |
| 1190 | } |
| 1191 | |
| 1192 | /** |
| 1193 | * Set whether this action is available when the wearable device is not connected to |
| 1194 | * a companion device. The user can still trigger this action when the wearable device is |
| 1195 | * offline, but a visual hint will indicate that the action may not be available. |
| 1196 | * Defaults to true. |
| 1197 | */ |
| 1198 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1199 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1200 | return this; |
| 1201 | } |
| 1202 | |
| 1203 | /** |
| 1204 | * Get whether this action is available when the wearable device is not connected to |
| 1205 | * a companion device. The user can still trigger this action when the wearable device is |
| 1206 | * offline, but a visual hint will indicate that the action may not be available. |
| 1207 | * Defaults to true. |
| 1208 | */ |
| 1209 | public boolean isAvailableOffline() { |
| 1210 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1211 | } |
| 1212 | |
| 1213 | private void setFlag(int mask, boolean value) { |
| 1214 | if (value) { |
| 1215 | mFlags |= mask; |
| 1216 | } else { |
| 1217 | mFlags &= ~mask; |
| 1218 | } |
| 1219 | } |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 1220 | |
| 1221 | /** |
| 1222 | * Set a label to display while the wearable is preparing to automatically execute the |
| 1223 | * action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1224 | * |
| 1225 | * @param label the label to display while the action is being prepared to execute |
| 1226 | * @return this object for method chaining |
| 1227 | */ |
| 1228 | public WearableExtender setInProgressLabel(CharSequence label) { |
| 1229 | mInProgressLabel = label; |
| 1230 | return this; |
| 1231 | } |
| 1232 | |
| 1233 | /** |
| 1234 | * Get the label to display while the wearable is preparing to automatically execute |
| 1235 | * the action. This is usually a 'ing' verb ending in ellipsis like "Sending..." |
| 1236 | * |
| 1237 | * @return the label to display while the action is being prepared to execute |
| 1238 | */ |
| 1239 | public CharSequence getInProgressLabel() { |
| 1240 | return mInProgressLabel; |
| 1241 | } |
| 1242 | |
| 1243 | /** |
| 1244 | * Set a label to display to confirm that the action should be executed. |
| 1245 | * This is usually an imperative verb like "Send". |
| 1246 | * |
| 1247 | * @param label the label to confirm the action should be executed |
| 1248 | * @return this object for method chaining |
| 1249 | */ |
| 1250 | public WearableExtender setConfirmLabel(CharSequence label) { |
| 1251 | mConfirmLabel = label; |
| 1252 | return this; |
| 1253 | } |
| 1254 | |
| 1255 | /** |
| 1256 | * Get the label to display to confirm that the action should be executed. |
| 1257 | * This is usually an imperative verb like "Send". |
| 1258 | * |
| 1259 | * @return the label to confirm the action should be executed |
| 1260 | */ |
| 1261 | public CharSequence getConfirmLabel() { |
| 1262 | return mConfirmLabel; |
| 1263 | } |
| 1264 | |
| 1265 | /** |
| 1266 | * Set a label to display to cancel the action. |
| 1267 | * This is usually an imperative verb, like "Cancel". |
| 1268 | * |
| 1269 | * @param label the label to display to cancel the action |
| 1270 | * @return this object for method chaining |
| 1271 | */ |
| 1272 | public WearableExtender setCancelLabel(CharSequence label) { |
| 1273 | mCancelLabel = label; |
| 1274 | return this; |
| 1275 | } |
| 1276 | |
| 1277 | /** |
| 1278 | * Get the label to display to cancel the action. |
| 1279 | * This is usually an imperative verb like "Cancel". |
| 1280 | * |
| 1281 | * @return the label to display to cancel the action |
| 1282 | */ |
| 1283 | public CharSequence getCancelLabel() { |
| 1284 | return mCancelLabel; |
| 1285 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 1286 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1287 | } |
| 1288 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1289 | /** |
| 1290 | * Array of all {@link Action} structures attached to this notification by |
| 1291 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1292 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1293 | * interface for invoking actions. |
| 1294 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1295 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1296 | |
| 1297 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1298 | * Replacement version of this notification whose content will be shown |
| 1299 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1300 | * and {@link #VISIBILITY_PUBLIC}. |
| 1301 | */ |
| 1302 | public Notification publicVersion; |
| 1303 | |
| 1304 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1305 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1306 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1307 | */ |
| 1308 | public Notification() |
| 1309 | { |
| 1310 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1311 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1312 | } |
| 1313 | |
| 1314 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1315 | * @hide |
| 1316 | */ |
| 1317 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1318 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1319 | { |
| 1320 | this.when = when; |
| 1321 | this.icon = icon; |
| 1322 | this.tickerText = tickerText; |
| 1323 | setLatestEventInfo(context, contentTitle, contentText, |
| 1324 | PendingIntent.getActivity(context, 0, contentIntent, 0)); |
| 1325 | } |
| 1326 | |
| 1327 | /** |
| 1328 | * Constructs a Notification object with the information needed to |
| 1329 | * have a status bar icon without the standard expanded view. |
| 1330 | * |
| 1331 | * @param icon The resource id of the icon to put in the status bar. |
| 1332 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1333 | * activates. |
| 1334 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1335 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1336 | * |
| 1337 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1339 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1340 | public Notification(int icon, CharSequence tickerText, long when) |
| 1341 | { |
| 1342 | this.icon = icon; |
| 1343 | this.tickerText = tickerText; |
| 1344 | this.when = when; |
| 1345 | } |
| 1346 | |
| 1347 | /** |
| 1348 | * Unflatten the notification from a parcel. |
| 1349 | */ |
| 1350 | public Notification(Parcel parcel) |
| 1351 | { |
| 1352 | int version = parcel.readInt(); |
| 1353 | |
| 1354 | when = parcel.readLong(); |
| 1355 | icon = parcel.readInt(); |
| 1356 | number = parcel.readInt(); |
| 1357 | if (parcel.readInt() != 0) { |
| 1358 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1359 | } |
| 1360 | if (parcel.readInt() != 0) { |
| 1361 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1362 | } |
| 1363 | if (parcel.readInt() != 0) { |
| 1364 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1365 | } |
| 1366 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1367 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1368 | } |
| 1369 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1370 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1371 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1372 | if (parcel.readInt() != 0) { |
| 1373 | largeIcon = Bitmap.CREATOR.createFromParcel(parcel); |
| 1374 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1375 | defaults = parcel.readInt(); |
| 1376 | flags = parcel.readInt(); |
| 1377 | if (parcel.readInt() != 0) { |
| 1378 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1379 | } |
| 1380 | |
| 1381 | audioStreamType = parcel.readInt(); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1382 | if (parcel.readInt() != 0) { |
| 1383 | audioAttributes = AudioAttributes.CREATOR.createFromParcel(parcel); |
| 1384 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1385 | vibrate = parcel.createLongArray(); |
| 1386 | ledARGB = parcel.readInt(); |
| 1387 | ledOnMS = parcel.readInt(); |
| 1388 | ledOffMS = parcel.readInt(); |
| 1389 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1390 | |
| 1391 | if (parcel.readInt() != 0) { |
| 1392 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1393 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1394 | |
| 1395 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1396 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1397 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1398 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1399 | mGroupKey = parcel.readString(); |
| 1400 | |
| 1401 | mSortKey = parcel.readString(); |
| 1402 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1403 | extras = parcel.readBundle(); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1404 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1405 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1406 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1407 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1408 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1409 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1410 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1411 | if (parcel.readInt() != 0) { |
| 1412 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1413 | } |
| 1414 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1415 | visibility = parcel.readInt(); |
| 1416 | |
| 1417 | if (parcel.readInt() != 0) { |
| 1418 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1419 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1420 | |
| 1421 | color = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1422 | } |
| 1423 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1424 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1425 | public Notification clone() { |
| 1426 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1427 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1428 | return that; |
| 1429 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1430 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1431 | /** |
| 1432 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1433 | * of this into that. |
| 1434 | * @hide |
| 1435 | */ |
| 1436 | public void cloneInto(Notification that, boolean heavy) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1437 | that.when = this.when; |
| 1438 | that.icon = this.icon; |
| 1439 | that.number = this.number; |
| 1440 | |
| 1441 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1442 | that.contentIntent = this.contentIntent; |
| 1443 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1444 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1445 | |
| 1446 | if (this.tickerText != null) { |
| 1447 | that.tickerText = this.tickerText.toString(); |
| 1448 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1449 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1450 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1451 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1452 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1453 | that.contentView = this.contentView.clone(); |
| 1454 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1455 | if (heavy && this.largeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1456 | that.largeIcon = Bitmap.createBitmap(this.largeIcon); |
| 1457 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1458 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1459 | that.sound = this.sound; // android.net.Uri is immutable |
| 1460 | that.audioStreamType = this.audioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1461 | if (this.audioAttributes != null) { |
| 1462 | that.audioAttributes = new AudioAttributes.Builder(this.audioAttributes).build(); |
| 1463 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1464 | |
| 1465 | final long[] vibrate = this.vibrate; |
| 1466 | if (vibrate != null) { |
| 1467 | final int N = vibrate.length; |
| 1468 | final long[] vib = that.vibrate = new long[N]; |
| 1469 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1470 | } |
| 1471 | |
| 1472 | that.ledARGB = this.ledARGB; |
| 1473 | that.ledOnMS = this.ledOnMS; |
| 1474 | that.ledOffMS = this.ledOffMS; |
| 1475 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1476 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1477 | that.flags = this.flags; |
| 1478 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1479 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1480 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1481 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1482 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1483 | that.mGroupKey = this.mGroupKey; |
| 1484 | |
| 1485 | that.mSortKey = this.mSortKey; |
| 1486 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1487 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1488 | try { |
| 1489 | that.extras = new Bundle(this.extras); |
| 1490 | // will unparcel |
| 1491 | that.extras.size(); |
| 1492 | } catch (BadParcelableException e) { |
| 1493 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 1494 | that.extras = null; |
| 1495 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1496 | } |
| 1497 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1498 | if (this.actions != null) { |
| 1499 | that.actions = new Action[this.actions.length]; |
| 1500 | for(int i=0; i<this.actions.length; i++) { |
| 1501 | that.actions[i] = this.actions[i].clone(); |
| 1502 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1503 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1504 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1505 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1506 | that.bigContentView = this.bigContentView.clone(); |
| 1507 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1508 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1509 | if (heavy && this.headsUpContentView != null) { |
| 1510 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 1511 | } |
| 1512 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1513 | that.visibility = this.visibility; |
| 1514 | |
| 1515 | if (this.publicVersion != null) { |
| 1516 | that.publicVersion = new Notification(); |
| 1517 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 1518 | } |
| 1519 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1520 | that.color = this.color; |
| 1521 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1522 | if (!heavy) { |
| 1523 | that.lightenPayload(); // will clean out extras |
| 1524 | } |
| 1525 | } |
| 1526 | |
| 1527 | /** |
| 1528 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 1529 | * listeners when the full contents are not necessary. |
| 1530 | * @hide |
| 1531 | */ |
| 1532 | public final void lightenPayload() { |
| 1533 | tickerView = null; |
| 1534 | contentView = null; |
| 1535 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1536 | headsUpContentView = null; |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1537 | largeIcon = null; |
| 1538 | if (extras != null) { |
| 1539 | extras.remove(Notification.EXTRA_LARGE_ICON); |
| 1540 | extras.remove(Notification.EXTRA_LARGE_ICON_BIG); |
| 1541 | extras.remove(Notification.EXTRA_PICTURE); |
Christoph Studer | 223f44e | 2014-09-02 14:59:32 +0200 | [diff] [blame] | 1542 | extras.remove(Notification.EXTRA_BIG_TEXT); |
Christoph Studer | b82bc78 | 2014-08-20 14:29:43 +0200 | [diff] [blame] | 1543 | // Prevent light notifications from being rebuilt. |
| 1544 | extras.remove(Builder.EXTRA_NEEDS_REBUILD); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1545 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1546 | } |
| 1547 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1548 | /** |
| 1549 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 1550 | * means it had better not be some custom Parcelable implementation. |
| 1551 | * @hide |
| 1552 | */ |
| 1553 | public static CharSequence safeCharSequence(CharSequence cs) { |
Christoph Studer | 535ec61 | 2014-09-03 15:47:47 +0200 | [diff] [blame] | 1554 | if (cs == null) return cs; |
| 1555 | if (cs.length() > MAX_CHARSEQUENCE_LENGTH) { |
| 1556 | cs = cs.subSequence(0, MAX_CHARSEQUENCE_LENGTH); |
| 1557 | } |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1558 | if (cs instanceof Parcelable) { |
| 1559 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 1560 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 1561 | return cs.toString(); |
| 1562 | } |
| 1563 | |
| 1564 | return cs; |
| 1565 | } |
| 1566 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1567 | public int describeContents() { |
| 1568 | return 0; |
| 1569 | } |
| 1570 | |
| 1571 | /** |
| 1572 | * Flatten this notification from a parcel. |
| 1573 | */ |
| 1574 | public void writeToParcel(Parcel parcel, int flags) |
| 1575 | { |
| 1576 | parcel.writeInt(1); |
| 1577 | |
| 1578 | parcel.writeLong(when); |
| 1579 | parcel.writeInt(icon); |
| 1580 | parcel.writeInt(number); |
| 1581 | if (contentIntent != null) { |
| 1582 | parcel.writeInt(1); |
| 1583 | contentIntent.writeToParcel(parcel, 0); |
| 1584 | } else { |
| 1585 | parcel.writeInt(0); |
| 1586 | } |
| 1587 | if (deleteIntent != null) { |
| 1588 | parcel.writeInt(1); |
| 1589 | deleteIntent.writeToParcel(parcel, 0); |
| 1590 | } else { |
| 1591 | parcel.writeInt(0); |
| 1592 | } |
| 1593 | if (tickerText != null) { |
| 1594 | parcel.writeInt(1); |
| 1595 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 1596 | } else { |
| 1597 | parcel.writeInt(0); |
| 1598 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1599 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1600 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1601 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1602 | } else { |
| 1603 | parcel.writeInt(0); |
| 1604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1605 | if (contentView != null) { |
| 1606 | parcel.writeInt(1); |
| 1607 | contentView.writeToParcel(parcel, 0); |
| 1608 | } else { |
| 1609 | parcel.writeInt(0); |
| 1610 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1611 | if (largeIcon != null) { |
| 1612 | parcel.writeInt(1); |
| 1613 | largeIcon.writeToParcel(parcel, 0); |
| 1614 | } else { |
| 1615 | parcel.writeInt(0); |
| 1616 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1617 | |
| 1618 | parcel.writeInt(defaults); |
| 1619 | parcel.writeInt(this.flags); |
| 1620 | |
| 1621 | if (sound != null) { |
| 1622 | parcel.writeInt(1); |
| 1623 | sound.writeToParcel(parcel, 0); |
| 1624 | } else { |
| 1625 | parcel.writeInt(0); |
| 1626 | } |
| 1627 | parcel.writeInt(audioStreamType); |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1628 | |
| 1629 | if (audioAttributes != null) { |
| 1630 | parcel.writeInt(1); |
| 1631 | audioAttributes.writeToParcel(parcel, 0); |
| 1632 | } else { |
| 1633 | parcel.writeInt(0); |
| 1634 | } |
| 1635 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1636 | parcel.writeLongArray(vibrate); |
| 1637 | parcel.writeInt(ledARGB); |
| 1638 | parcel.writeInt(ledOnMS); |
| 1639 | parcel.writeInt(ledOffMS); |
| 1640 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1641 | |
| 1642 | if (fullScreenIntent != null) { |
| 1643 | parcel.writeInt(1); |
| 1644 | fullScreenIntent.writeToParcel(parcel, 0); |
| 1645 | } else { |
| 1646 | parcel.writeInt(0); |
| 1647 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1648 | |
| 1649 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1650 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1651 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1652 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1653 | parcel.writeString(mGroupKey); |
| 1654 | |
| 1655 | parcel.writeString(mSortKey); |
| 1656 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1657 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1658 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1659 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1660 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1661 | if (bigContentView != null) { |
| 1662 | parcel.writeInt(1); |
| 1663 | bigContentView.writeToParcel(parcel, 0); |
| 1664 | } else { |
| 1665 | parcel.writeInt(0); |
| 1666 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1667 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1668 | if (headsUpContentView != null) { |
| 1669 | parcel.writeInt(1); |
| 1670 | headsUpContentView.writeToParcel(parcel, 0); |
| 1671 | } else { |
| 1672 | parcel.writeInt(0); |
| 1673 | } |
| 1674 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1675 | parcel.writeInt(visibility); |
| 1676 | |
| 1677 | if (publicVersion != null) { |
| 1678 | parcel.writeInt(1); |
| 1679 | publicVersion.writeToParcel(parcel, 0); |
| 1680 | } else { |
| 1681 | parcel.writeInt(0); |
| 1682 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1683 | |
| 1684 | parcel.writeInt(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1685 | } |
| 1686 | |
| 1687 | /** |
| 1688 | * Parcelable.Creator that instantiates Notification objects |
| 1689 | */ |
| 1690 | public static final Parcelable.Creator<Notification> CREATOR |
| 1691 | = new Parcelable.Creator<Notification>() |
| 1692 | { |
| 1693 | public Notification createFromParcel(Parcel parcel) |
| 1694 | { |
| 1695 | return new Notification(parcel); |
| 1696 | } |
| 1697 | |
| 1698 | public Notification[] newArray(int size) |
| 1699 | { |
| 1700 | return new Notification[size]; |
| 1701 | } |
| 1702 | }; |
| 1703 | |
| 1704 | /** |
| 1705 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 1706 | * layout. |
| 1707 | * |
| 1708 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 1709 | * in the view.</p> |
| 1710 | * @param context The context for your application / activity. |
| 1711 | * @param contentTitle The title that goes in the expanded entry. |
| 1712 | * @param contentText The text that goes in the expanded entry. |
| 1713 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 1714 | * If this is an activity, it must include the |
| 1715 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 1716 | * that you take care of task management as described in the |
| 1717 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 1718 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1719 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1720 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1721 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1722 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1723 | public void setLatestEventInfo(Context context, |
| 1724 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1725 | Notification.Builder builder = new Notification.Builder(context); |
| 1726 | |
| 1727 | // First, ensure that key pieces of information that may have been set directly |
| 1728 | // are preserved |
| 1729 | builder.setWhen(this.when); |
| 1730 | builder.setSmallIcon(this.icon); |
| 1731 | builder.setPriority(this.priority); |
| 1732 | builder.setTicker(this.tickerText); |
| 1733 | builder.setNumber(this.number); |
Selim Cinek | 255dd04 | 2014-08-19 22:29:02 +0200 | [diff] [blame] | 1734 | builder.setColor(this.color); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1735 | builder.mFlags = this.flags; |
| 1736 | builder.setSound(this.sound, this.audioStreamType); |
| 1737 | builder.setDefaults(this.defaults); |
| 1738 | builder.setVibrate(this.vibrate); |
| 1739 | |
| 1740 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1741 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1742 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1743 | } |
| 1744 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1745 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1746 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1747 | builder.setContentIntent(contentIntent); |
| 1748 | builder.buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1749 | } |
| 1750 | |
| 1751 | @Override |
| 1752 | public String toString() { |
| 1753 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1754 | sb.append("Notification(pri="); |
| 1755 | sb.append(priority); |
| 1756 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1757 | if (contentView != null) { |
| 1758 | sb.append(contentView.getPackage()); |
| 1759 | sb.append("/0x"); |
| 1760 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 1761 | } else { |
| 1762 | sb.append("null"); |
| 1763 | } |
| 1764 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1765 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 1766 | sb.append("default"); |
| 1767 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1768 | int N = this.vibrate.length-1; |
| 1769 | sb.append("["); |
| 1770 | for (int i=0; i<N; i++) { |
| 1771 | sb.append(this.vibrate[i]); |
| 1772 | sb.append(','); |
| 1773 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 1774 | if (N != -1) { |
| 1775 | sb.append(this.vibrate[N]); |
| 1776 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1777 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | } else { |
| 1779 | sb.append("null"); |
| 1780 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1781 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1782 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1783 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1784 | } else if (this.sound != null) { |
| 1785 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1786 | } else { |
| 1787 | sb.append("null"); |
| 1788 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1789 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1790 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1791 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1792 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1793 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1794 | if (this.category != null) { |
| 1795 | sb.append(" category="); |
| 1796 | sb.append(this.category); |
| 1797 | } |
| 1798 | if (this.mGroupKey != null) { |
| 1799 | sb.append(" groupKey="); |
| 1800 | sb.append(this.mGroupKey); |
| 1801 | } |
| 1802 | if (this.mSortKey != null) { |
| 1803 | sb.append(" sortKey="); |
| 1804 | sb.append(this.mSortKey); |
| 1805 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1806 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1807 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1808 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1809 | } |
| 1810 | sb.append(" vis="); |
| 1811 | sb.append(visibilityToString(this.visibility)); |
| 1812 | if (this.publicVersion != null) { |
| 1813 | sb.append(" publicVersion="); |
| 1814 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1815 | } |
| 1816 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1817 | return sb.toString(); |
| 1818 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1819 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1820 | /** |
| 1821 | * {@hide} |
| 1822 | */ |
| 1823 | public static String visibilityToString(int vis) { |
| 1824 | switch (vis) { |
| 1825 | case VISIBILITY_PRIVATE: |
| 1826 | return "PRIVATE"; |
| 1827 | case VISIBILITY_PUBLIC: |
| 1828 | return "PUBLIC"; |
| 1829 | case VISIBILITY_SECRET: |
| 1830 | return "SECRET"; |
| 1831 | default: |
| 1832 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 1833 | } |
| 1834 | } |
| 1835 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1836 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1837 | * @hide |
| 1838 | */ |
| 1839 | public boolean isValid() { |
| 1840 | // Would like to check for icon!=0 here, too, but NotificationManagerService accepts that |
| 1841 | // for legacy reasons. |
| 1842 | return contentView != null || extras.getBoolean(Builder.EXTRA_REBUILD_CONTENT_VIEW); |
| 1843 | } |
| 1844 | |
| 1845 | /** |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1846 | * @hide |
| 1847 | */ |
| 1848 | public boolean isGroupSummary() { |
| 1849 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 1850 | } |
| 1851 | |
| 1852 | /** |
| 1853 | * @hide |
| 1854 | */ |
| 1855 | public boolean isGroupChild() { |
| 1856 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 1857 | } |
| 1858 | |
| 1859 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1860 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1861 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1862 | * 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] | 1863 | * content views using the platform's notification layout template. If your app supports |
| 1864 | * versions of Android as old as API level 4, you can instead use |
| 1865 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 1866 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 1867 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1868 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1869 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1870 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1871 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1872 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1873 | * .setContentTitle("New mail from " + sender.toString()) |
| 1874 | * .setContentText(subject) |
| 1875 | * .setSmallIcon(R.drawable.new_mail) |
| 1876 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1877 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1878 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1879 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1880 | public static class Builder { |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 1881 | private static final int MAX_ACTION_BUTTONS = 3; |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 1882 | private static final float LARGE_TEXT_SCALE = 1.3f; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1883 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1884 | /** |
| 1885 | * @hide |
| 1886 | */ |
| 1887 | public static final String EXTRA_NEEDS_REBUILD = "android.rebuild"; |
| 1888 | |
| 1889 | /** |
| 1890 | * @hide |
| 1891 | */ |
| 1892 | public static final String EXTRA_REBUILD_LARGE_ICON = "android.rebuild.largeIcon"; |
| 1893 | /** |
| 1894 | * @hide |
| 1895 | */ |
| 1896 | public static final String EXTRA_REBUILD_CONTENT_VIEW = "android.rebuild.contentView"; |
| 1897 | /** |
| 1898 | * @hide |
| 1899 | */ |
| 1900 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 1901 | "android.rebuild.contentViewActionCount"; |
| 1902 | /** |
| 1903 | * @hide |
| 1904 | */ |
| 1905 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW |
| 1906 | = "android.rebuild.bigView"; |
| 1907 | /** |
| 1908 | * @hide |
| 1909 | */ |
| 1910 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 1911 | = "android.rebuild.bigViewActionCount"; |
| 1912 | /** |
| 1913 | * @hide |
| 1914 | */ |
| 1915 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW |
| 1916 | = "android.rebuild.hudView"; |
| 1917 | /** |
| 1918 | * @hide |
| 1919 | */ |
| 1920 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 1921 | = "android.rebuild.hudViewActionCount"; |
| 1922 | |
| 1923 | /** |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 1924 | * The ApplicationInfo of the package that created the notification, used to create |
| 1925 | * a context to rebuild the notification via a Builder. |
| 1926 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1927 | */ |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 1928 | private static final String EXTRA_REBUILD_CONTEXT_APPLICATION_INFO = |
| 1929 | "android.rebuild.applicationInfo"; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1930 | |
| 1931 | // Whether to enable stripping (at post time) & rebuilding (at listener receive time) of |
| 1932 | // memory intensive resources. |
| 1933 | private static final boolean STRIP_AND_REBUILD = true; |
| 1934 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1935 | private Context mContext; |
| 1936 | |
| 1937 | private long mWhen; |
| 1938 | private int mSmallIcon; |
| 1939 | private int mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1940 | private int mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1941 | private CharSequence mContentTitle; |
| 1942 | private CharSequence mContentText; |
| 1943 | private CharSequence mContentInfo; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1944 | private CharSequence mSubText; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1945 | private PendingIntent mContentIntent; |
| 1946 | private RemoteViews mContentView; |
| 1947 | private PendingIntent mDeleteIntent; |
| 1948 | private PendingIntent mFullScreenIntent; |
| 1949 | private CharSequence mTickerText; |
| 1950 | private RemoteViews mTickerView; |
| 1951 | private Bitmap mLargeIcon; |
| 1952 | private Uri mSound; |
| 1953 | private int mAudioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1954 | private AudioAttributes mAudioAttributes; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1955 | private long[] mVibrate; |
| 1956 | private int mLedArgb; |
| 1957 | private int mLedOnMs; |
| 1958 | private int mLedOffMs; |
| 1959 | private int mDefaults; |
| 1960 | private int mFlags; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1961 | private int mProgressMax; |
| 1962 | private int mProgress; |
| 1963 | private boolean mProgressIndeterminate; |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1964 | private String mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1965 | private String mGroupKey; |
| 1966 | private String mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1967 | private Bundle mExtras; |
| 1968 | private int mPriority; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1969 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1970 | private boolean mUseChronometer; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1971 | private Style mStyle; |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1972 | private boolean mShowWhen = true; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1973 | private int mVisibility = VISIBILITY_PRIVATE; |
| 1974 | private Notification mPublicVersion = null; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1975 | private final NotificationColorUtil mColorUtil; |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 1976 | private ArrayList<String> mPeople; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1977 | private int mColor = COLOR_DEFAULT; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 1978 | |
| 1979 | /** |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 1980 | * The user that built the notification originally. |
| 1981 | */ |
| 1982 | private int mOriginatingUserId; |
| 1983 | |
| 1984 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1985 | * Contains extras related to rebuilding during the build phase. |
| 1986 | */ |
| 1987 | private Bundle mRebuildBundle = new Bundle(); |
| 1988 | /** |
| 1989 | * Contains the notification to rebuild when this Builder is in "rebuild" mode. |
| 1990 | * Null otherwise. |
| 1991 | */ |
| 1992 | private Notification mRebuildNotification = null; |
| 1993 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1994 | /** |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 1995 | * Whether the build notification has three lines. This is used to make the top padding for |
| 1996 | * both the contracted and expanded layout consistent. |
| 1997 | * |
| 1998 | * <p> |
| 1999 | * This field is only valid during the build phase. |
| 2000 | */ |
| 2001 | private boolean mHasThreeLines; |
| 2002 | |
| 2003 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2004 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2005 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2006 | |
| 2007 | * <table> |
| 2008 | * <tr><th align=right>priority</th> |
| 2009 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 2010 | * <tr><th align=right>when</th> |
| 2011 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 2012 | * <tr><th align=right>audio stream</th> |
| 2013 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 2014 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2015 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2016 | |
| 2017 | * @param context |
| 2018 | * A {@link Context} that will be used by the Builder to construct the |
| 2019 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2020 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2021 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2022 | public Builder(Context context) { |
Adam Powell | bf06fa0 | 2014-05-30 12:32:18 -0700 | [diff] [blame] | 2023 | /* |
| 2024 | * Important compatibility note! |
| 2025 | * Some apps out in the wild create a Notification.Builder in their Activity subclass |
| 2026 | * constructor for later use. At this point Activities - themselves subclasses of |
| 2027 | * ContextWrapper - do not have their inner Context populated yet. This means that |
| 2028 | * any calls to Context methods from within this constructor can cause NPEs in existing |
| 2029 | * apps. Any data populated from mContext should therefore be populated lazily to |
| 2030 | * preserve compatibility. |
| 2031 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2032 | mContext = context; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2033 | |
| 2034 | // Set defaults to match the defaults of a Notification |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2035 | mWhen = System.currentTimeMillis(); |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2036 | mAudioStreamType = STREAM_DEFAULT; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2037 | mAudioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2038 | mPriority = PRIORITY_DEFAULT; |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2039 | mPeople = new ArrayList<String>(); |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2040 | |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 2041 | mColorUtil = context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.LOLLIPOP ? |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 2042 | NotificationColorUtil.getInstance(mContext) : null; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2043 | } |
| 2044 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2045 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2046 | * Creates a Builder for rebuilding the given Notification. |
| 2047 | * <p> |
| 2048 | * Call {@link #rebuild()} to retrieve the rebuilt version of 'n'. |
| 2049 | */ |
| 2050 | private Builder(Context context, Notification n) { |
| 2051 | this(context); |
| 2052 | mRebuildNotification = n; |
| 2053 | restoreFromNotification(n); |
| 2054 | |
| 2055 | Style style = null; |
| 2056 | Bundle extras = n.extras; |
| 2057 | String templateClass = extras.getString(EXTRA_TEMPLATE); |
| 2058 | if (!TextUtils.isEmpty(templateClass)) { |
| 2059 | Class<? extends Style> styleClass = getNotificationStyleClass(templateClass); |
| 2060 | if (styleClass == null) { |
| 2061 | Log.d(TAG, "Unknown style class: " + styleClass); |
| 2062 | return; |
| 2063 | } |
| 2064 | |
| 2065 | try { |
| 2066 | Constructor<? extends Style> constructor = styleClass.getConstructor(); |
| 2067 | style = constructor.newInstance(); |
| 2068 | style.restoreFromExtras(extras); |
| 2069 | } catch (Throwable t) { |
| 2070 | Log.e(TAG, "Could not create Style", t); |
| 2071 | return; |
| 2072 | } |
| 2073 | } |
| 2074 | if (style != null) { |
| 2075 | setStyle(style); |
| 2076 | } |
| 2077 | } |
| 2078 | |
| 2079 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2080 | * Add a timestamp pertaining to the notification (usually the time the event occurred). |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2081 | * It will be shown in the notification content view by default; use |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2082 | * {@link #setShowWhen(boolean) setShowWhen} to control this. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2083 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2084 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2085 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2086 | public Builder setWhen(long when) { |
| 2087 | mWhen = when; |
| 2088 | return this; |
| 2089 | } |
| 2090 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2091 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2092 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2093 | * in the content view. |
| 2094 | */ |
| 2095 | public Builder setShowWhen(boolean show) { |
| 2096 | mShowWhen = show; |
| 2097 | return this; |
| 2098 | } |
| 2099 | |
| 2100 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2101 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2102 | * |
| 2103 | * 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] | 2104 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2105 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2106 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2107 | * |
| 2108 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2109 | * @see Notification#when |
| 2110 | */ |
| 2111 | public Builder setUsesChronometer(boolean b) { |
| 2112 | mUseChronometer = b; |
| 2113 | return this; |
| 2114 | } |
| 2115 | |
| 2116 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2117 | * Set the small icon resource, which will be used to represent the notification in the |
| 2118 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2119 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2120 | |
| 2121 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 2122 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 2123 | * icon will be moved to the right-hand side. |
| 2124 | * |
| 2125 | |
| 2126 | * @param icon |
| 2127 | * A resource ID in the application's package of the drawable to use. |
| 2128 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2129 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2130 | public Builder setSmallIcon(int icon) { |
| 2131 | mSmallIcon = icon; |
| 2132 | return this; |
| 2133 | } |
| 2134 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2135 | /** |
| 2136 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 2137 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 2138 | * LevelListDrawable}. |
| 2139 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2140 | * @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] | 2141 | * @param level The level to use for the icon. |
| 2142 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2143 | * @see Notification#icon |
| 2144 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2145 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2146 | public Builder setSmallIcon(int icon, int level) { |
| 2147 | mSmallIcon = icon; |
| 2148 | mSmallIconLevel = level; |
| 2149 | return this; |
| 2150 | } |
| 2151 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2152 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2153 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2154 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2155 | public Builder setContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2156 | mContentTitle = safeCharSequence(title); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2157 | return this; |
| 2158 | } |
| 2159 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2160 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2161 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2162 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2163 | public Builder setContentText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2164 | mContentText = safeCharSequence(text); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2165 | return this; |
| 2166 | } |
| 2167 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2168 | /** |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2169 | * Set the third line of text in the platform notification template. |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2170 | * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the |
| 2171 | * same location in the standard template. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2172 | */ |
| 2173 | public Builder setSubText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2174 | mSubText = safeCharSequence(text); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2175 | return this; |
| 2176 | } |
| 2177 | |
| 2178 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2179 | * Set the large number at the right-hand side of the notification. This is |
| 2180 | * equivalent to setContentInfo, although it might show the number in a different |
| 2181 | * font size for readability. |
| 2182 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2183 | public Builder setNumber(int number) { |
| 2184 | mNumber = number; |
| 2185 | return this; |
| 2186 | } |
| 2187 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2188 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2189 | * A small piece of additional information pertaining to this notification. |
| 2190 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2191 | * The platform template will draw this on the last line of the notification, at the far |
| 2192 | * right (to the right of a smallIcon if it has been placed there). |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2193 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2194 | public Builder setContentInfo(CharSequence info) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2195 | mContentInfo = safeCharSequence(info); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2196 | return this; |
| 2197 | } |
| 2198 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2199 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2200 | * Set the progress this notification represents. |
| 2201 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2202 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2203 | */ |
| 2204 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 2205 | mProgressMax = max; |
| 2206 | mProgress = progress; |
| 2207 | mProgressIndeterminate = indeterminate; |
| 2208 | return this; |
| 2209 | } |
| 2210 | |
| 2211 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2212 | * Supply a custom RemoteViews to use instead of the platform template. |
| 2213 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2214 | * @see Notification#contentView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2215 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2216 | public Builder setContent(RemoteViews views) { |
| 2217 | mContentView = views; |
| 2218 | return this; |
| 2219 | } |
| 2220 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2221 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2222 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 2223 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2224 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 2225 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 2226 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2227 | * 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] | 2228 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2229 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2230 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2231 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2232 | public Builder setContentIntent(PendingIntent intent) { |
| 2233 | mContentIntent = intent; |
| 2234 | return this; |
| 2235 | } |
| 2236 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2237 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2238 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 2239 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2240 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2241 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2242 | public Builder setDeleteIntent(PendingIntent intent) { |
| 2243 | mDeleteIntent = intent; |
| 2244 | return this; |
| 2245 | } |
| 2246 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2247 | /** |
| 2248 | * An intent to launch instead of posting the notification to the status bar. |
| 2249 | * Only for use with extremely high-priority notifications demanding the user's |
| 2250 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 2251 | * alarm clock that the user has explicitly set to a particular time. |
| 2252 | * If this facility is used for something else, please give the user an option |
| 2253 | * to turn it off and use a normal notification, as this can be extremely |
| 2254 | * disruptive. |
| 2255 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2256 | * <p> |
| 2257 | * The system UI may choose to display a heads-up notification, instead of |
| 2258 | * launching this intent, while the user is using the device. |
| 2259 | * </p> |
| 2260 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2261 | * @param intent The pending intent to launch. |
| 2262 | * @param highPriority Passing true will cause this notification to be sent |
| 2263 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2264 | * |
| 2265 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2266 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2267 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 2268 | mFullScreenIntent = intent; |
| 2269 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 2270 | return this; |
| 2271 | } |
| 2272 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2273 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2274 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2275 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2276 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2277 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2278 | public Builder setTicker(CharSequence tickerText) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2279 | mTickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2280 | return this; |
| 2281 | } |
| 2282 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2283 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2284 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2285 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2286 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2287 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2288 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2289 | mTickerText = safeCharSequence(tickerText); |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2290 | mTickerView = views; // we'll save it for you anyway |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2291 | return this; |
| 2292 | } |
| 2293 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2294 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2295 | * Add a large icon to the notification (and the ticker on some devices). |
| 2296 | * |
| 2297 | * In the platform template, this image will be shown on the left of the notification view |
| 2298 | * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side). |
| 2299 | * |
| 2300 | * @see Notification#largeIcon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2301 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2302 | public Builder setLargeIcon(Bitmap icon) { |
| 2303 | mLargeIcon = icon; |
| 2304 | return this; |
| 2305 | } |
| 2306 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2307 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2308 | * Set the sound to play. |
| 2309 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2310 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 2311 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2312 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2313 | * <p> |
| 2314 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2315 | * </p> |
| 2316 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2317 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2318 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2319 | public Builder setSound(Uri sound) { |
| 2320 | mSound = sound; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2321 | mAudioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2322 | return this; |
| 2323 | } |
| 2324 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2325 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2326 | * 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] | 2327 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2328 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 2329 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2330 | * <p> |
| 2331 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2332 | * </p> |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2333 | * @deprecated use {@link #setSound(Uri, AudioAttributes)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2334 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2335 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 2336 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2337 | public Builder setSound(Uri sound, int streamType) { |
| 2338 | mSound = sound; |
| 2339 | mAudioStreamType = streamType; |
| 2340 | return this; |
| 2341 | } |
| 2342 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2343 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2344 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 2345 | * use during playback. |
| 2346 | * |
| 2347 | * <p> |
| 2348 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2349 | * </p> |
| 2350 | * |
| 2351 | * @see Notification#sound |
| 2352 | */ |
| 2353 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
| 2354 | mSound = sound; |
| 2355 | mAudioAttributes = audioAttributes; |
| 2356 | return this; |
| 2357 | } |
| 2358 | |
| 2359 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2360 | * Set the vibration pattern to use. |
| 2361 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2362 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 2363 | * <code>pattern</code> parameter. |
| 2364 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2365 | * <p> |
| 2366 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 2367 | * </p> |
| 2368 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2369 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2370 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2371 | public Builder setVibrate(long[] pattern) { |
| 2372 | mVibrate = pattern; |
| 2373 | return this; |
| 2374 | } |
| 2375 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2376 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2377 | * Set the desired color for the indicator LED on the device, as well as the |
| 2378 | * blink duty cycle (specified in milliseconds). |
| 2379 | * |
| 2380 | |
| 2381 | * Not all devices will honor all (or even any) of these values. |
| 2382 | * |
| 2383 | |
| 2384 | * @see Notification#ledARGB |
| 2385 | * @see Notification#ledOnMS |
| 2386 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2387 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2388 | public Builder setLights(int argb, int onMs, int offMs) { |
| 2389 | mLedArgb = argb; |
| 2390 | mLedOnMs = onMs; |
| 2391 | mLedOffMs = offMs; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2392 | return this; |
| 2393 | } |
| 2394 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2395 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2396 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2397 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2398 | |
| 2399 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 2400 | * must take care of canceling them. |
| 2401 | * |
| 2402 | |
| 2403 | * They are typically used to indicate a background task that the user is actively engaged |
| 2404 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 2405 | * (e.g., a file download, sync operation, active network connection). |
| 2406 | * |
| 2407 | |
| 2408 | * @see Notification#FLAG_ONGOING_EVENT |
| 2409 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2410 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2411 | public Builder setOngoing(boolean ongoing) { |
| 2412 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 2413 | return this; |
| 2414 | } |
| 2415 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2416 | /** |
| 2417 | * Set this flag if you would only like the sound, vibrate |
| 2418 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2419 | * |
| 2420 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2421 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2422 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 2423 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 2424 | return this; |
| 2425 | } |
| 2426 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2427 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2428 | * Make this notification automatically dismissed when the user touches it. The |
| 2429 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 2430 | * |
| 2431 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2432 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2433 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 2434 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2435 | return this; |
| 2436 | } |
| 2437 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2438 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2439 | * Set whether or not this notification should not bridge to other devices. |
| 2440 | * |
| 2441 | * <p>Some notifications can be bridged to other devices for remote display. |
| 2442 | * This hint can be set to recommend this notification not be bridged. |
| 2443 | */ |
| 2444 | public Builder setLocalOnly(boolean localOnly) { |
| 2445 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 2446 | return this; |
| 2447 | } |
| 2448 | |
| 2449 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2450 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2451 | * <p> |
| 2452 | * The value should be one or more of the following fields combined with |
| 2453 | * bitwise-or: |
| 2454 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 2455 | * <p> |
| 2456 | * For all default values, use {@link #DEFAULT_ALL}. |
| 2457 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2458 | public Builder setDefaults(int defaults) { |
| 2459 | mDefaults = defaults; |
| 2460 | return this; |
| 2461 | } |
| 2462 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2463 | /** |
| 2464 | * Set the priority of this notification. |
| 2465 | * |
| 2466 | * @see Notification#priority |
| 2467 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2468 | public Builder setPriority(@Priority int pri) { |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2469 | mPriority = pri; |
| 2470 | return this; |
| 2471 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2472 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2473 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2474 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2475 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2476 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2477 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2478 | public Builder setCategory(String category) { |
| 2479 | mCategory = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2480 | return this; |
| 2481 | } |
| 2482 | |
| 2483 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2484 | * Add a person that is relevant to this notification. |
| 2485 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2486 | * <P> |
| 2487 | * Depending on user preferences, this annotation may allow the notification to pass |
| 2488 | * through interruption filters, and to appear more prominently in the user interface. |
| 2489 | * </P> |
| 2490 | * |
| 2491 | * <P> |
| 2492 | * The person should be specified by the {@code String} representation of a |
| 2493 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 2494 | * </P> |
| 2495 | * |
| 2496 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 2497 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 2498 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 2499 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 2500 | * </P> |
| 2501 | * |
| 2502 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2503 | * @see Notification#EXTRA_PEOPLE |
| 2504 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2505 | public Builder addPerson(String uri) { |
| 2506 | mPeople.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2507 | return this; |
| 2508 | } |
| 2509 | |
| 2510 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2511 | * Set this notification to be part of a group of notifications sharing the same key. |
| 2512 | * Grouped notifications may display in a cluster or stack on devices which |
| 2513 | * support such rendering. |
| 2514 | * |
| 2515 | * <p>To make this notification the summary for its group, also call |
| 2516 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 2517 | * {@link #setSortKey}. |
| 2518 | * @param groupKey The group key of the group. |
| 2519 | * @return this object for method chaining |
| 2520 | */ |
| 2521 | public Builder setGroup(String groupKey) { |
| 2522 | mGroupKey = groupKey; |
| 2523 | return this; |
| 2524 | } |
| 2525 | |
| 2526 | /** |
| 2527 | * Set this notification to be the group summary for a group of notifications. |
| 2528 | * Grouped notifications may display in a cluster or stack on devices which |
| 2529 | * support such rendering. Requires a group key also be set using {@link #setGroup}. |
| 2530 | * @param isGroupSummary Whether this notification should be a group summary. |
| 2531 | * @return this object for method chaining |
| 2532 | */ |
| 2533 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 2534 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 2535 | return this; |
| 2536 | } |
| 2537 | |
| 2538 | /** |
| 2539 | * Set a sort key that orders this notification among other notifications from the |
| 2540 | * same package. This can be useful if an external sort was already applied and an app |
| 2541 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 2542 | * value, although providing different priorities in addition to providing sort key may |
| 2543 | * cause this value to be ignored. |
| 2544 | * |
| 2545 | * <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] | 2546 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2547 | * |
| 2548 | * @see String#compareTo(String) |
| 2549 | */ |
| 2550 | public Builder setSortKey(String sortKey) { |
| 2551 | mSortKey = sortKey; |
| 2552 | return this; |
| 2553 | } |
| 2554 | |
| 2555 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2556 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2557 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2558 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 2559 | * |
| 2560 | * @see Notification#extras |
| 2561 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2562 | public Builder addExtras(Bundle extras) { |
| 2563 | if (extras != null) { |
| 2564 | if (mExtras == null) { |
| 2565 | mExtras = new Bundle(extras); |
| 2566 | } else { |
| 2567 | mExtras.putAll(extras); |
| 2568 | } |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2569 | } |
| 2570 | return this; |
| 2571 | } |
| 2572 | |
| 2573 | /** |
| 2574 | * Set metadata for this notification. |
| 2575 | * |
| 2576 | * <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] | 2577 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2578 | * called. |
| 2579 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2580 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 2581 | * Use {@link #addExtras} to merge in metadata instead. |
| 2582 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2583 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2584 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2585 | public Builder setExtras(Bundle extras) { |
| 2586 | mExtras = extras; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2587 | return this; |
| 2588 | } |
| 2589 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2590 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2591 | * Get the current metadata Bundle used by this notification Builder. |
| 2592 | * |
| 2593 | * <p>The returned Bundle is shared with this Builder. |
| 2594 | * |
| 2595 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 2596 | * {@link #build()} is called. |
| 2597 | * |
| 2598 | * @see Notification#extras |
| 2599 | */ |
| 2600 | public Bundle getExtras() { |
| 2601 | if (mExtras == null) { |
| 2602 | mExtras = new Bundle(); |
| 2603 | } |
| 2604 | return mExtras; |
| 2605 | } |
| 2606 | |
| 2607 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2608 | * Add an action to this notification. Actions are typically displayed by |
| 2609 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2610 | * <p> |
| 2611 | * Every action must have an icon (32dp square and matching the |
| 2612 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2613 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2614 | * <p> |
| 2615 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2616 | * the order they were added. Actions will not be displayed when the notification is |
| 2617 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2618 | * 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] | 2619 | * |
| 2620 | * @param icon Resource ID of a drawable that represents the action. |
| 2621 | * @param title Text describing the action. |
| 2622 | * @param intent PendingIntent to be fired when the action is invoked. |
| 2623 | */ |
| 2624 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2625 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2626 | return this; |
| 2627 | } |
| 2628 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2629 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2630 | * Add an action to this notification. Actions are typically displayed by |
| 2631 | * the system as a button adjacent to the notification content. |
| 2632 | * <p> |
| 2633 | * Every action must have an icon (32dp square and matching the |
| 2634 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2635 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2636 | * <p> |
| 2637 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2638 | * the order they were added. Actions will not be displayed when the notification is |
| 2639 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2640 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 2641 | * |
| 2642 | * @param action The action to add. |
| 2643 | */ |
| 2644 | public Builder addAction(Action action) { |
| 2645 | mActions.add(action); |
| 2646 | return this; |
| 2647 | } |
| 2648 | |
| 2649 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2650 | * Add a rich notification style to be applied at build time. |
| 2651 | * |
| 2652 | * @param style Object responsible for modifying the notification style. |
| 2653 | */ |
| 2654 | public Builder setStyle(Style style) { |
| 2655 | if (mStyle != style) { |
| 2656 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2657 | if (mStyle != null) { |
| 2658 | mStyle.setBuilder(this); |
| 2659 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2660 | } |
| 2661 | return this; |
| 2662 | } |
| 2663 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2664 | /** |
| 2665 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2666 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2667 | * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), |
| 2668 | * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. |
| 2669 | * |
| 2670 | * @return The same Builder. |
| 2671 | */ |
| 2672 | public Builder setVisibility(int visibility) { |
| 2673 | mVisibility = visibility; |
| 2674 | return this; |
| 2675 | } |
| 2676 | |
| 2677 | /** |
| 2678 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 2679 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 2680 | * @param n A replacement notification, presumably with some or all info redacted. |
| 2681 | * @return The same Builder. |
| 2682 | */ |
| 2683 | public Builder setPublicVersion(Notification n) { |
| 2684 | mPublicVersion = n; |
| 2685 | return this; |
| 2686 | } |
| 2687 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2688 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2689 | * Apply an extender to this notification builder. Extenders may be used to add |
| 2690 | * metadata or change options on this builder. |
| 2691 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2692 | public Builder extend(Extender extender) { |
| 2693 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2694 | return this; |
| 2695 | } |
| 2696 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2697 | private void setFlag(int mask, boolean value) { |
| 2698 | if (value) { |
| 2699 | mFlags |= mask; |
| 2700 | } else { |
| 2701 | mFlags &= ~mask; |
| 2702 | } |
| 2703 | } |
| 2704 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2705 | /** |
| 2706 | * Sets {@link Notification#color}. |
| 2707 | * |
| 2708 | * @param argb The accent color to use |
| 2709 | * |
| 2710 | * @return The same Builder. |
| 2711 | */ |
| 2712 | public Builder setColor(int argb) { |
| 2713 | mColor = argb; |
| 2714 | return this; |
| 2715 | } |
| 2716 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2717 | private Drawable getProfileBadgeDrawable() { |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2718 | // Note: This assumes that the current user can read the profile badge of the |
| 2719 | // originating user. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2720 | return mContext.getPackageManager().getUserBadgeForDensity( |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 2721 | new UserHandle(mOriginatingUserId), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2722 | } |
| 2723 | |
| 2724 | private Bitmap getProfileBadge() { |
| 2725 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2726 | if (badge == null) { |
| 2727 | return null; |
| 2728 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2729 | final int size = mContext.getResources().getDimensionPixelSize( |
| 2730 | R.dimen.notification_badge_size); |
| 2731 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2732 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2733 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2734 | badge.draw(canvas); |
| 2735 | return bitmap; |
| 2736 | } |
| 2737 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2738 | private boolean addProfileBadge(RemoteViews contentView, int resId) { |
| 2739 | Bitmap profileBadge = getProfileBadge(); |
| 2740 | |
| 2741 | contentView.setViewVisibility(R.id.profile_badge_large_template, View.GONE); |
| 2742 | contentView.setViewVisibility(R.id.profile_badge_line2, View.GONE); |
| 2743 | contentView.setViewVisibility(R.id.profile_badge_line3, View.GONE); |
| 2744 | |
| 2745 | if (profileBadge != null) { |
| 2746 | contentView.setImageViewBitmap(resId, profileBadge); |
| 2747 | contentView.setViewVisibility(resId, View.VISIBLE); |
| 2748 | |
| 2749 | // Make sure Line 3 is visible. As badge will be here if there |
| 2750 | // is no text to display. |
| 2751 | if (resId == R.id.profile_badge_line3) { |
| 2752 | contentView.setViewVisibility(R.id.line3, View.VISIBLE); |
| 2753 | } |
| 2754 | return true; |
| 2755 | } |
| 2756 | return false; |
| 2757 | } |
| 2758 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2759 | private void shrinkLine3Text(RemoteViews contentView) { |
| 2760 | float subTextSize = mContext.getResources().getDimensionPixelSize( |
| 2761 | R.dimen.notification_subtext_size); |
| 2762 | contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); |
| 2763 | } |
| 2764 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2765 | private void unshrinkLine3Text(RemoteViews contentView) { |
| 2766 | float regularTextSize = mContext.getResources().getDimensionPixelSize( |
| 2767 | com.android.internal.R.dimen.notification_text_size); |
| 2768 | contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, regularTextSize); |
| 2769 | } |
| 2770 | |
| 2771 | private void resetStandardTemplate(RemoteViews contentView) { |
| 2772 | removeLargeIconBackground(contentView); |
| 2773 | contentView.setViewPadding(R.id.icon, 0, 0, 0, 0); |
| 2774 | contentView.setImageViewResource(R.id.icon, 0); |
| 2775 | contentView.setInt(R.id.icon, "setBackgroundResource", 0); |
| 2776 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
| 2777 | contentView.setInt(R.id.right_icon, "setBackgroundResource", 0); |
| 2778 | contentView.setImageViewResource(R.id.right_icon, 0); |
| 2779 | contentView.setImageViewResource(R.id.icon, 0); |
| 2780 | contentView.setTextViewText(R.id.title, null); |
| 2781 | contentView.setTextViewText(R.id.text, null); |
| 2782 | unshrinkLine3Text(contentView); |
| 2783 | contentView.setTextViewText(R.id.text2, null); |
| 2784 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2785 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 2786 | contentView.setViewVisibility(R.id.time, View.GONE); |
| 2787 | contentView.setViewVisibility(R.id.line3, View.GONE); |
| 2788 | contentView.setViewVisibility(R.id.overflow_divider, View.GONE); |
| 2789 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 2790 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
| 2791 | contentView.setViewVisibility(R.id.time, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2792 | } |
| 2793 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2794 | private RemoteViews applyStandardTemplate(int resId) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2795 | return applyStandardTemplate(resId, true /* hasProgress */); |
| 2796 | } |
| 2797 | |
| 2798 | /** |
| 2799 | * @param hasProgress whether the progress bar should be shown and set |
| 2800 | */ |
| 2801 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 2802 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 2803 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2804 | resetStandardTemplate(contentView); |
| 2805 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2806 | boolean showLine3 = false; |
| 2807 | boolean showLine2 = false; |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2808 | boolean contentTextInLine2 = false; |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2809 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2810 | if (mLargeIcon != null) { |
| 2811 | contentView.setImageViewBitmap(R.id.icon, mLargeIcon); |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 2812 | processLargeLegacyIcon(mLargeIcon, contentView); |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2813 | contentView.setImageViewResource(R.id.right_icon, mSmallIcon); |
| 2814 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 2815 | processSmallRightIcon(mSmallIcon, contentView); |
| 2816 | } else { // small icon at left |
| 2817 | contentView.setImageViewResource(R.id.icon, mSmallIcon); |
| 2818 | contentView.setViewVisibility(R.id.icon, View.VISIBLE); |
| 2819 | processSmallIconAsLarge(mSmallIcon, contentView); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2820 | } |
| 2821 | if (mContentTitle != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2822 | contentView.setTextViewText(R.id.title, processLegacyText(mContentTitle)); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2823 | } |
| 2824 | if (mContentText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2825 | contentView.setTextViewText(R.id.text, processLegacyText(mContentText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2826 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2827 | } |
| 2828 | if (mContentInfo != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2829 | contentView.setTextViewText(R.id.info, processLegacyText(mContentInfo)); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2830 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2831 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2832 | } else if (mNumber > 0) { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 2833 | final int tooBig = mContext.getResources().getInteger( |
| 2834 | R.integer.status_bar_notification_info_maxnum); |
| 2835 | if (mNumber > tooBig) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2836 | contentView.setTextViewText(R.id.info, processLegacyText( |
| 2837 | mContext.getResources().getString( |
| 2838 | R.string.status_bar_notification_info_overflow))); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 2839 | } else { |
| 2840 | NumberFormat f = NumberFormat.getIntegerInstance(); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2841 | contentView.setTextViewText(R.id.info, processLegacyText(f.format(mNumber))); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 2842 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2843 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2844 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2845 | } else { |
| 2846 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 2847 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2848 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2849 | // Need to show three lines? |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2850 | if (mSubText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2851 | contentView.setTextViewText(R.id.text, processLegacyText(mSubText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2852 | if (mContentText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2853 | contentView.setTextViewText(R.id.text2, processLegacyText(mContentText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2854 | contentView.setViewVisibility(R.id.text2, View.VISIBLE); |
| 2855 | showLine2 = true; |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2856 | contentTextInLine2 = true; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2857 | } else { |
| 2858 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2859 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2860 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2861 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2862 | if (hasProgress && (mProgressMax != 0 || mProgressIndeterminate)) { |
Christoph Studer | aca4b25 | 2014-09-09 15:58:41 +0200 | [diff] [blame] | 2863 | contentView.setViewVisibility(R.id.progress, View.VISIBLE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2864 | contentView.setProgressBar( |
| 2865 | R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 2866 | contentView.setProgressBackgroundTintList( |
| 2867 | R.id.progress, ColorStateList.valueOf(mContext.getResources().getColor( |
| 2868 | R.color.notification_progress_background_color))); |
| 2869 | if (mColor != COLOR_DEFAULT) { |
| 2870 | ColorStateList colorStateList = ColorStateList.valueOf(mColor); |
| 2871 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 2872 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
| 2873 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2874 | showLine2 = true; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2875 | } else { |
| 2876 | contentView.setViewVisibility(R.id.progress, View.GONE); |
| 2877 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2878 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2879 | if (showLine2) { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2880 | |
| 2881 | // need to shrink all the type to make sure everything fits |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2882 | shrinkLine3Text(contentView); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2883 | } |
| 2884 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2885 | if (showsTimeOrChronometer()) { |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2886 | if (mUseChronometer) { |
| 2887 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 2888 | contentView.setLong(R.id.chronometer, "setBase", |
| 2889 | mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 2890 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 2891 | } else { |
| 2892 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 2893 | contentView.setLong(R.id.time, "setTime", mWhen); |
| 2894 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2895 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2896 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2897 | // Adjust padding depending on line count and font size. |
| 2898 | contentView.setViewPadding(R.id.line1, 0, calculateTopPadding(mContext, |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2899 | mHasThreeLines, mContext.getResources().getConfiguration().fontScale), |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2900 | 0, 0); |
| 2901 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2902 | // We want to add badge to first line of text. |
| 2903 | boolean addedBadge = addProfileBadge(contentView, |
| 2904 | contentTextInLine2 ? R.id.profile_badge_line2 : R.id.profile_badge_line3); |
| 2905 | // If we added the badge to line 3 then we should show line 3. |
| 2906 | if (addedBadge && !contentTextInLine2) { |
| 2907 | showLine3 = true; |
| 2908 | } |
| 2909 | |
| 2910 | // Note getStandardView may hide line 3 again. |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2911 | contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2912 | contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2913 | return contentView; |
| 2914 | } |
| 2915 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2916 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2917 | * @return true if the built notification will show the time or the chronometer; false |
| 2918 | * otherwise |
| 2919 | */ |
| 2920 | private boolean showsTimeOrChronometer() { |
| 2921 | return mWhen != 0 && mShowWhen; |
| 2922 | } |
| 2923 | |
| 2924 | /** |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2925 | * Logic to find out whether the notification is going to have three lines in the contracted |
| 2926 | * layout. This is used to adjust the top padding. |
| 2927 | * |
| 2928 | * @return true if the notification is going to have three lines; false if the notification |
| 2929 | * is going to have one or two lines |
| 2930 | */ |
| 2931 | private boolean hasThreeLines() { |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2932 | boolean contentTextInLine2 = mSubText != null && mContentText != null; |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2933 | boolean hasProgress = mStyle == null || mStyle.hasProgress(); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2934 | // If we have content text in line 2, badge goes into line 2, or line 3 otherwise |
| 2935 | boolean badgeInLine3 = getProfileBadgeDrawable() != null && !contentTextInLine2; |
| 2936 | boolean hasLine3 = mContentText != null || mContentInfo != null || mNumber > 0 |
| 2937 | || badgeInLine3; |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2938 | boolean hasLine2 = (mSubText != null && mContentText != null) || |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2939 | (hasProgress && mSubText == null |
| 2940 | && (mProgressMax != 0 || mProgressIndeterminate)); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2941 | return hasLine2 && hasLine3; |
| 2942 | } |
| 2943 | |
| 2944 | /** |
| 2945 | * @hide |
| 2946 | */ |
| 2947 | public static int calculateTopPadding(Context ctx, boolean hasThreeLines, |
| 2948 | float fontScale) { |
| 2949 | int padding = ctx.getResources().getDimensionPixelSize(hasThreeLines |
| 2950 | ? R.dimen.notification_top_pad_narrow |
| 2951 | : R.dimen.notification_top_pad); |
| 2952 | int largePadding = ctx.getResources().getDimensionPixelSize(hasThreeLines |
| 2953 | ? R.dimen.notification_top_pad_large_text_narrow |
| 2954 | : R.dimen.notification_top_pad_large_text); |
| 2955 | float largeFactor = (MathUtils.constrain(fontScale, 1.0f, LARGE_TEXT_SCALE) - 1f) |
| 2956 | / (LARGE_TEXT_SCALE - 1f); |
| 2957 | |
| 2958 | // Linearly interpolate the padding between large and normal with the font scale ranging |
| 2959 | // from 1f to LARGE_TEXT_SCALE |
| 2960 | return Math.round((1 - largeFactor) * padding + largeFactor * largePadding); |
| 2961 | } |
| 2962 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2963 | private void resetStandardTemplateWithActions(RemoteViews big) { |
| 2964 | big.setViewVisibility(R.id.actions, View.GONE); |
| 2965 | big.setViewVisibility(R.id.action_divider, View.GONE); |
| 2966 | big.removeAllViews(R.id.actions); |
| 2967 | } |
| 2968 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2969 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2970 | RemoteViews big = applyStandardTemplate(layoutId); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2971 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2972 | resetStandardTemplateWithActions(big); |
| 2973 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2974 | int N = mActions.size(); |
| 2975 | if (N > 0) { |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2976 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2977 | big.setViewVisibility(R.id.action_divider, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2978 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2979 | for (int i=0; i<N; i++) { |
| 2980 | final RemoteViews button = generateActionButton(mActions.get(i)); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2981 | big.addView(R.id.actions, button); |
| 2982 | } |
| 2983 | } |
| 2984 | return big; |
| 2985 | } |
| 2986 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2987 | private RemoteViews makeContentView() { |
| 2988 | if (mContentView != null) { |
| 2989 | return mContentView; |
| 2990 | } else { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2991 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2992 | } |
| 2993 | } |
| 2994 | |
| 2995 | private RemoteViews makeTickerView() { |
| 2996 | if (mTickerView != null) { |
| 2997 | return mTickerView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2998 | } |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2999 | return null; // tickers are not created by default anymore |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3000 | } |
| 3001 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3002 | private RemoteViews makeBigContentView() { |
| 3003 | if (mActions.size() == 0) return null; |
| 3004 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3005 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3006 | } |
| 3007 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3008 | private RemoteViews makeHeadsUpContentView() { |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3009 | if (mActions.size() == 0) return null; |
| 3010 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3011 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3012 | } |
| 3013 | |
| 3014 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3015 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3016 | final boolean tombstone = (action.actionIntent == null); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3017 | RemoteViews button = new RemoteViews(mContext.getPackageName(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3018 | tombstone ? getActionTombstoneLayoutResource() |
| 3019 | : getActionLayoutResource()); |
Chris Wren | 8749ac8a | 2013-12-03 14:31:01 -0500 | [diff] [blame] | 3020 | button.setTextViewCompoundDrawablesRelative(R.id.action0, action.icon, 0, 0, 0); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3021 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3022 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3023 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3024 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3025 | button.setContentDescription(R.id.action0, action.title); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3026 | processLegacyAction(action, button); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3027 | return button; |
| 3028 | } |
| 3029 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3030 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3031 | * @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] | 3032 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3033 | */ |
| 3034 | private boolean isLegacy() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3035 | return mColorUtil != null; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3036 | } |
| 3037 | |
| 3038 | private void processLegacyAction(Action action, RemoteViews button) { |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 3039 | if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, action.icon)) { |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 3040 | button.setTextViewCompoundDrawablesRelativeColorFilter(R.id.action0, 0, |
| 3041 | mContext.getResources().getColor(R.color.notification_action_color_filter), |
| 3042 | PorterDuff.Mode.MULTIPLY); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3043 | } |
| 3044 | } |
| 3045 | |
| 3046 | private CharSequence processLegacyText(CharSequence charSequence) { |
| 3047 | if (isLegacy()) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3048 | return mColorUtil.invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3049 | } else { |
| 3050 | return charSequence; |
| 3051 | } |
| 3052 | } |
| 3053 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3054 | /** |
| 3055 | * Apply any necessary background to smallIcons being used in the largeIcon spot. |
| 3056 | */ |
| 3057 | private void processSmallIconAsLarge(int largeIconId, RemoteViews contentView) { |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame^] | 3058 | if (!isLegacy()) { |
| 3059 | contentView.setDrawableParameters(R.id.icon, false, -1, |
| 3060 | 0xFFFFFFFF, |
| 3061 | PorterDuff.Mode.SRC_ATOP, -1); |
| 3062 | } |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 3063 | if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, largeIconId)) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3064 | applyLargeIconBackground(contentView); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3065 | } |
| 3066 | } |
| 3067 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3068 | /** |
| 3069 | * Apply any necessary background to a largeIcon if it's a fake smallIcon (that is, |
| 3070 | * if it's grayscale). |
| 3071 | */ |
| 3072 | // TODO: also check bounds, transparency, that sort of thing. |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 3073 | private void processLargeLegacyIcon(Bitmap largeIcon, RemoteViews contentView) { |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 3074 | if (isLegacy() && mColorUtil.isGrayscaleIcon(largeIcon)) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3075 | applyLargeIconBackground(contentView); |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3076 | } else { |
| 3077 | removeLargeIconBackground(contentView); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3078 | } |
| 3079 | } |
| 3080 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3081 | /** |
| 3082 | * Add a colored circle behind the largeIcon slot. |
| 3083 | */ |
| 3084 | private void applyLargeIconBackground(RemoteViews contentView) { |
| 3085 | contentView.setInt(R.id.icon, "setBackgroundResource", |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3086 | R.drawable.notification_icon_legacy_bg); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3087 | |
| 3088 | contentView.setDrawableParameters( |
| 3089 | R.id.icon, |
| 3090 | true, |
| 3091 | -1, |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3092 | resolveColor(), |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3093 | PorterDuff.Mode.SRC_ATOP, |
| 3094 | -1); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3095 | |
| 3096 | int padding = mContext.getResources().getDimensionPixelSize( |
| 3097 | R.dimen.notification_large_icon_circle_padding); |
| 3098 | contentView.setViewPadding(R.id.icon, padding, padding, padding, padding); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3099 | } |
| 3100 | |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3101 | private void removeLargeIconBackground(RemoteViews contentView) { |
| 3102 | contentView.setInt(R.id.icon, "setBackgroundResource", 0); |
| 3103 | } |
| 3104 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3105 | /** |
| 3106 | * Recolor small icons when used in the R.id.right_icon slot. |
| 3107 | */ |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3108 | private void processSmallRightIcon(int smallIconDrawableId, |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3109 | RemoteViews contentView) { |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame^] | 3110 | if (!isLegacy()) { |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3111 | contentView.setDrawableParameters(R.id.right_icon, false, -1, |
| 3112 | 0xFFFFFFFF, |
| 3113 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame^] | 3114 | } |
| 3115 | if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, smallIconDrawableId)) { |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3116 | contentView.setInt(R.id.right_icon, |
| 3117 | "setBackgroundResource", |
| 3118 | R.drawable.notification_icon_legacy_bg); |
| 3119 | |
| 3120 | contentView.setDrawableParameters( |
| 3121 | R.id.right_icon, |
| 3122 | true, |
| 3123 | -1, |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3124 | resolveColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3125 | PorterDuff.Mode.SRC_ATOP, |
| 3126 | -1); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3127 | } |
| 3128 | } |
| 3129 | |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3130 | private int sanitizeColor() { |
| 3131 | if (mColor != COLOR_DEFAULT) { |
| 3132 | mColor |= 0xFF000000; // no alpha for custom colors |
| 3133 | } |
| 3134 | return mColor; |
| 3135 | } |
| 3136 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3137 | private int resolveColor() { |
| 3138 | if (mColor == COLOR_DEFAULT) { |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3139 | return mContext.getResources().getColor(R.color.notification_icon_bg_color); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3140 | } |
| 3141 | return mColor; |
| 3142 | } |
| 3143 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3144 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3145 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3146 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3147 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3148 | public Notification buildUnstyled() { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3149 | Notification n = new Notification(); |
| 3150 | n.when = mWhen; |
| 3151 | n.icon = mSmallIcon; |
| 3152 | n.iconLevel = mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3153 | n.number = mNumber; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3154 | |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3155 | n.color = sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3156 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3157 | setBuilderContentView(n, makeContentView()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3158 | n.contentIntent = mContentIntent; |
| 3159 | n.deleteIntent = mDeleteIntent; |
| 3160 | n.fullScreenIntent = mFullScreenIntent; |
| 3161 | n.tickerText = mTickerText; |
| 3162 | n.tickerView = makeTickerView(); |
| 3163 | n.largeIcon = mLargeIcon; |
| 3164 | n.sound = mSound; |
| 3165 | n.audioStreamType = mAudioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3166 | n.audioAttributes = mAudioAttributes; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3167 | n.vibrate = mVibrate; |
| 3168 | n.ledARGB = mLedArgb; |
| 3169 | n.ledOnMS = mLedOnMs; |
| 3170 | n.ledOffMS = mLedOffMs; |
| 3171 | n.defaults = mDefaults; |
| 3172 | n.flags = mFlags; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3173 | setBuilderBigContentView(n, makeBigContentView()); |
| 3174 | setBuilderHeadsUpContentView(n, makeHeadsUpContentView()); |
Daniel Sandler | 26c1343 | 2013-04-04 11:01:04 -0400 | [diff] [blame] | 3175 | if (mLedOnMs != 0 || mLedOffMs != 0) { |
Joe Onorato | 8d0b655 | 2010-11-22 16:09:29 -0800 | [diff] [blame] | 3176 | n.flags |= FLAG_SHOW_LIGHTS; |
| 3177 | } |
| 3178 | if ((mDefaults & DEFAULT_LIGHTS) != 0) { |
| 3179 | n.flags |= FLAG_SHOW_LIGHTS; |
| 3180 | } |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3181 | n.category = mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3182 | n.mGroupKey = mGroupKey; |
| 3183 | n.mSortKey = mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3184 | n.priority = mPriority; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3185 | if (mActions.size() > 0) { |
| 3186 | n.actions = new Action[mActions.size()]; |
| 3187 | mActions.toArray(n.actions); |
| 3188 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3189 | n.visibility = mVisibility; |
| 3190 | |
| 3191 | if (mPublicVersion != null) { |
| 3192 | n.publicVersion = new Notification(); |
| 3193 | mPublicVersion.cloneInto(n.publicVersion, true); |
| 3194 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3195 | // Note: If you're adding new fields, also update restoreFromNotitification(). |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3196 | return n; |
| 3197 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3198 | |
| 3199 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3200 | * Capture, in the provided bundle, semantic information used in the construction of |
| 3201 | * this Notification object. |
| 3202 | * @hide |
| 3203 | */ |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3204 | public void populateExtras(Bundle extras) { |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3205 | // Store original information used in the construction of this object |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 3206 | extras.putInt(EXTRA_ORIGINATING_USERID, mOriginatingUserId); |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3207 | extras.putParcelable(EXTRA_REBUILD_CONTEXT_APPLICATION_INFO, |
| 3208 | mContext.getApplicationInfo()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3209 | extras.putCharSequence(EXTRA_TITLE, mContentTitle); |
| 3210 | extras.putCharSequence(EXTRA_TEXT, mContentText); |
| 3211 | extras.putCharSequence(EXTRA_SUB_TEXT, mSubText); |
| 3212 | extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo); |
| 3213 | extras.putInt(EXTRA_SMALL_ICON, mSmallIcon); |
| 3214 | extras.putInt(EXTRA_PROGRESS, mProgress); |
| 3215 | extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax); |
| 3216 | extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate); |
| 3217 | extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer); |
| 3218 | extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen); |
John Spurlock | ac08a47 | 2013-06-10 11:37:08 -0400 | [diff] [blame] | 3219 | if (mLargeIcon != null) { |
| 3220 | extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 3221 | } |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3222 | if (!mPeople.isEmpty()) { |
| 3223 | extras.putStringArray(EXTRA_PEOPLE, mPeople.toArray(new String[mPeople.size()])); |
| 3224 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3225 | // NOTE: If you're adding new extras also update restoreFromNotification(). |
| 3226 | } |
| 3227 | |
| 3228 | |
| 3229 | /** |
| 3230 | * @hide |
| 3231 | */ |
| 3232 | public static void stripForDelivery(Notification n) { |
| 3233 | if (!STRIP_AND_REBUILD) { |
| 3234 | return; |
| 3235 | } |
| 3236 | |
| 3237 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
| 3238 | // Only strip views for known Styles because we won't know how to |
| 3239 | // re-create them otherwise. |
| 3240 | boolean stripViews = TextUtils.isEmpty(templateClass) || |
| 3241 | getNotificationStyleClass(templateClass) != null; |
| 3242 | |
| 3243 | boolean isStripped = false; |
| 3244 | |
| 3245 | if (n.largeIcon != null && n.extras.containsKey(EXTRA_LARGE_ICON)) { |
| 3246 | // TODO: Would like to check for equality here, but if the notification |
| 3247 | // has been cloned, we can't. |
| 3248 | n.largeIcon = null; |
| 3249 | n.extras.putBoolean(EXTRA_REBUILD_LARGE_ICON, true); |
| 3250 | isStripped = true; |
| 3251 | } |
| 3252 | // Get rid of unmodified BuilderRemoteViews. |
| 3253 | |
| 3254 | if (stripViews && |
| 3255 | n.contentView instanceof BuilderRemoteViews && |
| 3256 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 3257 | n.contentView.getSequenceNumber()) { |
| 3258 | n.contentView = null; |
| 3259 | n.extras.putBoolean(EXTRA_REBUILD_CONTENT_VIEW, true); |
| 3260 | n.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 3261 | isStripped = true; |
| 3262 | } |
| 3263 | if (stripViews && |
| 3264 | n.bigContentView instanceof BuilderRemoteViews && |
| 3265 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 3266 | n.bigContentView.getSequenceNumber()) { |
| 3267 | n.bigContentView = null; |
| 3268 | n.extras.putBoolean(EXTRA_REBUILD_BIG_CONTENT_VIEW, true); |
| 3269 | n.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 3270 | isStripped = true; |
| 3271 | } |
| 3272 | if (stripViews && |
| 3273 | n.headsUpContentView instanceof BuilderRemoteViews && |
| 3274 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 3275 | n.headsUpContentView.getSequenceNumber()) { |
| 3276 | n.headsUpContentView = null; |
| 3277 | n.extras.putBoolean(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW, true); |
| 3278 | n.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 3279 | isStripped = true; |
| 3280 | } |
| 3281 | |
| 3282 | if (isStripped) { |
| 3283 | n.extras.putBoolean(EXTRA_NEEDS_REBUILD, true); |
| 3284 | } |
| 3285 | } |
| 3286 | |
| 3287 | /** |
| 3288 | * @hide |
| 3289 | */ |
| 3290 | public static Notification rebuild(Context context, Notification n) { |
| 3291 | Bundle extras = n.extras; |
| 3292 | if (!extras.getBoolean(EXTRA_NEEDS_REBUILD)) return n; |
| 3293 | extras.remove(EXTRA_NEEDS_REBUILD); |
| 3294 | |
| 3295 | // Re-create notification context so we can access app resources. |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3296 | ApplicationInfo applicationInfo = extras.getParcelable( |
| 3297 | EXTRA_REBUILD_CONTEXT_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3298 | Context builderContext; |
| 3299 | try { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3300 | builderContext = context.createApplicationContext(applicationInfo, |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3301 | Context.CONTEXT_RESTRICTED); |
| 3302 | } catch (NameNotFoundException e) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3303 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3304 | builderContext = context; // try with our context |
| 3305 | } |
| 3306 | |
| 3307 | Builder b = new Builder(builderContext, n); |
| 3308 | return b.rebuild(); |
| 3309 | } |
| 3310 | |
| 3311 | /** |
| 3312 | * Rebuilds the notification passed in to the rebuild-constructor |
| 3313 | * {@link #Builder(Context, Notification)}. |
| 3314 | * |
| 3315 | * <p> |
| 3316 | * Throws IllegalStateException when invoked on a Builder that isn't in rebuild mode. |
| 3317 | * |
| 3318 | * @hide |
| 3319 | */ |
| 3320 | private Notification rebuild() { |
| 3321 | if (mRebuildNotification == null) { |
| 3322 | throw new IllegalStateException("rebuild() only valid when in 'rebuild' mode."); |
| 3323 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3324 | mHasThreeLines = hasThreeLines(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3325 | |
| 3326 | Bundle extras = mRebuildNotification.extras; |
| 3327 | |
| 3328 | if (extras.getBoolean(EXTRA_REBUILD_LARGE_ICON)) { |
| 3329 | mRebuildNotification.largeIcon = extras.getParcelable(EXTRA_LARGE_ICON); |
| 3330 | } |
| 3331 | extras.remove(EXTRA_REBUILD_LARGE_ICON); |
| 3332 | |
| 3333 | if (extras.getBoolean(EXTRA_REBUILD_CONTENT_VIEW)) { |
| 3334 | setBuilderContentView(mRebuildNotification, makeContentView()); |
| 3335 | if (mStyle != null) { |
| 3336 | mStyle.populateContentView(mRebuildNotification); |
| 3337 | } |
| 3338 | } |
| 3339 | extras.remove(EXTRA_REBUILD_CONTENT_VIEW); |
| 3340 | |
| 3341 | if (extras.getBoolean(EXTRA_REBUILD_BIG_CONTENT_VIEW)) { |
| 3342 | setBuilderBigContentView(mRebuildNotification, makeBigContentView()); |
| 3343 | if (mStyle != null) { |
| 3344 | mStyle.populateBigContentView(mRebuildNotification); |
| 3345 | } |
| 3346 | } |
| 3347 | extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW); |
| 3348 | |
| 3349 | if (extras.getBoolean(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW)) { |
| 3350 | setBuilderHeadsUpContentView(mRebuildNotification, makeHeadsUpContentView()); |
| 3351 | if (mStyle != null) { |
| 3352 | mStyle.populateHeadsUpContentView(mRebuildNotification); |
| 3353 | } |
| 3354 | } |
| 3355 | extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW); |
| 3356 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3357 | mHasThreeLines = false; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3358 | return mRebuildNotification; |
| 3359 | } |
| 3360 | |
| 3361 | private static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 3362 | Class<? extends Style>[] classes = new Class[]{ |
| 3363 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class}; |
| 3364 | for (Class<? extends Style> innerClass : classes) { |
| 3365 | if (templateClass.equals(innerClass.getName())) { |
| 3366 | return innerClass; |
| 3367 | } |
| 3368 | } |
| 3369 | return null; |
| 3370 | } |
| 3371 | |
| 3372 | private void setBuilderContentView(Notification n, RemoteViews contentView) { |
| 3373 | n.contentView = contentView; |
| 3374 | if (contentView instanceof BuilderRemoteViews) { |
| 3375 | mRebuildBundle.putInt(Builder.EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 3376 | contentView.getSequenceNumber()); |
| 3377 | } |
| 3378 | } |
| 3379 | |
| 3380 | private void setBuilderBigContentView(Notification n, RemoteViews bigContentView) { |
| 3381 | n.bigContentView = bigContentView; |
| 3382 | if (bigContentView instanceof BuilderRemoteViews) { |
| 3383 | mRebuildBundle.putInt(Builder.EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 3384 | bigContentView.getSequenceNumber()); |
| 3385 | } |
| 3386 | } |
| 3387 | |
| 3388 | private void setBuilderHeadsUpContentView(Notification n, |
| 3389 | RemoteViews headsUpContentView) { |
| 3390 | n.headsUpContentView = headsUpContentView; |
| 3391 | if (headsUpContentView instanceof BuilderRemoteViews) { |
| 3392 | mRebuildBundle.putInt(Builder.EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 3393 | headsUpContentView.getSequenceNumber()); |
| 3394 | } |
| 3395 | } |
| 3396 | |
| 3397 | private void restoreFromNotification(Notification n) { |
| 3398 | |
| 3399 | // Notification fields. |
| 3400 | mWhen = n.when; |
| 3401 | mSmallIcon = n.icon; |
| 3402 | mSmallIconLevel = n.iconLevel; |
| 3403 | mNumber = n.number; |
| 3404 | |
| 3405 | mColor = n.color; |
| 3406 | |
| 3407 | mContentView = n.contentView; |
| 3408 | mDeleteIntent = n.deleteIntent; |
| 3409 | mFullScreenIntent = n.fullScreenIntent; |
| 3410 | mTickerText = n.tickerText; |
| 3411 | mTickerView = n.tickerView; |
| 3412 | mLargeIcon = n.largeIcon; |
| 3413 | mSound = n.sound; |
| 3414 | mAudioStreamType = n.audioStreamType; |
| 3415 | mAudioAttributes = n.audioAttributes; |
| 3416 | |
| 3417 | mVibrate = n.vibrate; |
| 3418 | mLedArgb = n.ledARGB; |
| 3419 | mLedOnMs = n.ledOnMS; |
| 3420 | mLedOffMs = n.ledOffMS; |
| 3421 | mDefaults = n.defaults; |
| 3422 | mFlags = n.flags; |
| 3423 | |
| 3424 | mCategory = n.category; |
| 3425 | mGroupKey = n.mGroupKey; |
| 3426 | mSortKey = n.mSortKey; |
| 3427 | mPriority = n.priority; |
| 3428 | mActions.clear(); |
| 3429 | if (n.actions != null) { |
| 3430 | Collections.addAll(mActions, n.actions); |
| 3431 | } |
| 3432 | mVisibility = n.visibility; |
| 3433 | |
| 3434 | mPublicVersion = n.publicVersion; |
| 3435 | |
| 3436 | // Extras. |
| 3437 | Bundle extras = n.extras; |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 3438 | mOriginatingUserId = extras.getInt(EXTRA_ORIGINATING_USERID); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3439 | mContentTitle = extras.getCharSequence(EXTRA_TITLE); |
| 3440 | mContentText = extras.getCharSequence(EXTRA_TEXT); |
| 3441 | mSubText = extras.getCharSequence(EXTRA_SUB_TEXT); |
| 3442 | mContentInfo = extras.getCharSequence(EXTRA_INFO_TEXT); |
| 3443 | mSmallIcon = extras.getInt(EXTRA_SMALL_ICON); |
| 3444 | mProgress = extras.getInt(EXTRA_PROGRESS); |
| 3445 | mProgressMax = extras.getInt(EXTRA_PROGRESS_MAX); |
| 3446 | mProgressIndeterminate = extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 3447 | mUseChronometer = extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 3448 | mShowWhen = extras.getBoolean(EXTRA_SHOW_WHEN); |
| 3449 | if (extras.containsKey(EXTRA_LARGE_ICON)) { |
| 3450 | mLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON); |
| 3451 | } |
| 3452 | if (extras.containsKey(EXTRA_PEOPLE)) { |
| 3453 | mPeople.clear(); |
| 3454 | Collections.addAll(mPeople, extras.getStringArray(EXTRA_PEOPLE)); |
| 3455 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3456 | } |
| 3457 | |
| 3458 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3459 | * @deprecated Use {@link #build()} instead. |
| 3460 | */ |
| 3461 | @Deprecated |
| 3462 | public Notification getNotification() { |
| 3463 | return build(); |
| 3464 | } |
| 3465 | |
| 3466 | /** |
| 3467 | * Combine all of the options that have been set and return a new {@link Notification} |
| 3468 | * object. |
| 3469 | */ |
| 3470 | public Notification build() { |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 3471 | mOriginatingUserId = mContext.getUserId(); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3472 | mHasThreeLines = hasThreeLines(); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 3473 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3474 | Notification n = buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3475 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3476 | if (mStyle != null) { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3477 | n = mStyle.buildStyled(n); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3478 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3479 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3480 | if (mExtras != null) { |
| 3481 | n.extras.putAll(mExtras); |
| 3482 | } |
| 3483 | |
| 3484 | if (mRebuildBundle.size() > 0) { |
| 3485 | n.extras.putAll(mRebuildBundle); |
| 3486 | mRebuildBundle.clear(); |
| 3487 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3488 | |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3489 | populateExtras(n.extras); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3490 | if (mStyle != null) { |
| 3491 | mStyle.addExtras(n.extras); |
| 3492 | } |
| 3493 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3494 | mHasThreeLines = false; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3495 | return n; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3496 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3497 | |
| 3498 | /** |
| 3499 | * Apply this Builder to an existing {@link Notification} object. |
| 3500 | * |
| 3501 | * @hide |
| 3502 | */ |
| 3503 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 3504 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3505 | return n; |
| 3506 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3507 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3508 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3509 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3510 | } |
| 3511 | |
| 3512 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3513 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3514 | } |
| 3515 | |
| 3516 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3517 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3521 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3522 | } |
| 3523 | |
| 3524 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3525 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3526 | } |
| 3527 | |
| 3528 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3529 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3530 | } |
| 3531 | |
| 3532 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3533 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3534 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3535 | } |
| 3536 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3537 | /** |
| 3538 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 3539 | * object. |
| 3540 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3541 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3542 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3543 | |
| 3544 | /** |
| 3545 | * @hide |
| 3546 | */ |
| 3547 | protected CharSequence mSummaryText = null; |
| 3548 | |
| 3549 | /** |
| 3550 | * @hide |
| 3551 | */ |
| 3552 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3553 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3554 | protected Builder mBuilder; |
| 3555 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3556 | /** |
| 3557 | * Overrides ContentTitle in the big form of the template. |
| 3558 | * This defaults to the value passed to setContentTitle(). |
| 3559 | */ |
| 3560 | protected void internalSetBigContentTitle(CharSequence title) { |
| 3561 | mBigContentTitle = title; |
| 3562 | } |
| 3563 | |
| 3564 | /** |
| 3565 | * Set the first line of text after the detail section in the big form of the template. |
| 3566 | */ |
| 3567 | protected void internalSetSummaryText(CharSequence cs) { |
| 3568 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3569 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3570 | } |
| 3571 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3572 | public void setBuilder(Builder builder) { |
| 3573 | if (mBuilder != builder) { |
| 3574 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3575 | if (mBuilder != null) { |
| 3576 | mBuilder.setStyle(this); |
| 3577 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3578 | } |
| 3579 | } |
| 3580 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3581 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3582 | if (mBuilder == null) { |
| 3583 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 3584 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3585 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3586 | |
| 3587 | protected RemoteViews getStandardView(int layoutId) { |
| 3588 | checkBuilder(); |
| 3589 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3590 | // Nasty. |
| 3591 | CharSequence oldBuilderContentTitle = mBuilder.mContentTitle; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3592 | if (mBigContentTitle != null) { |
| 3593 | mBuilder.setContentTitle(mBigContentTitle); |
| 3594 | } |
| 3595 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3596 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 3597 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3598 | mBuilder.mContentTitle = oldBuilderContentTitle; |
| 3599 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3600 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 3601 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 3602 | } else { |
| 3603 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3604 | } |
| 3605 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3606 | // The last line defaults to the subtext, but can be replaced by mSummaryText |
| 3607 | final CharSequence overflowText = |
| 3608 | mSummaryTextSet ? mSummaryText |
| 3609 | : mBuilder.mSubText; |
| 3610 | if (overflowText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3611 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(overflowText)); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3612 | contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 3613 | contentView.setViewVisibility(R.id.line3, View.VISIBLE); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 3614 | } else { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3615 | // Clear text in case we use the line to show the profile badge. |
| 3616 | contentView.setTextViewText(R.id.text, ""); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 3617 | contentView.setViewVisibility(R.id.overflow_divider, View.GONE); |
| 3618 | contentView.setViewVisibility(R.id.line3, View.GONE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3619 | } |
| 3620 | |
| 3621 | return contentView; |
| 3622 | } |
| 3623 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3624 | /** |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3625 | * Changes the padding of the first line such that the big and small content view have the |
| 3626 | * same top padding. |
| 3627 | * |
| 3628 | * @hide |
| 3629 | */ |
| 3630 | protected void applyTopPadding(RemoteViews contentView) { |
| 3631 | int topPadding = Builder.calculateTopPadding(mBuilder.mContext, |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3632 | mBuilder.mHasThreeLines, |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3633 | mBuilder.mContext.getResources().getConfiguration().fontScale); |
| 3634 | contentView.setViewPadding(R.id.line1, 0, topPadding, 0, 0); |
| 3635 | } |
| 3636 | |
| 3637 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3638 | * @hide |
| 3639 | */ |
| 3640 | public void addExtras(Bundle extras) { |
| 3641 | if (mSummaryTextSet) { |
| 3642 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 3643 | } |
| 3644 | if (mBigContentTitle != null) { |
| 3645 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 3646 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 3647 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3648 | } |
| 3649 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3650 | /** |
| 3651 | * @hide |
| 3652 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3653 | protected void restoreFromExtras(Bundle extras) { |
| 3654 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 3655 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 3656 | mSummaryTextSet = true; |
| 3657 | } |
| 3658 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 3659 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 3660 | } |
| 3661 | } |
| 3662 | |
| 3663 | |
| 3664 | /** |
| 3665 | * @hide |
| 3666 | */ |
| 3667 | public Notification buildStyled(Notification wip) { |
| 3668 | populateTickerView(wip); |
| 3669 | populateContentView(wip); |
| 3670 | populateBigContentView(wip); |
| 3671 | populateHeadsUpContentView(wip); |
| 3672 | return wip; |
| 3673 | } |
| 3674 | |
| 3675 | // The following methods are split out so we can re-create notification partially. |
| 3676 | /** |
| 3677 | * @hide |
| 3678 | */ |
| 3679 | protected void populateTickerView(Notification wip) {} |
| 3680 | /** |
| 3681 | * @hide |
| 3682 | */ |
| 3683 | protected void populateContentView(Notification wip) {} |
| 3684 | |
| 3685 | /** |
| 3686 | * @hide |
| 3687 | */ |
| 3688 | protected void populateBigContentView(Notification wip) {} |
| 3689 | |
| 3690 | /** |
| 3691 | * @hide |
| 3692 | */ |
| 3693 | protected void populateHeadsUpContentView(Notification wip) {} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3694 | |
| 3695 | /** |
| 3696 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 3697 | * attached to. |
| 3698 | * |
| 3699 | * @return the fully constructed Notification. |
| 3700 | */ |
| 3701 | public Notification build() { |
| 3702 | checkBuilder(); |
| 3703 | return mBuilder.build(); |
| 3704 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3705 | |
| 3706 | /** |
| 3707 | * @hide |
| 3708 | * @return true if the style positions the progress bar on the second line; false if the |
| 3709 | * style hides the progress bar |
| 3710 | */ |
| 3711 | protected boolean hasProgress() { |
| 3712 | return true; |
| 3713 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3714 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3715 | |
| 3716 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3717 | * 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] | 3718 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3719 | * 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] | 3720 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3721 | * Notification notif = new Notification.Builder(mContext) |
| 3722 | * .setContentTitle("New photo from " + sender.toString()) |
| 3723 | * .setContentText(subject) |
| 3724 | * .setSmallIcon(R.drawable.new_post) |
| 3725 | * .setLargeIcon(aBitmap) |
| 3726 | * .setStyle(new Notification.BigPictureStyle() |
| 3727 | * .bigPicture(aBigBitmap)) |
| 3728 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3729 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3730 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3731 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3732 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3733 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3734 | private Bitmap mPicture; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3735 | private Bitmap mBigLargeIcon; |
| 3736 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3737 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3738 | public BigPictureStyle() { |
| 3739 | } |
| 3740 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3741 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3742 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3743 | } |
| 3744 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3745 | /** |
| 3746 | * Overrides ContentTitle in the big form of the template. |
| 3747 | * This defaults to the value passed to setContentTitle(). |
| 3748 | */ |
| 3749 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3750 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3751 | return this; |
| 3752 | } |
| 3753 | |
| 3754 | /** |
| 3755 | * Set the first line of text after the detail section in the big form of the template. |
| 3756 | */ |
| 3757 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3758 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3759 | return this; |
| 3760 | } |
| 3761 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3762 | /** |
| 3763 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 3764 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3765 | public BigPictureStyle bigPicture(Bitmap b) { |
| 3766 | mPicture = b; |
| 3767 | return this; |
| 3768 | } |
| 3769 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3770 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3771 | * Override the large icon when the big notification is shown. |
| 3772 | */ |
| 3773 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
| 3774 | mBigLargeIconSet = true; |
| 3775 | mBigLargeIcon = b; |
| 3776 | return this; |
| 3777 | } |
| 3778 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3779 | private RemoteViews makeBigContentView() { |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3780 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3781 | |
| 3782 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
| 3783 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3784 | applyTopPadding(contentView); |
| 3785 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3786 | boolean twoTextLines = mBuilder.mSubText != null && mBuilder.mContentText != null; |
| 3787 | mBuilder.addProfileBadge(contentView, |
| 3788 | twoTextLines ? R.id.profile_badge_line2 : R.id.profile_badge_line3); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3789 | return contentView; |
| 3790 | } |
| 3791 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3792 | /** |
| 3793 | * @hide |
| 3794 | */ |
| 3795 | public void addExtras(Bundle extras) { |
| 3796 | super.addExtras(extras); |
| 3797 | |
| 3798 | if (mBigLargeIconSet) { |
| 3799 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 3800 | } |
| 3801 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 3802 | } |
| 3803 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3804 | /** |
| 3805 | * @hide |
| 3806 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3807 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3808 | protected void restoreFromExtras(Bundle extras) { |
| 3809 | super.restoreFromExtras(extras); |
| 3810 | |
| 3811 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
| 3812 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3813 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3814 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 3815 | } |
| 3816 | |
| 3817 | /** |
| 3818 | * @hide |
| 3819 | */ |
| 3820 | @Override |
| 3821 | public void populateBigContentView(Notification wip) { |
| 3822 | mBuilder.setBuilderBigContentView(wip, makeBigContentView()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3823 | } |
| 3824 | } |
| 3825 | |
| 3826 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3827 | * 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] | 3828 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3829 | * 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] | 3830 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3831 | * Notification notif = new Notification.Builder(mContext) |
| 3832 | * .setContentTitle("New mail from " + sender.toString()) |
| 3833 | * .setContentText(subject) |
| 3834 | * .setSmallIcon(R.drawable.new_mail) |
| 3835 | * .setLargeIcon(aBitmap) |
| 3836 | * .setStyle(new Notification.BigTextStyle() |
| 3837 | * .bigText(aVeryLongString)) |
| 3838 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3839 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3840 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3841 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3842 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3843 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3844 | |
| 3845 | private static final int MAX_LINES = 13; |
| 3846 | private static final int LINES_CONSUMED_BY_ACTIONS = 3; |
| 3847 | private static final int LINES_CONSUMED_BY_SUMMARY = 2; |
| 3848 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3849 | private CharSequence mBigText; |
| 3850 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3851 | public BigTextStyle() { |
| 3852 | } |
| 3853 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3854 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3855 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3856 | } |
| 3857 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3858 | /** |
| 3859 | * Overrides ContentTitle in the big form of the template. |
| 3860 | * This defaults to the value passed to setContentTitle(). |
| 3861 | */ |
| 3862 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3863 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3864 | return this; |
| 3865 | } |
| 3866 | |
| 3867 | /** |
| 3868 | * Set the first line of text after the detail section in the big form of the template. |
| 3869 | */ |
| 3870 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3871 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3872 | return this; |
| 3873 | } |
| 3874 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3875 | /** |
| 3876 | * Provide the longer text to be displayed in the big form of the |
| 3877 | * template in place of the content text. |
| 3878 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3879 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3880 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3881 | return this; |
| 3882 | } |
| 3883 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3884 | /** |
| 3885 | * @hide |
| 3886 | */ |
| 3887 | public void addExtras(Bundle extras) { |
| 3888 | super.addExtras(extras); |
| 3889 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3890 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 3891 | } |
| 3892 | |
| 3893 | /** |
| 3894 | * @hide |
| 3895 | */ |
| 3896 | @Override |
| 3897 | protected void restoreFromExtras(Bundle extras) { |
| 3898 | super.restoreFromExtras(extras); |
| 3899 | |
| 3900 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3901 | } |
| 3902 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3903 | private RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3904 | |
| 3905 | // Nasty |
| 3906 | CharSequence oldBuilderContentText = mBuilder.mContentText; |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 3907 | mBuilder.mContentText = null; |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 3908 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3909 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3910 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3911 | mBuilder.mContentText = oldBuilderContentText; |
| 3912 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3913 | contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3914 | contentView.setViewVisibility(R.id.big_text, View.VISIBLE); |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3915 | contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines()); |
Chris Wren | 3c5f9243 | 2012-05-04 16:31:17 -0400 | [diff] [blame] | 3916 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3917 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3918 | applyTopPadding(contentView); |
| 3919 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3920 | mBuilder.shrinkLine3Text(contentView); |
| 3921 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3922 | mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template); |
| 3923 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3924 | return contentView; |
| 3925 | } |
| 3926 | |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3927 | private int calculateMaxLines() { |
| 3928 | int lineCount = MAX_LINES; |
| 3929 | boolean hasActions = mBuilder.mActions.size() > 0; |
| 3930 | boolean hasSummary = (mSummaryTextSet ? mSummaryText : mBuilder.mSubText) != null; |
| 3931 | if (hasActions) { |
| 3932 | lineCount -= LINES_CONSUMED_BY_ACTIONS; |
| 3933 | } |
| 3934 | if (hasSummary) { |
| 3935 | lineCount -= LINES_CONSUMED_BY_SUMMARY; |
| 3936 | } |
| 3937 | |
| 3938 | // If we have less top padding at the top, we can fit less lines. |
| 3939 | if (!mBuilder.mHasThreeLines) { |
| 3940 | lineCount--; |
| 3941 | } |
| 3942 | return lineCount; |
| 3943 | } |
| 3944 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3945 | /** |
| 3946 | * @hide |
| 3947 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3948 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3949 | public void populateBigContentView(Notification wip) { |
| 3950 | mBuilder.setBuilderBigContentView(wip, makeBigContentView()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3951 | } |
| 3952 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3953 | |
| 3954 | /** |
| 3955 | * 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] | 3956 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3957 | * 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] | 3958 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3959 | * Notification notif = new Notification.Builder(mContext) |
| 3960 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 3961 | * .setContentText(subject) |
| 3962 | * .setSmallIcon(R.drawable.new_mail) |
| 3963 | * .setLargeIcon(aBitmap) |
| 3964 | * .setStyle(new Notification.InboxStyle() |
| 3965 | * .addLine(str1) |
| 3966 | * .addLine(str2) |
| 3967 | * .setContentTitle("") |
| 3968 | * .setSummaryText("+3 more")) |
| 3969 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3970 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3971 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3972 | * @see Notification#bigContentView |
| 3973 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3974 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3975 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 3976 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3977 | public InboxStyle() { |
| 3978 | } |
| 3979 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3980 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3981 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3982 | } |
| 3983 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3984 | /** |
| 3985 | * Overrides ContentTitle in the big form of the template. |
| 3986 | * This defaults to the value passed to setContentTitle(). |
| 3987 | */ |
| 3988 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3989 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3990 | return this; |
| 3991 | } |
| 3992 | |
| 3993 | /** |
| 3994 | * Set the first line of text after the detail section in the big form of the template. |
| 3995 | */ |
| 3996 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3997 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3998 | return this; |
| 3999 | } |
| 4000 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4001 | /** |
| 4002 | * Append a line to the digest section of the Inbox notification. |
| 4003 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4004 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4005 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4006 | return this; |
| 4007 | } |
| 4008 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4009 | /** |
| 4010 | * @hide |
| 4011 | */ |
| 4012 | public void addExtras(Bundle extras) { |
| 4013 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4014 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4015 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 4016 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 4017 | } |
| 4018 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4019 | /** |
| 4020 | * @hide |
| 4021 | */ |
| 4022 | @Override |
| 4023 | protected void restoreFromExtras(Bundle extras) { |
| 4024 | super.restoreFromExtras(extras); |
| 4025 | |
| 4026 | mTexts.clear(); |
| 4027 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 4028 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 4029 | } |
| 4030 | } |
| 4031 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4032 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4033 | // Remove the content text so line3 disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4034 | |
| 4035 | // Nasty |
| 4036 | CharSequence oldBuilderContentText = mBuilder.mContentText; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4037 | mBuilder.mContentText = null; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4038 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4039 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4040 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4041 | mBuilder.mContentText = oldBuilderContentText; |
| 4042 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4043 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4044 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4045 | 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] | 4046 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4047 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 4048 | // Make sure all rows are gone in case we reuse a view. |
| 4049 | for (int rowId : rowIds) { |
| 4050 | contentView.setViewVisibility(rowId, View.GONE); |
| 4051 | } |
| 4052 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4053 | final boolean largeText = |
| 4054 | mBuilder.mContext.getResources().getConfiguration().fontScale > 1f; |
| 4055 | final float subTextSize = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4056 | R.dimen.notification_subtext_size); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4057 | int i=0; |
| 4058 | while (i < mTexts.size() && i < rowIds.length) { |
| 4059 | CharSequence str = mTexts.get(i); |
| 4060 | if (str != null && !str.equals("")) { |
| 4061 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4062 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4063 | if (largeText) { |
| 4064 | contentView.setTextViewTextSize(rowIds[i], TypedValue.COMPLEX_UNIT_PX, |
| 4065 | subTextSize); |
| 4066 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4067 | } |
| 4068 | i++; |
| 4069 | } |
| 4070 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 4071 | contentView.setViewVisibility(R.id.inbox_end_pad, |
| 4072 | mTexts.size() > 0 ? View.VISIBLE : View.GONE); |
| 4073 | |
| 4074 | contentView.setViewVisibility(R.id.inbox_more, |
| 4075 | mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE); |
Chris Wren | 29bb6d9 | 2012-05-17 18:09:42 -0400 | [diff] [blame] | 4076 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4077 | applyTopPadding(contentView); |
| 4078 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4079 | mBuilder.shrinkLine3Text(contentView); |
| 4080 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4081 | mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template); |
| 4082 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4083 | return contentView; |
| 4084 | } |
| 4085 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4086 | /** |
| 4087 | * @hide |
| 4088 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4089 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4090 | public void populateBigContentView(Notification wip) { |
| 4091 | mBuilder.setBuilderBigContentView(wip, makeBigContentView()); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4092 | } |
| 4093 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4094 | |
| 4095 | /** |
| 4096 | * Notification style for media playback notifications. |
| 4097 | * |
| 4098 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 4099 | * {@link Notification.Action}s specified with |
| 4100 | * {@link Notification.Builder#addAction(int, CharSequence, PendingIntent) addAction} will be |
| 4101 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 4102 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 4103 | * treated as album artwork. |
| 4104 | * |
| 4105 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 4106 | * {@link Notification#contentView}; by providing action indices to |
| 4107 | * {@link #setShowActionsInCompactView(int...)} you can promote up to 2 actions to be displayed |
| 4108 | * in the standard view alongside the usual content. |
| 4109 | * |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4110 | * Notifications created with MediaStyle will have their category set to |
| 4111 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 4112 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
| 4113 | * |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4114 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 4115 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4116 | * the System UI can identify this as a notification representing an active media session |
| 4117 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 4118 | * |
| 4119 | * To use this style with your Notification, feed it to |
| 4120 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4121 | * <pre class="prettyprint"> |
| 4122 | * Notification noti = new Notification.Builder() |
| 4123 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 4124 | * .setContentTitle("Track title") |
| 4125 | * .setContentText("Artist - Album") |
| 4126 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4127 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 4128 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4129 | * .build(); |
| 4130 | * </pre> |
| 4131 | * |
| 4132 | * @see Notification#bigContentView |
| 4133 | */ |
| 4134 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4135 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4136 | static final int MAX_MEDIA_BUTTONS = 5; |
| 4137 | |
| 4138 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4139 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4140 | |
| 4141 | public MediaStyle() { |
| 4142 | } |
| 4143 | |
| 4144 | public MediaStyle(Builder builder) { |
| 4145 | setBuilder(builder); |
| 4146 | } |
| 4147 | |
| 4148 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4149 | * 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] | 4150 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4151 | * |
| 4152 | * @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] | 4153 | */ |
| 4154 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 4155 | mActionsToShowInCompact = actions; |
| 4156 | return this; |
| 4157 | } |
| 4158 | |
| 4159 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4160 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 4161 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4162 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4163 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4164 | mToken = token; |
| 4165 | return this; |
| 4166 | } |
| 4167 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4168 | /** |
| 4169 | * @hide |
| 4170 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4171 | @Override |
| 4172 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4173 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4174 | if (wip.category == null) { |
| 4175 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 4176 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4177 | return wip; |
| 4178 | } |
| 4179 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4180 | /** |
| 4181 | * @hide |
| 4182 | */ |
| 4183 | @Override |
| 4184 | public void populateContentView(Notification wip) { |
| 4185 | mBuilder.setBuilderContentView(wip, makeMediaContentView()); |
| 4186 | } |
| 4187 | |
| 4188 | /** |
| 4189 | * @hide |
| 4190 | */ |
| 4191 | @Override |
| 4192 | public void populateBigContentView(Notification wip) { |
| 4193 | mBuilder.setBuilderBigContentView(wip, makeMediaBigContentView()); |
| 4194 | } |
| 4195 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4196 | /** @hide */ |
| 4197 | @Override |
| 4198 | public void addExtras(Bundle extras) { |
| 4199 | super.addExtras(extras); |
| 4200 | |
| 4201 | if (mToken != null) { |
| 4202 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 4203 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 4204 | if (mActionsToShowInCompact != null) { |
| 4205 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 4206 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4207 | } |
| 4208 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4209 | /** |
| 4210 | * @hide |
| 4211 | */ |
| 4212 | @Override |
| 4213 | protected void restoreFromExtras(Bundle extras) { |
| 4214 | super.restoreFromExtras(extras); |
| 4215 | |
| 4216 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 4217 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 4218 | } |
| 4219 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 4220 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 4221 | } |
| 4222 | } |
| 4223 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4224 | private RemoteViews generateMediaActionButton(Action action) { |
| 4225 | final boolean tombstone = (action.actionIntent == null); |
| 4226 | RemoteViews button = new RemoteViews(mBuilder.mContext.getPackageName(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4227 | R.layout.notification_material_media_action); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4228 | button.setImageViewResource(R.id.action0, action.icon); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4229 | button.setDrawableParameters(R.id.action0, false, -1, |
| 4230 | 0xFFFFFFFF, |
| 4231 | PorterDuff.Mode.SRC_ATOP, -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4232 | if (!tombstone) { |
| 4233 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 4234 | } |
| 4235 | button.setContentDescription(R.id.action0, action.title); |
| 4236 | return button; |
| 4237 | } |
| 4238 | |
| 4239 | private RemoteViews makeMediaContentView() { |
| 4240 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4241 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4242 | |
| 4243 | final int numActions = mBuilder.mActions.size(); |
| 4244 | final int N = mActionsToShowInCompact == null |
| 4245 | ? 0 |
| 4246 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4247 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4248 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4249 | for (int i = 0; i < N; i++) { |
| 4250 | if (i >= numActions) { |
| 4251 | throw new IllegalArgumentException(String.format( |
| 4252 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 4253 | i, numActions - 1)); |
| 4254 | } |
| 4255 | |
| 4256 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
| 4257 | final RemoteViews button = generateMediaActionButton(action); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4258 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4259 | } |
| 4260 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4261 | styleText(view); |
| 4262 | hideRightIcon(view); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4263 | return view; |
| 4264 | } |
| 4265 | |
| 4266 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4267 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
| 4268 | RemoteViews big = mBuilder.applyStandardTemplate(getBigLayoutResource(actionCount), |
| 4269 | false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4270 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4271 | if (actionCount > 0) { |
| 4272 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 4273 | for (int i = 0; i < actionCount; i++) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4274 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i)); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4275 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4276 | } |
| 4277 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4278 | styleText(big); |
| 4279 | hideRightIcon(big); |
| 4280 | applyTopPadding(big); |
| 4281 | big.setViewVisibility(android.R.id.progress, View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4282 | return big; |
| 4283 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4284 | |
| 4285 | private int getBigLayoutResource(int actionCount) { |
| 4286 | if (actionCount <= 3) { |
| 4287 | return R.layout.notification_template_material_big_media_narrow; |
| 4288 | } else { |
| 4289 | return R.layout.notification_template_material_big_media; |
| 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | private void hideRightIcon(RemoteViews contentView) { |
| 4294 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
| 4295 | } |
| 4296 | |
| 4297 | /** |
| 4298 | * Applies the special text colors for media notifications to all text views. |
| 4299 | */ |
| 4300 | private void styleText(RemoteViews contentView) { |
| 4301 | int primaryColor = mBuilder.mContext.getResources().getColor( |
| 4302 | R.color.notification_media_primary_color); |
| 4303 | int secondaryColor = mBuilder.mContext.getResources().getColor( |
| 4304 | R.color.notification_media_secondary_color); |
| 4305 | contentView.setTextColor(R.id.title, primaryColor); |
| 4306 | if (mBuilder.showsTimeOrChronometer()) { |
| 4307 | if (mBuilder.mUseChronometer) { |
| 4308 | contentView.setTextColor(R.id.chronometer, secondaryColor); |
| 4309 | } else { |
| 4310 | contentView.setTextColor(R.id.time, secondaryColor); |
| 4311 | } |
| 4312 | } |
| 4313 | contentView.setTextColor(R.id.text2, secondaryColor); |
| 4314 | contentView.setTextColor(R.id.text, secondaryColor); |
| 4315 | contentView.setTextColor(R.id.info, secondaryColor); |
| 4316 | } |
| 4317 | |
| 4318 | /** |
| 4319 | * @hide |
| 4320 | */ |
| 4321 | @Override |
| 4322 | protected boolean hasProgress() { |
| 4323 | return false; |
| 4324 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4325 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4326 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4327 | // When adding a new Style subclass here, don't forget to update |
| 4328 | // Builder.getNotificationStyleClass. |
| 4329 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4330 | /** |
| 4331 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 4332 | * metadata or change options on a notification builder. |
| 4333 | */ |
| 4334 | public interface Extender { |
| 4335 | /** |
| 4336 | * Apply this extender to a notification builder. |
| 4337 | * @param builder the builder to be modified. |
| 4338 | * @return the build object for chaining. |
| 4339 | */ |
| 4340 | public Builder extend(Builder builder); |
| 4341 | } |
| 4342 | |
| 4343 | /** |
| 4344 | * Helper class to add wearable extensions to notifications. |
| 4345 | * <p class="note"> See |
| 4346 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 4347 | * for Android Wear</a> for more information on how to use this class. |
| 4348 | * <p> |
| 4349 | * To create a notification with wearable extensions: |
| 4350 | * <ol> |
| 4351 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 4352 | * properties. |
| 4353 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 4354 | * <li>Set wearable-specific properties using the |
| 4355 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 4356 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 4357 | * notification. |
| 4358 | * <li>Post the notification to the notification system with the |
| 4359 | * {@code NotificationManager.notify(...)} methods. |
| 4360 | * </ol> |
| 4361 | * |
| 4362 | * <pre class="prettyprint"> |
| 4363 | * Notification notif = new Notification.Builder(mContext) |
| 4364 | * .setContentTitle("New mail from " + sender.toString()) |
| 4365 | * .setContentText(subject) |
| 4366 | * .setSmallIcon(R.drawable.new_mail) |
| 4367 | * .extend(new Notification.WearableExtender() |
| 4368 | * .setContentIcon(R.drawable.new_mail)) |
| 4369 | * .build(); |
| 4370 | * NotificationManager notificationManger = |
| 4371 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 4372 | * notificationManger.notify(0, notif);</pre> |
| 4373 | * |
| 4374 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 4375 | * {@code WearableExtender(Notification)} constructor, |
| 4376 | * and then using the {@code get} methods to access values. |
| 4377 | * |
| 4378 | * <pre class="prettyprint"> |
| 4379 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 4380 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4381 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4382 | */ |
| 4383 | public static final class WearableExtender implements Extender { |
| 4384 | /** |
| 4385 | * Sentinel value for an action index that is unset. |
| 4386 | */ |
| 4387 | public static final int UNSET_ACTION_INDEX = -1; |
| 4388 | |
| 4389 | /** |
| 4390 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 4391 | * default sizing. |
| 4392 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
| 4393 | * the default is {@link #SIZE_LARGE}. All other notifications size automatically based |
| 4394 | * on their content. |
| 4395 | */ |
| 4396 | public static final int SIZE_DEFAULT = 0; |
| 4397 | |
| 4398 | /** |
| 4399 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4400 | * with an extra small size. |
| 4401 | * <p>This value is only applicable for custom display notifications created using |
| 4402 | * {@link #setDisplayIntent}. |
| 4403 | */ |
| 4404 | public static final int SIZE_XSMALL = 1; |
| 4405 | |
| 4406 | /** |
| 4407 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4408 | * with a small size. |
| 4409 | * <p>This value is only applicable for custom display notifications created using |
| 4410 | * {@link #setDisplayIntent}. |
| 4411 | */ |
| 4412 | public static final int SIZE_SMALL = 2; |
| 4413 | |
| 4414 | /** |
| 4415 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4416 | * with a medium size. |
| 4417 | * <p>This value is only applicable for custom display notifications created using |
| 4418 | * {@link #setDisplayIntent}. |
| 4419 | */ |
| 4420 | public static final int SIZE_MEDIUM = 3; |
| 4421 | |
| 4422 | /** |
| 4423 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4424 | * with a large size. |
| 4425 | * <p>This value is only applicable for custom display notifications created using |
| 4426 | * {@link #setDisplayIntent}. |
| 4427 | */ |
| 4428 | public static final int SIZE_LARGE = 4; |
| 4429 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 4430 | /** |
| 4431 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4432 | * full screen. |
| 4433 | * <p>This value is only applicable for custom display notifications created using |
| 4434 | * {@link #setDisplayIntent}. |
| 4435 | */ |
| 4436 | public static final int SIZE_FULL_SCREEN = 5; |
| 4437 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4438 | /** |
| 4439 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 4440 | * short amount of time when this notification is displayed on the screen. This |
| 4441 | * is the default value. |
| 4442 | */ |
| 4443 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 4444 | |
| 4445 | /** |
| 4446 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 4447 | * for a longer amount of time when this notification is displayed on the screen. |
| 4448 | */ |
| 4449 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 4450 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4451 | /** Notification extra which contains wearable extensions */ |
| 4452 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 4453 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 4454 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4455 | private static final String KEY_ACTIONS = "actions"; |
| 4456 | private static final String KEY_FLAGS = "flags"; |
| 4457 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 4458 | private static final String KEY_PAGES = "pages"; |
| 4459 | private static final String KEY_BACKGROUND = "background"; |
| 4460 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 4461 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 4462 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 4463 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 4464 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 4465 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4466 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4467 | |
| 4468 | // Flags bitwise-ored to mFlags |
| 4469 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 4470 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 4471 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 4472 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4473 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4474 | |
| 4475 | // Default value for flags integer |
| 4476 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 4477 | |
| 4478 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 4479 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 4480 | |
| 4481 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 4482 | private int mFlags = DEFAULT_FLAGS; |
| 4483 | private PendingIntent mDisplayIntent; |
| 4484 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 4485 | private Bitmap mBackground; |
| 4486 | private int mContentIcon; |
| 4487 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 4488 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 4489 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 4490 | private int mCustomContentHeight; |
| 4491 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4492 | private int mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4493 | |
| 4494 | /** |
| 4495 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 4496 | * options. |
| 4497 | */ |
| 4498 | public WearableExtender() { |
| 4499 | } |
| 4500 | |
| 4501 | public WearableExtender(Notification notif) { |
| 4502 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 4503 | if (wearableBundle != null) { |
| 4504 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 4505 | if (actions != null) { |
| 4506 | mActions.addAll(actions); |
| 4507 | } |
| 4508 | |
| 4509 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 4510 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 4511 | |
| 4512 | Notification[] pages = getNotificationArrayFromBundle( |
| 4513 | wearableBundle, KEY_PAGES); |
| 4514 | if (pages != null) { |
| 4515 | Collections.addAll(mPages, pages); |
| 4516 | } |
| 4517 | |
| 4518 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 4519 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 4520 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 4521 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 4522 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 4523 | UNSET_ACTION_INDEX); |
| 4524 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 4525 | SIZE_DEFAULT); |
| 4526 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 4527 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4528 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4529 | } |
| 4530 | } |
| 4531 | |
| 4532 | /** |
| 4533 | * Apply wearable extensions to a notification that is being built. This is typically |
| 4534 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 4535 | * {@link android.app.Notification.Builder}. |
| 4536 | */ |
| 4537 | @Override |
| 4538 | public Notification.Builder extend(Notification.Builder builder) { |
| 4539 | Bundle wearableBundle = new Bundle(); |
| 4540 | |
| 4541 | if (!mActions.isEmpty()) { |
| 4542 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 4543 | } |
| 4544 | if (mFlags != DEFAULT_FLAGS) { |
| 4545 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 4546 | } |
| 4547 | if (mDisplayIntent != null) { |
| 4548 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 4549 | } |
| 4550 | if (!mPages.isEmpty()) { |
| 4551 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 4552 | new Notification[mPages.size()])); |
| 4553 | } |
| 4554 | if (mBackground != null) { |
| 4555 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 4556 | } |
| 4557 | if (mContentIcon != 0) { |
| 4558 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 4559 | } |
| 4560 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 4561 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 4562 | } |
| 4563 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 4564 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 4565 | mContentActionIndex); |
| 4566 | } |
| 4567 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 4568 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 4569 | } |
| 4570 | if (mCustomContentHeight != 0) { |
| 4571 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 4572 | } |
| 4573 | if (mGravity != DEFAULT_GRAVITY) { |
| 4574 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 4575 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4576 | if (mHintScreenTimeout != 0) { |
| 4577 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 4578 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4579 | |
| 4580 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 4581 | return builder; |
| 4582 | } |
| 4583 | |
| 4584 | @Override |
| 4585 | public WearableExtender clone() { |
| 4586 | WearableExtender that = new WearableExtender(); |
| 4587 | that.mActions = new ArrayList<Action>(this.mActions); |
| 4588 | that.mFlags = this.mFlags; |
| 4589 | that.mDisplayIntent = this.mDisplayIntent; |
| 4590 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 4591 | that.mBackground = this.mBackground; |
| 4592 | that.mContentIcon = this.mContentIcon; |
| 4593 | that.mContentIconGravity = this.mContentIconGravity; |
| 4594 | that.mContentActionIndex = this.mContentActionIndex; |
| 4595 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 4596 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 4597 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4598 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4599 | return that; |
| 4600 | } |
| 4601 | |
| 4602 | /** |
| 4603 | * Add a wearable action to this notification. |
| 4604 | * |
| 4605 | * <p>When wearable actions are added using this method, the set of actions that |
| 4606 | * show on a wearable device splits from devices that only show actions added |
| 4607 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 4608 | * of which actions display on different devices. |
| 4609 | * |
| 4610 | * @param action the action to add to this notification |
| 4611 | * @return this object for method chaining |
| 4612 | * @see android.app.Notification.Action |
| 4613 | */ |
| 4614 | public WearableExtender addAction(Action action) { |
| 4615 | mActions.add(action); |
| 4616 | return this; |
| 4617 | } |
| 4618 | |
| 4619 | /** |
| 4620 | * Adds wearable actions to this notification. |
| 4621 | * |
| 4622 | * <p>When wearable actions are added using this method, the set of actions that |
| 4623 | * show on a wearable device splits from devices that only show actions added |
| 4624 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 4625 | * of which actions display on different devices. |
| 4626 | * |
| 4627 | * @param actions the actions to add to this notification |
| 4628 | * @return this object for method chaining |
| 4629 | * @see android.app.Notification.Action |
| 4630 | */ |
| 4631 | public WearableExtender addActions(List<Action> actions) { |
| 4632 | mActions.addAll(actions); |
| 4633 | return this; |
| 4634 | } |
| 4635 | |
| 4636 | /** |
| 4637 | * Clear all wearable actions present on this builder. |
| 4638 | * @return this object for method chaining. |
| 4639 | * @see #addAction |
| 4640 | */ |
| 4641 | public WearableExtender clearActions() { |
| 4642 | mActions.clear(); |
| 4643 | return this; |
| 4644 | } |
| 4645 | |
| 4646 | /** |
| 4647 | * Get the wearable actions present on this notification. |
| 4648 | */ |
| 4649 | public List<Action> getActions() { |
| 4650 | return mActions; |
| 4651 | } |
| 4652 | |
| 4653 | /** |
| 4654 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4655 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 4656 | * |
| 4657 | * <pre class="prettyprint"> |
| 4658 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 4659 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 4660 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 4661 | * Notification notif = new Notification.Builder(context) |
| 4662 | * .extend(new Notification.WearableExtender() |
| 4663 | * .setDisplayIntent(displayPendingIntent) |
| 4664 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 4665 | * .build();</pre> |
| 4666 | * |
| 4667 | * <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] | 4668 | * should have an empty task affinity. It is also recommended to use the device |
| 4669 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4670 | * |
| 4671 | * <p>Example AndroidManifest.xml entry: |
| 4672 | * <pre class="prettyprint"> |
| 4673 | * <activity android:name="com.example.MyDisplayActivity" |
| 4674 | * android:exported="true" |
| 4675 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 4676 | * android:taskAffinity="" |
| 4677 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4678 | * |
| 4679 | * @param intent the {@link PendingIntent} for an activity |
| 4680 | * @return this object for method chaining |
| 4681 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 4682 | */ |
| 4683 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 4684 | mDisplayIntent = intent; |
| 4685 | return this; |
| 4686 | } |
| 4687 | |
| 4688 | /** |
| 4689 | * Get the intent to launch inside of an activity view when displaying this |
| 4690 | * notification. This {@code PendingIntent} should be for an activity. |
| 4691 | */ |
| 4692 | public PendingIntent getDisplayIntent() { |
| 4693 | return mDisplayIntent; |
| 4694 | } |
| 4695 | |
| 4696 | /** |
| 4697 | * Add an additional page of content to display with this notification. The current |
| 4698 | * notification forms the first page, and pages added using this function form |
| 4699 | * subsequent pages. This field can be used to separate a notification into multiple |
| 4700 | * sections. |
| 4701 | * |
| 4702 | * @param page the notification to add as another page |
| 4703 | * @return this object for method chaining |
| 4704 | * @see android.app.Notification.WearableExtender#getPages |
| 4705 | */ |
| 4706 | public WearableExtender addPage(Notification page) { |
| 4707 | mPages.add(page); |
| 4708 | return this; |
| 4709 | } |
| 4710 | |
| 4711 | /** |
| 4712 | * Add additional pages of content to display with this notification. The current |
| 4713 | * notification forms the first page, and pages added using this function form |
| 4714 | * subsequent pages. This field can be used to separate a notification into multiple |
| 4715 | * sections. |
| 4716 | * |
| 4717 | * @param pages a list of notifications |
| 4718 | * @return this object for method chaining |
| 4719 | * @see android.app.Notification.WearableExtender#getPages |
| 4720 | */ |
| 4721 | public WearableExtender addPages(List<Notification> pages) { |
| 4722 | mPages.addAll(pages); |
| 4723 | return this; |
| 4724 | } |
| 4725 | |
| 4726 | /** |
| 4727 | * Clear all additional pages present on this builder. |
| 4728 | * @return this object for method chaining. |
| 4729 | * @see #addPage |
| 4730 | */ |
| 4731 | public WearableExtender clearPages() { |
| 4732 | mPages.clear(); |
| 4733 | return this; |
| 4734 | } |
| 4735 | |
| 4736 | /** |
| 4737 | * Get the array of additional pages of content for displaying this notification. The |
| 4738 | * current notification forms the first page, and elements within this array form |
| 4739 | * subsequent pages. This field can be used to separate a notification into multiple |
| 4740 | * sections. |
| 4741 | * @return the pages for this notification |
| 4742 | */ |
| 4743 | public List<Notification> getPages() { |
| 4744 | return mPages; |
| 4745 | } |
| 4746 | |
| 4747 | /** |
| 4748 | * Set a background image to be displayed behind the notification content. |
| 4749 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 4750 | * will work with any notification style. |
| 4751 | * |
| 4752 | * @param background the background bitmap |
| 4753 | * @return this object for method chaining |
| 4754 | * @see android.app.Notification.WearableExtender#getBackground |
| 4755 | */ |
| 4756 | public WearableExtender setBackground(Bitmap background) { |
| 4757 | mBackground = background; |
| 4758 | return this; |
| 4759 | } |
| 4760 | |
| 4761 | /** |
| 4762 | * Get a background image to be displayed behind the notification content. |
| 4763 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 4764 | * will work with any notification style. |
| 4765 | * |
| 4766 | * @return the background image |
| 4767 | * @see android.app.Notification.WearableExtender#setBackground |
| 4768 | */ |
| 4769 | public Bitmap getBackground() { |
| 4770 | return mBackground; |
| 4771 | } |
| 4772 | |
| 4773 | /** |
| 4774 | * Set an icon that goes with the content of this notification. |
| 4775 | */ |
| 4776 | public WearableExtender setContentIcon(int icon) { |
| 4777 | mContentIcon = icon; |
| 4778 | return this; |
| 4779 | } |
| 4780 | |
| 4781 | /** |
| 4782 | * Get an icon that goes with the content of this notification. |
| 4783 | */ |
| 4784 | public int getContentIcon() { |
| 4785 | return mContentIcon; |
| 4786 | } |
| 4787 | |
| 4788 | /** |
| 4789 | * Set the gravity that the content icon should have within the notification display. |
| 4790 | * Supported values include {@link android.view.Gravity#START} and |
| 4791 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 4792 | * @see #setContentIcon |
| 4793 | */ |
| 4794 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 4795 | mContentIconGravity = contentIconGravity; |
| 4796 | return this; |
| 4797 | } |
| 4798 | |
| 4799 | /** |
| 4800 | * Get the gravity that the content icon should have within the notification display. |
| 4801 | * Supported values include {@link android.view.Gravity#START} and |
| 4802 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 4803 | * @see #getContentIcon |
| 4804 | */ |
| 4805 | public int getContentIconGravity() { |
| 4806 | return mContentIconGravity; |
| 4807 | } |
| 4808 | |
| 4809 | /** |
| 4810 | * 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] | 4811 | * this notification. This action will no longer display separately from the |
| 4812 | * notification's content. |
| 4813 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 4814 | * <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] | 4815 | * set, although the list of available actions comes from the main notification and not |
| 4816 | * from the child page's notification. |
| 4817 | * |
| 4818 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 4819 | * If wearable actions were added to the main notification, this index |
| 4820 | * will apply to that list, otherwise it will apply to the regular |
| 4821 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4822 | */ |
| 4823 | public WearableExtender setContentAction(int actionIndex) { |
| 4824 | mContentActionIndex = actionIndex; |
| 4825 | return this; |
| 4826 | } |
| 4827 | |
| 4828 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 4829 | * Get the index of the notification action, if any, that was specified as being clickable |
| 4830 | * 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] | 4831 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4832 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 4833 | * <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] | 4834 | * set, although the list of available actions comes from the main notification and not |
| 4835 | * from the child page's notification. |
| 4836 | * |
| 4837 | * <p>If wearable specific actions were added to the main notification, this index will |
| 4838 | * 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] | 4839 | * |
| 4840 | * @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] | 4841 | */ |
| 4842 | public int getContentAction() { |
| 4843 | return mContentActionIndex; |
| 4844 | } |
| 4845 | |
| 4846 | /** |
| 4847 | * Set the gravity that this notification should have within the available viewport space. |
| 4848 | * Supported values include {@link android.view.Gravity#TOP}, |
| 4849 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 4850 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 4851 | */ |
| 4852 | public WearableExtender setGravity(int gravity) { |
| 4853 | mGravity = gravity; |
| 4854 | return this; |
| 4855 | } |
| 4856 | |
| 4857 | /** |
| 4858 | * Get the gravity that this notification should have within the available viewport space. |
| 4859 | * Supported values include {@link android.view.Gravity#TOP}, |
| 4860 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 4861 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 4862 | */ |
| 4863 | public int getGravity() { |
| 4864 | return mGravity; |
| 4865 | } |
| 4866 | |
| 4867 | /** |
| 4868 | * Set the custom size preset for the display of this notification out of the available |
| 4869 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 4870 | * {@link #SIZE_LARGE}. |
| 4871 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 4872 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 4873 | * documentation for the preset in question. See also |
| 4874 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 4875 | */ |
| 4876 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 4877 | mCustomSizePreset = sizePreset; |
| 4878 | return this; |
| 4879 | } |
| 4880 | |
| 4881 | /** |
| 4882 | * Get the custom size preset for the display of this notification out of the available |
| 4883 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 4884 | * {@link #SIZE_LARGE}. |
| 4885 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 4886 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 4887 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 4888 | */ |
| 4889 | public int getCustomSizePreset() { |
| 4890 | return mCustomSizePreset; |
| 4891 | } |
| 4892 | |
| 4893 | /** |
| 4894 | * Set the custom height in pixels for the display of this notification's content. |
| 4895 | * <p>This option is only available for custom display notifications created |
| 4896 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 4897 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 4898 | * {@link #getCustomContentHeight}. |
| 4899 | */ |
| 4900 | public WearableExtender setCustomContentHeight(int height) { |
| 4901 | mCustomContentHeight = height; |
| 4902 | return this; |
| 4903 | } |
| 4904 | |
| 4905 | /** |
| 4906 | * Get the custom height in pixels for the display of this notification's content. |
| 4907 | * <p>This option is only available for custom display notifications created |
| 4908 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 4909 | * {@link #setCustomContentHeight}. |
| 4910 | */ |
| 4911 | public int getCustomContentHeight() { |
| 4912 | return mCustomContentHeight; |
| 4913 | } |
| 4914 | |
| 4915 | /** |
| 4916 | * Set whether the scrolling position for the contents of this notification should start |
| 4917 | * at the bottom of the contents instead of the top when the contents are too long to |
| 4918 | * display within the screen. Default is false (start scroll at the top). |
| 4919 | */ |
| 4920 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 4921 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 4922 | return this; |
| 4923 | } |
| 4924 | |
| 4925 | /** |
| 4926 | * Get whether the scrolling position for the contents of this notification should start |
| 4927 | * at the bottom of the contents instead of the top when the contents are too long to |
| 4928 | * display within the screen. Default is false (start scroll at the top). |
| 4929 | */ |
| 4930 | public boolean getStartScrollBottom() { |
| 4931 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 4932 | } |
| 4933 | |
| 4934 | /** |
| 4935 | * Set whether the content intent is available when the wearable device is not connected |
| 4936 | * to a companion device. The user can still trigger this intent when the wearable device |
| 4937 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 4938 | * Defaults to true. |
| 4939 | */ |
| 4940 | public WearableExtender setContentIntentAvailableOffline( |
| 4941 | boolean contentIntentAvailableOffline) { |
| 4942 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 4943 | return this; |
| 4944 | } |
| 4945 | |
| 4946 | /** |
| 4947 | * Get whether the content intent is available when the wearable device is not connected |
| 4948 | * to a companion device. The user can still trigger this intent when the wearable device |
| 4949 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 4950 | * Defaults to true. |
| 4951 | */ |
| 4952 | public boolean getContentIntentAvailableOffline() { |
| 4953 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 4954 | } |
| 4955 | |
| 4956 | /** |
| 4957 | * Set a hint that this notification's icon should not be displayed. |
| 4958 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 4959 | * @return this object for method chaining |
| 4960 | */ |
| 4961 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 4962 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 4963 | return this; |
| 4964 | } |
| 4965 | |
| 4966 | /** |
| 4967 | * Get a hint that this notification's icon should not be displayed. |
| 4968 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 4969 | * The default value is {@code false} if this was never set. |
| 4970 | */ |
| 4971 | public boolean getHintHideIcon() { |
| 4972 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 4973 | } |
| 4974 | |
| 4975 | /** |
| 4976 | * Set a visual hint that only the background image of this notification should be |
| 4977 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 4978 | * to sub-pages added using {@link #addPage}. |
| 4979 | */ |
| 4980 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 4981 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 4982 | return this; |
| 4983 | } |
| 4984 | |
| 4985 | /** |
| 4986 | * Get a visual hint that only the background image of this notification should be |
| 4987 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 4988 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 4989 | */ |
| 4990 | public boolean getHintShowBackgroundOnly() { |
| 4991 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 4992 | } |
| 4993 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4994 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 4995 | * Set a hint that this notification's background should not be clipped if possible, |
| 4996 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 4997 | * 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] | 4998 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 4999 | * @return this object for method chaining |
| 5000 | */ |
| 5001 | public WearableExtender setHintAvoidBackgroundClipping( |
| 5002 | boolean hintAvoidBackgroundClipping) { |
| 5003 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 5004 | return this; |
| 5005 | } |
| 5006 | |
| 5007 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5008 | * Get a hint that this notification's background should not be clipped if possible, |
| 5009 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5010 | * 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] | 5011 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 5012 | * otherwise. The default value is {@code false} if this was never set. |
| 5013 | */ |
| 5014 | public boolean getHintAvoidBackgroundClipping() { |
| 5015 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 5016 | } |
| 5017 | |
| 5018 | /** |
| 5019 | * Set a hint that the screen should remain on for at least this duration when |
| 5020 | * this notification is displayed on the screen. |
| 5021 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 5022 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5023 | * @return this object for method chaining |
| 5024 | */ |
| 5025 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 5026 | mHintScreenTimeout = timeout; |
| 5027 | return this; |
| 5028 | } |
| 5029 | |
| 5030 | /** |
| 5031 | * Get the duration, in milliseconds, that the screen should remain on for |
| 5032 | * when this notification is displayed. |
| 5033 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 5034 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5035 | */ |
| 5036 | public int getHintScreenTimeout() { |
| 5037 | return mHintScreenTimeout; |
| 5038 | } |
| 5039 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5040 | private void setFlag(int mask, boolean value) { |
| 5041 | if (value) { |
| 5042 | mFlags |= mask; |
| 5043 | } else { |
| 5044 | mFlags &= ~mask; |
| 5045 | } |
| 5046 | } |
| 5047 | } |
| 5048 | |
| 5049 | /** |
| 5050 | * Get an array of Notification objects from a parcelable array bundle field. |
| 5051 | * Update the bundle to have a typed array so fetches in the future don't need |
| 5052 | * to do an array copy. |
| 5053 | */ |
| 5054 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 5055 | Parcelable[] array = bundle.getParcelableArray(key); |
| 5056 | if (array instanceof Notification[] || array == null) { |
| 5057 | return (Notification[]) array; |
| 5058 | } |
| 5059 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 5060 | Notification[].class); |
| 5061 | bundle.putParcelableArray(key, typedArray); |
| 5062 | return typedArray; |
| 5063 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5064 | |
| 5065 | private static class BuilderRemoteViews extends RemoteViews { |
| 5066 | public BuilderRemoteViews(Parcel parcel) { |
| 5067 | super(parcel); |
| 5068 | } |
| 5069 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 5070 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 5071 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5072 | } |
| 5073 | |
| 5074 | @Override |
| 5075 | public BuilderRemoteViews clone() { |
| 5076 | Parcel p = Parcel.obtain(); |
| 5077 | writeToParcel(p, 0); |
| 5078 | p.setDataPosition(0); |
| 5079 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 5080 | p.recycle(); |
| 5081 | return brv; |
| 5082 | } |
| 5083 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5084 | } |