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 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 19 | import android.content.Context; |
| 20 | import android.content.Intent; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 21 | import android.content.res.Resources; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 22 | import android.graphics.Bitmap; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 23 | import android.media.AudioManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.net.Uri; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 25 | import android.os.BadParcelableException; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 26 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.os.Parcel; |
| 28 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 29 | import android.os.SystemClock; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 30 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.text.TextUtils; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 32 | import android.util.Log; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 33 | import android.util.TypedValue; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 34 | import android.view.View; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 35 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.widget.RemoteViews; |
| 37 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 38 | import com.android.internal.R; |
| 39 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 40 | import java.text.NumberFormat; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 41 | import java.util.ArrayList; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 42 | import java.util.Collections; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 43 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | /** |
| 45 | * A class that represents how a persistent notification is to be presented to |
| 46 | * the user using the {@link android.app.NotificationManager}. |
| 47 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 48 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 49 | * easier to construct Notifications.</p> |
| 50 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 51 | * <div class="special reference"> |
| 52 | * <h3>Developer Guides</h3> |
| 53 | * <p>For a guide to creating notifications, read the |
| 54 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 55 | * developer guide.</p> |
| 56 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 57 | */ |
| 58 | public class Notification implements Parcelable |
| 59 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 60 | private static final String TAG = "Notification"; |
| 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | /** |
| 63 | * Use all default values (where applicable). |
| 64 | */ |
| 65 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | /** |
| 68 | * Use the default notification sound. This will ignore any given |
| 69 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 70 | * |
| 71 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 73 | */ |
| 74 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 75 | public static final int DEFAULT_SOUND = 1; |
| 76 | |
| 77 | /** |
| 78 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 79 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 80 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 81 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 83 | */ |
| 84 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | /** |
| 88 | * Use the default notification lights. This will ignore the |
| 89 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 90 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 91 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 93 | */ |
| 94 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 96 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 98 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 99 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 100 | * Default value: {@link System#currentTimeMillis() Now}. |
| 101 | * |
| 102 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 103 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 104 | * 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] | 105 | * timestamped according to when the activity began. |
| 106 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 107 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 108 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 109 | * <ul> |
| 110 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 111 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 112 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 113 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 114 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 115 | * <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] | 116 | * </ul> |
| 117 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 118 | */ |
| 119 | public long when; |
| 120 | |
| 121 | /** |
| 122 | * 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] | 123 | * 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] | 124 | */ |
| 125 | public int icon; |
| 126 | |
| 127 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 128 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 129 | * leave it at its default value of 0. |
| 130 | * |
| 131 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 132 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 133 | */ |
| 134 | public int iconLevel; |
| 135 | |
| 136 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 137 | * The number of events that this notification represents. For example, in a new mail |
| 138 | * notification, this could be the number of unread messages. |
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 | * The system may or may not use this field to modify the appearance of the notification. For |
| 141 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 142 | * superimposed over the icon in the status bar. Starting with |
| 143 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 144 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 145 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 146 | * 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] | 147 | */ |
| 148 | public int number; |
| 149 | |
| 150 | /** |
| 151 | * The intent to execute when the expanded status entry is clicked. If |
| 152 | * this is an activity, it must include the |
| 153 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 154 | * that you take care of task management as described in the |
| 155 | * <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] | 156 | * Stack</a> document. In particular, make sure to read the notification section |
| 157 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 158 | * Notifications</a> for the correct ways to launch an application from a |
| 159 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 160 | */ |
| 161 | public PendingIntent contentIntent; |
| 162 | |
| 163 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 164 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 165 | * the "Clear All" button or by swiping it away individually. |
| 166 | * |
| 167 | * This probably shouldn't be launching an activity since several of those will be sent |
| 168 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 169 | */ |
| 170 | public PendingIntent deleteIntent; |
| 171 | |
| 172 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 173 | * 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] | 174 | * |
| 175 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 176 | */ |
| 177 | public PendingIntent fullScreenIntent; |
| 178 | |
| 179 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 180 | * Text to scroll across the screen when this item is added to |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 181 | * the status bar on large and smaller devices. |
| 182 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 183 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 184 | */ |
| 185 | public CharSequence tickerText; |
| 186 | |
| 187 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 188 | * The view to show as the ticker in the status bar when the notification |
| 189 | * is posted. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 190 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 191 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 192 | |
| 193 | /** |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 194 | * 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] | 195 | */ |
| 196 | public RemoteViews contentView; |
| 197 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 198 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 199 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 200 | * opportunity to show more detail. The system UI may choose to show this |
| 201 | * instead of the normal content view at its discretion. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 202 | */ |
| 203 | public RemoteViews bigContentView; |
| 204 | |
| 205 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 206 | * 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] | 207 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 208 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 209 | |
| 210 | /** |
| 211 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 212 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 213 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 214 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 215 | * </p> |
| 216 | */ |
| 217 | public Uri sound; |
| 218 | |
| 219 | /** |
| 220 | * Use this constant as the value for audioStreamType to request that |
| 221 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 222 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 223 | */ |
| 224 | public static final int STREAM_DEFAULT = -1; |
| 225 | |
| 226 | /** |
| 227 | * The audio stream type to use when playing the sound. |
| 228 | * Should be one of the STREAM_ constants from |
| 229 | * {@link android.media.AudioManager}. |
| 230 | */ |
| 231 | public int audioStreamType = STREAM_DEFAULT; |
| 232 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 233 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 234 | * The pattern with which to vibrate. |
| 235 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 236 | * <p> |
| 237 | * To vibrate the default pattern, see {@link #defaults}. |
| 238 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 239 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 240 | * @see android.os.Vibrator#vibrate(long[],int) |
| 241 | */ |
| 242 | public long[] vibrate; |
| 243 | |
| 244 | /** |
| 245 | * The color of the led. The hardware will do its best approximation. |
| 246 | * |
| 247 | * @see #FLAG_SHOW_LIGHTS |
| 248 | * @see #flags |
| 249 | */ |
| 250 | public int ledARGB; |
| 251 | |
| 252 | /** |
| 253 | * The number of milliseconds for the LED to be on while it's flashing. |
| 254 | * The hardware will do its best approximation. |
| 255 | * |
| 256 | * @see #FLAG_SHOW_LIGHTS |
| 257 | * @see #flags |
| 258 | */ |
| 259 | public int ledOnMS; |
| 260 | |
| 261 | /** |
| 262 | * The number of milliseconds for the LED to be off while it's flashing. |
| 263 | * The hardware will do its best approximation. |
| 264 | * |
| 265 | * @see #FLAG_SHOW_LIGHTS |
| 266 | * @see #flags |
| 267 | */ |
| 268 | public int ledOffMS; |
| 269 | |
| 270 | /** |
| 271 | * Specifies which values should be taken from the defaults. |
| 272 | * <p> |
| 273 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 274 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 275 | * values, use {@link #DEFAULT_ALL}. |
| 276 | * </p> |
| 277 | */ |
| 278 | public int defaults; |
| 279 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 280 | /** |
| 281 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 282 | * set if you want the LED on for this notification. |
| 283 | * <ul> |
| 284 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 285 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 286 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 287 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 288 | * be on and off to ledOnMS and ledOffMS.</li> |
| 289 | * </ul> |
| 290 | * <p> |
| 291 | * Since hardware varies, you are not guaranteed that any of the values |
| 292 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 293 | * because they will be set to values that work on any given hardware. |
| 294 | * <p> |
| 295 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 296 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 297 | */ |
| 298 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 299 | |
| 300 | /** |
| 301 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 302 | * set if this notification is in reference to something that is ongoing, |
| 303 | * like a phone call. It should not be set if this notification is in |
| 304 | * reference to something that happened at a particular point in time, |
| 305 | * like a missed phone call. |
| 306 | */ |
| 307 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 308 | |
| 309 | /** |
| 310 | * 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] | 311 | * the audio will be repeated until the notification is |
| 312 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 313 | */ |
| 314 | public static final int FLAG_INSISTENT = 0x00000004; |
| 315 | |
| 316 | /** |
| 317 | * 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] | 318 | * set if you would only like the sound, vibrate and ticker to be played |
| 319 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 320 | */ |
| 321 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 322 | |
| 323 | /** |
| 324 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 325 | * 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] | 326 | * user. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 327 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 328 | */ |
| 329 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 330 | |
| 331 | /** |
| 332 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 333 | * set if the notification should not be canceled when the user clicks |
| 334 | * the Clear all button. |
| 335 | */ |
| 336 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 337 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 338 | /** |
| 339 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 340 | * set if this notification represents a currently running service. This |
| 341 | * will normally be set for you by {@link Service#startForeground}. |
| 342 | */ |
| 343 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 344 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 345 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 346 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 347 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 348 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 349 | */ |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 350 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 351 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 352 | /** |
| 353 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 354 | * set if this notification is relevant to the current device only |
| 355 | * and it is not recommended that it bridge to other devices. |
| 356 | */ |
| 357 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 358 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 359 | /** |
| 360 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 361 | * set if this notification is the group summary for a group of notifications. |
| 362 | * Grouped notifications may display in a cluster or stack on devices which |
| 363 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 364 | */ |
| 365 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 366 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 367 | public int flags; |
| 368 | |
| 369 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 370 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 371 | * notifications, use this value for all notifications. |
| 372 | */ |
| 373 | public static final int PRIORITY_DEFAULT = 0; |
| 374 | |
| 375 | /** |
| 376 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 377 | * items smaller, or at a different position in the list, compared with your app's |
| 378 | * {@link #PRIORITY_DEFAULT} items. |
| 379 | */ |
| 380 | public static final int PRIORITY_LOW = -1; |
| 381 | |
| 382 | /** |
| 383 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 384 | * circumstances, such as detailed notification logs. |
| 385 | */ |
| 386 | public static final int PRIORITY_MIN = -2; |
| 387 | |
| 388 | /** |
| 389 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 390 | * show these items larger, or at a different position in notification lists, compared with |
| 391 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 392 | */ |
| 393 | public static final int PRIORITY_HIGH = 1; |
| 394 | |
| 395 | /** |
| 396 | * Highest {@link #priority}, for your application's most important items that require the |
| 397 | * user's prompt attention or input. |
| 398 | */ |
| 399 | public static final int PRIORITY_MAX = 2; |
| 400 | |
| 401 | /** |
| 402 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 403 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 404 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 405 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 406 | * 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] | 407 | * system will make a determination about how to interpret this priority when presenting |
| 408 | * the notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 409 | */ |
| 410 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 411 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 412 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 413 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 414 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 415 | */ |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 416 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 417 | |
| 418 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 419 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 420 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 421 | */ |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 422 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 423 | |
| 424 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 425 | * Notification category: asynchronous bulk message (email). |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 426 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 427 | */ |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 428 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 429 | |
| 430 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 431 | * Notification category: calendar event. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 432 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 433 | */ |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 434 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 435 | |
| 436 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 437 | * Notification category: promotion or advertisement. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 438 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 439 | */ |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 440 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 441 | |
| 442 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 443 | * Notification category: alarm or timer. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 444 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 445 | */ |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 446 | public static final String CATEGORY_ALARM = "alarm"; |
| 447 | |
| 448 | /** |
| 449 | * Notification category: progress of a long-running background operation. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 450 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 451 | */ |
| 452 | public static final String CATEGORY_PROGRESS = "progress"; |
| 453 | |
| 454 | /** |
| 455 | * Notification category: social network or sharing update. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 456 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 457 | */ |
| 458 | public static final String CATEGORY_SOCIAL = "social"; |
| 459 | |
| 460 | /** |
| 461 | * Notification category: error in background operation or authentication status. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 462 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 463 | */ |
| 464 | public static final String CATEGORY_ERROR = "err"; |
| 465 | |
| 466 | /** |
| 467 | * Notification category: media transport control for playback. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 468 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 469 | */ |
| 470 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 471 | |
| 472 | /** |
| 473 | * Notification category: system or device status update. Reserved for system use. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 474 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 475 | */ |
| 476 | public static final String CATEGORY_SYSTEM = "sys"; |
| 477 | |
| 478 | /** |
| 479 | * Notification category: indication of running background service. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 480 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 481 | */ |
| 482 | public static final String CATEGORY_SERVICE = "service"; |
| 483 | |
| 484 | /** |
| 485 | * Notification category: a specific, timely recommendation for a single thing. |
| 486 | * For example, a news app might want to recommend a news story it believes the user will |
| 487 | * want to read next. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 488 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 489 | */ |
| 490 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 491 | |
| 492 | /** |
| 493 | * Notification category: ongoing information about device or contextual status. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 494 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 495 | */ |
| 496 | public static final String CATEGORY_STATUS = "status"; |
| 497 | |
| 498 | /** |
| 499 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 500 | * that best describes this Notification. May be used by the system for ranking and filtering. |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 501 | * @hide |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 502 | */ |
| 503 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 504 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 505 | private String mGroupKey; |
| 506 | |
| 507 | /** |
| 508 | * Get the key used to group this notification into a cluster or stack |
| 509 | * with other notifications on devices which support such rendering. |
| 510 | */ |
| 511 | public String getGroup() { |
| 512 | return mGroupKey; |
| 513 | } |
| 514 | |
| 515 | private String mSortKey; |
| 516 | |
| 517 | /** |
| 518 | * Get a sort key that orders this notification among other notifications from the |
| 519 | * same package. This can be useful if an external sort was already applied and an app |
| 520 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 521 | * value, although providing different priorities in addition to providing sort key may |
| 522 | * cause this value to be ignored. |
| 523 | * |
| 524 | * <p>This sort key can also be used to order members of a notification group. See |
| 525 | * {@link Builder#setGroup}. |
| 526 | * |
| 527 | * @see String#compareTo(String) |
| 528 | */ |
| 529 | public String getSortKey() { |
| 530 | return mSortKey; |
| 531 | } |
| 532 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 533 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 534 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 535 | * <p> |
| 536 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 537 | * APIs, and are intended to be used by |
| 538 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 539 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 540 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 541 | public Bundle extras = new Bundle(); |
| 542 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 543 | /** |
| 544 | * {@link #extras} key: this is the title of the notification, |
| 545 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 546 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 547 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 548 | |
| 549 | /** |
| 550 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 551 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 552 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 553 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 554 | |
| 555 | /** |
| 556 | * {@link #extras} key: this is the main text payload, as supplied to |
| 557 | * {@link Builder#setContentText(CharSequence)}. |
| 558 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 559 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 560 | |
| 561 | /** |
| 562 | * {@link #extras} key: this is a third line of text, as supplied to |
| 563 | * {@link Builder#setSubText(CharSequence)}. |
| 564 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 565 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 566 | |
| 567 | /** |
| 568 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 569 | * {@link Builder#setContentInfo(CharSequence)}. |
| 570 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 571 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 572 | |
| 573 | /** |
| 574 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 575 | * alongside expanded notifications, as supplied to (e.g.) |
| 576 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 577 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 578 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 579 | |
| 580 | /** |
| 581 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 582 | * supplied to {@link Builder#setSmallIcon(int)}. |
| 583 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 584 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 585 | |
| 586 | /** |
| 587 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 588 | * notification payload, as |
| 589 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
| 590 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 591 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 592 | |
| 593 | /** |
| 594 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 595 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 596 | * shown in its expanded form, as supplied to |
| 597 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 598 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 599 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 600 | |
| 601 | /** |
| 602 | * {@link #extras} key: this is the progress value supplied to |
| 603 | * {@link Builder#setProgress(int, int, boolean)}. |
| 604 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 605 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 606 | |
| 607 | /** |
| 608 | * {@link #extras} key: this is the maximum value supplied to |
| 609 | * {@link Builder#setProgress(int, int, boolean)}. |
| 610 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 611 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 612 | |
| 613 | /** |
| 614 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 615 | * {@link Builder#setProgress(int, int, boolean)}. |
| 616 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 617 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 618 | |
| 619 | /** |
| 620 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 621 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 622 | * {@link Builder#setUsesChronometer(boolean)}. |
| 623 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 624 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 625 | |
| 626 | /** |
| 627 | * {@link #extras} key: whether {@link #when} should be shown, |
| 628 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 629 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 630 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 631 | |
| 632 | /** |
| 633 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 634 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 635 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 636 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 637 | |
| 638 | /** |
| 639 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 640 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 641 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 642 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
| 643 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 644 | /** |
| 645 | * {@link #extras} key: An array of people that this notification relates to, specified |
| 646 | * by contacts provider contact URI. |
| 647 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 648 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 649 | |
| 650 | /** |
Scott Greenwald | 9a05b31 | 2013-06-28 00:37:54 -0400 | [diff] [blame] | 651 | * @hide |
| 652 | * Extra added by NotificationManagerService to indicate whether a NotificationScorer |
| 653 | * modified the Notifications's score. |
| 654 | */ |
| 655 | public static final String EXTRA_SCORE_MODIFIED = "android.scoreModified"; |
| 656 | |
| 657 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 658 | * Not used. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 659 | * @hide |
| 660 | */ |
| 661 | public static final String EXTRA_AS_HEADS_UP = "headsup"; |
| 662 | |
| 663 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 664 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 665 | * Only available to notifications coming from the android package. |
| 666 | * @hide |
| 667 | */ |
| 668 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 669 | |
| 670 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 671 | * Value for {@link #EXTRA_AS_HEADS_UP}. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 672 | * @hide |
| 673 | */ |
| 674 | public static final int HEADS_UP_NEVER = 0; |
| 675 | |
| 676 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 677 | * Default value for {@link #EXTRA_AS_HEADS_UP}. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 678 | * @hide |
| 679 | */ |
| 680 | public static final int HEADS_UP_ALLOWED = 1; |
| 681 | |
| 682 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 683 | * Value for {@link #EXTRA_AS_HEADS_UP}. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 684 | * @hide |
| 685 | */ |
| 686 | public static final int HEADS_UP_REQUESTED = 2; |
| 687 | |
| 688 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 689 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 690 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 691 | * selected by the user. |
| 692 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 693 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 694 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 695 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 696 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 697 | public static class Action implements Parcelable { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 698 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 699 | private RemoteInput[] mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 700 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 701 | /** |
| 702 | * Small icon representing the action. |
| 703 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 704 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 705 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 706 | /** |
| 707 | * Title of the action. |
| 708 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 709 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 710 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 711 | /** |
| 712 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 713 | * may be rendered in a disabled presentation by the system UI. |
| 714 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 715 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 716 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 717 | private Action(Parcel in) { |
| 718 | icon = in.readInt(); |
| 719 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 720 | if (in.readInt() == 1) { |
| 721 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 722 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 723 | mExtras = in.readBundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 724 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 725 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 726 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 727 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 728 | * Use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 729 | */ |
| 730 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 731 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 732 | } |
| 733 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 734 | private Action(int icon, CharSequence title, PendingIntent intent, Bundle extras, |
| 735 | RemoteInput[] remoteInputs) { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 736 | this.icon = icon; |
| 737 | this.title = title; |
| 738 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 739 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 740 | this.mRemoteInputs = remoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 741 | } |
| 742 | |
| 743 | /** |
| 744 | * Get additional metadata carried around with this Action. |
| 745 | */ |
| 746 | public Bundle getExtras() { |
| 747 | return mExtras; |
| 748 | } |
| 749 | |
| 750 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 751 | * Get the list of inputs to be collected from the user when this action is sent. |
| 752 | * May return null if no remote inputs were added. |
| 753 | */ |
| 754 | public RemoteInput[] getRemoteInputs() { |
| 755 | return mRemoteInputs; |
| 756 | } |
| 757 | |
| 758 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 759 | * Builder class for {@link Action} objects. |
| 760 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 761 | public static final class Builder { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 762 | private final int mIcon; |
| 763 | private final CharSequence mTitle; |
| 764 | private final PendingIntent mIntent; |
| 765 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 766 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 767 | |
| 768 | /** |
| 769 | * Construct a new builder for {@link Action} object. |
| 770 | * @param icon icon to show for this action |
| 771 | * @param title the title of the action |
| 772 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 773 | */ |
| 774 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 775 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 776 | } |
| 777 | |
| 778 | /** |
| 779 | * Construct a new builder for {@link Action} object using the fields from an |
| 780 | * {@link Action}. |
| 781 | * @param action the action to read fields from. |
| 782 | */ |
| 783 | public Builder(Action action) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 784 | this(action.icon, action.title, action.actionIntent, new Bundle(action.mExtras), |
| 785 | action.getRemoteInputs()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 786 | } |
| 787 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 788 | private Builder(int icon, CharSequence title, PendingIntent intent, Bundle extras, |
| 789 | RemoteInput[] remoteInputs) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 790 | mIcon = icon; |
| 791 | mTitle = title; |
| 792 | mIntent = intent; |
| 793 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 794 | if (remoteInputs != null) { |
| 795 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 796 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 797 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 798 | } |
| 799 | |
| 800 | /** |
| 801 | * Merge additional metadata into this builder. |
| 802 | * |
| 803 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 804 | * |
| 805 | * @see Notification.Action#extras |
| 806 | */ |
| 807 | public Builder addExtras(Bundle extras) { |
| 808 | if (extras != null) { |
| 809 | mExtras.putAll(extras); |
| 810 | } |
| 811 | return this; |
| 812 | } |
| 813 | |
| 814 | /** |
| 815 | * Get the metadata Bundle used by this Builder. |
| 816 | * |
| 817 | * <p>The returned Bundle is shared with this Builder. |
| 818 | */ |
| 819 | public Bundle getExtras() { |
| 820 | return mExtras; |
| 821 | } |
| 822 | |
| 823 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 824 | * Add an input to be collected from the user when this action is sent. |
| 825 | * Response values can be retrieved from the fired intent by using the |
| 826 | * {@link RemoteInput#getResultsFromIntent} function. |
| 827 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 828 | * @return this object for method chaining |
| 829 | */ |
| 830 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 831 | if (mRemoteInputs == null) { |
| 832 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 833 | } |
| 834 | mRemoteInputs.add(remoteInput); |
| 835 | return this; |
| 836 | } |
| 837 | |
| 838 | /** |
| 839 | * Apply an extender to this action builder. Extenders may be used to add |
| 840 | * metadata or change options on this builder. |
| 841 | */ |
| 842 | public Builder apply(Extender extender) { |
| 843 | extender.applyTo(this); |
| 844 | return this; |
| 845 | } |
| 846 | |
| 847 | /** |
| 848 | * Extender interface for use with {@link #apply}. Extenders may be used to add |
| 849 | * metadata or change options on this builder. |
| 850 | */ |
| 851 | public interface Extender { |
| 852 | /** |
| 853 | * Apply this extender to a notification action builder. |
| 854 | * @param builder the builder to be modified. |
| 855 | * @return the build object for chaining. |
| 856 | */ |
| 857 | public Builder applyTo(Builder builder); |
| 858 | } |
| 859 | |
| 860 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 861 | * Combine all of the options that have been set and return a new {@link Action} |
| 862 | * object. |
| 863 | * @return the built action |
| 864 | */ |
| 865 | public Action build() { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 866 | RemoteInput[] remoteInputs = mRemoteInputs != null |
| 867 | ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null; |
| 868 | return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 869 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 870 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 871 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 872 | @Override |
| 873 | public Action clone() { |
| 874 | return new Action( |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 875 | icon, |
| 876 | title, |
| 877 | actionIntent, // safe to alias |
| 878 | new Bundle(mExtras), |
| 879 | getRemoteInputs()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 880 | } |
| 881 | @Override |
| 882 | public int describeContents() { |
| 883 | return 0; |
| 884 | } |
| 885 | @Override |
| 886 | public void writeToParcel(Parcel out, int flags) { |
| 887 | out.writeInt(icon); |
| 888 | TextUtils.writeToParcel(title, out, flags); |
| 889 | if (actionIntent != null) { |
| 890 | out.writeInt(1); |
| 891 | actionIntent.writeToParcel(out, flags); |
| 892 | } else { |
| 893 | out.writeInt(0); |
| 894 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 895 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 896 | out.writeTypedArray(mRemoteInputs, flags); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 897 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 898 | public static final Parcelable.Creator<Action> CREATOR = |
| 899 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 900 | public Action createFromParcel(Parcel in) { |
| 901 | return new Action(in); |
| 902 | } |
| 903 | public Action[] newArray(int size) { |
| 904 | return new Action[size]; |
| 905 | } |
| 906 | }; |
| 907 | } |
| 908 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 909 | /** |
| 910 | * Array of all {@link Action} structures attached to this notification by |
| 911 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 912 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 913 | * interface for invoking actions. |
| 914 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 915 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 916 | |
| 917 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 918 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 919 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 920 | */ |
| 921 | public Notification() |
| 922 | { |
| 923 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 924 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 925 | } |
| 926 | |
| 927 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 928 | * @hide |
| 929 | */ |
| 930 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 931 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 932 | { |
| 933 | this.when = when; |
| 934 | this.icon = icon; |
| 935 | this.tickerText = tickerText; |
| 936 | setLatestEventInfo(context, contentTitle, contentText, |
| 937 | PendingIntent.getActivity(context, 0, contentIntent, 0)); |
| 938 | } |
| 939 | |
| 940 | /** |
| 941 | * Constructs a Notification object with the information needed to |
| 942 | * have a status bar icon without the standard expanded view. |
| 943 | * |
| 944 | * @param icon The resource id of the icon to put in the status bar. |
| 945 | * @param tickerText The text that flows by in the status bar when the notification first |
| 946 | * activates. |
| 947 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 948 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 949 | * |
| 950 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 951 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 952 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 953 | public Notification(int icon, CharSequence tickerText, long when) |
| 954 | { |
| 955 | this.icon = icon; |
| 956 | this.tickerText = tickerText; |
| 957 | this.when = when; |
| 958 | } |
| 959 | |
| 960 | /** |
| 961 | * Unflatten the notification from a parcel. |
| 962 | */ |
| 963 | public Notification(Parcel parcel) |
| 964 | { |
| 965 | int version = parcel.readInt(); |
| 966 | |
| 967 | when = parcel.readLong(); |
| 968 | icon = parcel.readInt(); |
| 969 | number = parcel.readInt(); |
| 970 | if (parcel.readInt() != 0) { |
| 971 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 972 | } |
| 973 | if (parcel.readInt() != 0) { |
| 974 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 975 | } |
| 976 | if (parcel.readInt() != 0) { |
| 977 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 978 | } |
| 979 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 980 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 981 | } |
| 982 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 983 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 984 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 985 | if (parcel.readInt() != 0) { |
| 986 | largeIcon = Bitmap.CREATOR.createFromParcel(parcel); |
| 987 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 988 | defaults = parcel.readInt(); |
| 989 | flags = parcel.readInt(); |
| 990 | if (parcel.readInt() != 0) { |
| 991 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 992 | } |
| 993 | |
| 994 | audioStreamType = parcel.readInt(); |
| 995 | vibrate = parcel.createLongArray(); |
| 996 | ledARGB = parcel.readInt(); |
| 997 | ledOnMS = parcel.readInt(); |
| 998 | ledOffMS = parcel.readInt(); |
| 999 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1000 | |
| 1001 | if (parcel.readInt() != 0) { |
| 1002 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1003 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1004 | |
| 1005 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1006 | |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 1007 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1008 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1009 | mGroupKey = parcel.readString(); |
| 1010 | |
| 1011 | mSortKey = parcel.readString(); |
| 1012 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1013 | extras = parcel.readBundle(); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1014 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1015 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1016 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1017 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1018 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1019 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1020 | } |
| 1021 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1022 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1023 | public Notification clone() { |
| 1024 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1025 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1026 | return that; |
| 1027 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1028 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1029 | /** |
| 1030 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1031 | * of this into that. |
| 1032 | * @hide |
| 1033 | */ |
| 1034 | public void cloneInto(Notification that, boolean heavy) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1035 | that.when = this.when; |
| 1036 | that.icon = this.icon; |
| 1037 | that.number = this.number; |
| 1038 | |
| 1039 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1040 | that.contentIntent = this.contentIntent; |
| 1041 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1042 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1043 | |
| 1044 | if (this.tickerText != null) { |
| 1045 | that.tickerText = this.tickerText.toString(); |
| 1046 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1047 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1048 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1049 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1050 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1051 | that.contentView = this.contentView.clone(); |
| 1052 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1053 | if (heavy && this.largeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1054 | that.largeIcon = Bitmap.createBitmap(this.largeIcon); |
| 1055 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1056 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1057 | that.sound = this.sound; // android.net.Uri is immutable |
| 1058 | that.audioStreamType = this.audioStreamType; |
| 1059 | |
| 1060 | final long[] vibrate = this.vibrate; |
| 1061 | if (vibrate != null) { |
| 1062 | final int N = vibrate.length; |
| 1063 | final long[] vib = that.vibrate = new long[N]; |
| 1064 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1065 | } |
| 1066 | |
| 1067 | that.ledARGB = this.ledARGB; |
| 1068 | that.ledOnMS = this.ledOnMS; |
| 1069 | that.ledOffMS = this.ledOffMS; |
| 1070 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1071 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1072 | that.flags = this.flags; |
| 1073 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1074 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1075 | |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 1076 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1077 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1078 | that.mGroupKey = this.mGroupKey; |
| 1079 | |
| 1080 | that.mSortKey = this.mSortKey; |
| 1081 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1082 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1083 | try { |
| 1084 | that.extras = new Bundle(this.extras); |
| 1085 | // will unparcel |
| 1086 | that.extras.size(); |
| 1087 | } catch (BadParcelableException e) { |
| 1088 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 1089 | that.extras = null; |
| 1090 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1091 | } |
| 1092 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1093 | if (this.actions != null) { |
| 1094 | that.actions = new Action[this.actions.length]; |
| 1095 | for(int i=0; i<this.actions.length; i++) { |
| 1096 | that.actions[i] = this.actions[i].clone(); |
| 1097 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1098 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1099 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1100 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1101 | that.bigContentView = this.bigContentView.clone(); |
| 1102 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1103 | |
| 1104 | if (!heavy) { |
| 1105 | that.lightenPayload(); // will clean out extras |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | /** |
| 1110 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 1111 | * listeners when the full contents are not necessary. |
| 1112 | * @hide |
| 1113 | */ |
| 1114 | public final void lightenPayload() { |
| 1115 | tickerView = null; |
| 1116 | contentView = null; |
| 1117 | bigContentView = null; |
| 1118 | largeIcon = null; |
| 1119 | if (extras != null) { |
| 1120 | extras.remove(Notification.EXTRA_LARGE_ICON); |
| 1121 | extras.remove(Notification.EXTRA_LARGE_ICON_BIG); |
| 1122 | extras.remove(Notification.EXTRA_PICTURE); |
| 1123 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1124 | } |
| 1125 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1126 | /** |
| 1127 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 1128 | * means it had better not be some custom Parcelable implementation. |
| 1129 | * @hide |
| 1130 | */ |
| 1131 | public static CharSequence safeCharSequence(CharSequence cs) { |
| 1132 | if (cs instanceof Parcelable) { |
| 1133 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 1134 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 1135 | return cs.toString(); |
| 1136 | } |
| 1137 | |
| 1138 | return cs; |
| 1139 | } |
| 1140 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1141 | public int describeContents() { |
| 1142 | return 0; |
| 1143 | } |
| 1144 | |
| 1145 | /** |
| 1146 | * Flatten this notification from a parcel. |
| 1147 | */ |
| 1148 | public void writeToParcel(Parcel parcel, int flags) |
| 1149 | { |
| 1150 | parcel.writeInt(1); |
| 1151 | |
| 1152 | parcel.writeLong(when); |
| 1153 | parcel.writeInt(icon); |
| 1154 | parcel.writeInt(number); |
| 1155 | if (contentIntent != null) { |
| 1156 | parcel.writeInt(1); |
| 1157 | contentIntent.writeToParcel(parcel, 0); |
| 1158 | } else { |
| 1159 | parcel.writeInt(0); |
| 1160 | } |
| 1161 | if (deleteIntent != null) { |
| 1162 | parcel.writeInt(1); |
| 1163 | deleteIntent.writeToParcel(parcel, 0); |
| 1164 | } else { |
| 1165 | parcel.writeInt(0); |
| 1166 | } |
| 1167 | if (tickerText != null) { |
| 1168 | parcel.writeInt(1); |
| 1169 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 1170 | } else { |
| 1171 | parcel.writeInt(0); |
| 1172 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1173 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1174 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1175 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1176 | } else { |
| 1177 | parcel.writeInt(0); |
| 1178 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1179 | if (contentView != null) { |
| 1180 | parcel.writeInt(1); |
| 1181 | contentView.writeToParcel(parcel, 0); |
| 1182 | } else { |
| 1183 | parcel.writeInt(0); |
| 1184 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1185 | if (largeIcon != null) { |
| 1186 | parcel.writeInt(1); |
| 1187 | largeIcon.writeToParcel(parcel, 0); |
| 1188 | } else { |
| 1189 | parcel.writeInt(0); |
| 1190 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1191 | |
| 1192 | parcel.writeInt(defaults); |
| 1193 | parcel.writeInt(this.flags); |
| 1194 | |
| 1195 | if (sound != null) { |
| 1196 | parcel.writeInt(1); |
| 1197 | sound.writeToParcel(parcel, 0); |
| 1198 | } else { |
| 1199 | parcel.writeInt(0); |
| 1200 | } |
| 1201 | parcel.writeInt(audioStreamType); |
| 1202 | parcel.writeLongArray(vibrate); |
| 1203 | parcel.writeInt(ledARGB); |
| 1204 | parcel.writeInt(ledOnMS); |
| 1205 | parcel.writeInt(ledOffMS); |
| 1206 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1207 | |
| 1208 | if (fullScreenIntent != null) { |
| 1209 | parcel.writeInt(1); |
| 1210 | fullScreenIntent.writeToParcel(parcel, 0); |
| 1211 | } else { |
| 1212 | parcel.writeInt(0); |
| 1213 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1214 | |
| 1215 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1216 | |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 1217 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1218 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1219 | parcel.writeString(mGroupKey); |
| 1220 | |
| 1221 | parcel.writeString(mSortKey); |
| 1222 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1223 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1224 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1225 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1226 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1227 | if (bigContentView != null) { |
| 1228 | parcel.writeInt(1); |
| 1229 | bigContentView.writeToParcel(parcel, 0); |
| 1230 | } else { |
| 1231 | parcel.writeInt(0); |
| 1232 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | /** |
| 1236 | * Parcelable.Creator that instantiates Notification objects |
| 1237 | */ |
| 1238 | public static final Parcelable.Creator<Notification> CREATOR |
| 1239 | = new Parcelable.Creator<Notification>() |
| 1240 | { |
| 1241 | public Notification createFromParcel(Parcel parcel) |
| 1242 | { |
| 1243 | return new Notification(parcel); |
| 1244 | } |
| 1245 | |
| 1246 | public Notification[] newArray(int size) |
| 1247 | { |
| 1248 | return new Notification[size]; |
| 1249 | } |
| 1250 | }; |
| 1251 | |
| 1252 | /** |
| 1253 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 1254 | * layout. |
| 1255 | * |
| 1256 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 1257 | * in the view.</p> |
| 1258 | * @param context The context for your application / activity. |
| 1259 | * @param contentTitle The title that goes in the expanded entry. |
| 1260 | * @param contentText The text that goes in the expanded entry. |
| 1261 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 1262 | * If this is an activity, it must include the |
| 1263 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 1264 | * that you take care of task management as described in the |
| 1265 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 1266 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1267 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1268 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1269 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1270 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1271 | public void setLatestEventInfo(Context context, |
| 1272 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1273 | Notification.Builder builder = new Notification.Builder(context); |
| 1274 | |
| 1275 | // First, ensure that key pieces of information that may have been set directly |
| 1276 | // are preserved |
| 1277 | builder.setWhen(this.when); |
| 1278 | builder.setSmallIcon(this.icon); |
| 1279 | builder.setPriority(this.priority); |
| 1280 | builder.setTicker(this.tickerText); |
| 1281 | builder.setNumber(this.number); |
| 1282 | builder.mFlags = this.flags; |
| 1283 | builder.setSound(this.sound, this.audioStreamType); |
| 1284 | builder.setDefaults(this.defaults); |
| 1285 | builder.setVibrate(this.vibrate); |
| 1286 | |
| 1287 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1288 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1289 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1290 | } |
| 1291 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1292 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1293 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1294 | builder.setContentIntent(contentIntent); |
| 1295 | builder.buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1296 | } |
| 1297 | |
| 1298 | @Override |
| 1299 | public String toString() { |
| 1300 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1301 | sb.append("Notification(pri="); |
| 1302 | sb.append(priority); |
| 1303 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1304 | if (contentView != null) { |
| 1305 | sb.append(contentView.getPackage()); |
| 1306 | sb.append("/0x"); |
| 1307 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 1308 | } else { |
| 1309 | sb.append("null"); |
| 1310 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1311 | // TODO(dsandler): defaults take precedence over local values, so reorder the branches below |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1312 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1313 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 1314 | sb.append("default"); |
| 1315 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1316 | int N = this.vibrate.length-1; |
| 1317 | sb.append("["); |
| 1318 | for (int i=0; i<N; i++) { |
| 1319 | sb.append(this.vibrate[i]); |
| 1320 | sb.append(','); |
| 1321 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 1322 | if (N != -1) { |
| 1323 | sb.append(this.vibrate[N]); |
| 1324 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1325 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1326 | } else { |
| 1327 | sb.append("null"); |
| 1328 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1329 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1330 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1331 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1332 | } else if (this.sound != null) { |
| 1333 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1334 | } else { |
| 1335 | sb.append("null"); |
| 1336 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1337 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1338 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1339 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1340 | sb.append(Integer.toHexString(this.flags)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1341 | if (this.category != null) { |
| 1342 | sb.append(" category="); |
| 1343 | sb.append(this.category); |
| 1344 | } |
| 1345 | if (this.mGroupKey != null) { |
| 1346 | sb.append(" groupKey="); |
| 1347 | sb.append(this.mGroupKey); |
| 1348 | } |
| 1349 | if (this.mSortKey != null) { |
| 1350 | sb.append(" sortKey="); |
| 1351 | sb.append(this.mSortKey); |
| 1352 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1353 | if (actions != null) { |
| 1354 | sb.append(" "); |
| 1355 | sb.append(actions.length); |
| 1356 | sb.append(" action"); |
| 1357 | if (actions.length > 1) sb.append("s"); |
| 1358 | } |
| 1359 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1360 | return sb.toString(); |
| 1361 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1362 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1363 | /** {@hide} */ |
| 1364 | public void setUser(UserHandle user) { |
Amith Yamasani | ecbd68b | 2012-11-02 12:17:19 -0700 | [diff] [blame] | 1365 | if (user.getIdentifier() == UserHandle.USER_ALL) { |
| 1366 | user = UserHandle.OWNER; |
| 1367 | } |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1368 | if (tickerView != null) { |
| 1369 | tickerView.setUser(user); |
| 1370 | } |
| 1371 | if (contentView != null) { |
| 1372 | contentView.setUser(user); |
| 1373 | } |
| 1374 | if (bigContentView != null) { |
| 1375 | bigContentView.setUser(user); |
| 1376 | } |
| 1377 | } |
| 1378 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1379 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1380 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1381 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1382 | * 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] | 1383 | * content views using the platform's notification layout template. If your app supports |
| 1384 | * versions of Android as old as API level 4, you can instead use |
| 1385 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 1386 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 1387 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1388 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1389 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1390 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1391 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1392 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1393 | * .setContentTitle("New mail from " + sender.toString()) |
| 1394 | * .setContentText(subject) |
| 1395 | * .setSmallIcon(R.drawable.new_mail) |
| 1396 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1397 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1398 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1399 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1400 | public static class Builder { |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 1401 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1402 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1403 | private Context mContext; |
| 1404 | |
| 1405 | private long mWhen; |
| 1406 | private int mSmallIcon; |
| 1407 | private int mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1408 | private int mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1409 | private CharSequence mContentTitle; |
| 1410 | private CharSequence mContentText; |
| 1411 | private CharSequence mContentInfo; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1412 | private CharSequence mSubText; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1413 | private PendingIntent mContentIntent; |
| 1414 | private RemoteViews mContentView; |
| 1415 | private PendingIntent mDeleteIntent; |
| 1416 | private PendingIntent mFullScreenIntent; |
| 1417 | private CharSequence mTickerText; |
| 1418 | private RemoteViews mTickerView; |
| 1419 | private Bitmap mLargeIcon; |
| 1420 | private Uri mSound; |
| 1421 | private int mAudioStreamType; |
| 1422 | private long[] mVibrate; |
| 1423 | private int mLedArgb; |
| 1424 | private int mLedOnMs; |
| 1425 | private int mLedOffMs; |
| 1426 | private int mDefaults; |
| 1427 | private int mFlags; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1428 | private int mProgressMax; |
| 1429 | private int mProgress; |
| 1430 | private boolean mProgressIndeterminate; |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 1431 | private String mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1432 | private String mGroupKey; |
| 1433 | private String mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1434 | private Bundle mExtras; |
| 1435 | private int mPriority; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1436 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1437 | private boolean mUseChronometer; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1438 | private Style mStyle; |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1439 | private boolean mShowWhen = true; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1440 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1441 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1442 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1443 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1444 | |
| 1445 | * <table> |
| 1446 | * <tr><th align=right>priority</th> |
| 1447 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 1448 | * <tr><th align=right>when</th> |
| 1449 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 1450 | * <tr><th align=right>audio stream</th> |
| 1451 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 1452 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1453 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1454 | |
| 1455 | * @param context |
| 1456 | * A {@link Context} that will be used by the Builder to construct the |
| 1457 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 1458 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1459 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1460 | public Builder(Context context) { |
| 1461 | mContext = context; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1462 | |
| 1463 | // Set defaults to match the defaults of a Notification |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1464 | mWhen = System.currentTimeMillis(); |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1465 | mAudioStreamType = STREAM_DEFAULT; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1466 | mPriority = PRIORITY_DEFAULT; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1467 | } |
| 1468 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1469 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1470 | * 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] | 1471 | * It will be shown in the notification content view by default; use |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 1472 | * {@link #setShowWhen(boolean) setShowWhen} to control this. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1473 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1474 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1475 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1476 | public Builder setWhen(long when) { |
| 1477 | mWhen = when; |
| 1478 | return this; |
| 1479 | } |
| 1480 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1481 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 1482 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1483 | * in the content view. |
| 1484 | */ |
| 1485 | public Builder setShowWhen(boolean show) { |
| 1486 | mShowWhen = show; |
| 1487 | return this; |
| 1488 | } |
| 1489 | |
| 1490 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1491 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1492 | * |
| 1493 | * 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] | 1494 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1495 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1496 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 1497 | * |
| 1498 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1499 | * @see Notification#when |
| 1500 | */ |
| 1501 | public Builder setUsesChronometer(boolean b) { |
| 1502 | mUseChronometer = b; |
| 1503 | return this; |
| 1504 | } |
| 1505 | |
| 1506 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1507 | * Set the small icon resource, which will be used to represent the notification in the |
| 1508 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1509 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1510 | |
| 1511 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 1512 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 1513 | * icon will be moved to the right-hand side. |
| 1514 | * |
| 1515 | |
| 1516 | * @param icon |
| 1517 | * A resource ID in the application's package of the drawable to use. |
| 1518 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1519 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1520 | public Builder setSmallIcon(int icon) { |
| 1521 | mSmallIcon = icon; |
| 1522 | return this; |
| 1523 | } |
| 1524 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1525 | /** |
| 1526 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 1527 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 1528 | * LevelListDrawable}. |
| 1529 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1530 | * @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] | 1531 | * @param level The level to use for the icon. |
| 1532 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1533 | * @see Notification#icon |
| 1534 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1535 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1536 | public Builder setSmallIcon(int icon, int level) { |
| 1537 | mSmallIcon = icon; |
| 1538 | mSmallIconLevel = level; |
| 1539 | return this; |
| 1540 | } |
| 1541 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1542 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1543 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1544 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1545 | public Builder setContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1546 | mContentTitle = safeCharSequence(title); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1547 | return this; |
| 1548 | } |
| 1549 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1550 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1551 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1552 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1553 | public Builder setContentText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1554 | mContentText = safeCharSequence(text); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1555 | return this; |
| 1556 | } |
| 1557 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1558 | /** |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1559 | * Set the third line of text in the platform notification template. |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1560 | * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the |
| 1561 | * same location in the standard template. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1562 | */ |
| 1563 | public Builder setSubText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1564 | mSubText = safeCharSequence(text); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1565 | return this; |
| 1566 | } |
| 1567 | |
| 1568 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1569 | * Set the large number at the right-hand side of the notification. This is |
| 1570 | * equivalent to setContentInfo, although it might show the number in a different |
| 1571 | * font size for readability. |
| 1572 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1573 | public Builder setNumber(int number) { |
| 1574 | mNumber = number; |
| 1575 | return this; |
| 1576 | } |
| 1577 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1578 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1579 | * A small piece of additional information pertaining to this notification. |
| 1580 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1581 | * The platform template will draw this on the last line of the notification, at the far |
| 1582 | * 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] | 1583 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1584 | public Builder setContentInfo(CharSequence info) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1585 | mContentInfo = safeCharSequence(info); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1586 | return this; |
| 1587 | } |
| 1588 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1589 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1590 | * Set the progress this notification represents. |
| 1591 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1592 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1593 | */ |
| 1594 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 1595 | mProgressMax = max; |
| 1596 | mProgress = progress; |
| 1597 | mProgressIndeterminate = indeterminate; |
| 1598 | return this; |
| 1599 | } |
| 1600 | |
| 1601 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1602 | * Supply a custom RemoteViews to use instead of the platform template. |
| 1603 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1604 | * @see Notification#contentView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1605 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1606 | public Builder setContent(RemoteViews views) { |
| 1607 | mContentView = views; |
| 1608 | return this; |
| 1609 | } |
| 1610 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1611 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1612 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 1613 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1614 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 1615 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 1616 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1617 | * 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] | 1618 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1619 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1620 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1621 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1622 | public Builder setContentIntent(PendingIntent intent) { |
| 1623 | mContentIntent = intent; |
| 1624 | return this; |
| 1625 | } |
| 1626 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1627 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1628 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 1629 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1630 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1631 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1632 | public Builder setDeleteIntent(PendingIntent intent) { |
| 1633 | mDeleteIntent = intent; |
| 1634 | return this; |
| 1635 | } |
| 1636 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1637 | /** |
| 1638 | * An intent to launch instead of posting the notification to the status bar. |
| 1639 | * Only for use with extremely high-priority notifications demanding the user's |
| 1640 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 1641 | * alarm clock that the user has explicitly set to a particular time. |
| 1642 | * If this facility is used for something else, please give the user an option |
| 1643 | * to turn it off and use a normal notification, as this can be extremely |
| 1644 | * disruptive. |
| 1645 | * |
| 1646 | * @param intent The pending intent to launch. |
| 1647 | * @param highPriority Passing true will cause this notification to be sent |
| 1648 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1649 | * |
| 1650 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1651 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1652 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 1653 | mFullScreenIntent = intent; |
| 1654 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 1655 | return this; |
| 1656 | } |
| 1657 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1658 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1659 | * Set the "ticker" text which is displayed in the status bar when the notification first |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1660 | * arrives. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1661 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1662 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1663 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1664 | public Builder setTicker(CharSequence tickerText) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1665 | mTickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1666 | return this; |
| 1667 | } |
| 1668 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1669 | /** |
| 1670 | * Set the text that is displayed in the status bar when the notification first |
| 1671 | * arrives, and also a RemoteViews object that may be displayed instead on some |
| 1672 | * devices. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1673 | * |
| 1674 | * @see Notification#tickerText |
| 1675 | * @see Notification#tickerView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1676 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1677 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1678 | mTickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1679 | mTickerView = views; |
| 1680 | return this; |
| 1681 | } |
| 1682 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1683 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1684 | * Add a large icon to the notification (and the ticker on some devices). |
| 1685 | * |
| 1686 | * In the platform template, this image will be shown on the left of the notification view |
| 1687 | * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side). |
| 1688 | * |
| 1689 | * @see Notification#largeIcon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1690 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1691 | public Builder setLargeIcon(Bitmap icon) { |
| 1692 | mLargeIcon = icon; |
| 1693 | return this; |
| 1694 | } |
| 1695 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1696 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1697 | * Set the sound to play. |
| 1698 | * |
| 1699 | * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications. |
| 1700 | * |
| 1701 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1702 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 1703 | public Builder setSound(Uri sound) { |
| 1704 | mSound = sound; |
| 1705 | mAudioStreamType = STREAM_DEFAULT; |
| 1706 | return this; |
| 1707 | } |
| 1708 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1709 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1710 | * 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] | 1711 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1712 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 1713 | * |
| 1714 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1715 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1716 | public Builder setSound(Uri sound, int streamType) { |
| 1717 | mSound = sound; |
| 1718 | mAudioStreamType = streamType; |
| 1719 | return this; |
| 1720 | } |
| 1721 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1722 | /** |
| 1723 | * Set the vibration pattern to use. |
| 1724 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1725 | |
| 1726 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 1727 | * <code>pattern</code> parameter. |
| 1728 | * |
| 1729 | |
| 1730 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1731 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1732 | public Builder setVibrate(long[] pattern) { |
| 1733 | mVibrate = pattern; |
| 1734 | return this; |
| 1735 | } |
| 1736 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1737 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1738 | * Set the desired color for the indicator LED on the device, as well as the |
| 1739 | * blink duty cycle (specified in milliseconds). |
| 1740 | * |
| 1741 | |
| 1742 | * Not all devices will honor all (or even any) of these values. |
| 1743 | * |
| 1744 | |
| 1745 | * @see Notification#ledARGB |
| 1746 | * @see Notification#ledOnMS |
| 1747 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1748 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1749 | public Builder setLights(int argb, int onMs, int offMs) { |
| 1750 | mLedArgb = argb; |
| 1751 | mLedOnMs = onMs; |
| 1752 | mLedOffMs = offMs; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1753 | return this; |
| 1754 | } |
| 1755 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1756 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1757 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1758 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1759 | |
| 1760 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 1761 | * must take care of canceling them. |
| 1762 | * |
| 1763 | |
| 1764 | * They are typically used to indicate a background task that the user is actively engaged |
| 1765 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 1766 | * (e.g., a file download, sync operation, active network connection). |
| 1767 | * |
| 1768 | |
| 1769 | * @see Notification#FLAG_ONGOING_EVENT |
| 1770 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1771 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1772 | public Builder setOngoing(boolean ongoing) { |
| 1773 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 1774 | return this; |
| 1775 | } |
| 1776 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1777 | /** |
| 1778 | * Set this flag if you would only like the sound, vibrate |
| 1779 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1780 | * |
| 1781 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1782 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1783 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 1784 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 1785 | return this; |
| 1786 | } |
| 1787 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1788 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1789 | * Make this notification automatically dismissed when the user touches it. The |
| 1790 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 1791 | * |
| 1792 | * @see Notification#FLAG_AUTO_CANCEL |
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 setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 1795 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1796 | return this; |
| 1797 | } |
| 1798 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1799 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 1800 | * Set whether or not this notification should not bridge to other devices. |
| 1801 | * |
| 1802 | * <p>Some notifications can be bridged to other devices for remote display. |
| 1803 | * This hint can be set to recommend this notification not be bridged. |
| 1804 | */ |
| 1805 | public Builder setLocalOnly(boolean localOnly) { |
| 1806 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 1807 | return this; |
| 1808 | } |
| 1809 | |
| 1810 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1811 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1812 | * <p> |
| 1813 | * The value should be one or more of the following fields combined with |
| 1814 | * bitwise-or: |
| 1815 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 1816 | * <p> |
| 1817 | * For all default values, use {@link #DEFAULT_ALL}. |
| 1818 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1819 | public Builder setDefaults(int defaults) { |
| 1820 | mDefaults = defaults; |
| 1821 | return this; |
| 1822 | } |
| 1823 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1824 | /** |
| 1825 | * Set the priority of this notification. |
| 1826 | * |
| 1827 | * @see Notification#priority |
| 1828 | */ |
| 1829 | public Builder setPriority(int pri) { |
| 1830 | mPriority = pri; |
| 1831 | return this; |
| 1832 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1833 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1834 | /** |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 1835 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1836 | * |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 1837 | * @see Notification#category |
Griff Hazen | ed0c87e | 2014-05-05 15:15:12 -0700 | [diff] [blame] | 1838 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1839 | */ |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 1840 | public Builder setCategory(String category) { |
| 1841 | mCategory = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1842 | return this; |
| 1843 | } |
| 1844 | |
| 1845 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1846 | * Set this notification to be part of a group of notifications sharing the same key. |
| 1847 | * Grouped notifications may display in a cluster or stack on devices which |
| 1848 | * support such rendering. |
| 1849 | * |
| 1850 | * <p>To make this notification the summary for its group, also call |
| 1851 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 1852 | * {@link #setSortKey}. |
| 1853 | * @param groupKey The group key of the group. |
| 1854 | * @return this object for method chaining |
| 1855 | */ |
| 1856 | public Builder setGroup(String groupKey) { |
| 1857 | mGroupKey = groupKey; |
| 1858 | return this; |
| 1859 | } |
| 1860 | |
| 1861 | /** |
| 1862 | * Set this notification to be the group summary for a group of notifications. |
| 1863 | * Grouped notifications may display in a cluster or stack on devices which |
| 1864 | * support such rendering. Requires a group key also be set using {@link #setGroup}. |
| 1865 | * @param isGroupSummary Whether this notification should be a group summary. |
| 1866 | * @return this object for method chaining |
| 1867 | */ |
| 1868 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 1869 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 1870 | return this; |
| 1871 | } |
| 1872 | |
| 1873 | /** |
| 1874 | * Set a sort key that orders this notification among other notifications from the |
| 1875 | * same package. This can be useful if an external sort was already applied and an app |
| 1876 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 1877 | * value, although providing different priorities in addition to providing sort key may |
| 1878 | * cause this value to be ignored. |
| 1879 | * |
| 1880 | * <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^] | 1881 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1882 | * |
| 1883 | * @see String#compareTo(String) |
| 1884 | */ |
| 1885 | public Builder setSortKey(String sortKey) { |
| 1886 | mSortKey = sortKey; |
| 1887 | return this; |
| 1888 | } |
| 1889 | |
| 1890 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 1891 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1892 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 1893 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 1894 | * |
| 1895 | * @see Notification#extras |
| 1896 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1897 | public Builder addExtras(Bundle extras) { |
| 1898 | if (extras != null) { |
| 1899 | if (mExtras == null) { |
| 1900 | mExtras = new Bundle(extras); |
| 1901 | } else { |
| 1902 | mExtras.putAll(extras); |
| 1903 | } |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 1904 | } |
| 1905 | return this; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
| 1909 | * Set metadata for this notification. |
| 1910 | * |
| 1911 | * <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] | 1912 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1913 | * called. |
| 1914 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 1915 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 1916 | * Use {@link #addExtras} to merge in metadata instead. |
| 1917 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1918 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1919 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1920 | public Builder setExtras(Bundle extras) { |
| 1921 | mExtras = extras; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1922 | return this; |
| 1923 | } |
| 1924 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1925 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 1926 | * Get the current metadata Bundle used by this notification Builder. |
| 1927 | * |
| 1928 | * <p>The returned Bundle is shared with this Builder. |
| 1929 | * |
| 1930 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 1931 | * {@link #build()} is called. |
| 1932 | * |
| 1933 | * @see Notification#extras |
| 1934 | */ |
| 1935 | public Bundle getExtras() { |
| 1936 | if (mExtras == null) { |
| 1937 | mExtras = new Bundle(); |
| 1938 | } |
| 1939 | return mExtras; |
| 1940 | } |
| 1941 | |
| 1942 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1943 | * Add an action to this notification. Actions are typically displayed by |
| 1944 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1945 | * <p> |
| 1946 | * Every action must have an icon (32dp square and matching the |
| 1947 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 1948 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 1949 | * <p> |
| 1950 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 1951 | * the order they were added. Actions will not be displayed when the notification is |
| 1952 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 1953 | * 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] | 1954 | * |
| 1955 | * @param icon Resource ID of a drawable that represents the action. |
| 1956 | * @param title Text describing the action. |
| 1957 | * @param intent PendingIntent to be fired when the action is invoked. |
| 1958 | */ |
| 1959 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1960 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1961 | return this; |
| 1962 | } |
| 1963 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1964 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 1965 | * Add an action to this notification. Actions are typically displayed by |
| 1966 | * the system as a button adjacent to the notification content. |
| 1967 | * <p> |
| 1968 | * Every action must have an icon (32dp square and matching the |
| 1969 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 1970 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 1971 | * <p> |
| 1972 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 1973 | * the order they were added. Actions will not be displayed when the notification is |
| 1974 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 1975 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 1976 | * |
| 1977 | * @param action The action to add. |
| 1978 | */ |
| 1979 | public Builder addAction(Action action) { |
| 1980 | mActions.add(action); |
| 1981 | return this; |
| 1982 | } |
| 1983 | |
| 1984 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1985 | * Add a rich notification style to be applied at build time. |
| 1986 | * |
| 1987 | * @param style Object responsible for modifying the notification style. |
| 1988 | */ |
| 1989 | public Builder setStyle(Style style) { |
| 1990 | if (mStyle != style) { |
| 1991 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 1992 | if (mStyle != null) { |
| 1993 | mStyle.setBuilder(this); |
| 1994 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1995 | } |
| 1996 | return this; |
| 1997 | } |
| 1998 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1999 | /** |
| 2000 | * Apply an extender to this notification builder. Extenders may be used to add |
| 2001 | * metadata or change options on this builder. |
| 2002 | */ |
| 2003 | public Builder apply(Extender extender) { |
| 2004 | extender.applyTo(this); |
| 2005 | return this; |
| 2006 | } |
| 2007 | |
| 2008 | /** |
| 2009 | * Extender interface for use with {@link #apply}. Extenders may be used to add |
| 2010 | * metadata or change options on this builder. |
| 2011 | */ |
| 2012 | public interface Extender { |
| 2013 | /** |
| 2014 | * Apply this extender to a notification builder. |
| 2015 | * @param builder the builder to be modified. |
| 2016 | * @return the build object for chaining. |
| 2017 | */ |
| 2018 | public Builder applyTo(Builder builder); |
| 2019 | } |
| 2020 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2021 | private void setFlag(int mask, boolean value) { |
| 2022 | if (value) { |
| 2023 | mFlags |= mask; |
| 2024 | } else { |
| 2025 | mFlags &= ~mask; |
| 2026 | } |
| 2027 | } |
| 2028 | |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2029 | private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2030 | RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2031 | boolean showLine3 = false; |
| 2032 | boolean showLine2 = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2033 | int smallIconImageViewId = R.id.icon; |
| 2034 | if (mLargeIcon != null) { |
| 2035 | contentView.setImageViewBitmap(R.id.icon, mLargeIcon); |
| 2036 | smallIconImageViewId = R.id.right_icon; |
| 2037 | } |
Daniel Sandler | e95658c | 2012-05-10 00:33:54 -0400 | [diff] [blame] | 2038 | if (mPriority < PRIORITY_LOW) { |
| 2039 | contentView.setInt(R.id.icon, |
| 2040 | "setBackgroundResource", R.drawable.notification_template_icon_low_bg); |
| 2041 | contentView.setInt(R.id.status_bar_latest_event_content, |
| 2042 | "setBackgroundResource", R.drawable.notification_bg_low); |
| 2043 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2044 | if (mSmallIcon != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2045 | contentView.setImageViewResource(smallIconImageViewId, mSmallIcon); |
| 2046 | contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2047 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2048 | contentView.setViewVisibility(smallIconImageViewId, View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2049 | } |
| 2050 | if (mContentTitle != null) { |
| 2051 | contentView.setTextViewText(R.id.title, mContentTitle); |
| 2052 | } |
| 2053 | if (mContentText != null) { |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2054 | contentView.setTextViewText(R.id.text, mContentText); |
| 2055 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2056 | } |
| 2057 | if (mContentInfo != null) { |
| 2058 | contentView.setTextViewText(R.id.info, mContentInfo); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2059 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2060 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2061 | } else if (mNumber > 0) { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 2062 | final int tooBig = mContext.getResources().getInteger( |
| 2063 | R.integer.status_bar_notification_info_maxnum); |
| 2064 | if (mNumber > tooBig) { |
| 2065 | contentView.setTextViewText(R.id.info, mContext.getResources().getString( |
| 2066 | R.string.status_bar_notification_info_overflow)); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 2067 | } else { |
| 2068 | NumberFormat f = NumberFormat.getIntegerInstance(); |
| 2069 | contentView.setTextViewText(R.id.info, f.format(mNumber)); |
| 2070 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2071 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2072 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2073 | } else { |
| 2074 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 2075 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2076 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2077 | // Need to show three lines? |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2078 | if (mSubText != null) { |
| 2079 | contentView.setTextViewText(R.id.text, mSubText); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2080 | if (mContentText != null) { |
| 2081 | contentView.setTextViewText(R.id.text2, mContentText); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2082 | contentView.setViewVisibility(R.id.text2, View.VISIBLE); |
| 2083 | showLine2 = true; |
| 2084 | } else { |
| 2085 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2086 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2087 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2088 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2089 | if (mProgressMax != 0 || mProgressIndeterminate) { |
| 2090 | contentView.setProgressBar( |
| 2091 | R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); |
| 2092 | contentView.setViewVisibility(R.id.progress, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2093 | showLine2 = true; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2094 | } else { |
| 2095 | contentView.setViewVisibility(R.id.progress, View.GONE); |
| 2096 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2097 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2098 | if (showLine2) { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2099 | if (fitIn1U) { |
| 2100 | // need to shrink all the type to make sure everything fits |
| 2101 | final Resources res = mContext.getResources(); |
| 2102 | final float subTextSize = res.getDimensionPixelSize( |
| 2103 | R.dimen.notification_subtext_size); |
| 2104 | contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); |
| 2105 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2106 | // vertical centering |
| 2107 | contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); |
| 2108 | } |
| 2109 | |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2110 | if (mWhen != 0 && mShowWhen) { |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2111 | if (mUseChronometer) { |
| 2112 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 2113 | contentView.setLong(R.id.chronometer, "setBase", |
| 2114 | mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 2115 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 2116 | } else { |
| 2117 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 2118 | contentView.setLong(R.id.time, "setTime", mWhen); |
| 2119 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2120 | } else { |
| 2121 | contentView.setViewVisibility(R.id.time, View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2122 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2123 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2124 | contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2125 | contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2126 | return contentView; |
| 2127 | } |
| 2128 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2129 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2130 | RemoteViews big = applyStandardTemplate(layoutId, false); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2131 | |
| 2132 | int N = mActions.size(); |
| 2133 | if (N > 0) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2134 | // Log.d("Notification", "has actions: " + mContentText); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2135 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2136 | big.setViewVisibility(R.id.action_divider, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2137 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Chris Wren | 2c22eb0 | 2012-05-08 09:49:13 -0400 | [diff] [blame] | 2138 | big.removeAllViews(R.id.actions); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2139 | for (int i=0; i<N; i++) { |
| 2140 | final RemoteViews button = generateActionButton(mActions.get(i)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2141 | //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2142 | big.addView(R.id.actions, button); |
| 2143 | } |
| 2144 | } |
| 2145 | return big; |
| 2146 | } |
| 2147 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2148 | private RemoteViews makeContentView() { |
| 2149 | if (mContentView != null) { |
| 2150 | return mContentView; |
| 2151 | } else { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2152 | return applyStandardTemplate(R.layout.notification_template_base, true); // no more special large_icon flavor |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | private RemoteViews makeTickerView() { |
| 2157 | if (mTickerView != null) { |
| 2158 | return mTickerView; |
| 2159 | } else { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2160 | if (mContentView == null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2161 | return applyStandardTemplate(mLargeIcon == null |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2162 | ? R.layout.status_bar_latest_event_ticker |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2163 | : R.layout.status_bar_latest_event_ticker_large_icon, true); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2164 | } else { |
| 2165 | return null; |
| 2166 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2167 | } |
| 2168 | } |
| 2169 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2170 | private RemoteViews makeBigContentView() { |
| 2171 | if (mActions.size() == 0) return null; |
| 2172 | |
Chris Wren | b023bf8 | 2012-04-23 16:05:42 -0400 | [diff] [blame] | 2173 | return applyStandardTemplateWithActions(R.layout.notification_template_big_base); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2174 | } |
| 2175 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2176 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2177 | final boolean tombstone = (action.actionIntent == null); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2178 | RemoteViews button = new RemoteViews(mContext.getPackageName(), |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2179 | tombstone ? R.layout.notification_action_tombstone |
| 2180 | : R.layout.notification_action); |
Chris Wren | be63a95 | 2013-12-03 14:31:01 -0500 | [diff] [blame] | 2181 | button.setTextViewCompoundDrawablesRelative(R.id.action0, action.icon, 0, 0, 0); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2182 | button.setTextViewText(R.id.action0, action.title); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2183 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 2184 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 2185 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2186 | button.setContentDescription(R.id.action0, action.title); |
| 2187 | return button; |
| 2188 | } |
| 2189 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2190 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2191 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2192 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2193 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2194 | public Notification buildUnstyled() { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2195 | Notification n = new Notification(); |
| 2196 | n.when = mWhen; |
| 2197 | n.icon = mSmallIcon; |
| 2198 | n.iconLevel = mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2199 | n.number = mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2200 | n.contentView = makeContentView(); |
| 2201 | n.contentIntent = mContentIntent; |
| 2202 | n.deleteIntent = mDeleteIntent; |
| 2203 | n.fullScreenIntent = mFullScreenIntent; |
| 2204 | n.tickerText = mTickerText; |
| 2205 | n.tickerView = makeTickerView(); |
| 2206 | n.largeIcon = mLargeIcon; |
| 2207 | n.sound = mSound; |
| 2208 | n.audioStreamType = mAudioStreamType; |
| 2209 | n.vibrate = mVibrate; |
| 2210 | n.ledARGB = mLedArgb; |
| 2211 | n.ledOnMS = mLedOnMs; |
| 2212 | n.ledOffMS = mLedOffMs; |
| 2213 | n.defaults = mDefaults; |
| 2214 | n.flags = mFlags; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2215 | n.bigContentView = makeBigContentView(); |
Daniel Sandler | 26c1343 | 2013-04-04 11:01:04 -0400 | [diff] [blame] | 2216 | if (mLedOnMs != 0 || mLedOffMs != 0) { |
Joe Onorato | 8d0b655 | 2010-11-22 16:09:29 -0800 | [diff] [blame] | 2217 | n.flags |= FLAG_SHOW_LIGHTS; |
| 2218 | } |
| 2219 | if ((mDefaults & DEFAULT_LIGHTS) != 0) { |
| 2220 | n.flags |= FLAG_SHOW_LIGHTS; |
| 2221 | } |
John Spurlock | cf44a12 | 2014-03-24 11:02:36 -0400 | [diff] [blame] | 2222 | n.category = mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2223 | n.mGroupKey = mGroupKey; |
| 2224 | n.mSortKey = mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2225 | n.priority = mPriority; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2226 | if (mActions.size() > 0) { |
| 2227 | n.actions = new Action[mActions.size()]; |
| 2228 | mActions.toArray(n.actions); |
| 2229 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2230 | return n; |
| 2231 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2232 | |
| 2233 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2234 | * Capture, in the provided bundle, semantic information used in the construction of |
| 2235 | * this Notification object. |
| 2236 | * @hide |
| 2237 | */ |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2238 | public void populateExtras(Bundle extras) { |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2239 | // Store original information used in the construction of this object |
| 2240 | extras.putCharSequence(EXTRA_TITLE, mContentTitle); |
| 2241 | extras.putCharSequence(EXTRA_TEXT, mContentText); |
| 2242 | extras.putCharSequence(EXTRA_SUB_TEXT, mSubText); |
| 2243 | extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo); |
| 2244 | extras.putInt(EXTRA_SMALL_ICON, mSmallIcon); |
| 2245 | extras.putInt(EXTRA_PROGRESS, mProgress); |
| 2246 | extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax); |
| 2247 | extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate); |
| 2248 | extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer); |
| 2249 | extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen); |
John Spurlock | ac08a47 | 2013-06-10 11:37:08 -0400 | [diff] [blame] | 2250 | if (mLargeIcon != null) { |
| 2251 | extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 2252 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2253 | } |
| 2254 | |
| 2255 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2256 | * @deprecated Use {@link #build()} instead. |
| 2257 | */ |
| 2258 | @Deprecated |
| 2259 | public Notification getNotification() { |
| 2260 | return build(); |
| 2261 | } |
| 2262 | |
| 2263 | /** |
| 2264 | * Combine all of the options that have been set and return a new {@link Notification} |
| 2265 | * object. |
| 2266 | */ |
| 2267 | public Notification build() { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2268 | Notification n = buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2269 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2270 | if (mStyle != null) { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2271 | n = mStyle.buildStyled(n); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2272 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2273 | |
| 2274 | n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle(); |
| 2275 | |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2276 | populateExtras(n.extras); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2277 | if (mStyle != null) { |
| 2278 | mStyle.addExtras(n.extras); |
| 2279 | } |
| 2280 | |
| 2281 | return n; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2282 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2283 | |
| 2284 | /** |
| 2285 | * Apply this Builder to an existing {@link Notification} object. |
| 2286 | * |
| 2287 | * @hide |
| 2288 | */ |
| 2289 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2290 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2291 | return n; |
| 2292 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2293 | } |
| 2294 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2295 | /** |
| 2296 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 2297 | * object. |
| 2298 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2299 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2300 | private CharSequence mBigContentTitle; |
| 2301 | private CharSequence mSummaryText = null; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2302 | private boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2303 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2304 | protected Builder mBuilder; |
| 2305 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2306 | /** |
| 2307 | * Overrides ContentTitle in the big form of the template. |
| 2308 | * This defaults to the value passed to setContentTitle(). |
| 2309 | */ |
| 2310 | protected void internalSetBigContentTitle(CharSequence title) { |
| 2311 | mBigContentTitle = title; |
| 2312 | } |
| 2313 | |
| 2314 | /** |
| 2315 | * Set the first line of text after the detail section in the big form of the template. |
| 2316 | */ |
| 2317 | protected void internalSetSummaryText(CharSequence cs) { |
| 2318 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2319 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2320 | } |
| 2321 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2322 | public void setBuilder(Builder builder) { |
| 2323 | if (mBuilder != builder) { |
| 2324 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2325 | if (mBuilder != null) { |
| 2326 | mBuilder.setStyle(this); |
| 2327 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2328 | } |
| 2329 | } |
| 2330 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2331 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2332 | if (mBuilder == null) { |
| 2333 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 2334 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2335 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2336 | |
| 2337 | protected RemoteViews getStandardView(int layoutId) { |
| 2338 | checkBuilder(); |
| 2339 | |
| 2340 | if (mBigContentTitle != null) { |
| 2341 | mBuilder.setContentTitle(mBigContentTitle); |
| 2342 | } |
| 2343 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2344 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 2345 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2346 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 2347 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 2348 | } else { |
| 2349 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2350 | } |
| 2351 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2352 | // The last line defaults to the subtext, but can be replaced by mSummaryText |
| 2353 | final CharSequence overflowText = |
| 2354 | mSummaryTextSet ? mSummaryText |
| 2355 | : mBuilder.mSubText; |
| 2356 | if (overflowText != null) { |
| 2357 | contentView.setTextViewText(R.id.text, overflowText); |
| 2358 | contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2359 | contentView.setViewVisibility(R.id.line3, View.VISIBLE); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 2360 | } else { |
| 2361 | contentView.setViewVisibility(R.id.overflow_divider, View.GONE); |
| 2362 | contentView.setViewVisibility(R.id.line3, View.GONE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2363 | } |
| 2364 | |
| 2365 | return contentView; |
| 2366 | } |
| 2367 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2368 | /** |
| 2369 | * @hide |
| 2370 | */ |
| 2371 | public void addExtras(Bundle extras) { |
| 2372 | if (mSummaryTextSet) { |
| 2373 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 2374 | } |
| 2375 | if (mBigContentTitle != null) { |
| 2376 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 2377 | } |
| 2378 | } |
| 2379 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2380 | /** |
| 2381 | * @hide |
| 2382 | */ |
| 2383 | public abstract Notification buildStyled(Notification wip); |
| 2384 | |
| 2385 | /** |
| 2386 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 2387 | * attached to. |
| 2388 | * |
| 2389 | * @return the fully constructed Notification. |
| 2390 | */ |
| 2391 | public Notification build() { |
| 2392 | checkBuilder(); |
| 2393 | return mBuilder.build(); |
| 2394 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2395 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2396 | |
| 2397 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2398 | * 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] | 2399 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2400 | * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so: |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2401 | * <pre class="prettyprint"> |
| 2402 | * Notification noti = new Notification.BigPictureStyle( |
| 2403 | * new Notification.Builder() |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2404 | * .setContentTitle("New photo from " + sender.toString()) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2405 | * .setContentText(subject) |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2406 | * .setSmallIcon(R.drawable.new_post) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2407 | * .setLargeIcon(aBitmap)) |
| 2408 | * .bigPicture(aBigBitmap) |
| 2409 | * .build(); |
| 2410 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2411 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2412 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2413 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2414 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2415 | private Bitmap mPicture; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2416 | private Bitmap mBigLargeIcon; |
| 2417 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2418 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2419 | public BigPictureStyle() { |
| 2420 | } |
| 2421 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2422 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2423 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2424 | } |
| 2425 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2426 | /** |
| 2427 | * Overrides ContentTitle in the big form of the template. |
| 2428 | * This defaults to the value passed to setContentTitle(). |
| 2429 | */ |
| 2430 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2431 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2432 | return this; |
| 2433 | } |
| 2434 | |
| 2435 | /** |
| 2436 | * Set the first line of text after the detail section in the big form of the template. |
| 2437 | */ |
| 2438 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2439 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2440 | return this; |
| 2441 | } |
| 2442 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 2443 | /** |
| 2444 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 2445 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2446 | public BigPictureStyle bigPicture(Bitmap b) { |
| 2447 | mPicture = b; |
| 2448 | return this; |
| 2449 | } |
| 2450 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2451 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2452 | * Override the large icon when the big notification is shown. |
| 2453 | */ |
| 2454 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
| 2455 | mBigLargeIconSet = true; |
| 2456 | mBigLargeIcon = b; |
| 2457 | return this; |
| 2458 | } |
| 2459 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2460 | private RemoteViews makeBigContentView() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2461 | RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2462 | |
| 2463 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
| 2464 | |
| 2465 | return contentView; |
| 2466 | } |
| 2467 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2468 | /** |
| 2469 | * @hide |
| 2470 | */ |
| 2471 | public void addExtras(Bundle extras) { |
| 2472 | super.addExtras(extras); |
| 2473 | |
| 2474 | if (mBigLargeIconSet) { |
| 2475 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 2476 | } |
| 2477 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 2478 | } |
| 2479 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2480 | /** |
| 2481 | * @hide |
| 2482 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2483 | @Override |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2484 | public Notification buildStyled(Notification wip) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2485 | if (mBigLargeIconSet ) { |
| 2486 | mBuilder.mLargeIcon = mBigLargeIcon; |
| 2487 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2488 | wip.bigContentView = makeBigContentView(); |
| 2489 | return wip; |
| 2490 | } |
| 2491 | } |
| 2492 | |
| 2493 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2494 | * 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] | 2495 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2496 | * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so: |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2497 | * <pre class="prettyprint"> |
Daniel Sandler | 8768278 | 2012-11-07 14:04:42 -0500 | [diff] [blame] | 2498 | * Notification noti = new Notification.BigTextStyle( |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2499 | * new Notification.Builder() |
| 2500 | * .setContentTitle("New mail from " + sender.toString()) |
| 2501 | * .setContentText(subject) |
| 2502 | * .setSmallIcon(R.drawable.new_mail) |
| 2503 | * .setLargeIcon(aBitmap)) |
| 2504 | * .bigText(aVeryLongString) |
| 2505 | * .build(); |
| 2506 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2507 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2508 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2509 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2510 | public static class BigTextStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2511 | private CharSequence mBigText; |
| 2512 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2513 | public BigTextStyle() { |
| 2514 | } |
| 2515 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2516 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2517 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2518 | } |
| 2519 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2520 | /** |
| 2521 | * Overrides ContentTitle in the big form of the template. |
| 2522 | * This defaults to the value passed to setContentTitle(). |
| 2523 | */ |
| 2524 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2525 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2526 | return this; |
| 2527 | } |
| 2528 | |
| 2529 | /** |
| 2530 | * Set the first line of text after the detail section in the big form of the template. |
| 2531 | */ |
| 2532 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2533 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2534 | return this; |
| 2535 | } |
| 2536 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 2537 | /** |
| 2538 | * Provide the longer text to be displayed in the big form of the |
| 2539 | * template in place of the content text. |
| 2540 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2541 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2542 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2543 | return this; |
| 2544 | } |
| 2545 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2546 | /** |
| 2547 | * @hide |
| 2548 | */ |
| 2549 | public void addExtras(Bundle extras) { |
| 2550 | super.addExtras(extras); |
| 2551 | |
| 2552 | extras.putCharSequence(EXTRA_TEXT, mBigText); |
| 2553 | } |
| 2554 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2555 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2556 | // Remove the content text so line3 only shows if you have a summary |
| 2557 | final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2558 | mBuilder.mContentText = null; |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 2559 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2560 | RemoteViews contentView = getStandardView(R.layout.notification_template_big_text); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2561 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2562 | if (hadThreeLines) { |
| 2563 | // vertical centering |
| 2564 | contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); |
| 2565 | } |
| 2566 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2567 | contentView.setTextViewText(R.id.big_text, mBigText); |
| 2568 | contentView.setViewVisibility(R.id.big_text, View.VISIBLE); |
Chris Wren | 3c5f9243 | 2012-05-04 16:31:17 -0400 | [diff] [blame] | 2569 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2570 | |
| 2571 | return contentView; |
| 2572 | } |
| 2573 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2574 | /** |
| 2575 | * @hide |
| 2576 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2577 | @Override |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2578 | public Notification buildStyled(Notification wip) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2579 | wip.bigContentView = makeBigContentView(); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2580 | |
| 2581 | wip.extras.putCharSequence(EXTRA_TEXT, mBigText); |
| 2582 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2583 | return wip; |
| 2584 | } |
| 2585 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2586 | |
| 2587 | /** |
| 2588 | * 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] | 2589 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2590 | * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so: |
| 2591 | * <pre class="prettyprint"> |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2592 | * Notification noti = new Notification.InboxStyle( |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2593 | * new Notification.Builder() |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2594 | * .setContentTitle("5 New mails from " + sender.toString()) |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2595 | * .setContentText(subject) |
| 2596 | * .setSmallIcon(R.drawable.new_mail) |
| 2597 | * .setLargeIcon(aBitmap)) |
| 2598 | * .addLine(str1) |
| 2599 | * .addLine(str2) |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2600 | * .setContentTitle("") |
| 2601 | * .setSummaryText("+3 more") |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2602 | * .build(); |
| 2603 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2604 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2605 | * @see Notification#bigContentView |
| 2606 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2607 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2608 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 2609 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2610 | public InboxStyle() { |
| 2611 | } |
| 2612 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2613 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2614 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2615 | } |
| 2616 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2617 | /** |
| 2618 | * Overrides ContentTitle in the big form of the template. |
| 2619 | * This defaults to the value passed to setContentTitle(). |
| 2620 | */ |
| 2621 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2622 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2623 | return this; |
| 2624 | } |
| 2625 | |
| 2626 | /** |
| 2627 | * Set the first line of text after the detail section in the big form of the template. |
| 2628 | */ |
| 2629 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2630 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2631 | return this; |
| 2632 | } |
| 2633 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 2634 | /** |
| 2635 | * Append a line to the digest section of the Inbox notification. |
| 2636 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2637 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2638 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2639 | return this; |
| 2640 | } |
| 2641 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2642 | /** |
| 2643 | * @hide |
| 2644 | */ |
| 2645 | public void addExtras(Bundle extras) { |
| 2646 | super.addExtras(extras); |
| 2647 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 2648 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 2649 | } |
| 2650 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2651 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2652 | // Remove the content text so line3 disappears unless you have a summary |
| 2653 | mBuilder.mContentText = null; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2654 | RemoteViews contentView = getStandardView(R.layout.notification_template_inbox); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2655 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2656 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2657 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2658 | 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] | 2659 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2660 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 2661 | // Make sure all rows are gone in case we reuse a view. |
| 2662 | for (int rowId : rowIds) { |
| 2663 | contentView.setViewVisibility(rowId, View.GONE); |
| 2664 | } |
| 2665 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 2666 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2667 | int i=0; |
| 2668 | while (i < mTexts.size() && i < rowIds.length) { |
| 2669 | CharSequence str = mTexts.get(i); |
| 2670 | if (str != null && !str.equals("")) { |
| 2671 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
| 2672 | contentView.setTextViewText(rowIds[i], str); |
| 2673 | } |
| 2674 | i++; |
| 2675 | } |
| 2676 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 2677 | contentView.setViewVisibility(R.id.inbox_end_pad, |
| 2678 | mTexts.size() > 0 ? View.VISIBLE : View.GONE); |
| 2679 | |
| 2680 | contentView.setViewVisibility(R.id.inbox_more, |
| 2681 | mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE); |
Chris Wren | 29bb6d9 | 2012-05-17 18:09:42 -0400 | [diff] [blame] | 2682 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2683 | return contentView; |
| 2684 | } |
| 2685 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2686 | /** |
| 2687 | * @hide |
| 2688 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2689 | @Override |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2690 | public Notification buildStyled(Notification wip) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2691 | wip.bigContentView = makeBigContentView(); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2692 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2693 | return wip; |
| 2694 | } |
| 2695 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2696 | } |