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 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 19 | import com.android.internal.R; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.content.Context; |
| 22 | import android.content.Intent; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 23 | import android.graphics.Bitmap; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.net.Uri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 25 | import android.os.Bundle; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 26 | import android.os.IBinder; |
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; |
| 29 | import android.text.TextUtils; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 30 | import android.util.IntProperty; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 31 | import android.view.View; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 32 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 33 | import android.widget.RemoteViews; |
| 34 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 35 | import java.text.NumberFormat; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 36 | import java.util.ArrayList; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 37 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | /** |
| 39 | * A class that represents how a persistent notification is to be presented to |
| 40 | * the user using the {@link android.app.NotificationManager}. |
| 41 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 42 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 43 | * easier to construct Notifications.</p> |
| 44 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 45 | * <div class="special reference"> |
| 46 | * <h3>Developer Guides</h3> |
| 47 | * <p>For a guide to creating notifications, read the |
| 48 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 49 | * developer guide.</p> |
| 50 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 51 | */ |
| 52 | public class Notification implements Parcelable |
| 53 | { |
| 54 | /** |
| 55 | * Use all default values (where applicable). |
| 56 | */ |
| 57 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 58 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 59 | /** |
| 60 | * Use the default notification sound. This will ignore any given |
| 61 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 62 | * |
| 63 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 65 | */ |
| 66 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | public static final int DEFAULT_SOUND = 1; |
| 68 | |
| 69 | /** |
| 70 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 71 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 72 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 73 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 74 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 75 | */ |
| 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 78 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 79 | /** |
| 80 | * Use the default notification lights. This will ignore the |
| 81 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 82 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 83 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 84 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 85 | */ |
| 86 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 87 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 88 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 89 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 90 | * A timestamp related to this notification, in milliseconds since the epoch. |
| 91 | * |
| 92 | * Default value: {@link System#currentTimeMillis() Now}. |
| 93 | * |
| 94 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 95 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 96 | * yet to occur but about which the user is being informed). Indefinite events should be |
| 97 | * timestamped according to when the activity began. |
| 98 | * |
| 99 | * Some examples: |
| 100 | * |
| 101 | * <ul> |
| 102 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 103 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 104 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 105 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 106 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 107 | * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time. |
| 108 | * </ul> |
| 109 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 110 | */ |
| 111 | public long when; |
| 112 | |
| 113 | /** |
| 114 | * 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] | 115 | * 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] | 116 | */ |
| 117 | public int icon; |
| 118 | |
| 119 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 120 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 121 | * leave it at its default value of 0. |
| 122 | * |
| 123 | * @see android.widget.ImageView#setImageLevel |
| 124 | * @see android.graphics.drawable#setLevel |
| 125 | */ |
| 126 | public int iconLevel; |
| 127 | |
| 128 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 129 | * The number of events that this notification represents. For example, in a new mail |
| 130 | * notification, this could be the number of unread messages. |
| 131 | * |
| 132 | * The system may or may not use this field to modify the appearance of the notification. For |
| 133 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 134 | * superimposed over the icon in the status bar. Starting with |
| 135 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 136 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
| 137 | * |
| 138 | * 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] | 139 | */ |
| 140 | public int number; |
| 141 | |
| 142 | /** |
| 143 | * The intent to execute when the expanded status entry is clicked. If |
| 144 | * this is an activity, it must include the |
| 145 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 146 | * that you take care of task management as described in the |
| 147 | * <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] | 148 | * Stack</a> document. In particular, make sure to read the notification section |
| 149 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 150 | * Notifications</a> for the correct ways to launch an application from a |
| 151 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 152 | */ |
| 153 | public PendingIntent contentIntent; |
| 154 | |
| 155 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 156 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 157 | * the "Clear All" button or by swiping it away individually. |
| 158 | * |
| 159 | * This probably shouldn't be launching an activity since several of those will be sent |
| 160 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 161 | */ |
| 162 | public PendingIntent deleteIntent; |
| 163 | |
| 164 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 165 | * 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] | 166 | * |
| 167 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 168 | */ |
| 169 | public PendingIntent fullScreenIntent; |
| 170 | |
| 171 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 172 | * Text to scroll across the screen when this item is added to |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 173 | * the status bar on large and smaller devices. |
| 174 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 175 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 176 | */ |
| 177 | public CharSequence tickerText; |
| 178 | |
| 179 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 180 | * The view to show as the ticker in the status bar when the notification |
| 181 | * is posted. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 182 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 183 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 184 | |
| 185 | /** |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 186 | * 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] | 187 | */ |
| 188 | public RemoteViews contentView; |
| 189 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 190 | /** |
| 191 | * The view that will represent this notification in the pop-up "intruder alert" dialog. |
| 192 | * @hide |
| 193 | */ |
| 194 | public RemoteViews intruderView; |
| 195 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 196 | /** |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 197 | * A larger version of {@link #contentView}, giving the Notification an |
| 198 | * opportunity to show more detail. The system UI may choose to show this |
| 199 | * instead of the normal content view at its discretion. |
| 200 | * @hide |
| 201 | */ |
| 202 | public RemoteViews bigContentView; |
| 203 | |
| 204 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 205 | * 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] | 206 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 207 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | |
| 209 | /** |
| 210 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 211 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 212 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 213 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 214 | * </p> |
| 215 | */ |
| 216 | public Uri sound; |
| 217 | |
| 218 | /** |
| 219 | * Use this constant as the value for audioStreamType to request that |
| 220 | * the default stream type for notifications be used. Currently the |
| 221 | * default stream type is STREAM_RING. |
| 222 | */ |
| 223 | public static final int STREAM_DEFAULT = -1; |
| 224 | |
| 225 | /** |
| 226 | * The audio stream type to use when playing the sound. |
| 227 | * Should be one of the STREAM_ constants from |
| 228 | * {@link android.media.AudioManager}. |
| 229 | */ |
| 230 | public int audioStreamType = STREAM_DEFAULT; |
| 231 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 233 | * The pattern with which to vibrate. |
| 234 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | * <p> |
| 236 | * To vibrate the default pattern, see {@link #defaults}. |
| 237 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 238 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 239 | * @see android.os.Vibrator#vibrate(long[],int) |
| 240 | */ |
| 241 | public long[] vibrate; |
| 242 | |
| 243 | /** |
| 244 | * The color of the led. The hardware will do its best approximation. |
| 245 | * |
| 246 | * @see #FLAG_SHOW_LIGHTS |
| 247 | * @see #flags |
| 248 | */ |
| 249 | public int ledARGB; |
| 250 | |
| 251 | /** |
| 252 | * The number of milliseconds for the LED to be on while it's flashing. |
| 253 | * The hardware will do its best approximation. |
| 254 | * |
| 255 | * @see #FLAG_SHOW_LIGHTS |
| 256 | * @see #flags |
| 257 | */ |
| 258 | public int ledOnMS; |
| 259 | |
| 260 | /** |
| 261 | * The number of milliseconds for the LED to be off while it's flashing. |
| 262 | * The hardware will do its best approximation. |
| 263 | * |
| 264 | * @see #FLAG_SHOW_LIGHTS |
| 265 | * @see #flags |
| 266 | */ |
| 267 | public int ledOffMS; |
| 268 | |
| 269 | /** |
| 270 | * Specifies which values should be taken from the defaults. |
| 271 | * <p> |
| 272 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 273 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 274 | * values, use {@link #DEFAULT_ALL}. |
| 275 | * </p> |
| 276 | */ |
| 277 | public int defaults; |
| 278 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 279 | /** |
| 280 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 281 | * set if you want the LED on for this notification. |
| 282 | * <ul> |
| 283 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 284 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 285 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 286 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 287 | * be on and off to ledOnMS and ledOffMS.</li> |
| 288 | * </ul> |
| 289 | * <p> |
| 290 | * Since hardware varies, you are not guaranteed that any of the values |
| 291 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 292 | * because they will be set to values that work on any given hardware. |
| 293 | * <p> |
| 294 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 295 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 296 | */ |
| 297 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 298 | |
| 299 | /** |
| 300 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 301 | * set if this notification is in reference to something that is ongoing, |
| 302 | * like a phone call. It should not be set if this notification is in |
| 303 | * reference to something that happened at a particular point in time, |
| 304 | * like a missed phone call. |
| 305 | */ |
| 306 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 307 | |
| 308 | /** |
| 309 | * 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] | 310 | * the audio will be repeated until the notification is |
| 311 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 312 | */ |
| 313 | public static final int FLAG_INSISTENT = 0x00000004; |
| 314 | |
| 315 | /** |
| 316 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 317 | * set if you want the sound and/or vibration play each time the |
| 318 | * notification is sent, even if it has not been canceled before that. |
| 319 | */ |
| 320 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 321 | |
| 322 | /** |
| 323 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 324 | * set if the notification should be canceled when it is clicked by the |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 325 | * user. On tablets, the |
| 326 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 327 | */ |
| 328 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 329 | |
| 330 | /** |
| 331 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 332 | * set if the notification should not be canceled when the user clicks |
| 333 | * the Clear all button. |
| 334 | */ |
| 335 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 336 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 337 | /** |
| 338 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 339 | * set if this notification represents a currently running service. This |
| 340 | * will normally be set for you by {@link Service#startForeground}. |
| 341 | */ |
| 342 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 343 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 344 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 345 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
| 346 | * |
| 347 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 348 | */ |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 349 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 350 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 351 | public int flags; |
| 352 | |
| 353 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 354 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 355 | * notifications, use this value for all notifications. |
| 356 | */ |
| 357 | public static final int PRIORITY_DEFAULT = 0; |
| 358 | |
| 359 | /** |
| 360 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 361 | * items smaller, or at a different position in the list, compared with your app's |
| 362 | * {@link #PRIORITY_DEFAULT} items. |
| 363 | */ |
| 364 | public static final int PRIORITY_LOW = -1; |
| 365 | |
| 366 | /** |
| 367 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 368 | * circumstances, such as detailed notification logs. |
| 369 | */ |
| 370 | public static final int PRIORITY_MIN = -2; |
| 371 | |
| 372 | /** |
| 373 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 374 | * show these items larger, or at a different position in notification lists, compared with |
| 375 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 376 | */ |
| 377 | public static final int PRIORITY_HIGH = 1; |
| 378 | |
| 379 | /** |
| 380 | * Highest {@link #priority}, for your application's most important items that require the |
| 381 | * user's prompt attention or input. |
| 382 | */ |
| 383 | public static final int PRIORITY_MAX = 2; |
| 384 | |
| 385 | /** |
| 386 | * Relative priority for this notification. |
| 387 | * |
| 388 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 389 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 390 | * situations, while the user might be interrupted for a higher-priority notification. The |
| 391 | * system will make a determination about how to interpret notification priority as described in |
| 392 | * MUMBLE MUMBLE. |
| 393 | */ |
| 394 | public int priority; |
| 395 | |
| 396 | /** |
| 397 | * Notification type: incoming call (voice or video) or similar synchronous communication request. |
| 398 | */ |
| 399 | public static final String KIND_CALL = "android.call"; |
| 400 | |
| 401 | /** |
| 402 | * Notification type: incoming direct message (SMS, instant message, etc.). |
| 403 | */ |
| 404 | public static final String KIND_MESSAGE = "android.message"; |
| 405 | |
| 406 | /** |
| 407 | * Notification type: asynchronous bulk message (email). |
| 408 | */ |
| 409 | public static final String KIND_EMAIL = "android.email"; |
| 410 | |
| 411 | /** |
| 412 | * Notification type: calendar event. |
| 413 | */ |
| 414 | public static final String KIND_EVENT = "android.event"; |
| 415 | |
| 416 | /** |
| 417 | * Notification type: promotion or advertisement. |
| 418 | */ |
| 419 | public static final String KIND_PROMO = "android.promo"; |
| 420 | |
| 421 | /** |
| 422 | * If this notification matches of one or more special types (see the <code>KIND_*</code> |
| 423 | * constants), add them here, best match first. |
| 424 | */ |
| 425 | public String[] kind; |
| 426 | |
| 427 | /** |
| 428 | * Extra key for people values (type TBD). |
| 429 | * |
| 430 | * @hide |
| 431 | */ |
| 432 | public static final String EXTRA_PEOPLE = "android.people"; |
| 433 | |
| 434 | private Bundle extras; |
| 435 | |
| 436 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 437 | * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification. |
| 438 | * @hide |
| 439 | */ |
| 440 | private static class Action implements Parcelable { |
| 441 | public int icon; |
| 442 | public CharSequence title; |
| 443 | public PendingIntent actionIntent; |
| 444 | @SuppressWarnings("unused") |
| 445 | public Action() { } |
| 446 | private Action(Parcel in) { |
| 447 | icon = in.readInt(); |
| 448 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 449 | if (in.readInt() == 1) { |
| 450 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 451 | } |
| 452 | } |
| 453 | public Action(int icon_, CharSequence title_, PendingIntent intent_) { |
| 454 | this.icon = icon_; |
| 455 | this.title = title_; |
| 456 | this.actionIntent = intent_; |
| 457 | } |
| 458 | @Override |
| 459 | public Action clone() { |
| 460 | return new Action( |
| 461 | this.icon, |
| 462 | this.title.toString(), |
| 463 | this.actionIntent // safe to alias |
| 464 | ); |
| 465 | } |
| 466 | @Override |
| 467 | public int describeContents() { |
| 468 | return 0; |
| 469 | } |
| 470 | @Override |
| 471 | public void writeToParcel(Parcel out, int flags) { |
| 472 | out.writeInt(icon); |
| 473 | TextUtils.writeToParcel(title, out, flags); |
| 474 | if (actionIntent != null) { |
| 475 | out.writeInt(1); |
| 476 | actionIntent.writeToParcel(out, flags); |
| 477 | } else { |
| 478 | out.writeInt(0); |
| 479 | } |
| 480 | } |
| 481 | public static final Parcelable.Creator<Action> CREATOR |
| 482 | = new Parcelable.Creator<Action>() { |
| 483 | public Action createFromParcel(Parcel in) { |
| 484 | return new Action(in); |
| 485 | } |
| 486 | public Action[] newArray(int size) { |
| 487 | return new Action[size]; |
| 488 | } |
| 489 | }; |
| 490 | } |
| 491 | |
| 492 | private Action[] actions; |
| 493 | |
| 494 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 495 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 496 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 497 | */ |
| 498 | public Notification() |
| 499 | { |
| 500 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 501 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 502 | } |
| 503 | |
| 504 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 505 | * @hide |
| 506 | */ |
| 507 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 508 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 509 | { |
| 510 | this.when = when; |
| 511 | this.icon = icon; |
| 512 | this.tickerText = tickerText; |
| 513 | setLatestEventInfo(context, contentTitle, contentText, |
| 514 | PendingIntent.getActivity(context, 0, contentIntent, 0)); |
| 515 | } |
| 516 | |
| 517 | /** |
| 518 | * Constructs a Notification object with the information needed to |
| 519 | * have a status bar icon without the standard expanded view. |
| 520 | * |
| 521 | * @param icon The resource id of the icon to put in the status bar. |
| 522 | * @param tickerText The text that flows by in the status bar when the notification first |
| 523 | * activates. |
| 524 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 525 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 526 | * |
| 527 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 528 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 529 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 530 | public Notification(int icon, CharSequence tickerText, long when) |
| 531 | { |
| 532 | this.icon = icon; |
| 533 | this.tickerText = tickerText; |
| 534 | this.when = when; |
| 535 | } |
| 536 | |
| 537 | /** |
| 538 | * Unflatten the notification from a parcel. |
| 539 | */ |
| 540 | public Notification(Parcel parcel) |
| 541 | { |
| 542 | int version = parcel.readInt(); |
| 543 | |
| 544 | when = parcel.readLong(); |
| 545 | icon = parcel.readInt(); |
| 546 | number = parcel.readInt(); |
| 547 | if (parcel.readInt() != 0) { |
| 548 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 549 | } |
| 550 | if (parcel.readInt() != 0) { |
| 551 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 552 | } |
| 553 | if (parcel.readInt() != 0) { |
| 554 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 555 | } |
| 556 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 557 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 558 | } |
| 559 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 560 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 561 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 562 | if (parcel.readInt() != 0) { |
| 563 | largeIcon = Bitmap.CREATOR.createFromParcel(parcel); |
| 564 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 565 | defaults = parcel.readInt(); |
| 566 | flags = parcel.readInt(); |
| 567 | if (parcel.readInt() != 0) { |
| 568 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 569 | } |
| 570 | |
| 571 | audioStreamType = parcel.readInt(); |
| 572 | vibrate = parcel.createLongArray(); |
| 573 | ledARGB = parcel.readInt(); |
| 574 | ledOnMS = parcel.readInt(); |
| 575 | ledOffMS = parcel.readInt(); |
| 576 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 577 | |
| 578 | if (parcel.readInt() != 0) { |
| 579 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 580 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 581 | |
| 582 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 583 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 584 | kind = parcel.createStringArray(); // may set kind to null |
| 585 | |
| 586 | if (parcel.readInt() != 0) { |
| 587 | extras = parcel.readBundle(); |
| 588 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 589 | |
| 590 | actions = parcel.createTypedArray(Action.CREATOR); |
| 591 | if (parcel.readInt() != 0) { |
| 592 | intruderView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 593 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 594 | if (parcel.readInt() != 0) { |
| 595 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 596 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 599 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 600 | public Notification clone() { |
| 601 | Notification that = new Notification(); |
| 602 | |
| 603 | that.when = this.when; |
| 604 | that.icon = this.icon; |
| 605 | that.number = this.number; |
| 606 | |
| 607 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 608 | that.contentIntent = this.contentIntent; |
| 609 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 610 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 611 | |
| 612 | if (this.tickerText != null) { |
| 613 | that.tickerText = this.tickerText.toString(); |
| 614 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 615 | if (this.tickerView != null) { |
| 616 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 617 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 618 | if (this.contentView != null) { |
| 619 | that.contentView = this.contentView.clone(); |
| 620 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 621 | if (this.largeIcon != null) { |
| 622 | that.largeIcon = Bitmap.createBitmap(this.largeIcon); |
| 623 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 624 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 625 | that.sound = this.sound; // android.net.Uri is immutable |
| 626 | that.audioStreamType = this.audioStreamType; |
| 627 | |
| 628 | final long[] vibrate = this.vibrate; |
| 629 | if (vibrate != null) { |
| 630 | final int N = vibrate.length; |
| 631 | final long[] vib = that.vibrate = new long[N]; |
| 632 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 633 | } |
| 634 | |
| 635 | that.ledARGB = this.ledARGB; |
| 636 | that.ledOnMS = this.ledOnMS; |
| 637 | that.ledOffMS = this.ledOffMS; |
| 638 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 639 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 640 | that.flags = this.flags; |
| 641 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 642 | that.priority = this.priority; |
| 643 | |
| 644 | final String[] thiskind = this.kind; |
| 645 | if (thiskind != null) { |
| 646 | final int N = thiskind.length; |
| 647 | final String[] thatkind = that.kind = new String[N]; |
| 648 | System.arraycopy(thiskind, 0, thatkind, 0, N); |
| 649 | } |
| 650 | |
| 651 | if (this.extras != null) { |
| 652 | that.extras = new Bundle(this.extras); |
| 653 | |
| 654 | } |
| 655 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 656 | that.actions = new Action[this.actions.length]; |
| 657 | for(int i=0; i<this.actions.length; i++) { |
| 658 | that.actions[i] = this.actions[i].clone(); |
| 659 | } |
| 660 | if (this.intruderView != null) { |
| 661 | that.intruderView = this.intruderView.clone(); |
| 662 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 663 | if (this.bigContentView != null) { |
| 664 | that.bigContentView = this.bigContentView.clone(); |
| 665 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 666 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 667 | return that; |
| 668 | } |
| 669 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 670 | public int describeContents() { |
| 671 | return 0; |
| 672 | } |
| 673 | |
| 674 | /** |
| 675 | * Flatten this notification from a parcel. |
| 676 | */ |
| 677 | public void writeToParcel(Parcel parcel, int flags) |
| 678 | { |
| 679 | parcel.writeInt(1); |
| 680 | |
| 681 | parcel.writeLong(when); |
| 682 | parcel.writeInt(icon); |
| 683 | parcel.writeInt(number); |
| 684 | if (contentIntent != null) { |
| 685 | parcel.writeInt(1); |
| 686 | contentIntent.writeToParcel(parcel, 0); |
| 687 | } else { |
| 688 | parcel.writeInt(0); |
| 689 | } |
| 690 | if (deleteIntent != null) { |
| 691 | parcel.writeInt(1); |
| 692 | deleteIntent.writeToParcel(parcel, 0); |
| 693 | } else { |
| 694 | parcel.writeInt(0); |
| 695 | } |
| 696 | if (tickerText != null) { |
| 697 | parcel.writeInt(1); |
| 698 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 699 | } else { |
| 700 | parcel.writeInt(0); |
| 701 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 702 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 703 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 704 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 705 | } else { |
| 706 | parcel.writeInt(0); |
| 707 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | if (contentView != null) { |
| 709 | parcel.writeInt(1); |
| 710 | contentView.writeToParcel(parcel, 0); |
| 711 | } else { |
| 712 | parcel.writeInt(0); |
| 713 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 714 | if (largeIcon != null) { |
| 715 | parcel.writeInt(1); |
| 716 | largeIcon.writeToParcel(parcel, 0); |
| 717 | } else { |
| 718 | parcel.writeInt(0); |
| 719 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 720 | |
| 721 | parcel.writeInt(defaults); |
| 722 | parcel.writeInt(this.flags); |
| 723 | |
| 724 | if (sound != null) { |
| 725 | parcel.writeInt(1); |
| 726 | sound.writeToParcel(parcel, 0); |
| 727 | } else { |
| 728 | parcel.writeInt(0); |
| 729 | } |
| 730 | parcel.writeInt(audioStreamType); |
| 731 | parcel.writeLongArray(vibrate); |
| 732 | parcel.writeInt(ledARGB); |
| 733 | parcel.writeInt(ledOnMS); |
| 734 | parcel.writeInt(ledOffMS); |
| 735 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 736 | |
| 737 | if (fullScreenIntent != null) { |
| 738 | parcel.writeInt(1); |
| 739 | fullScreenIntent.writeToParcel(parcel, 0); |
| 740 | } else { |
| 741 | parcel.writeInt(0); |
| 742 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 743 | |
| 744 | parcel.writeInt(priority); |
| 745 | |
| 746 | parcel.writeStringArray(kind); // ok for null |
| 747 | |
| 748 | if (extras != null) { |
| 749 | parcel.writeInt(1); |
| 750 | extras.writeToParcel(parcel, 0); |
| 751 | } else { |
| 752 | parcel.writeInt(0); |
| 753 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 754 | |
| 755 | parcel.writeTypedArray(actions, 0); |
| 756 | |
| 757 | if (intruderView != null) { |
| 758 | parcel.writeInt(1); |
| 759 | intruderView.writeToParcel(parcel, 0); |
| 760 | } else { |
| 761 | parcel.writeInt(0); |
| 762 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 763 | |
| 764 | if (bigContentView != null) { |
| 765 | parcel.writeInt(1); |
| 766 | bigContentView.writeToParcel(parcel, 0); |
| 767 | } else { |
| 768 | parcel.writeInt(0); |
| 769 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /** |
| 773 | * Parcelable.Creator that instantiates Notification objects |
| 774 | */ |
| 775 | public static final Parcelable.Creator<Notification> CREATOR |
| 776 | = new Parcelable.Creator<Notification>() |
| 777 | { |
| 778 | public Notification createFromParcel(Parcel parcel) |
| 779 | { |
| 780 | return new Notification(parcel); |
| 781 | } |
| 782 | |
| 783 | public Notification[] newArray(int size) |
| 784 | { |
| 785 | return new Notification[size]; |
| 786 | } |
| 787 | }; |
| 788 | |
| 789 | /** |
| 790 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 791 | * layout. |
| 792 | * |
| 793 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 794 | * in the view.</p> |
| 795 | * @param context The context for your application / activity. |
| 796 | * @param contentTitle The title that goes in the expanded entry. |
| 797 | * @param contentText The text that goes in the expanded entry. |
| 798 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 799 | * If this is an activity, it must include the |
| 800 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 801 | * that you take care of task management as described in the |
| 802 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 803 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 804 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 805 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 806 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 807 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 808 | public void setLatestEventInfo(Context context, |
| 809 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
| 810 | RemoteViews contentView = new RemoteViews(context.getPackageName(), |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 811 | R.layout.status_bar_latest_event_content); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | if (this.icon != 0) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 813 | contentView.setImageViewResource(R.id.icon, this.icon); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 814 | } |
| 815 | if (contentTitle != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 816 | contentView.setTextViewText(R.id.title, contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 817 | } |
| 818 | if (contentText != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 819 | contentView.setTextViewText(R.id.text, contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 820 | } |
| 821 | if (this.when != 0) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 822 | contentView.setLong(R.id.time, "setTime", when); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 823 | } |
| 824 | |
| 825 | this.contentView = contentView; |
| 826 | this.contentIntent = contentIntent; |
| 827 | } |
| 828 | |
| 829 | @Override |
| 830 | public String toString() { |
| 831 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 832 | sb.append("Notification(pri="); |
| 833 | sb.append(priority); |
| 834 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 835 | if (contentView != null) { |
| 836 | sb.append(contentView.getPackage()); |
| 837 | sb.append("/0x"); |
| 838 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 839 | } else { |
| 840 | sb.append("null"); |
| 841 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 842 | // 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] | 843 | sb.append(" vibrate="); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 844 | if (this.vibrate != null) { |
| 845 | int N = this.vibrate.length-1; |
| 846 | sb.append("["); |
| 847 | for (int i=0; i<N; i++) { |
| 848 | sb.append(this.vibrate[i]); |
| 849 | sb.append(','); |
| 850 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 851 | if (N != -1) { |
| 852 | sb.append(this.vibrate[N]); |
| 853 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 854 | sb.append("]"); |
| 855 | } else if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 856 | sb.append("default"); |
| 857 | } else { |
| 858 | sb.append("null"); |
| 859 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 860 | sb.append(" sound="); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 861 | if (this.sound != null) { |
| 862 | sb.append(this.sound.toString()); |
| 863 | } else if ((this.defaults & DEFAULT_SOUND) != 0) { |
| 864 | sb.append("default"); |
| 865 | } else { |
| 866 | sb.append("null"); |
| 867 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 868 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 869 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 870 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 871 | sb.append(Integer.toHexString(this.flags)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 872 | sb.append(" kind=["); |
| 873 | if (this.kind == null) { |
| 874 | sb.append("null"); |
| 875 | } else { |
| 876 | for (int i=0; i<this.kind.length; i++) { |
| 877 | if (i>0) sb.append(","); |
| 878 | sb.append(this.kind[i]); |
| 879 | } |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 880 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 881 | sb.append("]"); |
| 882 | if (actions != null) { |
| 883 | sb.append(" "); |
| 884 | sb.append(actions.length); |
| 885 | sb.append(" action"); |
| 886 | if (actions.length > 1) sb.append("s"); |
| 887 | } |
| 888 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | return sb.toString(); |
| 890 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 891 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 892 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 893 | * Builder class for {@link Notification} objects. |
| 894 | * |
| 895 | * Provides a convenient way to set the various fields of a {@link Notification} and generate |
| 896 | * content views using the platform's notification layout template. |
| 897 | * |
| 898 | * Example: |
| 899 | * |
| 900 | * <pre class="prettyprint"> |
| 901 | * Notification noti = new Notification.Builder() |
| 902 | * .setContentTitle("New mail from " + sender.toString()) |
| 903 | * .setContentText(subject) |
| 904 | * .setSmallIcon(R.drawable.new_mail) |
| 905 | * .setLargeIcon(aBitmap) |
| 906 | * .getNotification(); |
| 907 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 908 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 909 | public static class Builder { |
| 910 | private Context mContext; |
| 911 | |
| 912 | private long mWhen; |
| 913 | private int mSmallIcon; |
| 914 | private int mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 915 | private int mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 916 | private CharSequence mContentTitle; |
| 917 | private CharSequence mContentText; |
| 918 | private CharSequence mContentInfo; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 919 | private CharSequence mSubText; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 920 | private PendingIntent mContentIntent; |
| 921 | private RemoteViews mContentView; |
| 922 | private PendingIntent mDeleteIntent; |
| 923 | private PendingIntent mFullScreenIntent; |
| 924 | private CharSequence mTickerText; |
| 925 | private RemoteViews mTickerView; |
| 926 | private Bitmap mLargeIcon; |
| 927 | private Uri mSound; |
| 928 | private int mAudioStreamType; |
| 929 | private long[] mVibrate; |
| 930 | private int mLedArgb; |
| 931 | private int mLedOnMs; |
| 932 | private int mLedOffMs; |
| 933 | private int mDefaults; |
| 934 | private int mFlags; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 935 | private int mProgressMax; |
| 936 | private int mProgress; |
| 937 | private boolean mProgressIndeterminate; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 938 | private ArrayList<String> mKindList = new ArrayList<String>(1); |
| 939 | private Bundle mExtras; |
| 940 | private int mPriority; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 941 | private ArrayList<Action> mActions = new ArrayList<Action>(3); |
Daniel Sandler | b2a1c23 | 2012-03-24 10:37:28 -0500 | [diff] [blame] | 942 | private boolean mCanHasIntruder; |
| 943 | private boolean mIntruderActionsShowText; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 944 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 945 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 946 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 947 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 948 | |
| 949 | * <table> |
| 950 | * <tr><th align=right>priority</th> |
| 951 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 952 | * <tr><th align=right>when</th> |
| 953 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 954 | * <tr><th align=right>audio stream</th> |
| 955 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 956 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 957 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 958 | |
| 959 | * @param context |
| 960 | * A {@link Context} that will be used by the Builder to construct the |
| 961 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 962 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 963 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 964 | public Builder(Context context) { |
| 965 | mContext = context; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 966 | |
| 967 | // Set defaults to match the defaults of a Notification |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 968 | mWhen = System.currentTimeMillis(); |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 969 | mAudioStreamType = STREAM_DEFAULT; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 970 | mPriority = PRIORITY_DEFAULT; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 971 | } |
| 972 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 973 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 974 | * Add a timestamp pertaining to the notification (usually the time the event occurred). |
| 975 | * |
| 976 | |
| 977 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 978 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 979 | public Builder setWhen(long when) { |
| 980 | mWhen = when; |
| 981 | return this; |
| 982 | } |
| 983 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 984 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 985 | * Set the small icon resource, which will be used to represent the notification in the |
| 986 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 987 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 988 | |
| 989 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 990 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 991 | * icon will be moved to the right-hand side. |
| 992 | * |
| 993 | |
| 994 | * @param icon |
| 995 | * A resource ID in the application's package of the drawable to use. |
| 996 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 997 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 998 | public Builder setSmallIcon(int icon) { |
| 999 | mSmallIcon = icon; |
| 1000 | return this; |
| 1001 | } |
| 1002 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1003 | /** |
| 1004 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 1005 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 1006 | * LevelListDrawable}. |
| 1007 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1008 | * @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] | 1009 | * @param level The level to use for the icon. |
| 1010 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1011 | * @see Notification#icon |
| 1012 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1013 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1014 | public Builder setSmallIcon(int icon, int level) { |
| 1015 | mSmallIcon = icon; |
| 1016 | mSmallIconLevel = level; |
| 1017 | return this; |
| 1018 | } |
| 1019 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1020 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1021 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1022 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1023 | public Builder setContentTitle(CharSequence title) { |
| 1024 | mContentTitle = title; |
| 1025 | return this; |
| 1026 | } |
| 1027 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1028 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1029 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1030 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1031 | public Builder setContentText(CharSequence text) { |
| 1032 | mContentText = text; |
| 1033 | return this; |
| 1034 | } |
| 1035 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1036 | /** |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1037 | * Set the third line of text in the platform notification template. |
| 1038 | * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the same location in the standard template. |
| 1039 | */ |
| 1040 | public Builder setSubText(CharSequence text) { |
| 1041 | mSubText = text; |
| 1042 | return this; |
| 1043 | } |
| 1044 | |
| 1045 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1046 | * Set the large number at the right-hand side of the notification. This is |
| 1047 | * equivalent to setContentInfo, although it might show the number in a different |
| 1048 | * font size for readability. |
| 1049 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1050 | public Builder setNumber(int number) { |
| 1051 | mNumber = number; |
| 1052 | return this; |
| 1053 | } |
| 1054 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1055 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1056 | * A small piece of additional information pertaining to this notification. |
| 1057 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1058 | * The platform template will draw this on the last line of the notification, at the far |
| 1059 | * 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] | 1060 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1061 | public Builder setContentInfo(CharSequence info) { |
| 1062 | mContentInfo = info; |
| 1063 | return this; |
| 1064 | } |
| 1065 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1066 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1067 | * Set the progress this notification represents. |
| 1068 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1069 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1070 | */ |
| 1071 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 1072 | mProgressMax = max; |
| 1073 | mProgress = progress; |
| 1074 | mProgressIndeterminate = indeterminate; |
| 1075 | return this; |
| 1076 | } |
| 1077 | |
| 1078 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1079 | * Supply a custom RemoteViews to use instead of the platform template. |
| 1080 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1081 | * @see Notification#contentView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1082 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1083 | public Builder setContent(RemoteViews views) { |
| 1084 | mContentView = views; |
| 1085 | return this; |
| 1086 | } |
| 1087 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1088 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1089 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 1090 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1091 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 1092 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 1093 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1094 | * 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^] | 1095 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1096 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1097 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1098 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1099 | public Builder setContentIntent(PendingIntent intent) { |
| 1100 | mContentIntent = intent; |
| 1101 | return this; |
| 1102 | } |
| 1103 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1104 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1105 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 1106 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1107 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1108 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1109 | public Builder setDeleteIntent(PendingIntent intent) { |
| 1110 | mDeleteIntent = intent; |
| 1111 | return this; |
| 1112 | } |
| 1113 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1114 | /** |
| 1115 | * An intent to launch instead of posting the notification to the status bar. |
| 1116 | * Only for use with extremely high-priority notifications demanding the user's |
| 1117 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 1118 | * alarm clock that the user has explicitly set to a particular time. |
| 1119 | * If this facility is used for something else, please give the user an option |
| 1120 | * to turn it off and use a normal notification, as this can be extremely |
| 1121 | * disruptive. |
| 1122 | * |
| 1123 | * @param intent The pending intent to launch. |
| 1124 | * @param highPriority Passing true will cause this notification to be sent |
| 1125 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1126 | * |
| 1127 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1128 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1129 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 1130 | mFullScreenIntent = intent; |
| 1131 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 1132 | return this; |
| 1133 | } |
| 1134 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1135 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1136 | * 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] | 1137 | * arrives. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1138 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1139 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1140 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1141 | public Builder setTicker(CharSequence tickerText) { |
| 1142 | mTickerText = tickerText; |
| 1143 | return this; |
| 1144 | } |
| 1145 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1146 | /** |
| 1147 | * Set the text that is displayed in the status bar when the notification first |
| 1148 | * arrives, and also a RemoteViews object that may be displayed instead on some |
| 1149 | * devices. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1150 | * |
| 1151 | * @see Notification#tickerText |
| 1152 | * @see Notification#tickerView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1153 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1154 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
| 1155 | mTickerText = tickerText; |
| 1156 | mTickerView = views; |
| 1157 | return this; |
| 1158 | } |
| 1159 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1160 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1161 | * Add a large icon to the notification (and the ticker on some devices). |
| 1162 | * |
| 1163 | * In the platform template, this image will be shown on the left of the notification view |
| 1164 | * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side). |
| 1165 | * |
| 1166 | * @see Notification#largeIcon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1167 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1168 | public Builder setLargeIcon(Bitmap icon) { |
| 1169 | mLargeIcon = icon; |
| 1170 | return this; |
| 1171 | } |
| 1172 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1173 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1174 | * Set the sound to play. |
| 1175 | * |
| 1176 | * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications. |
| 1177 | * |
| 1178 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1179 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 1180 | public Builder setSound(Uri sound) { |
| 1181 | mSound = sound; |
| 1182 | mAudioStreamType = STREAM_DEFAULT; |
| 1183 | return this; |
| 1184 | } |
| 1185 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1186 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1187 | * 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] | 1188 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1189 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 1190 | * |
| 1191 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1192 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1193 | public Builder setSound(Uri sound, int streamType) { |
| 1194 | mSound = sound; |
| 1195 | mAudioStreamType = streamType; |
| 1196 | return this; |
| 1197 | } |
| 1198 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1199 | /** |
| 1200 | * Set the vibration pattern to use. |
| 1201 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1202 | |
| 1203 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 1204 | * <code>pattern</code> parameter. |
| 1205 | * |
| 1206 | |
| 1207 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1208 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1209 | public Builder setVibrate(long[] pattern) { |
| 1210 | mVibrate = pattern; |
| 1211 | return this; |
| 1212 | } |
| 1213 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1214 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1215 | * Set the desired color for the indicator LED on the device, as well as the |
| 1216 | * blink duty cycle (specified in milliseconds). |
| 1217 | * |
| 1218 | |
| 1219 | * Not all devices will honor all (or even any) of these values. |
| 1220 | * |
| 1221 | |
| 1222 | * @see Notification#ledARGB |
| 1223 | * @see Notification#ledOnMS |
| 1224 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1225 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1226 | public Builder setLights(int argb, int onMs, int offMs) { |
| 1227 | mLedArgb = argb; |
| 1228 | mLedOnMs = onMs; |
| 1229 | mLedOffMs = offMs; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1230 | return this; |
| 1231 | } |
| 1232 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1233 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1234 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1235 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1236 | |
| 1237 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 1238 | * must take care of canceling them. |
| 1239 | * |
| 1240 | |
| 1241 | * They are typically used to indicate a background task that the user is actively engaged |
| 1242 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 1243 | * (e.g., a file download, sync operation, active network connection). |
| 1244 | * |
| 1245 | |
| 1246 | * @see Notification#FLAG_ONGOING_EVENT |
| 1247 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1248 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1249 | public Builder setOngoing(boolean ongoing) { |
| 1250 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 1251 | return this; |
| 1252 | } |
| 1253 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1254 | /** |
| 1255 | * Set this flag if you would only like the sound, vibrate |
| 1256 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1257 | * |
| 1258 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1259 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1260 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 1261 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 1262 | return this; |
| 1263 | } |
| 1264 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1265 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1266 | * Make this notification automatically dismissed when the user touches it. The |
| 1267 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 1268 | * |
| 1269 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1270 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1271 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 1272 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1273 | return this; |
| 1274 | } |
| 1275 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1276 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1277 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1278 | * <p> |
| 1279 | * The value should be one or more of the following fields combined with |
| 1280 | * bitwise-or: |
| 1281 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 1282 | * <p> |
| 1283 | * For all default values, use {@link #DEFAULT_ALL}. |
| 1284 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1285 | public Builder setDefaults(int defaults) { |
| 1286 | mDefaults = defaults; |
| 1287 | return this; |
| 1288 | } |
| 1289 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1290 | /** |
| 1291 | * Set the priority of this notification. |
| 1292 | * |
| 1293 | * @see Notification#priority |
| 1294 | */ |
| 1295 | public Builder setPriority(int pri) { |
| 1296 | mPriority = pri; |
| 1297 | return this; |
| 1298 | } |
| 1299 | |
| 1300 | /** |
| 1301 | * Add a kind (category) to this notification. Optional. |
| 1302 | * |
| 1303 | * @see Notification#kind |
| 1304 | */ |
| 1305 | public Builder addKind(String k) { |
| 1306 | mKindList.add(k); |
| 1307 | return this; |
| 1308 | } |
| 1309 | |
| 1310 | /** |
| 1311 | * Add metadata to this notification. |
| 1312 | * |
| 1313 | * A reference to the Bundle is held for the lifetime of this Builder, and the Bundle's |
| 1314 | * current contents are copied into the Notification each time {@link #getNotification()} is |
| 1315 | * called. |
| 1316 | * |
| 1317 | * @see Notification#extras |
| 1318 | * @hide |
| 1319 | */ |
| 1320 | public Builder setExtras(Bundle bag) { |
| 1321 | mExtras = bag; |
| 1322 | return this; |
| 1323 | } |
| 1324 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1325 | /** |
| 1326 | * Add an action to this notification. Actions are typically displayed by |
| 1327 | * the system as a button adjacent to the notification content. |
| 1328 | * |
| 1329 | * @param icon Resource ID of a drawable that represents the action. |
| 1330 | * @param title Text describing the action. |
| 1331 | * @param intent PendingIntent to be fired when the action is invoked. |
| 1332 | */ |
| 1333 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
| 1334 | mActions.add(new Action(icon, title, intent)); |
| 1335 | return this; |
| 1336 | } |
| 1337 | |
Daniel Sandler | b2a1c23 | 2012-03-24 10:37:28 -0500 | [diff] [blame] | 1338 | /** |
| 1339 | * Specify whether this notification should pop up as an |
| 1340 | * "intruder alert" (a small window that shares the screen with the |
| 1341 | * current activity). This sort of notification is (as the name implies) |
| 1342 | * very intrusive, so use it sparingly for notifications that require |
| 1343 | * the user's attention. |
| 1344 | * |
| 1345 | * Notes: |
| 1346 | * <ul> |
| 1347 | * <li>Intruder alerts only show when the screen is on.</li> |
| 1348 | * <li>Intruder alerts take precedence over fullScreenIntents.</li> |
| 1349 | * </ul> |
| 1350 | * |
| 1351 | * @param intrude Whether to pop up an intruder alert (default false). |
| 1352 | */ |
| 1353 | public Builder setUsesIntruderAlert(boolean intrude) { |
| 1354 | mCanHasIntruder = intrude; |
| 1355 | return this; |
| 1356 | } |
| 1357 | |
| 1358 | /** |
| 1359 | * Control text on intruder alert action buttons. By default, action |
| 1360 | * buttons in intruders do not show textual labels. |
| 1361 | * |
| 1362 | * @param showActionText Whether to show text labels beneath action |
| 1363 | * icons (default false). |
| 1364 | */ |
| 1365 | public Builder setIntruderActionsShowText(boolean showActionText) { |
| 1366 | mIntruderActionsShowText = showActionText; |
| 1367 | return this; |
| 1368 | } |
| 1369 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1370 | private void setFlag(int mask, boolean value) { |
| 1371 | if (value) { |
| 1372 | mFlags |= mask; |
| 1373 | } else { |
| 1374 | mFlags &= ~mask; |
| 1375 | } |
| 1376 | } |
| 1377 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1378 | private RemoteViews applyStandardTemplate(int resId) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1379 | RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1380 | boolean hasLine3 = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1381 | boolean hasLine2 = false; |
| 1382 | int smallIconImageViewId = R.id.icon; |
| 1383 | if (mLargeIcon != null) { |
| 1384 | contentView.setImageViewBitmap(R.id.icon, mLargeIcon); |
| 1385 | smallIconImageViewId = R.id.right_icon; |
| 1386 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1387 | if (mSmallIcon != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1388 | contentView.setImageViewResource(smallIconImageViewId, mSmallIcon); |
| 1389 | contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1390 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1391 | contentView.setViewVisibility(smallIconImageViewId, View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1392 | } |
| 1393 | if (mContentTitle != null) { |
| 1394 | contentView.setTextViewText(R.id.title, mContentTitle); |
| 1395 | } |
| 1396 | if (mContentText != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1397 | contentView.setTextViewText( |
| 1398 | (mSubText != null) ? R.id.text2 : R.id.text, |
| 1399 | mContentText); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1400 | hasLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1401 | } |
| 1402 | if (mContentInfo != null) { |
| 1403 | contentView.setTextViewText(R.id.info, mContentInfo); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1404 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
| 1405 | hasLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1406 | } else if (mNumber > 0) { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 1407 | final int tooBig = mContext.getResources().getInteger( |
| 1408 | R.integer.status_bar_notification_info_maxnum); |
| 1409 | if (mNumber > tooBig) { |
| 1410 | contentView.setTextViewText(R.id.info, mContext.getResources().getString( |
| 1411 | R.string.status_bar_notification_info_overflow)); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 1412 | } else { |
| 1413 | NumberFormat f = NumberFormat.getIntegerInstance(); |
| 1414 | contentView.setTextViewText(R.id.info, f.format(mNumber)); |
| 1415 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1416 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
| 1417 | hasLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1418 | } else { |
| 1419 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 1420 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1421 | |
| 1422 | if (mSubText != null) { |
| 1423 | contentView.setTextViewText(R.id.text, mSubText); |
| 1424 | contentView.setViewVisibility(R.id.text2, View.VISIBLE); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1425 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1426 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 1427 | if (mProgressMax != 0 || mProgressIndeterminate) { |
| 1428 | contentView.setProgressBar( |
| 1429 | R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); |
| 1430 | contentView.setViewVisibility(R.id.progress, View.VISIBLE); |
| 1431 | } else { |
| 1432 | contentView.setViewVisibility(R.id.progress, View.GONE); |
| 1433 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1434 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1435 | if (mWhen != 0) { |
| 1436 | contentView.setLong(R.id.time, "setTime", mWhen); |
| 1437 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1438 | contentView.setViewVisibility(R.id.line3, hasLine3 ? View.VISIBLE : View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1439 | return contentView; |
| 1440 | } |
| 1441 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1442 | private RemoteViews makeContentView() { |
| 1443 | if (mContentView != null) { |
| 1444 | return mContentView; |
| 1445 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1446 | return applyStandardTemplate(R.layout.status_bar_latest_event_content); // no more special large_icon flavor |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1447 | } |
| 1448 | } |
| 1449 | |
| 1450 | private RemoteViews makeTickerView() { |
| 1451 | if (mTickerView != null) { |
| 1452 | return mTickerView; |
| 1453 | } else { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1454 | if (mContentView == null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1455 | return applyStandardTemplate(mLargeIcon == null |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1456 | ? R.layout.status_bar_latest_event_ticker |
| 1457 | : R.layout.status_bar_latest_event_ticker_large_icon); |
| 1458 | } else { |
| 1459 | return null; |
| 1460 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1461 | } |
| 1462 | } |
| 1463 | |
Daniel Sandler | b2a1c23 | 2012-03-24 10:37:28 -0500 | [diff] [blame] | 1464 | private RemoteViews makeIntruderView(boolean showLabels) { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1465 | RemoteViews intruderView = new RemoteViews(mContext.getPackageName(), |
| 1466 | R.layout.notification_intruder_content); |
| 1467 | if (mLargeIcon != null) { |
| 1468 | intruderView.setImageViewBitmap(R.id.icon, mLargeIcon); |
| 1469 | intruderView.setViewVisibility(R.id.icon, View.VISIBLE); |
| 1470 | } else if (mSmallIcon != 0) { |
| 1471 | intruderView.setImageViewResource(R.id.icon, mSmallIcon); |
| 1472 | intruderView.setViewVisibility(R.id.icon, View.VISIBLE); |
| 1473 | } else { |
| 1474 | intruderView.setViewVisibility(R.id.icon, View.GONE); |
| 1475 | } |
| 1476 | if (mContentTitle != null) { |
| 1477 | intruderView.setTextViewText(R.id.title, mContentTitle); |
| 1478 | } |
| 1479 | if (mContentText != null) { |
| 1480 | intruderView.setTextViewText(R.id.text, mContentText); |
| 1481 | } |
| 1482 | if (mActions.size() > 0) { |
| 1483 | intruderView.setViewVisibility(R.id.actions, View.VISIBLE); |
| 1484 | int N = mActions.size(); |
| 1485 | if (N>3) N=3; |
| 1486 | final int[] BUTTONS = { R.id.action0, R.id.action1, R.id.action2 }; |
| 1487 | for (int i=0; i<N; i++) { |
| 1488 | final Action action = mActions.get(i); |
| 1489 | final int buttonId = BUTTONS[i]; |
| 1490 | |
| 1491 | intruderView.setViewVisibility(buttonId, View.VISIBLE); |
Daniel Sandler | b2a1c23 | 2012-03-24 10:37:28 -0500 | [diff] [blame] | 1492 | intruderView.setTextViewText(buttonId, showLabels ? action.title : null); |
| 1493 | intruderView.setTextViewCompoundDrawables(buttonId, 0, action.icon, 0, 0); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1494 | intruderView.setContentDescription(buttonId, action.title); |
| 1495 | intruderView.setOnClickPendingIntent(buttonId, action.actionIntent); |
| 1496 | } |
| 1497 | } else { |
| 1498 | intruderView.setViewVisibility(R.id.actions, View.GONE); |
| 1499 | } |
| 1500 | return intruderView; |
| 1501 | } |
| 1502 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1503 | /** |
| 1504 | * Combine all of the options that have been set and return a new {@link Notification} |
| 1505 | * object. |
| 1506 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1507 | public Notification getNotification() { |
| 1508 | Notification n = new Notification(); |
| 1509 | n.when = mWhen; |
| 1510 | n.icon = mSmallIcon; |
| 1511 | n.iconLevel = mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1512 | n.number = mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1513 | n.contentView = makeContentView(); |
| 1514 | n.contentIntent = mContentIntent; |
| 1515 | n.deleteIntent = mDeleteIntent; |
| 1516 | n.fullScreenIntent = mFullScreenIntent; |
| 1517 | n.tickerText = mTickerText; |
| 1518 | n.tickerView = makeTickerView(); |
| 1519 | n.largeIcon = mLargeIcon; |
| 1520 | n.sound = mSound; |
| 1521 | n.audioStreamType = mAudioStreamType; |
| 1522 | n.vibrate = mVibrate; |
| 1523 | n.ledARGB = mLedArgb; |
| 1524 | n.ledOnMS = mLedOnMs; |
| 1525 | n.ledOffMS = mLedOffMs; |
| 1526 | n.defaults = mDefaults; |
| 1527 | n.flags = mFlags; |
Daniel Sandler | b2a1c23 | 2012-03-24 10:37:28 -0500 | [diff] [blame] | 1528 | if (mCanHasIntruder) { |
| 1529 | n.intruderView = makeIntruderView(mIntruderActionsShowText); |
| 1530 | } |
Joe Onorato | 8d0b655 | 2010-11-22 16:09:29 -0800 | [diff] [blame] | 1531 | if (mLedOnMs != 0 && mLedOffMs != 0) { |
| 1532 | n.flags |= FLAG_SHOW_LIGHTS; |
| 1533 | } |
| 1534 | if ((mDefaults & DEFAULT_LIGHTS) != 0) { |
| 1535 | n.flags |= FLAG_SHOW_LIGHTS; |
| 1536 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1537 | if (mKindList.size() > 0) { |
| 1538 | n.kind = new String[mKindList.size()]; |
| 1539 | mKindList.toArray(n.kind); |
| 1540 | } else { |
| 1541 | n.kind = null; |
| 1542 | } |
| 1543 | n.priority = mPriority; |
| 1544 | n.extras = mExtras != null ? new Bundle(mExtras) : null; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1545 | if (mActions.size() > 0) { |
| 1546 | n.actions = new Action[mActions.size()]; |
| 1547 | mActions.toArray(n.actions); |
| 1548 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1549 | return n; |
| 1550 | } |
| 1551 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame^] | 1552 | |
| 1553 | /** |
| 1554 | * @hide because this API is still very rough |
| 1555 | * |
| 1556 | * This is a "rebuilder": It consumes a Builder object and modifies its output. |
| 1557 | * |
| 1558 | * This represents the "big picture" style notification, with a large Bitmap atop the usual notification. |
| 1559 | * |
| 1560 | * Usage: |
| 1561 | * <pre class="prettyprint"> |
| 1562 | * Notification noti = new Notification.BigPictureStyle( |
| 1563 | * new Notification.Builder() |
| 1564 | * .setContentTitle("New mail from " + sender.toString()) |
| 1565 | * .setContentText(subject) |
| 1566 | * .setSmallIcon(R.drawable.new_mail) |
| 1567 | * .setLargeIcon(aBitmap)) |
| 1568 | * .bigPicture(aBigBitmap) |
| 1569 | * .build(); |
| 1570 | * </pre> |
| 1571 | */ |
| 1572 | public static class BigPictureStyle { |
| 1573 | private Builder mBuilder; |
| 1574 | private Bitmap mPicture; |
| 1575 | |
| 1576 | public BigPictureStyle(Builder builder) { |
| 1577 | mBuilder = builder; |
| 1578 | } |
| 1579 | |
| 1580 | public BigPictureStyle bigPicture(Bitmap b) { |
| 1581 | mPicture = b; |
| 1582 | return this; |
| 1583 | } |
| 1584 | |
| 1585 | private RemoteViews makeBigContentView() { |
| 1586 | RemoteViews contentView = mBuilder.applyStandardTemplate(R.layout.notification_template_big_picture); |
| 1587 | |
| 1588 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
| 1589 | |
| 1590 | return contentView; |
| 1591 | } |
| 1592 | |
| 1593 | public Notification build() { |
| 1594 | Notification wip = mBuilder.getNotification(); |
| 1595 | wip.bigContentView = makeBigContentView(); |
| 1596 | return wip; |
| 1597 | } |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * @hide because this API is still very rough |
| 1602 | * |
| 1603 | * This is a "rebuilder": It consumes a Builder object and modifies its output. |
| 1604 | * |
| 1605 | * This represents the "big text" style notification, with more area for the main content text to be read in its entirety. |
| 1606 | * |
| 1607 | * Usage: |
| 1608 | * <pre class="prettyprint"> |
| 1609 | * Notification noti = new Notification.BigPictureStyle( |
| 1610 | * new Notification.Builder() |
| 1611 | * .setContentTitle("New mail from " + sender.toString()) |
| 1612 | * .setContentText(subject) |
| 1613 | * .setSmallIcon(R.drawable.new_mail) |
| 1614 | * .setLargeIcon(aBitmap)) |
| 1615 | * .bigText(aVeryLongString) |
| 1616 | * .build(); |
| 1617 | * </pre> |
| 1618 | */ |
| 1619 | public static class BigTextStyle { |
| 1620 | private Builder mBuilder; |
| 1621 | private CharSequence mBigText; |
| 1622 | |
| 1623 | public BigTextStyle(Builder builder) { |
| 1624 | mBuilder = builder; |
| 1625 | } |
| 1626 | |
| 1627 | public BigTextStyle bigText(CharSequence cs) { |
| 1628 | mBigText = cs; |
| 1629 | return this; |
| 1630 | } |
| 1631 | |
| 1632 | private RemoteViews makeBigContentView() { |
| 1633 | RemoteViews contentView = mBuilder.applyStandardTemplate(R.layout.status_bar_latest_event_content); |
| 1634 | |
| 1635 | contentView.setTextViewText(R.id.big_text, mBigText); |
| 1636 | contentView.setViewVisibility(R.id.big_text, View.VISIBLE); |
| 1637 | contentView.setTextViewText(R.id.text, ""); // XXX: what do do with this spot? |
| 1638 | |
| 1639 | return contentView; |
| 1640 | } |
| 1641 | |
| 1642 | public Notification build() { |
| 1643 | Notification wip = mBuilder.getNotification(); |
| 1644 | wip.bigContentView = makeBigContentView(); |
| 1645 | return wip; |
| 1646 | } |
| 1647 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1648 | } |