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); |
Sean Barbeau | 6ae0b1b | 2014-07-19 21:31:41 -0700 | [diff] [blame] | 1739 | builder.setDeleteIntent(this.deleteIntent); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1740 | |
| 1741 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1742 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1743 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1744 | } |
| 1745 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1746 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1747 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1748 | builder.setContentIntent(contentIntent); |
| 1749 | builder.buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1750 | } |
| 1751 | |
| 1752 | @Override |
| 1753 | public String toString() { |
| 1754 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1755 | sb.append("Notification(pri="); |
| 1756 | sb.append(priority); |
| 1757 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1758 | if (contentView != null) { |
| 1759 | sb.append(contentView.getPackage()); |
| 1760 | sb.append("/0x"); |
| 1761 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 1762 | } else { |
| 1763 | sb.append("null"); |
| 1764 | } |
| 1765 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1766 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 1767 | sb.append("default"); |
| 1768 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1769 | int N = this.vibrate.length-1; |
| 1770 | sb.append("["); |
| 1771 | for (int i=0; i<N; i++) { |
| 1772 | sb.append(this.vibrate[i]); |
| 1773 | sb.append(','); |
| 1774 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 1775 | if (N != -1) { |
| 1776 | sb.append(this.vibrate[N]); |
| 1777 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1778 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1779 | } else { |
| 1780 | sb.append("null"); |
| 1781 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1782 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1783 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1784 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1785 | } else if (this.sound != null) { |
| 1786 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1787 | } else { |
| 1788 | sb.append("null"); |
| 1789 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1790 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1791 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1792 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1793 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1794 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1795 | if (this.category != null) { |
| 1796 | sb.append(" category="); |
| 1797 | sb.append(this.category); |
| 1798 | } |
| 1799 | if (this.mGroupKey != null) { |
| 1800 | sb.append(" groupKey="); |
| 1801 | sb.append(this.mGroupKey); |
| 1802 | } |
| 1803 | if (this.mSortKey != null) { |
| 1804 | sb.append(" sortKey="); |
| 1805 | sb.append(this.mSortKey); |
| 1806 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1807 | if (actions != null) { |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1808 | sb.append(" actions="); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1809 | sb.append(actions.length); |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1810 | } |
| 1811 | sb.append(" vis="); |
| 1812 | sb.append(visibilityToString(this.visibility)); |
| 1813 | if (this.publicVersion != null) { |
| 1814 | sb.append(" publicVersion="); |
| 1815 | sb.append(publicVersion.toString()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1816 | } |
| 1817 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1818 | return sb.toString(); |
| 1819 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1820 | |
Dan Sandler | 1b71878 | 2014-07-18 12:43:45 -0400 | [diff] [blame] | 1821 | /** |
| 1822 | * {@hide} |
| 1823 | */ |
| 1824 | public static String visibilityToString(int vis) { |
| 1825 | switch (vis) { |
| 1826 | case VISIBILITY_PRIVATE: |
| 1827 | return "PRIVATE"; |
| 1828 | case VISIBILITY_PUBLIC: |
| 1829 | return "PUBLIC"; |
| 1830 | case VISIBILITY_SECRET: |
| 1831 | return "SECRET"; |
| 1832 | default: |
| 1833 | return "UNKNOWN(" + String.valueOf(vis) + ")"; |
| 1834 | } |
| 1835 | } |
| 1836 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1837 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1838 | * @hide |
| 1839 | */ |
| 1840 | public boolean isValid() { |
| 1841 | // Would like to check for icon!=0 here, too, but NotificationManagerService accepts that |
| 1842 | // for legacy reasons. |
| 1843 | return contentView != null || extras.getBoolean(Builder.EXTRA_REBUILD_CONTENT_VIEW); |
| 1844 | } |
| 1845 | |
| 1846 | /** |
Christoph Studer | c8db24b | 2014-07-25 17:50:30 +0200 | [diff] [blame] | 1847 | * @hide |
| 1848 | */ |
| 1849 | public boolean isGroupSummary() { |
| 1850 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) != 0; |
| 1851 | } |
| 1852 | |
| 1853 | /** |
| 1854 | * @hide |
| 1855 | */ |
| 1856 | public boolean isGroupChild() { |
| 1857 | return mGroupKey != null && (flags & FLAG_GROUP_SUMMARY) == 0; |
| 1858 | } |
| 1859 | |
| 1860 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1861 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1862 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1863 | * 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] | 1864 | * content views using the platform's notification layout template. If your app supports |
| 1865 | * versions of Android as old as API level 4, you can instead use |
| 1866 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 1867 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 1868 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1869 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1870 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1871 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1872 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1873 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1874 | * .setContentTitle("New mail from " + sender.toString()) |
| 1875 | * .setContentText(subject) |
| 1876 | * .setSmallIcon(R.drawable.new_mail) |
| 1877 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1878 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1879 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1880 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1881 | public static class Builder { |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 1882 | private static final int MAX_ACTION_BUTTONS = 3; |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 1883 | private static final float LARGE_TEXT_SCALE = 1.3f; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1884 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1885 | /** |
| 1886 | * @hide |
| 1887 | */ |
| 1888 | public static final String EXTRA_NEEDS_REBUILD = "android.rebuild"; |
| 1889 | |
| 1890 | /** |
| 1891 | * @hide |
| 1892 | */ |
| 1893 | public static final String EXTRA_REBUILD_LARGE_ICON = "android.rebuild.largeIcon"; |
| 1894 | /** |
| 1895 | * @hide |
| 1896 | */ |
| 1897 | public static final String EXTRA_REBUILD_CONTENT_VIEW = "android.rebuild.contentView"; |
| 1898 | /** |
| 1899 | * @hide |
| 1900 | */ |
| 1901 | public static final String EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT = |
| 1902 | "android.rebuild.contentViewActionCount"; |
| 1903 | /** |
| 1904 | * @hide |
| 1905 | */ |
| 1906 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW |
| 1907 | = "android.rebuild.bigView"; |
| 1908 | /** |
| 1909 | * @hide |
| 1910 | */ |
| 1911 | public static final String EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT |
| 1912 | = "android.rebuild.bigViewActionCount"; |
| 1913 | /** |
| 1914 | * @hide |
| 1915 | */ |
| 1916 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW |
| 1917 | = "android.rebuild.hudView"; |
| 1918 | /** |
| 1919 | * @hide |
| 1920 | */ |
| 1921 | public static final String EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT |
| 1922 | = "android.rebuild.hudViewActionCount"; |
| 1923 | |
| 1924 | /** |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 1925 | * The ApplicationInfo of the package that created the notification, used to create |
| 1926 | * a context to rebuild the notification via a Builder. |
| 1927 | * @hide |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1928 | */ |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 1929 | private static final String EXTRA_REBUILD_CONTEXT_APPLICATION_INFO = |
| 1930 | "android.rebuild.applicationInfo"; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1931 | |
| 1932 | // Whether to enable stripping (at post time) & rebuilding (at listener receive time) of |
| 1933 | // memory intensive resources. |
| 1934 | private static final boolean STRIP_AND_REBUILD = true; |
| 1935 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1936 | private Context mContext; |
| 1937 | |
| 1938 | private long mWhen; |
| 1939 | private int mSmallIcon; |
| 1940 | private int mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1941 | private int mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1942 | private CharSequence mContentTitle; |
| 1943 | private CharSequence mContentText; |
| 1944 | private CharSequence mContentInfo; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1945 | private CharSequence mSubText; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1946 | private PendingIntent mContentIntent; |
| 1947 | private RemoteViews mContentView; |
| 1948 | private PendingIntent mDeleteIntent; |
| 1949 | private PendingIntent mFullScreenIntent; |
| 1950 | private CharSequence mTickerText; |
| 1951 | private RemoteViews mTickerView; |
| 1952 | private Bitmap mLargeIcon; |
| 1953 | private Uri mSound; |
| 1954 | private int mAudioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 1955 | private AudioAttributes mAudioAttributes; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1956 | private long[] mVibrate; |
| 1957 | private int mLedArgb; |
| 1958 | private int mLedOnMs; |
| 1959 | private int mLedOffMs; |
| 1960 | private int mDefaults; |
| 1961 | private int mFlags; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1962 | private int mProgressMax; |
| 1963 | private int mProgress; |
| 1964 | private boolean mProgressIndeterminate; |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1965 | private String mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1966 | private String mGroupKey; |
| 1967 | private String mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1968 | private Bundle mExtras; |
| 1969 | private int mPriority; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1970 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1971 | private boolean mUseChronometer; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1972 | private Style mStyle; |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1973 | private boolean mShowWhen = true; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1974 | private int mVisibility = VISIBILITY_PRIVATE; |
| 1975 | private Notification mPublicVersion = null; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1976 | private final NotificationColorUtil mColorUtil; |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 1977 | private ArrayList<String> mPeople; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1978 | private int mColor = COLOR_DEFAULT; |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 1979 | |
| 1980 | /** |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 1981 | * The user that built the notification originally. |
| 1982 | */ |
| 1983 | private int mOriginatingUserId; |
| 1984 | |
| 1985 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 1986 | * Contains extras related to rebuilding during the build phase. |
| 1987 | */ |
| 1988 | private Bundle mRebuildBundle = new Bundle(); |
| 1989 | /** |
| 1990 | * Contains the notification to rebuild when this Builder is in "rebuild" mode. |
| 1991 | * Null otherwise. |
| 1992 | */ |
| 1993 | private Notification mRebuildNotification = null; |
| 1994 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1995 | /** |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 1996 | * Whether the build notification has three lines. This is used to make the top padding for |
| 1997 | * both the contracted and expanded layout consistent. |
| 1998 | * |
| 1999 | * <p> |
| 2000 | * This field is only valid during the build phase. |
| 2001 | */ |
| 2002 | private boolean mHasThreeLines; |
| 2003 | |
| 2004 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2005 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2006 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2007 | |
| 2008 | * <table> |
| 2009 | * <tr><th align=right>priority</th> |
| 2010 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 2011 | * <tr><th align=right>when</th> |
| 2012 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 2013 | * <tr><th align=right>audio stream</th> |
| 2014 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 2015 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2016 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2017 | |
| 2018 | * @param context |
| 2019 | * A {@link Context} that will be used by the Builder to construct the |
| 2020 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 2021 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2022 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2023 | public Builder(Context context) { |
Adam Powell | bf06fa0 | 2014-05-30 12:32:18 -0700 | [diff] [blame] | 2024 | /* |
| 2025 | * Important compatibility note! |
| 2026 | * Some apps out in the wild create a Notification.Builder in their Activity subclass |
| 2027 | * constructor for later use. At this point Activities - themselves subclasses of |
| 2028 | * ContextWrapper - do not have their inner Context populated yet. This means that |
| 2029 | * any calls to Context methods from within this constructor can cause NPEs in existing |
| 2030 | * apps. Any data populated from mContext should therefore be populated lazily to |
| 2031 | * preserve compatibility. |
| 2032 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2033 | mContext = context; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2034 | |
| 2035 | // Set defaults to match the defaults of a Notification |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2036 | mWhen = System.currentTimeMillis(); |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 2037 | mAudioStreamType = STREAM_DEFAULT; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2038 | mAudioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2039 | mPriority = PRIORITY_DEFAULT; |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2040 | mPeople = new ArrayList<String>(); |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2041 | |
Dianne Hackborn | 955d8d6 | 2014-10-07 20:17:19 -0700 | [diff] [blame] | 2042 | mColorUtil = context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.LOLLIPOP ? |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 2043 | NotificationColorUtil.getInstance(mContext) : null; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2044 | } |
| 2045 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2046 | /** |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 2047 | * Creates a Builder for rebuilding the given Notification. |
| 2048 | * <p> |
| 2049 | * Call {@link #rebuild()} to retrieve the rebuilt version of 'n'. |
| 2050 | */ |
| 2051 | private Builder(Context context, Notification n) { |
| 2052 | this(context); |
| 2053 | mRebuildNotification = n; |
| 2054 | restoreFromNotification(n); |
| 2055 | |
| 2056 | Style style = null; |
| 2057 | Bundle extras = n.extras; |
| 2058 | String templateClass = extras.getString(EXTRA_TEMPLATE); |
| 2059 | if (!TextUtils.isEmpty(templateClass)) { |
| 2060 | Class<? extends Style> styleClass = getNotificationStyleClass(templateClass); |
| 2061 | if (styleClass == null) { |
| 2062 | Log.d(TAG, "Unknown style class: " + styleClass); |
| 2063 | return; |
| 2064 | } |
| 2065 | |
| 2066 | try { |
| 2067 | Constructor<? extends Style> constructor = styleClass.getConstructor(); |
| 2068 | style = constructor.newInstance(); |
| 2069 | style.restoreFromExtras(extras); |
| 2070 | } catch (Throwable t) { |
| 2071 | Log.e(TAG, "Could not create Style", t); |
| 2072 | return; |
| 2073 | } |
| 2074 | } |
| 2075 | if (style != null) { |
| 2076 | setStyle(style); |
| 2077 | } |
| 2078 | } |
| 2079 | |
| 2080 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2081 | * 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] | 2082 | * It will be shown in the notification content view by default; use |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2083 | * {@link #setShowWhen(boolean) setShowWhen} to control this. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2084 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2085 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2086 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2087 | public Builder setWhen(long when) { |
| 2088 | mWhen = when; |
| 2089 | return this; |
| 2090 | } |
| 2091 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2092 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 2093 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2094 | * in the content view. |
| 2095 | */ |
| 2096 | public Builder setShowWhen(boolean show) { |
| 2097 | mShowWhen = show; |
| 2098 | return this; |
| 2099 | } |
| 2100 | |
| 2101 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2102 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2103 | * |
| 2104 | * 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] | 2105 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2106 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 2107 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 2108 | * |
| 2109 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2110 | * @see Notification#when |
| 2111 | */ |
| 2112 | public Builder setUsesChronometer(boolean b) { |
| 2113 | mUseChronometer = b; |
| 2114 | return this; |
| 2115 | } |
| 2116 | |
| 2117 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2118 | * Set the small icon resource, which will be used to represent the notification in the |
| 2119 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2120 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2121 | |
| 2122 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 2123 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 2124 | * icon will be moved to the right-hand side. |
| 2125 | * |
| 2126 | |
| 2127 | * @param icon |
| 2128 | * A resource ID in the application's package of the drawable to use. |
| 2129 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2130 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2131 | public Builder setSmallIcon(int icon) { |
| 2132 | mSmallIcon = icon; |
| 2133 | return this; |
| 2134 | } |
| 2135 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2136 | /** |
| 2137 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 2138 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 2139 | * LevelListDrawable}. |
| 2140 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2141 | * @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] | 2142 | * @param level The level to use for the icon. |
| 2143 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2144 | * @see Notification#icon |
| 2145 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2146 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2147 | public Builder setSmallIcon(int icon, int level) { |
| 2148 | mSmallIcon = icon; |
| 2149 | mSmallIconLevel = level; |
| 2150 | return this; |
| 2151 | } |
| 2152 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2153 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2154 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2155 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2156 | public Builder setContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2157 | mContentTitle = safeCharSequence(title); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2158 | return this; |
| 2159 | } |
| 2160 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2161 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2162 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2163 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2164 | public Builder setContentText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2165 | mContentText = safeCharSequence(text); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2166 | return this; |
| 2167 | } |
| 2168 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2169 | /** |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2170 | * Set the third line of text in the platform notification template. |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2171 | * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the |
| 2172 | * same location in the standard template. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2173 | */ |
| 2174 | public Builder setSubText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2175 | mSubText = safeCharSequence(text); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2176 | return this; |
| 2177 | } |
| 2178 | |
| 2179 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2180 | * Set the large number at the right-hand side of the notification. This is |
| 2181 | * equivalent to setContentInfo, although it might show the number in a different |
| 2182 | * font size for readability. |
| 2183 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2184 | public Builder setNumber(int number) { |
| 2185 | mNumber = number; |
| 2186 | return this; |
| 2187 | } |
| 2188 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2189 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2190 | * A small piece of additional information pertaining to this notification. |
| 2191 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2192 | * The platform template will draw this on the last line of the notification, at the far |
| 2193 | * 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] | 2194 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2195 | public Builder setContentInfo(CharSequence info) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2196 | mContentInfo = safeCharSequence(info); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2197 | return this; |
| 2198 | } |
| 2199 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2200 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2201 | * Set the progress this notification represents. |
| 2202 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2203 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2204 | */ |
| 2205 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 2206 | mProgressMax = max; |
| 2207 | mProgress = progress; |
| 2208 | mProgressIndeterminate = indeterminate; |
| 2209 | return this; |
| 2210 | } |
| 2211 | |
| 2212 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2213 | * Supply a custom RemoteViews to use instead of the platform template. |
| 2214 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2215 | * @see Notification#contentView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2216 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2217 | public Builder setContent(RemoteViews views) { |
| 2218 | mContentView = views; |
| 2219 | return this; |
| 2220 | } |
| 2221 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2222 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2223 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 2224 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2225 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 2226 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 2227 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2228 | * 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] | 2229 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2230 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2231 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2232 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2233 | public Builder setContentIntent(PendingIntent intent) { |
| 2234 | mContentIntent = intent; |
| 2235 | return this; |
| 2236 | } |
| 2237 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2238 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2239 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 2240 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2241 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2242 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2243 | public Builder setDeleteIntent(PendingIntent intent) { |
| 2244 | mDeleteIntent = intent; |
| 2245 | return this; |
| 2246 | } |
| 2247 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2248 | /** |
| 2249 | * An intent to launch instead of posting the notification to the status bar. |
| 2250 | * Only for use with extremely high-priority notifications demanding the user's |
| 2251 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 2252 | * alarm clock that the user has explicitly set to a particular time. |
| 2253 | * If this facility is used for something else, please give the user an option |
| 2254 | * to turn it off and use a normal notification, as this can be extremely |
| 2255 | * disruptive. |
| 2256 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2257 | * <p> |
| 2258 | * The system UI may choose to display a heads-up notification, instead of |
| 2259 | * launching this intent, while the user is using the device. |
| 2260 | * </p> |
| 2261 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2262 | * @param intent The pending intent to launch. |
| 2263 | * @param highPriority Passing true will cause this notification to be sent |
| 2264 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2265 | * |
| 2266 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2267 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2268 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 2269 | mFullScreenIntent = intent; |
| 2270 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 2271 | return this; |
| 2272 | } |
| 2273 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2274 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2275 | * Set the "ticker" text which is sent to accessibility services. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2276 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2277 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2278 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2279 | public Builder setTicker(CharSequence tickerText) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2280 | mTickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2281 | return this; |
| 2282 | } |
| 2283 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2284 | /** |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2285 | * Obsolete version of {@link #setTicker(CharSequence)}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2286 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2287 | */ |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2288 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2289 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2290 | mTickerText = safeCharSequence(tickerText); |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 2291 | mTickerView = views; // we'll save it for you anyway |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2292 | return this; |
| 2293 | } |
| 2294 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2295 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2296 | * Add a large icon to the notification (and the ticker on some devices). |
| 2297 | * |
| 2298 | * In the platform template, this image will be shown on the left of the notification view |
| 2299 | * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side). |
| 2300 | * |
| 2301 | * @see Notification#largeIcon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2302 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2303 | public Builder setLargeIcon(Bitmap icon) { |
| 2304 | mLargeIcon = icon; |
| 2305 | return this; |
| 2306 | } |
| 2307 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2308 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2309 | * Set the sound to play. |
| 2310 | * |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2311 | * It will be played using the {@link #AUDIO_ATTRIBUTES_DEFAULT default audio attributes} |
| 2312 | * for notifications. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2313 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2314 | * <p> |
| 2315 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2316 | * </p> |
| 2317 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2318 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2319 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2320 | public Builder setSound(Uri sound) { |
| 2321 | mSound = sound; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2322 | mAudioAttributes = AUDIO_ATTRIBUTES_DEFAULT; |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 2323 | return this; |
| 2324 | } |
| 2325 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2326 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2327 | * 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] | 2328 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2329 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 2330 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2331 | * <p> |
| 2332 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2333 | * </p> |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2334 | * @deprecated use {@link #setSound(Uri, AudioAttributes)} instead. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2335 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2336 | */ |
Jean-Michel Trivi | 81f871e | 2014-08-06 16:32:38 -0700 | [diff] [blame] | 2337 | @Deprecated |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2338 | public Builder setSound(Uri sound, int streamType) { |
| 2339 | mSound = sound; |
| 2340 | mAudioStreamType = streamType; |
| 2341 | return this; |
| 2342 | } |
| 2343 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2344 | /** |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 2345 | * Set the sound to play, along with specific {@link AudioAttributes audio attributes} to |
| 2346 | * use during playback. |
| 2347 | * |
| 2348 | * <p> |
| 2349 | * A notification that is noisy is more likely to be presented as a heads-up notification. |
| 2350 | * </p> |
| 2351 | * |
| 2352 | * @see Notification#sound |
| 2353 | */ |
| 2354 | public Builder setSound(Uri sound, AudioAttributes audioAttributes) { |
| 2355 | mSound = sound; |
| 2356 | mAudioAttributes = audioAttributes; |
| 2357 | return this; |
| 2358 | } |
| 2359 | |
| 2360 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2361 | * Set the vibration pattern to use. |
| 2362 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2363 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 2364 | * <code>pattern</code> parameter. |
| 2365 | * |
Chris Wren | 47c20a1 | 2014-06-18 17:27:29 -0400 | [diff] [blame] | 2366 | * <p> |
| 2367 | * A notification that vibrates is more likely to be presented as a heads-up notification. |
| 2368 | * </p> |
| 2369 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2370 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2371 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2372 | public Builder setVibrate(long[] pattern) { |
| 2373 | mVibrate = pattern; |
| 2374 | return this; |
| 2375 | } |
| 2376 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2377 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2378 | * Set the desired color for the indicator LED on the device, as well as the |
| 2379 | * blink duty cycle (specified in milliseconds). |
| 2380 | * |
| 2381 | |
| 2382 | * Not all devices will honor all (or even any) of these values. |
| 2383 | * |
| 2384 | |
| 2385 | * @see Notification#ledARGB |
| 2386 | * @see Notification#ledOnMS |
| 2387 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2388 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2389 | public Builder setLights(int argb, int onMs, int offMs) { |
| 2390 | mLedArgb = argb; |
| 2391 | mLedOnMs = onMs; |
| 2392 | mLedOffMs = offMs; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2393 | return this; |
| 2394 | } |
| 2395 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2396 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2397 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2398 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2399 | |
| 2400 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 2401 | * must take care of canceling them. |
| 2402 | * |
| 2403 | |
| 2404 | * They are typically used to indicate a background task that the user is actively engaged |
| 2405 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 2406 | * (e.g., a file download, sync operation, active network connection). |
| 2407 | * |
| 2408 | |
| 2409 | * @see Notification#FLAG_ONGOING_EVENT |
| 2410 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2411 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2412 | public Builder setOngoing(boolean ongoing) { |
| 2413 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 2414 | return this; |
| 2415 | } |
| 2416 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2417 | /** |
| 2418 | * Set this flag if you would only like the sound, vibrate |
| 2419 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2420 | * |
| 2421 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2422 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2423 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 2424 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 2425 | return this; |
| 2426 | } |
| 2427 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2428 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2429 | * Make this notification automatically dismissed when the user touches it. The |
| 2430 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 2431 | * |
| 2432 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2433 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2434 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 2435 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2436 | return this; |
| 2437 | } |
| 2438 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2439 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2440 | * Set whether or not this notification should not bridge to other devices. |
| 2441 | * |
| 2442 | * <p>Some notifications can be bridged to other devices for remote display. |
| 2443 | * This hint can be set to recommend this notification not be bridged. |
| 2444 | */ |
| 2445 | public Builder setLocalOnly(boolean localOnly) { |
| 2446 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 2447 | return this; |
| 2448 | } |
| 2449 | |
| 2450 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2451 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2452 | * <p> |
| 2453 | * The value should be one or more of the following fields combined with |
| 2454 | * bitwise-or: |
| 2455 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 2456 | * <p> |
| 2457 | * For all default values, use {@link #DEFAULT_ALL}. |
| 2458 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2459 | public Builder setDefaults(int defaults) { |
| 2460 | mDefaults = defaults; |
| 2461 | return this; |
| 2462 | } |
| 2463 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2464 | /** |
| 2465 | * Set the priority of this notification. |
| 2466 | * |
| 2467 | * @see Notification#priority |
| 2468 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2469 | public Builder setPriority(@Priority int pri) { |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2470 | mPriority = pri; |
| 2471 | return this; |
| 2472 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2473 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2474 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2475 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2476 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2477 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2478 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2479 | public Builder setCategory(String category) { |
| 2480 | mCategory = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2481 | return this; |
| 2482 | } |
| 2483 | |
| 2484 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2485 | * Add a person that is relevant to this notification. |
| 2486 | * |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2487 | * <P> |
| 2488 | * Depending on user preferences, this annotation may allow the notification to pass |
| 2489 | * through interruption filters, and to appear more prominently in the user interface. |
| 2490 | * </P> |
| 2491 | * |
| 2492 | * <P> |
| 2493 | * The person should be specified by the {@code String} representation of a |
| 2494 | * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. |
| 2495 | * </P> |
| 2496 | * |
| 2497 | * <P>The system will also attempt to resolve {@code mailto:} and {@code tel:} schema |
| 2498 | * URIs. The path part of these URIs must exist in the contacts database, in the |
| 2499 | * appropriate column, or the reference will be discarded as invalid. Telephone schema |
| 2500 | * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. |
| 2501 | * </P> |
| 2502 | * |
| 2503 | * @param uri A URI for the person. |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2504 | * @see Notification#EXTRA_PEOPLE |
| 2505 | */ |
Chris Wren | e6c4893 | 2014-09-29 17:19:27 -0400 | [diff] [blame] | 2506 | public Builder addPerson(String uri) { |
| 2507 | mPeople.add(uri); |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2508 | return this; |
| 2509 | } |
| 2510 | |
| 2511 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2512 | * Set this notification to be part of a group of notifications sharing the same key. |
| 2513 | * Grouped notifications may display in a cluster or stack on devices which |
| 2514 | * support such rendering. |
| 2515 | * |
| 2516 | * <p>To make this notification the summary for its group, also call |
| 2517 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 2518 | * {@link #setSortKey}. |
| 2519 | * @param groupKey The group key of the group. |
| 2520 | * @return this object for method chaining |
| 2521 | */ |
| 2522 | public Builder setGroup(String groupKey) { |
| 2523 | mGroupKey = groupKey; |
| 2524 | return this; |
| 2525 | } |
| 2526 | |
| 2527 | /** |
| 2528 | * Set this notification to be the group summary for a group of notifications. |
| 2529 | * Grouped notifications may display in a cluster or stack on devices which |
| 2530 | * support such rendering. Requires a group key also be set using {@link #setGroup}. |
| 2531 | * @param isGroupSummary Whether this notification should be a group summary. |
| 2532 | * @return this object for method chaining |
| 2533 | */ |
| 2534 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 2535 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 2536 | return this; |
| 2537 | } |
| 2538 | |
| 2539 | /** |
| 2540 | * Set a sort key that orders this notification among other notifications from the |
| 2541 | * same package. This can be useful if an external sort was already applied and an app |
| 2542 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 2543 | * value, although providing different priorities in addition to providing sort key may |
| 2544 | * cause this value to be ignored. |
| 2545 | * |
| 2546 | * <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] | 2547 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2548 | * |
| 2549 | * @see String#compareTo(String) |
| 2550 | */ |
| 2551 | public Builder setSortKey(String sortKey) { |
| 2552 | mSortKey = sortKey; |
| 2553 | return this; |
| 2554 | } |
| 2555 | |
| 2556 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2557 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2558 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2559 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 2560 | * |
| 2561 | * @see Notification#extras |
| 2562 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2563 | public Builder addExtras(Bundle extras) { |
| 2564 | if (extras != null) { |
| 2565 | if (mExtras == null) { |
| 2566 | mExtras = new Bundle(extras); |
| 2567 | } else { |
| 2568 | mExtras.putAll(extras); |
| 2569 | } |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2570 | } |
| 2571 | return this; |
| 2572 | } |
| 2573 | |
| 2574 | /** |
| 2575 | * Set metadata for this notification. |
| 2576 | * |
| 2577 | * <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] | 2578 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2579 | * called. |
| 2580 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2581 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 2582 | * Use {@link #addExtras} to merge in metadata instead. |
| 2583 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2584 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2585 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2586 | public Builder setExtras(Bundle extras) { |
| 2587 | mExtras = extras; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2588 | return this; |
| 2589 | } |
| 2590 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2591 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2592 | * Get the current metadata Bundle used by this notification Builder. |
| 2593 | * |
| 2594 | * <p>The returned Bundle is shared with this Builder. |
| 2595 | * |
| 2596 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 2597 | * {@link #build()} is called. |
| 2598 | * |
| 2599 | * @see Notification#extras |
| 2600 | */ |
| 2601 | public Bundle getExtras() { |
| 2602 | if (mExtras == null) { |
| 2603 | mExtras = new Bundle(); |
| 2604 | } |
| 2605 | return mExtras; |
| 2606 | } |
| 2607 | |
| 2608 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2609 | * Add an action to this notification. Actions are typically displayed by |
| 2610 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2611 | * <p> |
| 2612 | * Every action must have an icon (32dp square and matching the |
| 2613 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2614 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2615 | * <p> |
| 2616 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2617 | * the order they were added. Actions will not be displayed when the notification is |
| 2618 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2619 | * 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] | 2620 | * |
| 2621 | * @param icon Resource ID of a drawable that represents the action. |
| 2622 | * @param title Text describing the action. |
| 2623 | * @param intent PendingIntent to be fired when the action is invoked. |
| 2624 | */ |
| 2625 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2626 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2627 | return this; |
| 2628 | } |
| 2629 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2630 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2631 | * Add an action to this notification. Actions are typically displayed by |
| 2632 | * the system as a button adjacent to the notification content. |
| 2633 | * <p> |
| 2634 | * Every action must have an icon (32dp square and matching the |
| 2635 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2636 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2637 | * <p> |
| 2638 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2639 | * the order they were added. Actions will not be displayed when the notification is |
| 2640 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2641 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 2642 | * |
| 2643 | * @param action The action to add. |
| 2644 | */ |
| 2645 | public Builder addAction(Action action) { |
| 2646 | mActions.add(action); |
| 2647 | return this; |
| 2648 | } |
| 2649 | |
| 2650 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2651 | * Add a rich notification style to be applied at build time. |
| 2652 | * |
| 2653 | * @param style Object responsible for modifying the notification style. |
| 2654 | */ |
| 2655 | public Builder setStyle(Style style) { |
| 2656 | if (mStyle != style) { |
| 2657 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2658 | if (mStyle != null) { |
| 2659 | mStyle.setBuilder(this); |
| 2660 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2661 | } |
| 2662 | return this; |
| 2663 | } |
| 2664 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2665 | /** |
| 2666 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2667 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2668 | * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), |
| 2669 | * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. |
| 2670 | * |
| 2671 | * @return The same Builder. |
| 2672 | */ |
| 2673 | public Builder setVisibility(int visibility) { |
| 2674 | mVisibility = visibility; |
| 2675 | return this; |
| 2676 | } |
| 2677 | |
| 2678 | /** |
| 2679 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 2680 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 2681 | * @param n A replacement notification, presumably with some or all info redacted. |
| 2682 | * @return The same Builder. |
| 2683 | */ |
| 2684 | public Builder setPublicVersion(Notification n) { |
| 2685 | mPublicVersion = n; |
| 2686 | return this; |
| 2687 | } |
| 2688 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2689 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2690 | * Apply an extender to this notification builder. Extenders may be used to add |
| 2691 | * metadata or change options on this builder. |
| 2692 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2693 | public Builder extend(Extender extender) { |
| 2694 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2695 | return this; |
| 2696 | } |
| 2697 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2698 | private void setFlag(int mask, boolean value) { |
| 2699 | if (value) { |
| 2700 | mFlags |= mask; |
| 2701 | } else { |
| 2702 | mFlags &= ~mask; |
| 2703 | } |
| 2704 | } |
| 2705 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2706 | /** |
| 2707 | * Sets {@link Notification#color}. |
| 2708 | * |
| 2709 | * @param argb The accent color to use |
| 2710 | * |
| 2711 | * @return The same Builder. |
| 2712 | */ |
| 2713 | public Builder setColor(int argb) { |
| 2714 | mColor = argb; |
| 2715 | return this; |
| 2716 | } |
| 2717 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2718 | private Drawable getProfileBadgeDrawable() { |
Christoph Studer | 7ac80e6 | 2014-08-04 16:01:57 +0200 | [diff] [blame] | 2719 | // Note: This assumes that the current user can read the profile badge of the |
| 2720 | // originating user. |
Svetoslav | c7d62f0 | 2014-09-04 15:39:54 -0700 | [diff] [blame] | 2721 | return mContext.getPackageManager().getUserBadgeForDensity( |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 2722 | new UserHandle(mOriginatingUserId), 0); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2723 | } |
| 2724 | |
| 2725 | private Bitmap getProfileBadge() { |
| 2726 | Drawable badge = getProfileBadgeDrawable(); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2727 | if (badge == null) { |
| 2728 | return null; |
| 2729 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2730 | final int size = mContext.getResources().getDimensionPixelSize( |
| 2731 | R.dimen.notification_badge_size); |
| 2732 | Bitmap bitmap = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2733 | Canvas canvas = new Canvas(bitmap); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2734 | badge.setBounds(0, 0, size, size); |
Kenny Guy | 8a0101b | 2014-05-08 23:34:12 +0100 | [diff] [blame] | 2735 | badge.draw(canvas); |
| 2736 | return bitmap; |
| 2737 | } |
| 2738 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2739 | private boolean addProfileBadge(RemoteViews contentView, int resId) { |
| 2740 | Bitmap profileBadge = getProfileBadge(); |
| 2741 | |
| 2742 | contentView.setViewVisibility(R.id.profile_badge_large_template, View.GONE); |
| 2743 | contentView.setViewVisibility(R.id.profile_badge_line2, View.GONE); |
| 2744 | contentView.setViewVisibility(R.id.profile_badge_line3, View.GONE); |
| 2745 | |
| 2746 | if (profileBadge != null) { |
| 2747 | contentView.setImageViewBitmap(resId, profileBadge); |
| 2748 | contentView.setViewVisibility(resId, View.VISIBLE); |
| 2749 | |
| 2750 | // Make sure Line 3 is visible. As badge will be here if there |
| 2751 | // is no text to display. |
| 2752 | if (resId == R.id.profile_badge_line3) { |
| 2753 | contentView.setViewVisibility(R.id.line3, View.VISIBLE); |
| 2754 | } |
| 2755 | return true; |
| 2756 | } |
| 2757 | return false; |
| 2758 | } |
| 2759 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2760 | private void shrinkLine3Text(RemoteViews contentView) { |
| 2761 | float subTextSize = mContext.getResources().getDimensionPixelSize( |
| 2762 | R.dimen.notification_subtext_size); |
| 2763 | contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); |
| 2764 | } |
| 2765 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2766 | private void unshrinkLine3Text(RemoteViews contentView) { |
| 2767 | float regularTextSize = mContext.getResources().getDimensionPixelSize( |
| 2768 | com.android.internal.R.dimen.notification_text_size); |
| 2769 | contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, regularTextSize); |
| 2770 | } |
| 2771 | |
| 2772 | private void resetStandardTemplate(RemoteViews contentView) { |
| 2773 | removeLargeIconBackground(contentView); |
| 2774 | contentView.setViewPadding(R.id.icon, 0, 0, 0, 0); |
| 2775 | contentView.setImageViewResource(R.id.icon, 0); |
| 2776 | contentView.setInt(R.id.icon, "setBackgroundResource", 0); |
| 2777 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
| 2778 | contentView.setInt(R.id.right_icon, "setBackgroundResource", 0); |
| 2779 | contentView.setImageViewResource(R.id.right_icon, 0); |
| 2780 | contentView.setImageViewResource(R.id.icon, 0); |
| 2781 | contentView.setTextViewText(R.id.title, null); |
| 2782 | contentView.setTextViewText(R.id.text, null); |
| 2783 | unshrinkLine3Text(contentView); |
| 2784 | contentView.setTextViewText(R.id.text2, null); |
| 2785 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2786 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 2787 | contentView.setViewVisibility(R.id.time, View.GONE); |
| 2788 | contentView.setViewVisibility(R.id.line3, View.GONE); |
| 2789 | contentView.setViewVisibility(R.id.overflow_divider, View.GONE); |
| 2790 | contentView.setViewVisibility(R.id.progress, View.GONE); |
Christoph Studer | ca1db71 | 2014-09-10 17:31:33 +0200 | [diff] [blame] | 2791 | contentView.setViewVisibility(R.id.chronometer, View.GONE); |
| 2792 | contentView.setViewVisibility(R.id.time, View.GONE); |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2793 | } |
| 2794 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2795 | private RemoteViews applyStandardTemplate(int resId) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2796 | return applyStandardTemplate(resId, true /* hasProgress */); |
| 2797 | } |
| 2798 | |
| 2799 | /** |
| 2800 | * @param hasProgress whether the progress bar should be shown and set |
| 2801 | */ |
| 2802 | private RemoteViews applyStandardTemplate(int resId, boolean hasProgress) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 2803 | RemoteViews contentView = new BuilderRemoteViews(mContext.getApplicationInfo(), resId); |
Dan Sandler | 539aad4 | 2014-08-04 00:43:39 -0400 | [diff] [blame] | 2804 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2805 | resetStandardTemplate(contentView); |
| 2806 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2807 | boolean showLine3 = false; |
| 2808 | boolean showLine2 = false; |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2809 | boolean contentTextInLine2 = false; |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2810 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2811 | if (mLargeIcon != null) { |
| 2812 | contentView.setImageViewBitmap(R.id.icon, mLargeIcon); |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 2813 | processLargeLegacyIcon(mLargeIcon, contentView); |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2814 | contentView.setImageViewResource(R.id.right_icon, mSmallIcon); |
| 2815 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 2816 | processSmallRightIcon(mSmallIcon, contentView); |
| 2817 | } else { // small icon at left |
| 2818 | contentView.setImageViewResource(R.id.icon, mSmallIcon); |
| 2819 | contentView.setViewVisibility(R.id.icon, View.VISIBLE); |
| 2820 | processSmallIconAsLarge(mSmallIcon, contentView); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2821 | } |
| 2822 | if (mContentTitle != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2823 | contentView.setTextViewText(R.id.title, processLegacyText(mContentTitle)); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2824 | } |
| 2825 | if (mContentText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2826 | contentView.setTextViewText(R.id.text, processLegacyText(mContentText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2827 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2828 | } |
| 2829 | if (mContentInfo != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2830 | contentView.setTextViewText(R.id.info, processLegacyText(mContentInfo)); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2831 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2832 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2833 | } else if (mNumber > 0) { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 2834 | final int tooBig = mContext.getResources().getInteger( |
| 2835 | R.integer.status_bar_notification_info_maxnum); |
| 2836 | if (mNumber > tooBig) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2837 | contentView.setTextViewText(R.id.info, processLegacyText( |
| 2838 | mContext.getResources().getString( |
| 2839 | R.string.status_bar_notification_info_overflow))); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 2840 | } else { |
| 2841 | NumberFormat f = NumberFormat.getIntegerInstance(); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2842 | contentView.setTextViewText(R.id.info, processLegacyText(f.format(mNumber))); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 2843 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2844 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2845 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2846 | } else { |
| 2847 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 2848 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2849 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2850 | // Need to show three lines? |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2851 | if (mSubText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2852 | contentView.setTextViewText(R.id.text, processLegacyText(mSubText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2853 | if (mContentText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2854 | contentView.setTextViewText(R.id.text2, processLegacyText(mContentText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2855 | contentView.setViewVisibility(R.id.text2, View.VISIBLE); |
| 2856 | showLine2 = true; |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2857 | contentTextInLine2 = true; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2858 | } else { |
| 2859 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2860 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2861 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2862 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2863 | if (hasProgress && (mProgressMax != 0 || mProgressIndeterminate)) { |
Christoph Studer | aca4b25 | 2014-09-09 15:58:41 +0200 | [diff] [blame] | 2864 | contentView.setViewVisibility(R.id.progress, View.VISIBLE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2865 | contentView.setProgressBar( |
| 2866 | R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); |
Jorim Jaggi | ef72a19 | 2014-08-26 21:57:46 +0200 | [diff] [blame] | 2867 | contentView.setProgressBackgroundTintList( |
| 2868 | R.id.progress, ColorStateList.valueOf(mContext.getResources().getColor( |
| 2869 | R.color.notification_progress_background_color))); |
| 2870 | if (mColor != COLOR_DEFAULT) { |
| 2871 | ColorStateList colorStateList = ColorStateList.valueOf(mColor); |
| 2872 | contentView.setProgressTintList(R.id.progress, colorStateList); |
| 2873 | contentView.setProgressIndeterminateTintList(R.id.progress, colorStateList); |
| 2874 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2875 | showLine2 = true; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2876 | } else { |
| 2877 | contentView.setViewVisibility(R.id.progress, View.GONE); |
| 2878 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2879 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2880 | if (showLine2) { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2881 | |
| 2882 | // need to shrink all the type to make sure everything fits |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2883 | shrinkLine3Text(contentView); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2884 | } |
| 2885 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2886 | if (showsTimeOrChronometer()) { |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2887 | if (mUseChronometer) { |
| 2888 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 2889 | contentView.setLong(R.id.chronometer, "setBase", |
| 2890 | mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 2891 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 2892 | } else { |
| 2893 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 2894 | contentView.setLong(R.id.time, "setTime", mWhen); |
| 2895 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2896 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2897 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2898 | // Adjust padding depending on line count and font size. |
| 2899 | contentView.setViewPadding(R.id.line1, 0, calculateTopPadding(mContext, |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2900 | mHasThreeLines, mContext.getResources().getConfiguration().fontScale), |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2901 | 0, 0); |
| 2902 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 2903 | // We want to add badge to first line of text. |
| 2904 | boolean addedBadge = addProfileBadge(contentView, |
| 2905 | contentTextInLine2 ? R.id.profile_badge_line2 : R.id.profile_badge_line3); |
| 2906 | // If we added the badge to line 3 then we should show line 3. |
| 2907 | if (addedBadge && !contentTextInLine2) { |
| 2908 | showLine3 = true; |
| 2909 | } |
| 2910 | |
| 2911 | // Note getStandardView may hide line 3 again. |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2912 | contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2913 | contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2914 | return contentView; |
| 2915 | } |
| 2916 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2917 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2918 | * @return true if the built notification will show the time or the chronometer; false |
| 2919 | * otherwise |
| 2920 | */ |
| 2921 | private boolean showsTimeOrChronometer() { |
| 2922 | return mWhen != 0 && mShowWhen; |
| 2923 | } |
| 2924 | |
| 2925 | /** |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2926 | * Logic to find out whether the notification is going to have three lines in the contracted |
| 2927 | * layout. This is used to adjust the top padding. |
| 2928 | * |
| 2929 | * @return true if the notification is going to have three lines; false if the notification |
| 2930 | * is going to have one or two lines |
| 2931 | */ |
| 2932 | private boolean hasThreeLines() { |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2933 | boolean contentTextInLine2 = mSubText != null && mContentText != null; |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2934 | boolean hasProgress = mStyle == null || mStyle.hasProgress(); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 2935 | // If we have content text in line 2, badge goes into line 2, or line 3 otherwise |
| 2936 | boolean badgeInLine3 = getProfileBadgeDrawable() != null && !contentTextInLine2; |
| 2937 | boolean hasLine3 = mContentText != null || mContentInfo != null || mNumber > 0 |
| 2938 | || badgeInLine3; |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2939 | boolean hasLine2 = (mSubText != null && mContentText != null) || |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 2940 | (hasProgress && mSubText == null |
| 2941 | && (mProgressMax != 0 || mProgressIndeterminate)); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2942 | return hasLine2 && hasLine3; |
| 2943 | } |
| 2944 | |
| 2945 | /** |
| 2946 | * @hide |
| 2947 | */ |
| 2948 | public static int calculateTopPadding(Context ctx, boolean hasThreeLines, |
| 2949 | float fontScale) { |
| 2950 | int padding = ctx.getResources().getDimensionPixelSize(hasThreeLines |
| 2951 | ? R.dimen.notification_top_pad_narrow |
| 2952 | : R.dimen.notification_top_pad); |
| 2953 | int largePadding = ctx.getResources().getDimensionPixelSize(hasThreeLines |
| 2954 | ? R.dimen.notification_top_pad_large_text_narrow |
| 2955 | : R.dimen.notification_top_pad_large_text); |
| 2956 | float largeFactor = (MathUtils.constrain(fontScale, 1.0f, LARGE_TEXT_SCALE) - 1f) |
| 2957 | / (LARGE_TEXT_SCALE - 1f); |
| 2958 | |
| 2959 | // Linearly interpolate the padding between large and normal with the font scale ranging |
| 2960 | // from 1f to LARGE_TEXT_SCALE |
| 2961 | return Math.round((1 - largeFactor) * padding + largeFactor * largePadding); |
| 2962 | } |
| 2963 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2964 | private void resetStandardTemplateWithActions(RemoteViews big) { |
| 2965 | big.setViewVisibility(R.id.actions, View.GONE); |
| 2966 | big.setViewVisibility(R.id.action_divider, View.GONE); |
| 2967 | big.removeAllViews(R.id.actions); |
| 2968 | } |
| 2969 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2970 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2971 | RemoteViews big = applyStandardTemplate(layoutId); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2972 | |
Christoph Studer | fe71843 | 2014-09-01 18:21:18 +0200 | [diff] [blame] | 2973 | resetStandardTemplateWithActions(big); |
| 2974 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2975 | int N = mActions.size(); |
| 2976 | if (N > 0) { |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2977 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2978 | big.setViewVisibility(R.id.action_divider, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2979 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2980 | for (int i=0; i<N; i++) { |
| 2981 | final RemoteViews button = generateActionButton(mActions.get(i)); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2982 | big.addView(R.id.actions, button); |
| 2983 | } |
| 2984 | } |
| 2985 | return big; |
| 2986 | } |
| 2987 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2988 | private RemoteViews makeContentView() { |
| 2989 | if (mContentView != null) { |
| 2990 | return mContentView; |
| 2991 | } else { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 2992 | return applyStandardTemplate(getBaseLayoutResource()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2993 | } |
| 2994 | } |
| 2995 | |
| 2996 | private RemoteViews makeTickerView() { |
| 2997 | if (mTickerView != null) { |
| 2998 | return mTickerView; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2999 | } |
Dan Sandler | 5fcdf6e | 2014-07-18 11:31:15 -0400 | [diff] [blame] | 3000 | return null; // tickers are not created by default anymore |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3001 | } |
| 3002 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3003 | private RemoteViews makeBigContentView() { |
| 3004 | if (mActions.size() == 0) return null; |
| 3005 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3006 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3007 | } |
| 3008 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3009 | private RemoteViews makeHeadsUpContentView() { |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3010 | if (mActions.size() == 0) return null; |
| 3011 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3012 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 3013 | } |
| 3014 | |
| 3015 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3016 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3017 | final boolean tombstone = (action.actionIntent == null); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3018 | RemoteViews button = new RemoteViews(mContext.getPackageName(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3019 | tombstone ? getActionTombstoneLayoutResource() |
| 3020 | : getActionLayoutResource()); |
Chris Wren | 8749ac8a | 2013-12-03 14:31:01 -0500 | [diff] [blame] | 3021 | button.setTextViewCompoundDrawablesRelative(R.id.action0, action.icon, 0, 0, 0); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3022 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 3023 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3024 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 3025 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3026 | button.setContentDescription(R.id.action0, action.title); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3027 | processLegacyAction(action, button); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 3028 | return button; |
| 3029 | } |
| 3030 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3031 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3032 | * @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] | 3033 | * doesn't create material notifications by itself) app. |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3034 | */ |
| 3035 | private boolean isLegacy() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3036 | return mColorUtil != null; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3037 | } |
| 3038 | |
| 3039 | private void processLegacyAction(Action action, RemoteViews button) { |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 3040 | if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, action.icon)) { |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 3041 | button.setTextViewCompoundDrawablesRelativeColorFilter(R.id.action0, 0, |
| 3042 | mContext.getResources().getColor(R.color.notification_action_color_filter), |
| 3043 | PorterDuff.Mode.MULTIPLY); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3044 | } |
| 3045 | } |
| 3046 | |
| 3047 | private CharSequence processLegacyText(CharSequence charSequence) { |
| 3048 | if (isLegacy()) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3049 | return mColorUtil.invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3050 | } else { |
| 3051 | return charSequence; |
| 3052 | } |
| 3053 | } |
| 3054 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3055 | /** |
| 3056 | * Apply any necessary background to smallIcons being used in the largeIcon spot. |
| 3057 | */ |
| 3058 | private void processSmallIconAsLarge(int largeIconId, RemoteViews contentView) { |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3059 | if (!isLegacy()) { |
| 3060 | contentView.setDrawableParameters(R.id.icon, false, -1, |
| 3061 | 0xFFFFFFFF, |
| 3062 | PorterDuff.Mode.SRC_ATOP, -1); |
| 3063 | } |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 3064 | if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, largeIconId)) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3065 | applyLargeIconBackground(contentView); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3066 | } |
| 3067 | } |
| 3068 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3069 | /** |
| 3070 | * Apply any necessary background to a largeIcon if it's a fake smallIcon (that is, |
| 3071 | * if it's grayscale). |
| 3072 | */ |
| 3073 | // TODO: also check bounds, transparency, that sort of thing. |
Christoph Studer | 239f835 | 2014-08-25 15:13:18 +0200 | [diff] [blame] | 3074 | private void processLargeLegacyIcon(Bitmap largeIcon, RemoteViews contentView) { |
Dan Sandler | 05c362d | 2014-09-03 00:16:27 +0200 | [diff] [blame] | 3075 | if (isLegacy() && mColorUtil.isGrayscaleIcon(largeIcon)) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3076 | applyLargeIconBackground(contentView); |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3077 | } else { |
| 3078 | removeLargeIconBackground(contentView); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3079 | } |
| 3080 | } |
| 3081 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3082 | /** |
| 3083 | * Add a colored circle behind the largeIcon slot. |
| 3084 | */ |
| 3085 | private void applyLargeIconBackground(RemoteViews contentView) { |
| 3086 | contentView.setInt(R.id.icon, "setBackgroundResource", |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3087 | R.drawable.notification_icon_legacy_bg); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3088 | |
| 3089 | contentView.setDrawableParameters( |
| 3090 | R.id.icon, |
| 3091 | true, |
| 3092 | -1, |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3093 | resolveColor(), |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3094 | PorterDuff.Mode.SRC_ATOP, |
| 3095 | -1); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3096 | |
| 3097 | int padding = mContext.getResources().getDimensionPixelSize( |
| 3098 | R.dimen.notification_large_icon_circle_padding); |
| 3099 | contentView.setViewPadding(R.id.icon, padding, padding, padding, padding); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3100 | } |
| 3101 | |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3102 | private void removeLargeIconBackground(RemoteViews contentView) { |
| 3103 | contentView.setInt(R.id.icon, "setBackgroundResource", 0); |
| 3104 | } |
| 3105 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3106 | /** |
| 3107 | * Recolor small icons when used in the R.id.right_icon slot. |
| 3108 | */ |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3109 | private void processSmallRightIcon(int smallIconDrawableId, |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3110 | RemoteViews contentView) { |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3111 | if (!isLegacy()) { |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3112 | contentView.setDrawableParameters(R.id.right_icon, false, -1, |
| 3113 | 0xFFFFFFFF, |
| 3114 | PorterDuff.Mode.SRC_ATOP, -1); |
Jorim Jaggi | 92df1f2 | 2014-12-16 19:44:41 +0100 | [diff] [blame] | 3115 | } |
| 3116 | if (!isLegacy() || mColorUtil.isGrayscaleIcon(mContext, smallIconDrawableId)) { |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3117 | contentView.setInt(R.id.right_icon, |
| 3118 | "setBackgroundResource", |
| 3119 | R.drawable.notification_icon_legacy_bg); |
| 3120 | |
| 3121 | contentView.setDrawableParameters( |
| 3122 | R.id.right_icon, |
| 3123 | true, |
| 3124 | -1, |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3125 | resolveColor(), |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 3126 | PorterDuff.Mode.SRC_ATOP, |
| 3127 | -1); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3128 | } |
| 3129 | } |
| 3130 | |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3131 | private int sanitizeColor() { |
| 3132 | if (mColor != COLOR_DEFAULT) { |
| 3133 | mColor |= 0xFF000000; // no alpha for custom colors |
| 3134 | } |
| 3135 | return mColor; |
| 3136 | } |
| 3137 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3138 | private int resolveColor() { |
| 3139 | if (mColor == COLOR_DEFAULT) { |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3140 | return mContext.getResources().getColor(R.color.notification_icon_bg_color); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3141 | } |
| 3142 | return mColor; |
| 3143 | } |
| 3144 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3145 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3146 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3147 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 3148 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3149 | public Notification buildUnstyled() { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3150 | Notification n = new Notification(); |
| 3151 | n.when = mWhen; |
| 3152 | n.icon = mSmallIcon; |
| 3153 | n.iconLevel = mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 3154 | n.number = mNumber; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3155 | |
Jorim Jaggi | 7441931 | 2014-06-10 20:57:21 +0200 | [diff] [blame] | 3156 | n.color = sanitizeColor(); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 3157 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3158 | setBuilderContentView(n, makeContentView()); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3159 | n.contentIntent = mContentIntent; |
| 3160 | n.deleteIntent = mDeleteIntent; |
| 3161 | n.fullScreenIntent = mFullScreenIntent; |
| 3162 | n.tickerText = mTickerText; |
| 3163 | n.tickerView = makeTickerView(); |
| 3164 | n.largeIcon = mLargeIcon; |
| 3165 | n.sound = mSound; |
| 3166 | n.audioStreamType = mAudioStreamType; |
John Spurlock | c0650f02 | 2014-07-19 13:22:39 -0400 | [diff] [blame] | 3167 | n.audioAttributes = mAudioAttributes; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3168 | n.vibrate = mVibrate; |
| 3169 | n.ledARGB = mLedArgb; |
| 3170 | n.ledOnMS = mLedOnMs; |
| 3171 | n.ledOffMS = mLedOffMs; |
| 3172 | n.defaults = mDefaults; |
| 3173 | n.flags = mFlags; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3174 | setBuilderBigContentView(n, makeBigContentView()); |
| 3175 | setBuilderHeadsUpContentView(n, makeHeadsUpContentView()); |
Daniel Sandler | 26c1343 | 2013-04-04 11:01:04 -0400 | [diff] [blame] | 3176 | if (mLedOnMs != 0 || mLedOffMs != 0) { |
Joe Onorato | 8d0b655 | 2010-11-22 16:09:29 -0800 | [diff] [blame] | 3177 | n.flags |= FLAG_SHOW_LIGHTS; |
| 3178 | } |
| 3179 | if ((mDefaults & DEFAULT_LIGHTS) != 0) { |
| 3180 | n.flags |= FLAG_SHOW_LIGHTS; |
| 3181 | } |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 3182 | n.category = mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 3183 | n.mGroupKey = mGroupKey; |
| 3184 | n.mSortKey = mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 3185 | n.priority = mPriority; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 3186 | if (mActions.size() > 0) { |
| 3187 | n.actions = new Action[mActions.size()]; |
| 3188 | mActions.toArray(n.actions); |
| 3189 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 3190 | n.visibility = mVisibility; |
| 3191 | |
| 3192 | if (mPublicVersion != null) { |
| 3193 | n.publicVersion = new Notification(); |
| 3194 | mPublicVersion.cloneInto(n.publicVersion, true); |
| 3195 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3196 | // Note: If you're adding new fields, also update restoreFromNotitification(). |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3197 | return n; |
| 3198 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3199 | |
| 3200 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3201 | * Capture, in the provided bundle, semantic information used in the construction of |
| 3202 | * this Notification object. |
| 3203 | * @hide |
| 3204 | */ |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3205 | public void populateExtras(Bundle extras) { |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3206 | // Store original information used in the construction of this object |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 3207 | extras.putInt(EXTRA_ORIGINATING_USERID, mOriginatingUserId); |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3208 | extras.putParcelable(EXTRA_REBUILD_CONTEXT_APPLICATION_INFO, |
| 3209 | mContext.getApplicationInfo()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3210 | extras.putCharSequence(EXTRA_TITLE, mContentTitle); |
| 3211 | extras.putCharSequence(EXTRA_TEXT, mContentText); |
| 3212 | extras.putCharSequence(EXTRA_SUB_TEXT, mSubText); |
| 3213 | extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo); |
| 3214 | extras.putInt(EXTRA_SMALL_ICON, mSmallIcon); |
| 3215 | extras.putInt(EXTRA_PROGRESS, mProgress); |
| 3216 | extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax); |
| 3217 | extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate); |
| 3218 | extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer); |
| 3219 | extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen); |
John Spurlock | ac08a47 | 2013-06-10 11:37:08 -0400 | [diff] [blame] | 3220 | if (mLargeIcon != null) { |
| 3221 | extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 3222 | } |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 3223 | if (!mPeople.isEmpty()) { |
| 3224 | extras.putStringArray(EXTRA_PEOPLE, mPeople.toArray(new String[mPeople.size()])); |
| 3225 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3226 | // NOTE: If you're adding new extras also update restoreFromNotification(). |
| 3227 | } |
| 3228 | |
| 3229 | |
| 3230 | /** |
| 3231 | * @hide |
| 3232 | */ |
| 3233 | public static void stripForDelivery(Notification n) { |
| 3234 | if (!STRIP_AND_REBUILD) { |
| 3235 | return; |
| 3236 | } |
| 3237 | |
| 3238 | String templateClass = n.extras.getString(EXTRA_TEMPLATE); |
| 3239 | // Only strip views for known Styles because we won't know how to |
| 3240 | // re-create them otherwise. |
| 3241 | boolean stripViews = TextUtils.isEmpty(templateClass) || |
| 3242 | getNotificationStyleClass(templateClass) != null; |
| 3243 | |
| 3244 | boolean isStripped = false; |
| 3245 | |
| 3246 | if (n.largeIcon != null && n.extras.containsKey(EXTRA_LARGE_ICON)) { |
| 3247 | // TODO: Would like to check for equality here, but if the notification |
| 3248 | // has been cloned, we can't. |
| 3249 | n.largeIcon = null; |
| 3250 | n.extras.putBoolean(EXTRA_REBUILD_LARGE_ICON, true); |
| 3251 | isStripped = true; |
| 3252 | } |
| 3253 | // Get rid of unmodified BuilderRemoteViews. |
| 3254 | |
| 3255 | if (stripViews && |
| 3256 | n.contentView instanceof BuilderRemoteViews && |
| 3257 | n.extras.getInt(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 3258 | n.contentView.getSequenceNumber()) { |
| 3259 | n.contentView = null; |
| 3260 | n.extras.putBoolean(EXTRA_REBUILD_CONTENT_VIEW, true); |
| 3261 | n.extras.remove(EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT); |
| 3262 | isStripped = true; |
| 3263 | } |
| 3264 | if (stripViews && |
| 3265 | n.bigContentView instanceof BuilderRemoteViews && |
| 3266 | n.extras.getInt(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 3267 | n.bigContentView.getSequenceNumber()) { |
| 3268 | n.bigContentView = null; |
| 3269 | n.extras.putBoolean(EXTRA_REBUILD_BIG_CONTENT_VIEW, true); |
| 3270 | n.extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT); |
| 3271 | isStripped = true; |
| 3272 | } |
| 3273 | if (stripViews && |
| 3274 | n.headsUpContentView instanceof BuilderRemoteViews && |
| 3275 | n.extras.getInt(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, -1) == |
| 3276 | n.headsUpContentView.getSequenceNumber()) { |
| 3277 | n.headsUpContentView = null; |
| 3278 | n.extras.putBoolean(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW, true); |
| 3279 | n.extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT); |
| 3280 | isStripped = true; |
| 3281 | } |
| 3282 | |
| 3283 | if (isStripped) { |
| 3284 | n.extras.putBoolean(EXTRA_NEEDS_REBUILD, true); |
| 3285 | } |
| 3286 | } |
| 3287 | |
| 3288 | /** |
| 3289 | * @hide |
| 3290 | */ |
| 3291 | public static Notification rebuild(Context context, Notification n) { |
| 3292 | Bundle extras = n.extras; |
| 3293 | if (!extras.getBoolean(EXTRA_NEEDS_REBUILD)) return n; |
| 3294 | extras.remove(EXTRA_NEEDS_REBUILD); |
| 3295 | |
| 3296 | // Re-create notification context so we can access app resources. |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3297 | ApplicationInfo applicationInfo = extras.getParcelable( |
| 3298 | EXTRA_REBUILD_CONTEXT_APPLICATION_INFO); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3299 | Context builderContext; |
| 3300 | try { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3301 | builderContext = context.createApplicationContext(applicationInfo, |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3302 | Context.CONTEXT_RESTRICTED); |
| 3303 | } catch (NameNotFoundException e) { |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 3304 | Log.e(TAG, "ApplicationInfo " + applicationInfo + " not found"); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3305 | builderContext = context; // try with our context |
| 3306 | } |
| 3307 | |
| 3308 | Builder b = new Builder(builderContext, n); |
| 3309 | return b.rebuild(); |
| 3310 | } |
| 3311 | |
| 3312 | /** |
| 3313 | * Rebuilds the notification passed in to the rebuild-constructor |
| 3314 | * {@link #Builder(Context, Notification)}. |
| 3315 | * |
| 3316 | * <p> |
| 3317 | * Throws IllegalStateException when invoked on a Builder that isn't in rebuild mode. |
| 3318 | * |
| 3319 | * @hide |
| 3320 | */ |
| 3321 | private Notification rebuild() { |
| 3322 | if (mRebuildNotification == null) { |
| 3323 | throw new IllegalStateException("rebuild() only valid when in 'rebuild' mode."); |
| 3324 | } |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3325 | mHasThreeLines = hasThreeLines(); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3326 | |
| 3327 | Bundle extras = mRebuildNotification.extras; |
| 3328 | |
| 3329 | if (extras.getBoolean(EXTRA_REBUILD_LARGE_ICON)) { |
| 3330 | mRebuildNotification.largeIcon = extras.getParcelable(EXTRA_LARGE_ICON); |
| 3331 | } |
| 3332 | extras.remove(EXTRA_REBUILD_LARGE_ICON); |
| 3333 | |
| 3334 | if (extras.getBoolean(EXTRA_REBUILD_CONTENT_VIEW)) { |
| 3335 | setBuilderContentView(mRebuildNotification, makeContentView()); |
| 3336 | if (mStyle != null) { |
| 3337 | mStyle.populateContentView(mRebuildNotification); |
| 3338 | } |
| 3339 | } |
| 3340 | extras.remove(EXTRA_REBUILD_CONTENT_VIEW); |
| 3341 | |
| 3342 | if (extras.getBoolean(EXTRA_REBUILD_BIG_CONTENT_VIEW)) { |
| 3343 | setBuilderBigContentView(mRebuildNotification, makeBigContentView()); |
| 3344 | if (mStyle != null) { |
| 3345 | mStyle.populateBigContentView(mRebuildNotification); |
| 3346 | } |
| 3347 | } |
| 3348 | extras.remove(EXTRA_REBUILD_BIG_CONTENT_VIEW); |
| 3349 | |
| 3350 | if (extras.getBoolean(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW)) { |
| 3351 | setBuilderHeadsUpContentView(mRebuildNotification, makeHeadsUpContentView()); |
| 3352 | if (mStyle != null) { |
| 3353 | mStyle.populateHeadsUpContentView(mRebuildNotification); |
| 3354 | } |
| 3355 | } |
| 3356 | extras.remove(EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW); |
| 3357 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3358 | mHasThreeLines = false; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3359 | return mRebuildNotification; |
| 3360 | } |
| 3361 | |
| 3362 | private static Class<? extends Style> getNotificationStyleClass(String templateClass) { |
| 3363 | Class<? extends Style>[] classes = new Class[]{ |
| 3364 | BigTextStyle.class, BigPictureStyle.class, InboxStyle.class, MediaStyle.class}; |
| 3365 | for (Class<? extends Style> innerClass : classes) { |
| 3366 | if (templateClass.equals(innerClass.getName())) { |
| 3367 | return innerClass; |
| 3368 | } |
| 3369 | } |
| 3370 | return null; |
| 3371 | } |
| 3372 | |
| 3373 | private void setBuilderContentView(Notification n, RemoteViews contentView) { |
| 3374 | n.contentView = contentView; |
| 3375 | if (contentView instanceof BuilderRemoteViews) { |
| 3376 | mRebuildBundle.putInt(Builder.EXTRA_REBUILD_CONTENT_VIEW_ACTION_COUNT, |
| 3377 | contentView.getSequenceNumber()); |
| 3378 | } |
| 3379 | } |
| 3380 | |
| 3381 | private void setBuilderBigContentView(Notification n, RemoteViews bigContentView) { |
| 3382 | n.bigContentView = bigContentView; |
| 3383 | if (bigContentView instanceof BuilderRemoteViews) { |
| 3384 | mRebuildBundle.putInt(Builder.EXTRA_REBUILD_BIG_CONTENT_VIEW_ACTION_COUNT, |
| 3385 | bigContentView.getSequenceNumber()); |
| 3386 | } |
| 3387 | } |
| 3388 | |
| 3389 | private void setBuilderHeadsUpContentView(Notification n, |
| 3390 | RemoteViews headsUpContentView) { |
| 3391 | n.headsUpContentView = headsUpContentView; |
| 3392 | if (headsUpContentView instanceof BuilderRemoteViews) { |
| 3393 | mRebuildBundle.putInt(Builder.EXTRA_REBUILD_HEADS_UP_CONTENT_VIEW_ACTION_COUNT, |
| 3394 | headsUpContentView.getSequenceNumber()); |
| 3395 | } |
| 3396 | } |
| 3397 | |
| 3398 | private void restoreFromNotification(Notification n) { |
| 3399 | |
| 3400 | // Notification fields. |
| 3401 | mWhen = n.when; |
| 3402 | mSmallIcon = n.icon; |
| 3403 | mSmallIconLevel = n.iconLevel; |
| 3404 | mNumber = n.number; |
| 3405 | |
| 3406 | mColor = n.color; |
| 3407 | |
| 3408 | mContentView = n.contentView; |
| 3409 | mDeleteIntent = n.deleteIntent; |
| 3410 | mFullScreenIntent = n.fullScreenIntent; |
| 3411 | mTickerText = n.tickerText; |
| 3412 | mTickerView = n.tickerView; |
| 3413 | mLargeIcon = n.largeIcon; |
| 3414 | mSound = n.sound; |
| 3415 | mAudioStreamType = n.audioStreamType; |
| 3416 | mAudioAttributes = n.audioAttributes; |
| 3417 | |
| 3418 | mVibrate = n.vibrate; |
| 3419 | mLedArgb = n.ledARGB; |
| 3420 | mLedOnMs = n.ledOnMS; |
| 3421 | mLedOffMs = n.ledOffMS; |
| 3422 | mDefaults = n.defaults; |
| 3423 | mFlags = n.flags; |
| 3424 | |
| 3425 | mCategory = n.category; |
| 3426 | mGroupKey = n.mGroupKey; |
| 3427 | mSortKey = n.mSortKey; |
| 3428 | mPriority = n.priority; |
| 3429 | mActions.clear(); |
| 3430 | if (n.actions != null) { |
| 3431 | Collections.addAll(mActions, n.actions); |
| 3432 | } |
| 3433 | mVisibility = n.visibility; |
| 3434 | |
| 3435 | mPublicVersion = n.publicVersion; |
| 3436 | |
| 3437 | // Extras. |
| 3438 | Bundle extras = n.extras; |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 3439 | mOriginatingUserId = extras.getInt(EXTRA_ORIGINATING_USERID); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3440 | mContentTitle = extras.getCharSequence(EXTRA_TITLE); |
| 3441 | mContentText = extras.getCharSequence(EXTRA_TEXT); |
| 3442 | mSubText = extras.getCharSequence(EXTRA_SUB_TEXT); |
| 3443 | mContentInfo = extras.getCharSequence(EXTRA_INFO_TEXT); |
| 3444 | mSmallIcon = extras.getInt(EXTRA_SMALL_ICON); |
| 3445 | mProgress = extras.getInt(EXTRA_PROGRESS); |
| 3446 | mProgressMax = extras.getInt(EXTRA_PROGRESS_MAX); |
| 3447 | mProgressIndeterminate = extras.getBoolean(EXTRA_PROGRESS_INDETERMINATE); |
| 3448 | mUseChronometer = extras.getBoolean(EXTRA_SHOW_CHRONOMETER); |
| 3449 | mShowWhen = extras.getBoolean(EXTRA_SHOW_WHEN); |
| 3450 | if (extras.containsKey(EXTRA_LARGE_ICON)) { |
| 3451 | mLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON); |
| 3452 | } |
| 3453 | if (extras.containsKey(EXTRA_PEOPLE)) { |
| 3454 | mPeople.clear(); |
| 3455 | Collections.addAll(mPeople, extras.getStringArray(EXTRA_PEOPLE)); |
| 3456 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3457 | } |
| 3458 | |
| 3459 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3460 | * @deprecated Use {@link #build()} instead. |
| 3461 | */ |
| 3462 | @Deprecated |
| 3463 | public Notification getNotification() { |
| 3464 | return build(); |
| 3465 | } |
| 3466 | |
| 3467 | /** |
| 3468 | * Combine all of the options that have been set and return a new {@link Notification} |
| 3469 | * object. |
| 3470 | */ |
| 3471 | public Notification build() { |
Kenny Guy | 8942bcd | 2014-09-08 21:09:47 +0100 | [diff] [blame] | 3472 | mOriginatingUserId = mContext.getUserId(); |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3473 | mHasThreeLines = hasThreeLines(); |
Christoph Studer | 943aa67 | 2014-08-03 20:31:16 +0200 | [diff] [blame] | 3474 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3475 | Notification n = buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3476 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3477 | if (mStyle != null) { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3478 | n = mStyle.buildStyled(n); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3479 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3480 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3481 | if (mExtras != null) { |
| 3482 | n.extras.putAll(mExtras); |
| 3483 | } |
| 3484 | |
| 3485 | if (mRebuildBundle.size() > 0) { |
| 3486 | n.extras.putAll(mRebuildBundle); |
| 3487 | mRebuildBundle.clear(); |
| 3488 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3489 | |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 3490 | populateExtras(n.extras); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3491 | if (mStyle != null) { |
| 3492 | mStyle.addExtras(n.extras); |
| 3493 | } |
| 3494 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3495 | mHasThreeLines = false; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3496 | return n; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3497 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3498 | |
| 3499 | /** |
| 3500 | * Apply this Builder to an existing {@link Notification} object. |
| 3501 | * |
| 3502 | * @hide |
| 3503 | */ |
| 3504 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 3505 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3506 | return n; |
| 3507 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3508 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3509 | private int getBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3510 | return R.layout.notification_template_material_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3511 | } |
| 3512 | |
| 3513 | private int getBigBaseLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3514 | return R.layout.notification_template_material_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3515 | } |
| 3516 | |
| 3517 | private int getBigPictureLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3518 | return R.layout.notification_template_material_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3519 | } |
| 3520 | |
| 3521 | private int getBigTextLayoutResource() { |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3522 | return R.layout.notification_template_material_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3523 | } |
| 3524 | |
| 3525 | private int getInboxLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3526 | return R.layout.notification_template_material_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | private int getActionLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3530 | return R.layout.notification_material_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3531 | } |
| 3532 | |
| 3533 | private int getActionTombstoneLayoutResource() { |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 3534 | return R.layout.notification_material_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3535 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3536 | } |
| 3537 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3538 | /** |
| 3539 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 3540 | * object. |
| 3541 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 3542 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3543 | private CharSequence mBigContentTitle; |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3544 | |
| 3545 | /** |
| 3546 | * @hide |
| 3547 | */ |
| 3548 | protected CharSequence mSummaryText = null; |
| 3549 | |
| 3550 | /** |
| 3551 | * @hide |
| 3552 | */ |
| 3553 | protected boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3554 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3555 | protected Builder mBuilder; |
| 3556 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3557 | /** |
| 3558 | * Overrides ContentTitle in the big form of the template. |
| 3559 | * This defaults to the value passed to setContentTitle(). |
| 3560 | */ |
| 3561 | protected void internalSetBigContentTitle(CharSequence title) { |
| 3562 | mBigContentTitle = title; |
| 3563 | } |
| 3564 | |
| 3565 | /** |
| 3566 | * Set the first line of text after the detail section in the big form of the template. |
| 3567 | */ |
| 3568 | protected void internalSetSummaryText(CharSequence cs) { |
| 3569 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3570 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3571 | } |
| 3572 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3573 | public void setBuilder(Builder builder) { |
| 3574 | if (mBuilder != builder) { |
| 3575 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 3576 | if (mBuilder != null) { |
| 3577 | mBuilder.setStyle(this); |
| 3578 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3579 | } |
| 3580 | } |
| 3581 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3582 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3583 | if (mBuilder == null) { |
| 3584 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 3585 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3586 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3587 | |
| 3588 | protected RemoteViews getStandardView(int layoutId) { |
| 3589 | checkBuilder(); |
| 3590 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3591 | // Nasty. |
| 3592 | CharSequence oldBuilderContentTitle = mBuilder.mContentTitle; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3593 | if (mBigContentTitle != null) { |
| 3594 | mBuilder.setContentTitle(mBigContentTitle); |
| 3595 | } |
| 3596 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3597 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 3598 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3599 | mBuilder.mContentTitle = oldBuilderContentTitle; |
| 3600 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3601 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 3602 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 3603 | } else { |
| 3604 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3605 | } |
| 3606 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3607 | // The last line defaults to the subtext, but can be replaced by mSummaryText |
| 3608 | final CharSequence overflowText = |
| 3609 | mSummaryTextSet ? mSummaryText |
| 3610 | : mBuilder.mSubText; |
| 3611 | if (overflowText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3612 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(overflowText)); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3613 | contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 3614 | contentView.setViewVisibility(R.id.line3, View.VISIBLE); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 3615 | } else { |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3616 | // Clear text in case we use the line to show the profile badge. |
| 3617 | contentView.setTextViewText(R.id.text, ""); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 3618 | contentView.setViewVisibility(R.id.overflow_divider, View.GONE); |
| 3619 | contentView.setViewVisibility(R.id.line3, View.GONE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3620 | } |
| 3621 | |
| 3622 | return contentView; |
| 3623 | } |
| 3624 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3625 | /** |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3626 | * Changes the padding of the first line such that the big and small content view have the |
| 3627 | * same top padding. |
| 3628 | * |
| 3629 | * @hide |
| 3630 | */ |
| 3631 | protected void applyTopPadding(RemoteViews contentView) { |
| 3632 | int topPadding = Builder.calculateTopPadding(mBuilder.mContext, |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3633 | mBuilder.mHasThreeLines, |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3634 | mBuilder.mContext.getResources().getConfiguration().fontScale); |
| 3635 | contentView.setViewPadding(R.id.line1, 0, topPadding, 0, 0); |
| 3636 | } |
| 3637 | |
| 3638 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3639 | * @hide |
| 3640 | */ |
| 3641 | public void addExtras(Bundle extras) { |
| 3642 | if (mSummaryTextSet) { |
| 3643 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 3644 | } |
| 3645 | if (mBigContentTitle != null) { |
| 3646 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 3647 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 3648 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3649 | } |
| 3650 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3651 | /** |
| 3652 | * @hide |
| 3653 | */ |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3654 | protected void restoreFromExtras(Bundle extras) { |
| 3655 | if (extras.containsKey(EXTRA_SUMMARY_TEXT)) { |
| 3656 | mSummaryText = extras.getCharSequence(EXTRA_SUMMARY_TEXT); |
| 3657 | mSummaryTextSet = true; |
| 3658 | } |
| 3659 | if (extras.containsKey(EXTRA_TITLE_BIG)) { |
| 3660 | mBigContentTitle = extras.getCharSequence(EXTRA_TITLE_BIG); |
| 3661 | } |
| 3662 | } |
| 3663 | |
| 3664 | |
| 3665 | /** |
| 3666 | * @hide |
| 3667 | */ |
| 3668 | public Notification buildStyled(Notification wip) { |
| 3669 | populateTickerView(wip); |
| 3670 | populateContentView(wip); |
| 3671 | populateBigContentView(wip); |
| 3672 | populateHeadsUpContentView(wip); |
| 3673 | return wip; |
| 3674 | } |
| 3675 | |
| 3676 | // The following methods are split out so we can re-create notification partially. |
| 3677 | /** |
| 3678 | * @hide |
| 3679 | */ |
| 3680 | protected void populateTickerView(Notification wip) {} |
| 3681 | /** |
| 3682 | * @hide |
| 3683 | */ |
| 3684 | protected void populateContentView(Notification wip) {} |
| 3685 | |
| 3686 | /** |
| 3687 | * @hide |
| 3688 | */ |
| 3689 | protected void populateBigContentView(Notification wip) {} |
| 3690 | |
| 3691 | /** |
| 3692 | * @hide |
| 3693 | */ |
| 3694 | protected void populateHeadsUpContentView(Notification wip) {} |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3695 | |
| 3696 | /** |
| 3697 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 3698 | * attached to. |
| 3699 | * |
| 3700 | * @return the fully constructed Notification. |
| 3701 | */ |
| 3702 | public Notification build() { |
| 3703 | checkBuilder(); |
| 3704 | return mBuilder.build(); |
| 3705 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 3706 | |
| 3707 | /** |
| 3708 | * @hide |
| 3709 | * @return true if the style positions the progress bar on the second line; false if the |
| 3710 | * style hides the progress bar |
| 3711 | */ |
| 3712 | protected boolean hasProgress() { |
| 3713 | return true; |
| 3714 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 3715 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3716 | |
| 3717 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3718 | * 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] | 3719 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3720 | * 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] | 3721 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3722 | * Notification notif = new Notification.Builder(mContext) |
| 3723 | * .setContentTitle("New photo from " + sender.toString()) |
| 3724 | * .setContentText(subject) |
| 3725 | * .setSmallIcon(R.drawable.new_post) |
| 3726 | * .setLargeIcon(aBitmap) |
| 3727 | * .setStyle(new Notification.BigPictureStyle() |
| 3728 | * .bigPicture(aBigBitmap)) |
| 3729 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3730 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3731 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3732 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3733 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3734 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3735 | private Bitmap mPicture; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3736 | private Bitmap mBigLargeIcon; |
| 3737 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3738 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3739 | public BigPictureStyle() { |
| 3740 | } |
| 3741 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3742 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3743 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3744 | } |
| 3745 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3746 | /** |
| 3747 | * Overrides ContentTitle in the big form of the template. |
| 3748 | * This defaults to the value passed to setContentTitle(). |
| 3749 | */ |
| 3750 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3751 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3752 | return this; |
| 3753 | } |
| 3754 | |
| 3755 | /** |
| 3756 | * Set the first line of text after the detail section in the big form of the template. |
| 3757 | */ |
| 3758 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3759 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3760 | return this; |
| 3761 | } |
| 3762 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3763 | /** |
| 3764 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 3765 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3766 | public BigPictureStyle bigPicture(Bitmap b) { |
| 3767 | mPicture = b; |
| 3768 | return this; |
| 3769 | } |
| 3770 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3771 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3772 | * Override the large icon when the big notification is shown. |
| 3773 | */ |
| 3774 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
| 3775 | mBigLargeIconSet = true; |
| 3776 | mBigLargeIcon = b; |
| 3777 | return this; |
| 3778 | } |
| 3779 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3780 | private RemoteViews makeBigContentView() { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3781 | |
| 3782 | // Replace mLargeIcon with mBigLargeIcon if mBigLargeIconSet |
| 3783 | // This covers the following cases: |
| 3784 | // 1. mBigLargeIconSet -> mBigLargeIcon (null or non-null) applies, overrides |
| 3785 | // mLargeIcon |
| 3786 | // 2. !mBigLargeIconSet -> mLargeIcon applies |
| 3787 | Bitmap oldLargeIcon = null; |
| 3788 | if (mBigLargeIconSet) { |
| 3789 | oldLargeIcon = mBuilder.mLargeIcon; |
| 3790 | mBuilder.mLargeIcon = mBigLargeIcon; |
| 3791 | } |
| 3792 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3793 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3794 | |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3795 | if (mBigLargeIconSet) { |
| 3796 | mBuilder.mLargeIcon = oldLargeIcon; |
| 3797 | } |
| 3798 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3799 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
| 3800 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3801 | applyTopPadding(contentView); |
| 3802 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3803 | boolean twoTextLines = mBuilder.mSubText != null && mBuilder.mContentText != null; |
| 3804 | mBuilder.addProfileBadge(contentView, |
| 3805 | twoTextLines ? R.id.profile_badge_line2 : R.id.profile_badge_line3); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3806 | return contentView; |
| 3807 | } |
| 3808 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3809 | /** |
| 3810 | * @hide |
| 3811 | */ |
| 3812 | public void addExtras(Bundle extras) { |
| 3813 | super.addExtras(extras); |
| 3814 | |
| 3815 | if (mBigLargeIconSet) { |
| 3816 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 3817 | } |
| 3818 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 3819 | } |
| 3820 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3821 | /** |
| 3822 | * @hide |
| 3823 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3824 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3825 | protected void restoreFromExtras(Bundle extras) { |
| 3826 | super.restoreFromExtras(extras); |
| 3827 | |
| 3828 | if (extras.containsKey(EXTRA_LARGE_ICON_BIG)) { |
Christoph Studer | 5c510ee | 2014-12-15 16:32:27 +0100 | [diff] [blame] | 3829 | mBigLargeIconSet = true; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3830 | mBigLargeIcon = extras.getParcelable(EXTRA_LARGE_ICON_BIG); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 3831 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3832 | mPicture = extras.getParcelable(EXTRA_PICTURE); |
| 3833 | } |
| 3834 | |
| 3835 | /** |
| 3836 | * @hide |
| 3837 | */ |
| 3838 | @Override |
| 3839 | public void populateBigContentView(Notification wip) { |
| 3840 | mBuilder.setBuilderBigContentView(wip, makeBigContentView()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3841 | } |
| 3842 | } |
| 3843 | |
| 3844 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3845 | * 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] | 3846 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3847 | * 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] | 3848 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3849 | * Notification notif = new Notification.Builder(mContext) |
| 3850 | * .setContentTitle("New mail from " + sender.toString()) |
| 3851 | * .setContentText(subject) |
| 3852 | * .setSmallIcon(R.drawable.new_mail) |
| 3853 | * .setLargeIcon(aBitmap) |
| 3854 | * .setStyle(new Notification.BigTextStyle() |
| 3855 | * .bigText(aVeryLongString)) |
| 3856 | * .build(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3857 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3858 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 3859 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3860 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3861 | public static class BigTextStyle extends Style { |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3862 | |
| 3863 | private static final int MAX_LINES = 13; |
| 3864 | private static final int LINES_CONSUMED_BY_ACTIONS = 3; |
| 3865 | private static final int LINES_CONSUMED_BY_SUMMARY = 2; |
| 3866 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3867 | private CharSequence mBigText; |
| 3868 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3869 | public BigTextStyle() { |
| 3870 | } |
| 3871 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3872 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3873 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3874 | } |
| 3875 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3876 | /** |
| 3877 | * Overrides ContentTitle in the big form of the template. |
| 3878 | * This defaults to the value passed to setContentTitle(). |
| 3879 | */ |
| 3880 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3881 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3882 | return this; |
| 3883 | } |
| 3884 | |
| 3885 | /** |
| 3886 | * Set the first line of text after the detail section in the big form of the template. |
| 3887 | */ |
| 3888 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3889 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3890 | return this; |
| 3891 | } |
| 3892 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3893 | /** |
| 3894 | * Provide the longer text to be displayed in the big form of the |
| 3895 | * template in place of the content text. |
| 3896 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3897 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3898 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3899 | return this; |
| 3900 | } |
| 3901 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3902 | /** |
| 3903 | * @hide |
| 3904 | */ |
| 3905 | public void addExtras(Bundle extras) { |
| 3906 | super.addExtras(extras); |
| 3907 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3908 | extras.putCharSequence(EXTRA_BIG_TEXT, mBigText); |
| 3909 | } |
| 3910 | |
| 3911 | /** |
| 3912 | * @hide |
| 3913 | */ |
| 3914 | @Override |
| 3915 | protected void restoreFromExtras(Bundle extras) { |
| 3916 | super.restoreFromExtras(extras); |
| 3917 | |
| 3918 | mBigText = extras.getCharSequence(EXTRA_BIG_TEXT); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3919 | } |
| 3920 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3921 | private RemoteViews makeBigContentView() { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3922 | |
| 3923 | // Nasty |
| 3924 | CharSequence oldBuilderContentText = mBuilder.mContentText; |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 3925 | mBuilder.mContentText = null; |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 3926 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3927 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3928 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3929 | mBuilder.mContentText = oldBuilderContentText; |
| 3930 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3931 | contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3932 | contentView.setViewVisibility(R.id.big_text, View.VISIBLE); |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3933 | contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines()); |
Chris Wren | 3c5f9243 | 2012-05-04 16:31:17 -0400 | [diff] [blame] | 3934 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3935 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 3936 | applyTopPadding(contentView); |
| 3937 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 3938 | mBuilder.shrinkLine3Text(contentView); |
| 3939 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 3940 | mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template); |
| 3941 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3942 | return contentView; |
| 3943 | } |
| 3944 | |
Jorim Jaggi | 457a10d | 2014-09-08 16:18:23 +0200 | [diff] [blame] | 3945 | private int calculateMaxLines() { |
| 3946 | int lineCount = MAX_LINES; |
| 3947 | boolean hasActions = mBuilder.mActions.size() > 0; |
| 3948 | boolean hasSummary = (mSummaryTextSet ? mSummaryText : mBuilder.mSubText) != null; |
| 3949 | if (hasActions) { |
| 3950 | lineCount -= LINES_CONSUMED_BY_ACTIONS; |
| 3951 | } |
| 3952 | if (hasSummary) { |
| 3953 | lineCount -= LINES_CONSUMED_BY_SUMMARY; |
| 3954 | } |
| 3955 | |
| 3956 | // If we have less top padding at the top, we can fit less lines. |
| 3957 | if (!mBuilder.mHasThreeLines) { |
| 3958 | lineCount--; |
| 3959 | } |
| 3960 | return lineCount; |
| 3961 | } |
| 3962 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3963 | /** |
| 3964 | * @hide |
| 3965 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3966 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 3967 | public void populateBigContentView(Notification wip) { |
| 3968 | mBuilder.setBuilderBigContentView(wip, makeBigContentView()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3969 | } |
| 3970 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3971 | |
| 3972 | /** |
| 3973 | * 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] | 3974 | * |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3975 | * 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] | 3976 | * <pre class="prettyprint"> |
Robert Ly | 91c5ce3 | 2014-06-08 15:37:00 -0700 | [diff] [blame] | 3977 | * Notification notif = new Notification.Builder(mContext) |
| 3978 | * .setContentTitle("5 New mails from " + sender.toString()) |
| 3979 | * .setContentText(subject) |
| 3980 | * .setSmallIcon(R.drawable.new_mail) |
| 3981 | * .setLargeIcon(aBitmap) |
| 3982 | * .setStyle(new Notification.InboxStyle() |
| 3983 | * .addLine(str1) |
| 3984 | * .addLine(str2) |
| 3985 | * .setContentTitle("") |
| 3986 | * .setSummaryText("+3 more")) |
| 3987 | * .build(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3988 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3989 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3990 | * @see Notification#bigContentView |
| 3991 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3992 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3993 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 3994 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3995 | public InboxStyle() { |
| 3996 | } |
| 3997 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3998 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3999 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4000 | } |
| 4001 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4002 | /** |
| 4003 | * Overrides ContentTitle in the big form of the template. |
| 4004 | * This defaults to the value passed to setContentTitle(). |
| 4005 | */ |
| 4006 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4007 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4008 | return this; |
| 4009 | } |
| 4010 | |
| 4011 | /** |
| 4012 | * Set the first line of text after the detail section in the big form of the template. |
| 4013 | */ |
| 4014 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4015 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4016 | return this; |
| 4017 | } |
| 4018 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 4019 | /** |
| 4020 | * Append a line to the digest section of the Inbox notification. |
| 4021 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4022 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 4023 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4024 | return this; |
| 4025 | } |
| 4026 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4027 | /** |
| 4028 | * @hide |
| 4029 | */ |
| 4030 | public void addExtras(Bundle extras) { |
| 4031 | super.addExtras(extras); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4032 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 4033 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 4034 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 4035 | } |
| 4036 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4037 | /** |
| 4038 | * @hide |
| 4039 | */ |
| 4040 | @Override |
| 4041 | protected void restoreFromExtras(Bundle extras) { |
| 4042 | super.restoreFromExtras(extras); |
| 4043 | |
| 4044 | mTexts.clear(); |
| 4045 | if (extras.containsKey(EXTRA_TEXT_LINES)) { |
| 4046 | Collections.addAll(mTexts, extras.getCharSequenceArray(EXTRA_TEXT_LINES)); |
| 4047 | } |
| 4048 | } |
| 4049 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4050 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4051 | // Remove the content text so line3 disappears unless you have a summary |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4052 | |
| 4053 | // Nasty |
| 4054 | CharSequence oldBuilderContentText = mBuilder.mContentText; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4055 | mBuilder.mContentText = null; |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4056 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 4057 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 4058 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4059 | mBuilder.mContentText = oldBuilderContentText; |
| 4060 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4061 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4062 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4063 | 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] | 4064 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 4065 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 4066 | // Make sure all rows are gone in case we reuse a view. |
| 4067 | for (int rowId : rowIds) { |
| 4068 | contentView.setViewVisibility(rowId, View.GONE); |
| 4069 | } |
| 4070 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4071 | final boolean largeText = |
| 4072 | mBuilder.mContext.getResources().getConfiguration().fontScale > 1f; |
| 4073 | final float subTextSize = mBuilder.mContext.getResources().getDimensionPixelSize( |
| 4074 | R.dimen.notification_subtext_size); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4075 | int i=0; |
| 4076 | while (i < mTexts.size() && i < rowIds.length) { |
| 4077 | CharSequence str = mTexts.get(i); |
| 4078 | if (str != null && !str.equals("")) { |
| 4079 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 4080 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4081 | if (largeText) { |
| 4082 | contentView.setTextViewTextSize(rowIds[i], TypedValue.COMPLEX_UNIT_PX, |
| 4083 | subTextSize); |
| 4084 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4085 | } |
| 4086 | i++; |
| 4087 | } |
| 4088 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 4089 | contentView.setViewVisibility(R.id.inbox_end_pad, |
| 4090 | mTexts.size() > 0 ? View.VISIBLE : View.GONE); |
| 4091 | |
| 4092 | contentView.setViewVisibility(R.id.inbox_more, |
| 4093 | mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE); |
Chris Wren | 29bb6d9 | 2012-05-17 18:09:42 -0400 | [diff] [blame] | 4094 | |
Jorim Jaggi | 445d3c0 | 2014-08-19 22:33:42 +0200 | [diff] [blame] | 4095 | applyTopPadding(contentView); |
| 4096 | |
Jorim Jaggi | d05aa3e | 2014-08-28 17:52:27 +0200 | [diff] [blame] | 4097 | mBuilder.shrinkLine3Text(contentView); |
| 4098 | |
Kenny Guy | 98193ea | 2014-07-24 19:54:37 +0100 | [diff] [blame] | 4099 | mBuilder.addProfileBadge(contentView, R.id.profile_badge_large_template); |
| 4100 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4101 | return contentView; |
| 4102 | } |
| 4103 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 4104 | /** |
| 4105 | * @hide |
| 4106 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 4107 | @Override |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4108 | public void populateBigContentView(Notification wip) { |
| 4109 | mBuilder.setBuilderBigContentView(wip, makeBigContentView()); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 4110 | } |
| 4111 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4112 | |
| 4113 | /** |
| 4114 | * Notification style for media playback notifications. |
| 4115 | * |
| 4116 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 4117 | * {@link Notification.Action}s specified with |
| 4118 | * {@link Notification.Builder#addAction(int, CharSequence, PendingIntent) addAction} will be |
| 4119 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 4120 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 4121 | * treated as album artwork. |
| 4122 | * |
| 4123 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 4124 | * {@link Notification#contentView}; by providing action indices to |
Christoph Studer | fde6f4d | 2014-12-12 13:23:26 +0100 | [diff] [blame] | 4125 | * {@link #setShowActionsInCompactView(int...)} you can promote up to 3 actions to be displayed |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4126 | * in the standard view alongside the usual content. |
| 4127 | * |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4128 | * Notifications created with MediaStyle will have their category set to |
| 4129 | * {@link Notification#CATEGORY_TRANSPORT CATEGORY_TRANSPORT} unless you set a different |
| 4130 | * category using {@link Notification.Builder#setCategory(String) setCategory()}. |
| 4131 | * |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4132 | * Finally, if you attach a {@link android.media.session.MediaSession.Token} using |
| 4133 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSession.Token)}, |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4134 | * the System UI can identify this as a notification representing an active media session |
| 4135 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 4136 | * |
| 4137 | * To use this style with your Notification, feed it to |
| 4138 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 4139 | * <pre class="prettyprint"> |
| 4140 | * Notification noti = new Notification.Builder() |
| 4141 | * .setSmallIcon(R.drawable.ic_stat_player) |
Christoph Studer | e935fe9 | 2014-11-24 14:18:06 +0100 | [diff] [blame] | 4142 | * .setContentTitle("Track title") |
| 4143 | * .setContentText("Artist - Album") |
| 4144 | * .setLargeIcon(albumArtBitmap)) |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4145 | * .setStyle(<b>new Notification.MediaStyle()</b> |
| 4146 | * .setMediaSession(mySession)) |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4147 | * .build(); |
| 4148 | * </pre> |
| 4149 | * |
| 4150 | * @see Notification#bigContentView |
| 4151 | */ |
| 4152 | public static class MediaStyle extends Style { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4153 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 3; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4154 | static final int MAX_MEDIA_BUTTONS = 5; |
| 4155 | |
| 4156 | private int[] mActionsToShowInCompact = null; |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4157 | private MediaSession.Token mToken; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4158 | |
| 4159 | public MediaStyle() { |
| 4160 | } |
| 4161 | |
| 4162 | public MediaStyle(Builder builder) { |
| 4163 | setBuilder(builder); |
| 4164 | } |
| 4165 | |
| 4166 | /** |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4167 | * 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] | 4168 | * notification view. |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4169 | * |
| 4170 | * @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] | 4171 | */ |
| 4172 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 4173 | mActionsToShowInCompact = actions; |
| 4174 | return this; |
| 4175 | } |
| 4176 | |
| 4177 | /** |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4178 | * Attach a {@link android.media.session.MediaSession.Token} to this Notification |
| 4179 | * to provide additional playback information and control to the SystemUI. |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4180 | */ |
Jeff Brown | dba34ba | 2014-06-24 20:46:03 -0700 | [diff] [blame] | 4181 | public MediaStyle setMediaSession(MediaSession.Token token) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4182 | mToken = token; |
| 4183 | return this; |
| 4184 | } |
| 4185 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4186 | /** |
| 4187 | * @hide |
| 4188 | */ |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4189 | @Override |
| 4190 | public Notification buildStyled(Notification wip) { |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4191 | super.buildStyled(wip); |
Bryan Mawhinney | 6be8de3 | 2014-07-18 10:35:12 +0100 | [diff] [blame] | 4192 | if (wip.category == null) { |
| 4193 | wip.category = Notification.CATEGORY_TRANSPORT; |
| 4194 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4195 | return wip; |
| 4196 | } |
| 4197 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4198 | /** |
| 4199 | * @hide |
| 4200 | */ |
| 4201 | @Override |
| 4202 | public void populateContentView(Notification wip) { |
| 4203 | mBuilder.setBuilderContentView(wip, makeMediaContentView()); |
| 4204 | } |
| 4205 | |
| 4206 | /** |
| 4207 | * @hide |
| 4208 | */ |
| 4209 | @Override |
| 4210 | public void populateBigContentView(Notification wip) { |
| 4211 | mBuilder.setBuilderBigContentView(wip, makeMediaBigContentView()); |
| 4212 | } |
| 4213 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4214 | /** @hide */ |
| 4215 | @Override |
| 4216 | public void addExtras(Bundle extras) { |
| 4217 | super.addExtras(extras); |
| 4218 | |
| 4219 | if (mToken != null) { |
| 4220 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 4221 | } |
Bryan Mawhinney | e191f90 | 2014-07-22 12:50:09 +0100 | [diff] [blame] | 4222 | if (mActionsToShowInCompact != null) { |
| 4223 | extras.putIntArray(EXTRA_COMPACT_ACTIONS, mActionsToShowInCompact); |
| 4224 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4225 | } |
| 4226 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4227 | /** |
| 4228 | * @hide |
| 4229 | */ |
| 4230 | @Override |
| 4231 | protected void restoreFromExtras(Bundle extras) { |
| 4232 | super.restoreFromExtras(extras); |
| 4233 | |
| 4234 | if (extras.containsKey(EXTRA_MEDIA_SESSION)) { |
| 4235 | mToken = extras.getParcelable(EXTRA_MEDIA_SESSION); |
| 4236 | } |
| 4237 | if (extras.containsKey(EXTRA_COMPACT_ACTIONS)) { |
| 4238 | mActionsToShowInCompact = extras.getIntArray(EXTRA_COMPACT_ACTIONS); |
| 4239 | } |
| 4240 | } |
| 4241 | |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4242 | private RemoteViews generateMediaActionButton(Action action) { |
| 4243 | final boolean tombstone = (action.actionIntent == null); |
| 4244 | RemoteViews button = new RemoteViews(mBuilder.mContext.getPackageName(), |
Alan Viverette | 3cb07a46 | 2014-06-06 14:19:53 -0700 | [diff] [blame] | 4245 | R.layout.notification_material_media_action); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4246 | button.setImageViewResource(R.id.action0, action.icon); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4247 | button.setDrawableParameters(R.id.action0, false, -1, |
| 4248 | 0xFFFFFFFF, |
| 4249 | PorterDuff.Mode.SRC_ATOP, -1); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4250 | if (!tombstone) { |
| 4251 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 4252 | } |
| 4253 | button.setContentDescription(R.id.action0, action.title); |
| 4254 | return button; |
| 4255 | } |
| 4256 | |
| 4257 | private RemoteViews makeMediaContentView() { |
| 4258 | RemoteViews view = mBuilder.applyStandardTemplate( |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4259 | R.layout.notification_template_material_media, false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4260 | |
| 4261 | final int numActions = mBuilder.mActions.size(); |
| 4262 | final int N = mActionsToShowInCompact == null |
| 4263 | ? 0 |
| 4264 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 4265 | if (N > 0) { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4266 | view.removeAllViews(com.android.internal.R.id.media_actions); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4267 | for (int i = 0; i < N; i++) { |
| 4268 | if (i >= numActions) { |
| 4269 | throw new IllegalArgumentException(String.format( |
| 4270 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 4271 | i, numActions - 1)); |
| 4272 | } |
| 4273 | |
| 4274 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
| 4275 | final RemoteViews button = generateMediaActionButton(action); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4276 | view.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4277 | } |
| 4278 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4279 | styleText(view); |
| 4280 | hideRightIcon(view); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4281 | return view; |
| 4282 | } |
| 4283 | |
| 4284 | private RemoteViews makeMediaBigContentView() { |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4285 | final int actionCount = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
| 4286 | RemoteViews big = mBuilder.applyStandardTemplate(getBigLayoutResource(actionCount), |
| 4287 | false /* hasProgress */); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4288 | |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4289 | if (actionCount > 0) { |
| 4290 | big.removeAllViews(com.android.internal.R.id.media_actions); |
| 4291 | for (int i = 0; i < actionCount; i++) { |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4292 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i)); |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4293 | big.addView(com.android.internal.R.id.media_actions, button); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4294 | } |
| 4295 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4296 | styleText(big); |
| 4297 | hideRightIcon(big); |
| 4298 | applyTopPadding(big); |
| 4299 | big.setViewVisibility(android.R.id.progress, View.GONE); |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4300 | return big; |
| 4301 | } |
Jorim Jaggi | 17ee3ec | 2014-08-29 03:47:31 +0200 | [diff] [blame] | 4302 | |
| 4303 | private int getBigLayoutResource(int actionCount) { |
| 4304 | if (actionCount <= 3) { |
| 4305 | return R.layout.notification_template_material_big_media_narrow; |
| 4306 | } else { |
| 4307 | return R.layout.notification_template_material_big_media; |
| 4308 | } |
| 4309 | } |
| 4310 | |
| 4311 | private void hideRightIcon(RemoteViews contentView) { |
| 4312 | contentView.setViewVisibility(R.id.right_icon, View.GONE); |
| 4313 | } |
| 4314 | |
| 4315 | /** |
| 4316 | * Applies the special text colors for media notifications to all text views. |
| 4317 | */ |
| 4318 | private void styleText(RemoteViews contentView) { |
| 4319 | int primaryColor = mBuilder.mContext.getResources().getColor( |
| 4320 | R.color.notification_media_primary_color); |
| 4321 | int secondaryColor = mBuilder.mContext.getResources().getColor( |
| 4322 | R.color.notification_media_secondary_color); |
| 4323 | contentView.setTextColor(R.id.title, primaryColor); |
| 4324 | if (mBuilder.showsTimeOrChronometer()) { |
| 4325 | if (mBuilder.mUseChronometer) { |
| 4326 | contentView.setTextColor(R.id.chronometer, secondaryColor); |
| 4327 | } else { |
| 4328 | contentView.setTextColor(R.id.time, secondaryColor); |
| 4329 | } |
| 4330 | } |
| 4331 | contentView.setTextColor(R.id.text2, secondaryColor); |
| 4332 | contentView.setTextColor(R.id.text, secondaryColor); |
| 4333 | contentView.setTextColor(R.id.info, secondaryColor); |
| 4334 | } |
| 4335 | |
| 4336 | /** |
| 4337 | * @hide |
| 4338 | */ |
| 4339 | @Override |
| 4340 | protected boolean hasProgress() { |
| 4341 | return false; |
| 4342 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 4343 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4344 | |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 4345 | // When adding a new Style subclass here, don't forget to update |
| 4346 | // Builder.getNotificationStyleClass. |
| 4347 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4348 | /** |
| 4349 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 4350 | * metadata or change options on a notification builder. |
| 4351 | */ |
| 4352 | public interface Extender { |
| 4353 | /** |
| 4354 | * Apply this extender to a notification builder. |
| 4355 | * @param builder the builder to be modified. |
| 4356 | * @return the build object for chaining. |
| 4357 | */ |
| 4358 | public Builder extend(Builder builder); |
| 4359 | } |
| 4360 | |
| 4361 | /** |
| 4362 | * Helper class to add wearable extensions to notifications. |
| 4363 | * <p class="note"> See |
| 4364 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 4365 | * for Android Wear</a> for more information on how to use this class. |
| 4366 | * <p> |
| 4367 | * To create a notification with wearable extensions: |
| 4368 | * <ol> |
| 4369 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 4370 | * properties. |
| 4371 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 4372 | * <li>Set wearable-specific properties using the |
| 4373 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 4374 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 4375 | * notification. |
| 4376 | * <li>Post the notification to the notification system with the |
| 4377 | * {@code NotificationManager.notify(...)} methods. |
| 4378 | * </ol> |
| 4379 | * |
| 4380 | * <pre class="prettyprint"> |
| 4381 | * Notification notif = new Notification.Builder(mContext) |
| 4382 | * .setContentTitle("New mail from " + sender.toString()) |
| 4383 | * .setContentText(subject) |
| 4384 | * .setSmallIcon(R.drawable.new_mail) |
| 4385 | * .extend(new Notification.WearableExtender() |
| 4386 | * .setContentIcon(R.drawable.new_mail)) |
| 4387 | * .build(); |
| 4388 | * NotificationManager notificationManger = |
| 4389 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 4390 | * notificationManger.notify(0, notif);</pre> |
| 4391 | * |
| 4392 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 4393 | * {@code WearableExtender(Notification)} constructor, |
| 4394 | * and then using the {@code get} methods to access values. |
| 4395 | * |
| 4396 | * <pre class="prettyprint"> |
| 4397 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 4398 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4399 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4400 | */ |
| 4401 | public static final class WearableExtender implements Extender { |
| 4402 | /** |
| 4403 | * Sentinel value for an action index that is unset. |
| 4404 | */ |
| 4405 | public static final int UNSET_ACTION_INDEX = -1; |
| 4406 | |
| 4407 | /** |
| 4408 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 4409 | * default sizing. |
| 4410 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
| 4411 | * the default is {@link #SIZE_LARGE}. All other notifications size automatically based |
| 4412 | * on their content. |
| 4413 | */ |
| 4414 | public static final int SIZE_DEFAULT = 0; |
| 4415 | |
| 4416 | /** |
| 4417 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4418 | * with an extra small size. |
| 4419 | * <p>This value is only applicable for custom display notifications created using |
| 4420 | * {@link #setDisplayIntent}. |
| 4421 | */ |
| 4422 | public static final int SIZE_XSMALL = 1; |
| 4423 | |
| 4424 | /** |
| 4425 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4426 | * with a small size. |
| 4427 | * <p>This value is only applicable for custom display notifications created using |
| 4428 | * {@link #setDisplayIntent}. |
| 4429 | */ |
| 4430 | public static final int SIZE_SMALL = 2; |
| 4431 | |
| 4432 | /** |
| 4433 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4434 | * with a medium size. |
| 4435 | * <p>This value is only applicable for custom display notifications created using |
| 4436 | * {@link #setDisplayIntent}. |
| 4437 | */ |
| 4438 | public static final int SIZE_MEDIUM = 3; |
| 4439 | |
| 4440 | /** |
| 4441 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4442 | * with a large size. |
| 4443 | * <p>This value is only applicable for custom display notifications created using |
| 4444 | * {@link #setDisplayIntent}. |
| 4445 | */ |
| 4446 | public static final int SIZE_LARGE = 4; |
| 4447 | |
Griff Hazen | d5f11f9 | 2014-05-27 15:40:09 -0700 | [diff] [blame] | 4448 | /** |
| 4449 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 4450 | * full screen. |
| 4451 | * <p>This value is only applicable for custom display notifications created using |
| 4452 | * {@link #setDisplayIntent}. |
| 4453 | */ |
| 4454 | public static final int SIZE_FULL_SCREEN = 5; |
| 4455 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4456 | /** |
| 4457 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on for a |
| 4458 | * short amount of time when this notification is displayed on the screen. This |
| 4459 | * is the default value. |
| 4460 | */ |
| 4461 | public static final int SCREEN_TIMEOUT_SHORT = 0; |
| 4462 | |
| 4463 | /** |
| 4464 | * Sentinel value for use with {@link #setHintScreenTimeout} to keep the screen on |
| 4465 | * for a longer amount of time when this notification is displayed on the screen. |
| 4466 | */ |
| 4467 | public static final int SCREEN_TIMEOUT_LONG = -1; |
| 4468 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4469 | /** Notification extra which contains wearable extensions */ |
| 4470 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 4471 | |
Pete Gast | af6781d | 2014-10-07 15:17:05 -0400 | [diff] [blame] | 4472 | // Keys within EXTRA_WEARABLE_EXTENSIONS for wearable options. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4473 | private static final String KEY_ACTIONS = "actions"; |
| 4474 | private static final String KEY_FLAGS = "flags"; |
| 4475 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 4476 | private static final String KEY_PAGES = "pages"; |
| 4477 | private static final String KEY_BACKGROUND = "background"; |
| 4478 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 4479 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 4480 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 4481 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 4482 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 4483 | private static final String KEY_GRAVITY = "gravity"; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4484 | private static final String KEY_HINT_SCREEN_TIMEOUT = "hintScreenTimeout"; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4485 | |
| 4486 | // Flags bitwise-ored to mFlags |
| 4487 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 4488 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 4489 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 4490 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4491 | private static final int FLAG_HINT_AVOID_BACKGROUND_CLIPPING = 1 << 4; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4492 | |
| 4493 | // Default value for flags integer |
| 4494 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 4495 | |
| 4496 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 4497 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 4498 | |
| 4499 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 4500 | private int mFlags = DEFAULT_FLAGS; |
| 4501 | private PendingIntent mDisplayIntent; |
| 4502 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 4503 | private Bitmap mBackground; |
| 4504 | private int mContentIcon; |
| 4505 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 4506 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 4507 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 4508 | private int mCustomContentHeight; |
| 4509 | private int mGravity = DEFAULT_GRAVITY; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4510 | private int mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4511 | |
| 4512 | /** |
| 4513 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 4514 | * options. |
| 4515 | */ |
| 4516 | public WearableExtender() { |
| 4517 | } |
| 4518 | |
| 4519 | public WearableExtender(Notification notif) { |
| 4520 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 4521 | if (wearableBundle != null) { |
| 4522 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 4523 | if (actions != null) { |
| 4524 | mActions.addAll(actions); |
| 4525 | } |
| 4526 | |
| 4527 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 4528 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 4529 | |
| 4530 | Notification[] pages = getNotificationArrayFromBundle( |
| 4531 | wearableBundle, KEY_PAGES); |
| 4532 | if (pages != null) { |
| 4533 | Collections.addAll(mPages, pages); |
| 4534 | } |
| 4535 | |
| 4536 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 4537 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 4538 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 4539 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 4540 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 4541 | UNSET_ACTION_INDEX); |
| 4542 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 4543 | SIZE_DEFAULT); |
| 4544 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 4545 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4546 | mHintScreenTimeout = wearableBundle.getInt(KEY_HINT_SCREEN_TIMEOUT); |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4547 | } |
| 4548 | } |
| 4549 | |
| 4550 | /** |
| 4551 | * Apply wearable extensions to a notification that is being built. This is typically |
| 4552 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 4553 | * {@link android.app.Notification.Builder}. |
| 4554 | */ |
| 4555 | @Override |
| 4556 | public Notification.Builder extend(Notification.Builder builder) { |
| 4557 | Bundle wearableBundle = new Bundle(); |
| 4558 | |
| 4559 | if (!mActions.isEmpty()) { |
| 4560 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 4561 | } |
| 4562 | if (mFlags != DEFAULT_FLAGS) { |
| 4563 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 4564 | } |
| 4565 | if (mDisplayIntent != null) { |
| 4566 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 4567 | } |
| 4568 | if (!mPages.isEmpty()) { |
| 4569 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 4570 | new Notification[mPages.size()])); |
| 4571 | } |
| 4572 | if (mBackground != null) { |
| 4573 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 4574 | } |
| 4575 | if (mContentIcon != 0) { |
| 4576 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 4577 | } |
| 4578 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 4579 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 4580 | } |
| 4581 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 4582 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 4583 | mContentActionIndex); |
| 4584 | } |
| 4585 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 4586 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 4587 | } |
| 4588 | if (mCustomContentHeight != 0) { |
| 4589 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 4590 | } |
| 4591 | if (mGravity != DEFAULT_GRAVITY) { |
| 4592 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 4593 | } |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4594 | if (mHintScreenTimeout != 0) { |
| 4595 | wearableBundle.putInt(KEY_HINT_SCREEN_TIMEOUT, mHintScreenTimeout); |
| 4596 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4597 | |
| 4598 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 4599 | return builder; |
| 4600 | } |
| 4601 | |
| 4602 | @Override |
| 4603 | public WearableExtender clone() { |
| 4604 | WearableExtender that = new WearableExtender(); |
| 4605 | that.mActions = new ArrayList<Action>(this.mActions); |
| 4606 | that.mFlags = this.mFlags; |
| 4607 | that.mDisplayIntent = this.mDisplayIntent; |
| 4608 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 4609 | that.mBackground = this.mBackground; |
| 4610 | that.mContentIcon = this.mContentIcon; |
| 4611 | that.mContentIconGravity = this.mContentIconGravity; |
| 4612 | that.mContentActionIndex = this.mContentActionIndex; |
| 4613 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 4614 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 4615 | that.mGravity = this.mGravity; |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 4616 | that.mHintScreenTimeout = this.mHintScreenTimeout; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4617 | return that; |
| 4618 | } |
| 4619 | |
| 4620 | /** |
| 4621 | * Add a wearable action to this notification. |
| 4622 | * |
| 4623 | * <p>When wearable actions are added using this method, the set of actions that |
| 4624 | * show on a wearable device splits from devices that only show actions added |
| 4625 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 4626 | * of which actions display on different devices. |
| 4627 | * |
| 4628 | * @param action the action to add to this notification |
| 4629 | * @return this object for method chaining |
| 4630 | * @see android.app.Notification.Action |
| 4631 | */ |
| 4632 | public WearableExtender addAction(Action action) { |
| 4633 | mActions.add(action); |
| 4634 | return this; |
| 4635 | } |
| 4636 | |
| 4637 | /** |
| 4638 | * Adds wearable actions to this notification. |
| 4639 | * |
| 4640 | * <p>When wearable actions are added using this method, the set of actions that |
| 4641 | * show on a wearable device splits from devices that only show actions added |
| 4642 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 4643 | * of which actions display on different devices. |
| 4644 | * |
| 4645 | * @param actions the actions to add to this notification |
| 4646 | * @return this object for method chaining |
| 4647 | * @see android.app.Notification.Action |
| 4648 | */ |
| 4649 | public WearableExtender addActions(List<Action> actions) { |
| 4650 | mActions.addAll(actions); |
| 4651 | return this; |
| 4652 | } |
| 4653 | |
| 4654 | /** |
| 4655 | * Clear all wearable actions present on this builder. |
| 4656 | * @return this object for method chaining. |
| 4657 | * @see #addAction |
| 4658 | */ |
| 4659 | public WearableExtender clearActions() { |
| 4660 | mActions.clear(); |
| 4661 | return this; |
| 4662 | } |
| 4663 | |
| 4664 | /** |
| 4665 | * Get the wearable actions present on this notification. |
| 4666 | */ |
| 4667 | public List<Action> getActions() { |
| 4668 | return mActions; |
| 4669 | } |
| 4670 | |
| 4671 | /** |
| 4672 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4673 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 4674 | * |
| 4675 | * <pre class="prettyprint"> |
| 4676 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 4677 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 4678 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 4679 | * Notification notif = new Notification.Builder(context) |
| 4680 | * .extend(new Notification.WearableExtender() |
| 4681 | * .setDisplayIntent(displayPendingIntent) |
| 4682 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 4683 | * .build();</pre> |
| 4684 | * |
| 4685 | * <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] | 4686 | * should have an empty task affinity. It is also recommended to use the device |
| 4687 | * default light theme. |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame] | 4688 | * |
| 4689 | * <p>Example AndroidManifest.xml entry: |
| 4690 | * <pre class="prettyprint"> |
| 4691 | * <activity android:name="com.example.MyDisplayActivity" |
| 4692 | * android:exported="true" |
| 4693 | * android:allowEmbedded="true" |
Griff Hazen | 831ca9d | 2014-06-17 00:38:38 -0700 | [diff] [blame] | 4694 | * android:taskAffinity="" |
| 4695 | * android:theme="@android:style/Theme.DeviceDefault.Light" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4696 | * |
| 4697 | * @param intent the {@link PendingIntent} for an activity |
| 4698 | * @return this object for method chaining |
| 4699 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 4700 | */ |
| 4701 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 4702 | mDisplayIntent = intent; |
| 4703 | return this; |
| 4704 | } |
| 4705 | |
| 4706 | /** |
| 4707 | * Get the intent to launch inside of an activity view when displaying this |
| 4708 | * notification. This {@code PendingIntent} should be for an activity. |
| 4709 | */ |
| 4710 | public PendingIntent getDisplayIntent() { |
| 4711 | return mDisplayIntent; |
| 4712 | } |
| 4713 | |
| 4714 | /** |
| 4715 | * Add an additional page of content to display with this notification. The current |
| 4716 | * notification forms the first page, and pages added using this function form |
| 4717 | * subsequent pages. This field can be used to separate a notification into multiple |
| 4718 | * sections. |
| 4719 | * |
| 4720 | * @param page the notification to add as another page |
| 4721 | * @return this object for method chaining |
| 4722 | * @see android.app.Notification.WearableExtender#getPages |
| 4723 | */ |
| 4724 | public WearableExtender addPage(Notification page) { |
| 4725 | mPages.add(page); |
| 4726 | return this; |
| 4727 | } |
| 4728 | |
| 4729 | /** |
| 4730 | * Add additional pages of content to display with this notification. The current |
| 4731 | * notification forms the first page, and pages added using this function form |
| 4732 | * subsequent pages. This field can be used to separate a notification into multiple |
| 4733 | * sections. |
| 4734 | * |
| 4735 | * @param pages a list of notifications |
| 4736 | * @return this object for method chaining |
| 4737 | * @see android.app.Notification.WearableExtender#getPages |
| 4738 | */ |
| 4739 | public WearableExtender addPages(List<Notification> pages) { |
| 4740 | mPages.addAll(pages); |
| 4741 | return this; |
| 4742 | } |
| 4743 | |
| 4744 | /** |
| 4745 | * Clear all additional pages present on this builder. |
| 4746 | * @return this object for method chaining. |
| 4747 | * @see #addPage |
| 4748 | */ |
| 4749 | public WearableExtender clearPages() { |
| 4750 | mPages.clear(); |
| 4751 | return this; |
| 4752 | } |
| 4753 | |
| 4754 | /** |
| 4755 | * Get the array of additional pages of content for displaying this notification. The |
| 4756 | * current notification forms the first page, and elements within this array form |
| 4757 | * subsequent pages. This field can be used to separate a notification into multiple |
| 4758 | * sections. |
| 4759 | * @return the pages for this notification |
| 4760 | */ |
| 4761 | public List<Notification> getPages() { |
| 4762 | return mPages; |
| 4763 | } |
| 4764 | |
| 4765 | /** |
| 4766 | * Set a background image to be displayed behind the notification content. |
| 4767 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 4768 | * will work with any notification style. |
| 4769 | * |
| 4770 | * @param background the background bitmap |
| 4771 | * @return this object for method chaining |
| 4772 | * @see android.app.Notification.WearableExtender#getBackground |
| 4773 | */ |
| 4774 | public WearableExtender setBackground(Bitmap background) { |
| 4775 | mBackground = background; |
| 4776 | return this; |
| 4777 | } |
| 4778 | |
| 4779 | /** |
| 4780 | * Get a background image to be displayed behind the notification content. |
| 4781 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 4782 | * will work with any notification style. |
| 4783 | * |
| 4784 | * @return the background image |
| 4785 | * @see android.app.Notification.WearableExtender#setBackground |
| 4786 | */ |
| 4787 | public Bitmap getBackground() { |
| 4788 | return mBackground; |
| 4789 | } |
| 4790 | |
| 4791 | /** |
| 4792 | * Set an icon that goes with the content of this notification. |
| 4793 | */ |
| 4794 | public WearableExtender setContentIcon(int icon) { |
| 4795 | mContentIcon = icon; |
| 4796 | return this; |
| 4797 | } |
| 4798 | |
| 4799 | /** |
| 4800 | * Get an icon that goes with the content of this notification. |
| 4801 | */ |
| 4802 | public int getContentIcon() { |
| 4803 | return mContentIcon; |
| 4804 | } |
| 4805 | |
| 4806 | /** |
| 4807 | * Set the gravity that the content icon should have within the notification display. |
| 4808 | * Supported values include {@link android.view.Gravity#START} and |
| 4809 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 4810 | * @see #setContentIcon |
| 4811 | */ |
| 4812 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 4813 | mContentIconGravity = contentIconGravity; |
| 4814 | return this; |
| 4815 | } |
| 4816 | |
| 4817 | /** |
| 4818 | * Get the gravity that the content icon should have within the notification display. |
| 4819 | * Supported values include {@link android.view.Gravity#START} and |
| 4820 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 4821 | * @see #getContentIcon |
| 4822 | */ |
| 4823 | public int getContentIconGravity() { |
| 4824 | return mContentIconGravity; |
| 4825 | } |
| 4826 | |
| 4827 | /** |
| 4828 | * 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] | 4829 | * this notification. This action will no longer display separately from the |
| 4830 | * notification's content. |
| 4831 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 4832 | * <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] | 4833 | * set, although the list of available actions comes from the main notification and not |
| 4834 | * from the child page's notification. |
| 4835 | * |
| 4836 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 4837 | * If wearable actions were added to the main notification, this index |
| 4838 | * will apply to that list, otherwise it will apply to the regular |
| 4839 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4840 | */ |
| 4841 | public WearableExtender setContentAction(int actionIndex) { |
| 4842 | mContentActionIndex = actionIndex; |
| 4843 | return this; |
| 4844 | } |
| 4845 | |
| 4846 | /** |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 4847 | * Get the index of the notification action, if any, that was specified as being clickable |
| 4848 | * 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] | 4849 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 4850 | * |
Griff Hazen | ca48d35 | 2014-05-28 22:37:13 -0700 | [diff] [blame] | 4851 | * <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] | 4852 | * set, although the list of available actions comes from the main notification and not |
| 4853 | * from the child page's notification. |
| 4854 | * |
| 4855 | * <p>If wearable specific actions were added to the main notification, this index will |
| 4856 | * 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] | 4857 | * |
| 4858 | * @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] | 4859 | */ |
| 4860 | public int getContentAction() { |
| 4861 | return mContentActionIndex; |
| 4862 | } |
| 4863 | |
| 4864 | /** |
| 4865 | * Set the gravity that this notification should have within the available viewport space. |
| 4866 | * Supported values include {@link android.view.Gravity#TOP}, |
| 4867 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 4868 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 4869 | */ |
| 4870 | public WearableExtender setGravity(int gravity) { |
| 4871 | mGravity = gravity; |
| 4872 | return this; |
| 4873 | } |
| 4874 | |
| 4875 | /** |
| 4876 | * Get the gravity that this notification should have within the available viewport space. |
| 4877 | * Supported values include {@link android.view.Gravity#TOP}, |
| 4878 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 4879 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 4880 | */ |
| 4881 | public int getGravity() { |
| 4882 | return mGravity; |
| 4883 | } |
| 4884 | |
| 4885 | /** |
| 4886 | * Set the custom size preset for the display of this notification out of the available |
| 4887 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 4888 | * {@link #SIZE_LARGE}. |
| 4889 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 4890 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 4891 | * documentation for the preset in question. See also |
| 4892 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 4893 | */ |
| 4894 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 4895 | mCustomSizePreset = sizePreset; |
| 4896 | return this; |
| 4897 | } |
| 4898 | |
| 4899 | /** |
| 4900 | * Get the custom size preset for the display of this notification out of the available |
| 4901 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 4902 | * {@link #SIZE_LARGE}. |
| 4903 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 4904 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 4905 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 4906 | */ |
| 4907 | public int getCustomSizePreset() { |
| 4908 | return mCustomSizePreset; |
| 4909 | } |
| 4910 | |
| 4911 | /** |
| 4912 | * Set the custom height in pixels for the display of this notification's content. |
| 4913 | * <p>This option is only available for custom display notifications created |
| 4914 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 4915 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 4916 | * {@link #getCustomContentHeight}. |
| 4917 | */ |
| 4918 | public WearableExtender setCustomContentHeight(int height) { |
| 4919 | mCustomContentHeight = height; |
| 4920 | return this; |
| 4921 | } |
| 4922 | |
| 4923 | /** |
| 4924 | * Get the custom height in pixels for the display of this notification's content. |
| 4925 | * <p>This option is only available for custom display notifications created |
| 4926 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 4927 | * {@link #setCustomContentHeight}. |
| 4928 | */ |
| 4929 | public int getCustomContentHeight() { |
| 4930 | return mCustomContentHeight; |
| 4931 | } |
| 4932 | |
| 4933 | /** |
| 4934 | * Set whether the scrolling position for the contents of this notification should start |
| 4935 | * at the bottom of the contents instead of the top when the contents are too long to |
| 4936 | * display within the screen. Default is false (start scroll at the top). |
| 4937 | */ |
| 4938 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 4939 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 4940 | return this; |
| 4941 | } |
| 4942 | |
| 4943 | /** |
| 4944 | * Get whether the scrolling position for the contents of this notification should start |
| 4945 | * at the bottom of the contents instead of the top when the contents are too long to |
| 4946 | * display within the screen. Default is false (start scroll at the top). |
| 4947 | */ |
| 4948 | public boolean getStartScrollBottom() { |
| 4949 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 4950 | } |
| 4951 | |
| 4952 | /** |
| 4953 | * Set whether the content intent is available when the wearable device is not connected |
| 4954 | * to a companion device. The user can still trigger this intent when the wearable device |
| 4955 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 4956 | * Defaults to true. |
| 4957 | */ |
| 4958 | public WearableExtender setContentIntentAvailableOffline( |
| 4959 | boolean contentIntentAvailableOffline) { |
| 4960 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 4961 | return this; |
| 4962 | } |
| 4963 | |
| 4964 | /** |
| 4965 | * Get whether the content intent is available when the wearable device is not connected |
| 4966 | * to a companion device. The user can still trigger this intent when the wearable device |
| 4967 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 4968 | * Defaults to true. |
| 4969 | */ |
| 4970 | public boolean getContentIntentAvailableOffline() { |
| 4971 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 4972 | } |
| 4973 | |
| 4974 | /** |
| 4975 | * Set a hint that this notification's icon should not be displayed. |
| 4976 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 4977 | * @return this object for method chaining |
| 4978 | */ |
| 4979 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 4980 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 4981 | return this; |
| 4982 | } |
| 4983 | |
| 4984 | /** |
| 4985 | * Get a hint that this notification's icon should not be displayed. |
| 4986 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 4987 | * The default value is {@code false} if this was never set. |
| 4988 | */ |
| 4989 | public boolean getHintHideIcon() { |
| 4990 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 4991 | } |
| 4992 | |
| 4993 | /** |
| 4994 | * Set a visual hint that only the background image of this notification should be |
| 4995 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 4996 | * to sub-pages added using {@link #addPage}. |
| 4997 | */ |
| 4998 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 4999 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 5000 | return this; |
| 5001 | } |
| 5002 | |
| 5003 | /** |
| 5004 | * Get a visual hint that only the background image of this notification should be |
| 5005 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 5006 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 5007 | */ |
| 5008 | public boolean getHintShowBackgroundOnly() { |
| 5009 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 5010 | } |
| 5011 | |
Griff Hazen | 5f2edfc | 2014-09-29 16:28:44 -0700 | [diff] [blame] | 5012 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5013 | * Set a hint that this notification's background should not be clipped if possible, |
| 5014 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5015 | * 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] | 5016 | * @param hintAvoidBackgroundClipping {@code true} to avoid clipping if possible. |
| 5017 | * @return this object for method chaining |
| 5018 | */ |
| 5019 | public WearableExtender setHintAvoidBackgroundClipping( |
| 5020 | boolean hintAvoidBackgroundClipping) { |
| 5021 | setFlag(FLAG_HINT_AVOID_BACKGROUND_CLIPPING, hintAvoidBackgroundClipping); |
| 5022 | return this; |
| 5023 | } |
| 5024 | |
| 5025 | /** |
Griff Hazen | 9c5be4e | 2014-11-17 17:47:50 -0800 | [diff] [blame] | 5026 | * Get a hint that this notification's background should not be clipped if possible, |
| 5027 | * and should instead be resized to fully display on the screen, retaining the aspect |
| 5028 | * 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] | 5029 | * @return {@code true} if it's ok if the background is clipped on the screen, false |
| 5030 | * otherwise. The default value is {@code false} if this was never set. |
| 5031 | */ |
| 5032 | public boolean getHintAvoidBackgroundClipping() { |
| 5033 | return (mFlags & FLAG_HINT_AVOID_BACKGROUND_CLIPPING) != 0; |
| 5034 | } |
| 5035 | |
| 5036 | /** |
| 5037 | * Set a hint that the screen should remain on for at least this duration when |
| 5038 | * this notification is displayed on the screen. |
| 5039 | * @param timeout The requested screen timeout in milliseconds. Can also be either |
| 5040 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5041 | * @return this object for method chaining |
| 5042 | */ |
| 5043 | public WearableExtender setHintScreenTimeout(int timeout) { |
| 5044 | mHintScreenTimeout = timeout; |
| 5045 | return this; |
| 5046 | } |
| 5047 | |
| 5048 | /** |
| 5049 | * Get the duration, in milliseconds, that the screen should remain on for |
| 5050 | * when this notification is displayed. |
| 5051 | * @return the duration in milliseconds if > 0, or either one of the sentinel values |
| 5052 | * {@link #SCREEN_TIMEOUT_SHORT} or {@link #SCREEN_TIMEOUT_LONG}. |
| 5053 | */ |
| 5054 | public int getHintScreenTimeout() { |
| 5055 | return mHintScreenTimeout; |
| 5056 | } |
| 5057 | |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5058 | private void setFlag(int mask, boolean value) { |
| 5059 | if (value) { |
| 5060 | mFlags |= mask; |
| 5061 | } else { |
| 5062 | mFlags &= ~mask; |
| 5063 | } |
| 5064 | } |
| 5065 | } |
| 5066 | |
| 5067 | /** |
Zhen Yu Song | 9d5528b | 2014-11-14 15:34:39 -0800 | [diff] [blame^] | 5068 | * <p>Helper class to add Android Auto extensions to notifications. To create a notification |
| 5069 | * with car extensions: |
| 5070 | * |
| 5071 | * <ol> |
| 5072 | * <li>Create an {@link Notification.Builder}, setting any desired |
| 5073 | * properties. |
| 5074 | * <li>Create a {@link CarExtender}. |
| 5075 | * <li>Set car-specific properties using the {@code add} and {@code set} methods of |
| 5076 | * {@link CarExtender}. |
| 5077 | * <li>Call {@link Notification.Builder#extend(Notification.Extender)} |
| 5078 | * to apply the extensions to a notification. |
| 5079 | * </ol> |
| 5080 | * |
| 5081 | * <pre class="prettyprint"> |
| 5082 | * Notification notification = new Notification.Builder(context) |
| 5083 | * ... |
| 5084 | * .extend(new CarExtender() |
| 5085 | * .set*(...)) |
| 5086 | * .build(); |
| 5087 | * </pre> |
| 5088 | * |
| 5089 | * <p>Car extensions can be accessed on an existing notification by using the |
| 5090 | * {@code CarExtender(Notification)} constructor, and then using the {@code get} methods |
| 5091 | * to access values. |
| 5092 | */ |
| 5093 | public static final class CarExtender implements Extender { |
| 5094 | private static final String TAG = "CarExtender"; |
| 5095 | |
| 5096 | private static final String EXTRA_CAR_EXTENDER = "android.car.EXTENSIONS"; |
| 5097 | private static final String EXTRA_LARGE_ICON = "large_icon"; |
| 5098 | private static final String EXTRA_CONVERSATION = "car_conversation"; |
| 5099 | private static final String EXTRA_COLOR = "app_color"; |
| 5100 | |
| 5101 | private Bitmap mLargeIcon; |
| 5102 | private UnreadConversation mUnreadConversation; |
| 5103 | private int mColor = Notification.COLOR_DEFAULT; |
| 5104 | |
| 5105 | /** |
| 5106 | * Create a {@link CarExtender} with default options. |
| 5107 | */ |
| 5108 | public CarExtender() { |
| 5109 | } |
| 5110 | |
| 5111 | /** |
| 5112 | * Create a {@link CarExtender} from the CarExtender options of an existing Notification. |
| 5113 | * |
| 5114 | * @param notif The notification from which to copy options. |
| 5115 | */ |
| 5116 | public CarExtender(Notification notif) { |
| 5117 | Bundle carBundle = notif.extras == null ? |
| 5118 | null : notif.extras.getBundle(EXTRA_CAR_EXTENDER); |
| 5119 | if (carBundle != null) { |
| 5120 | mLargeIcon = carBundle.getParcelable(EXTRA_LARGE_ICON); |
| 5121 | mColor = carBundle.getInt(EXTRA_COLOR, Notification.COLOR_DEFAULT); |
| 5122 | |
| 5123 | Bundle b = carBundle.getBundle(EXTRA_CONVERSATION); |
| 5124 | mUnreadConversation = UnreadConversation.getUnreadConversationFromBundle(b); |
| 5125 | } |
| 5126 | } |
| 5127 | |
| 5128 | /** |
| 5129 | * Apply car extensions to a notification that is being built. This is typically called by |
| 5130 | * the {@link Notification.Builder#extend(Notification.Extender)} |
| 5131 | * method of {@link Notification.Builder}. |
| 5132 | */ |
| 5133 | @Override |
| 5134 | public Notification.Builder extend(Notification.Builder builder) { |
| 5135 | Bundle carExtensions = new Bundle(); |
| 5136 | |
| 5137 | if (mLargeIcon != null) { |
| 5138 | carExtensions.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 5139 | } |
| 5140 | if (mColor != Notification.COLOR_DEFAULT) { |
| 5141 | carExtensions.putInt(EXTRA_COLOR, mColor); |
| 5142 | } |
| 5143 | |
| 5144 | if (mUnreadConversation != null) { |
| 5145 | Bundle b = mUnreadConversation.getBundleForUnreadConversation(); |
| 5146 | carExtensions.putBundle(EXTRA_CONVERSATION, b); |
| 5147 | } |
| 5148 | |
| 5149 | builder.getExtras().putBundle(EXTRA_CAR_EXTENDER, carExtensions); |
| 5150 | return builder; |
| 5151 | } |
| 5152 | |
| 5153 | /** |
| 5154 | * Sets the accent color to use when Android Auto presents the notification. |
| 5155 | * |
| 5156 | * Android Auto uses the color set with {@link Notification.Builder#setColor(int)} |
| 5157 | * to accent the displayed notification. However, not all colors are acceptable in an |
| 5158 | * automotive setting. This method can be used to override the color provided in the |
| 5159 | * notification in such a situation. |
| 5160 | */ |
| 5161 | public CarExtender setColor(int color) { |
| 5162 | mColor = color; |
| 5163 | return this; |
| 5164 | } |
| 5165 | |
| 5166 | /** |
| 5167 | * Gets the accent color. |
| 5168 | * |
| 5169 | * @see setColor |
| 5170 | */ |
| 5171 | public int getColor() { |
| 5172 | return mColor; |
| 5173 | } |
| 5174 | |
| 5175 | /** |
| 5176 | * Sets the large icon of the car notification. |
| 5177 | * |
| 5178 | * If no large icon is set in the extender, Android Auto will display the icon |
| 5179 | * specified by {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap)} |
| 5180 | * |
| 5181 | * @param largeIcon The large icon to use in the car notification. |
| 5182 | * @return This object for method chaining. |
| 5183 | */ |
| 5184 | public CarExtender setLargeIcon(Bitmap largeIcon) { |
| 5185 | mLargeIcon = largeIcon; |
| 5186 | return this; |
| 5187 | } |
| 5188 | |
| 5189 | /** |
| 5190 | * Gets the large icon used in this car notification, or null if no icon has been set. |
| 5191 | * |
| 5192 | * @return The large icon for the car notification. |
| 5193 | * @see CarExtender#setLargeIcon |
| 5194 | */ |
| 5195 | public Bitmap getLargeIcon() { |
| 5196 | return mLargeIcon; |
| 5197 | } |
| 5198 | |
| 5199 | /** |
| 5200 | * Sets the unread conversation in a message notification. |
| 5201 | * |
| 5202 | * @param unreadConversation The unread part of the conversation this notification conveys. |
| 5203 | * @return This object for method chaining. |
| 5204 | */ |
| 5205 | public CarExtender setUnreadConversation(UnreadConversation unreadConversation) { |
| 5206 | mUnreadConversation = unreadConversation; |
| 5207 | return this; |
| 5208 | } |
| 5209 | |
| 5210 | /** |
| 5211 | * Returns the unread conversation conveyed by this notification. |
| 5212 | * @see #setUnreadConversation(UnreadConversation) |
| 5213 | */ |
| 5214 | public UnreadConversation getUnreadConversation() { |
| 5215 | return mUnreadConversation; |
| 5216 | } |
| 5217 | |
| 5218 | /** |
| 5219 | * A class which holds the unread messages from a conversation. |
| 5220 | */ |
| 5221 | public static class UnreadConversation { |
| 5222 | private static final String KEY_AUTHOR = "author"; |
| 5223 | private static final String KEY_TEXT = "text"; |
| 5224 | private static final String KEY_MESSAGES = "messages"; |
| 5225 | private static final String KEY_REMOTE_INPUT = "remote_input"; |
| 5226 | private static final String KEY_ON_REPLY = "on_reply"; |
| 5227 | private static final String KEY_ON_READ = "on_read"; |
| 5228 | private static final String KEY_PARTICIPANTS = "participants"; |
| 5229 | private static final String KEY_TIMESTAMP = "timestamp"; |
| 5230 | |
| 5231 | private final String[] mMessages; |
| 5232 | private final RemoteInput mRemoteInput; |
| 5233 | private final PendingIntent mReplyPendingIntent; |
| 5234 | private final PendingIntent mReadPendingIntent; |
| 5235 | private final String[] mParticipants; |
| 5236 | private final long mLatestTimestamp; |
| 5237 | |
| 5238 | UnreadConversation(String[] messages, RemoteInput remoteInput, |
| 5239 | PendingIntent replyPendingIntent, PendingIntent readPendingIntent, |
| 5240 | String[] participants, long latestTimestamp) { |
| 5241 | mMessages = messages; |
| 5242 | mRemoteInput = remoteInput; |
| 5243 | mReadPendingIntent = readPendingIntent; |
| 5244 | mReplyPendingIntent = replyPendingIntent; |
| 5245 | mParticipants = participants; |
| 5246 | mLatestTimestamp = latestTimestamp; |
| 5247 | } |
| 5248 | |
| 5249 | /** |
| 5250 | * Gets the list of messages conveyed by this notification. |
| 5251 | */ |
| 5252 | public String[] getMessages() { |
| 5253 | return mMessages; |
| 5254 | } |
| 5255 | |
| 5256 | /** |
| 5257 | * Gets the remote input that will be used to convey the response to a message list, or |
| 5258 | * null if no such remote input exists. |
| 5259 | */ |
| 5260 | public RemoteInput getRemoteInput() { |
| 5261 | return mRemoteInput; |
| 5262 | } |
| 5263 | |
| 5264 | /** |
| 5265 | * Gets the pending intent that will be triggered when the user replies to this |
| 5266 | * notification. |
| 5267 | */ |
| 5268 | public PendingIntent getReplyPendingIntent() { |
| 5269 | return mReplyPendingIntent; |
| 5270 | } |
| 5271 | |
| 5272 | /** |
| 5273 | * Gets the pending intent that Android Auto will send after it reads aloud all messages |
| 5274 | * in this object's message list. |
| 5275 | */ |
| 5276 | public PendingIntent getReadPendingIntent() { |
| 5277 | return mReadPendingIntent; |
| 5278 | } |
| 5279 | |
| 5280 | /** |
| 5281 | * Gets the participants in the conversation. |
| 5282 | */ |
| 5283 | public String[] getParticipants() { |
| 5284 | return mParticipants; |
| 5285 | } |
| 5286 | |
| 5287 | /** |
| 5288 | * Gets the firs participant in the conversation. |
| 5289 | */ |
| 5290 | public String getParticipant() { |
| 5291 | return mParticipants.length > 0 ? mParticipants[0] : null; |
| 5292 | } |
| 5293 | |
| 5294 | /** |
| 5295 | * Gets the timestamp of the conversation. |
| 5296 | */ |
| 5297 | public long getLatestTimestamp() { |
| 5298 | return mLatestTimestamp; |
| 5299 | } |
| 5300 | |
| 5301 | Bundle getBundleForUnreadConversation() { |
| 5302 | Bundle b = new Bundle(); |
| 5303 | String author = null; |
| 5304 | if (mParticipants != null && mParticipants.length > 1) { |
| 5305 | author = mParticipants[0]; |
| 5306 | } |
| 5307 | Parcelable[] messages = new Parcelable[mMessages.length]; |
| 5308 | for (int i = 0; i < messages.length; i++) { |
| 5309 | Bundle m = new Bundle(); |
| 5310 | m.putString(KEY_TEXT, mMessages[i]); |
| 5311 | m.putString(KEY_AUTHOR, author); |
| 5312 | messages[i] = m; |
| 5313 | } |
| 5314 | b.putParcelableArray(KEY_MESSAGES, messages); |
| 5315 | if (mRemoteInput != null) { |
| 5316 | b.putParcelable(KEY_REMOTE_INPUT, mRemoteInput); |
| 5317 | } |
| 5318 | b.putParcelable(KEY_ON_REPLY, mReplyPendingIntent); |
| 5319 | b.putParcelable(KEY_ON_READ, mReadPendingIntent); |
| 5320 | b.putStringArray(KEY_PARTICIPANTS, mParticipants); |
| 5321 | b.putLong(KEY_TIMESTAMP, mLatestTimestamp); |
| 5322 | return b; |
| 5323 | } |
| 5324 | |
| 5325 | static UnreadConversation getUnreadConversationFromBundle(Bundle b) { |
| 5326 | if (b == null) { |
| 5327 | return null; |
| 5328 | } |
| 5329 | Parcelable[] parcelableMessages = b.getParcelableArray(KEY_MESSAGES); |
| 5330 | String[] messages = null; |
| 5331 | if (parcelableMessages != null) { |
| 5332 | String[] tmp = new String[parcelableMessages.length]; |
| 5333 | boolean success = true; |
| 5334 | for (int i = 0; i < tmp.length; i++) { |
| 5335 | if (!(parcelableMessages[i] instanceof Bundle)) { |
| 5336 | success = false; |
| 5337 | break; |
| 5338 | } |
| 5339 | tmp[i] = ((Bundle) parcelableMessages[i]).getString(KEY_TEXT); |
| 5340 | if (tmp[i] == null) { |
| 5341 | success = false; |
| 5342 | break; |
| 5343 | } |
| 5344 | } |
| 5345 | if (success) { |
| 5346 | messages = tmp; |
| 5347 | } else { |
| 5348 | return null; |
| 5349 | } |
| 5350 | } |
| 5351 | |
| 5352 | PendingIntent onRead = b.getParcelable(KEY_ON_READ); |
| 5353 | PendingIntent onReply = b.getParcelable(KEY_ON_REPLY); |
| 5354 | |
| 5355 | RemoteInput remoteInput = b.getParcelable(KEY_REMOTE_INPUT); |
| 5356 | |
| 5357 | String[] participants = b.getStringArray(KEY_PARTICIPANTS); |
| 5358 | if (participants == null || participants.length != 1) { |
| 5359 | return null; |
| 5360 | } |
| 5361 | |
| 5362 | return new UnreadConversation(messages, |
| 5363 | remoteInput, |
| 5364 | onReply, |
| 5365 | onRead, |
| 5366 | participants, b.getLong(KEY_TIMESTAMP)); |
| 5367 | } |
| 5368 | }; |
| 5369 | |
| 5370 | /** |
| 5371 | * Builder class for {@link CarExtender.UnreadConversation} objects. |
| 5372 | */ |
| 5373 | public static class Builder { |
| 5374 | private final List<String> mMessages = new ArrayList<String>(); |
| 5375 | private final String mParticipant; |
| 5376 | private RemoteInput mRemoteInput; |
| 5377 | private PendingIntent mReadPendingIntent; |
| 5378 | private PendingIntent mReplyPendingIntent; |
| 5379 | private long mLatestTimestamp; |
| 5380 | |
| 5381 | /** |
| 5382 | * Constructs a new builder for {@link CarExtender.UnreadConversation}. |
| 5383 | * |
| 5384 | * @param name The name of the other participant in the conversation. |
| 5385 | */ |
| 5386 | public Builder(String name) { |
| 5387 | mParticipant = name; |
| 5388 | } |
| 5389 | |
| 5390 | /** |
| 5391 | * Appends a new unread message to the list of messages for this conversation. |
| 5392 | * |
| 5393 | * The messages should be added from oldest to newest. |
| 5394 | * |
| 5395 | * @param message The text of the new unread message. |
| 5396 | * @return This object for method chaining. |
| 5397 | */ |
| 5398 | public Builder addMessage(String message) { |
| 5399 | mMessages.add(message); |
| 5400 | return this; |
| 5401 | } |
| 5402 | |
| 5403 | /** |
| 5404 | * Sets the pending intent and remote input which will convey the reply to this |
| 5405 | * notification. |
| 5406 | * |
| 5407 | * @param pendingIntent The pending intent which will be triggered on a reply. |
| 5408 | * @param remoteInput The remote input parcelable which will carry the reply. |
| 5409 | * @return This object for method chaining. |
| 5410 | * |
| 5411 | * @see CarExtender.UnreadConversation#getRemoteInput |
| 5412 | * @see CarExtender.UnreadConversation#getReplyPendingIntent |
| 5413 | */ |
| 5414 | public Builder setReplyAction( |
| 5415 | PendingIntent pendingIntent, RemoteInput remoteInput) { |
| 5416 | mRemoteInput = remoteInput; |
| 5417 | mReplyPendingIntent = pendingIntent; |
| 5418 | |
| 5419 | return this; |
| 5420 | } |
| 5421 | |
| 5422 | /** |
| 5423 | * Sets the pending intent that will be sent once the messages in this notification |
| 5424 | * are read. |
| 5425 | * |
| 5426 | * @param pendingIntent The pending intent to use. |
| 5427 | * @return This object for method chaining. |
| 5428 | */ |
| 5429 | public Builder setReadPendingIntent(PendingIntent pendingIntent) { |
| 5430 | mReadPendingIntent = pendingIntent; |
| 5431 | return this; |
| 5432 | } |
| 5433 | |
| 5434 | /** |
| 5435 | * Sets the timestamp of the most recent message in an unread conversation. |
| 5436 | * |
| 5437 | * If a messaging notification has been posted by your application and has not |
| 5438 | * yet been cancelled, posting a later notification with the same id and tag |
| 5439 | * but without a newer timestamp may result in Android Auto not displaying a |
| 5440 | * heads up notification for the later notification. |
| 5441 | * |
| 5442 | * @param timestamp The timestamp of the most recent message in the conversation. |
| 5443 | * @return This object for method chaining. |
| 5444 | */ |
| 5445 | public Builder setLatestTimestamp(long timestamp) { |
| 5446 | mLatestTimestamp = timestamp; |
| 5447 | return this; |
| 5448 | } |
| 5449 | |
| 5450 | /** |
| 5451 | * Builds a new unread conversation object. |
| 5452 | * |
| 5453 | * @return The new unread conversation object. |
| 5454 | */ |
| 5455 | public UnreadConversation build() { |
| 5456 | String[] messages = mMessages.toArray(new String[mMessages.size()]); |
| 5457 | String[] participants = { mParticipant }; |
| 5458 | return new UnreadConversation(messages, mRemoteInput, mReplyPendingIntent, |
| 5459 | mReadPendingIntent, participants, mLatestTimestamp); |
| 5460 | } |
| 5461 | } |
| 5462 | } |
| 5463 | |
| 5464 | /** |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 5465 | * Get an array of Notification objects from a parcelable array bundle field. |
| 5466 | * Update the bundle to have a typed array so fetches in the future don't need |
| 5467 | * to do an array copy. |
| 5468 | */ |
| 5469 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 5470 | Parcelable[] array = bundle.getParcelableArray(key); |
| 5471 | if (array instanceof Notification[] || array == null) { |
| 5472 | return (Notification[]) array; |
| 5473 | } |
| 5474 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 5475 | Notification[].class); |
| 5476 | bundle.putParcelableArray(key, typedArray); |
| 5477 | return typedArray; |
| 5478 | } |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5479 | |
| 5480 | private static class BuilderRemoteViews extends RemoteViews { |
| 5481 | public BuilderRemoteViews(Parcel parcel) { |
| 5482 | super(parcel); |
| 5483 | } |
| 5484 | |
Kenny Guy | 7732006 | 2014-08-27 21:37:15 +0100 | [diff] [blame] | 5485 | public BuilderRemoteViews(ApplicationInfo appInfo, int layoutId) { |
| 5486 | super(appInfo, layoutId); |
Christoph Studer | 4600f9b | 2014-07-22 22:44:43 +0200 | [diff] [blame] | 5487 | } |
| 5488 | |
| 5489 | @Override |
| 5490 | public BuilderRemoteViews clone() { |
| 5491 | Parcel p = Parcel.obtain(); |
| 5492 | writeToParcel(p, 0); |
| 5493 | p.setDataPosition(0); |
| 5494 | BuilderRemoteViews brv = new BuilderRemoteViews(p); |
| 5495 | p.recycle(); |
| 5496 | return brv; |
| 5497 | } |
| 5498 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 5499 | } |