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