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; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 24 | import android.media.AudioManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 25 | import android.net.Uri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 26 | import android.os.Bundle; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 27 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | import android.os.Parcel; |
| 29 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 30 | import android.os.SystemClock; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.text.TextUtils; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 32 | import android.util.IntProperty; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 33 | import android.util.Log; |
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 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 38 | import java.text.NumberFormat; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 39 | import java.util.ArrayList; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 40 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | /** |
| 42 | * A class that represents how a persistent notification is to be presented to |
| 43 | * the user using the {@link android.app.NotificationManager}. |
| 44 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 45 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 46 | * easier to construct Notifications.</p> |
| 47 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 48 | * <div class="special reference"> |
| 49 | * <h3>Developer Guides</h3> |
| 50 | * <p>For a guide to creating notifications, read the |
| 51 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 52 | * developer guide.</p> |
| 53 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | */ |
| 55 | public class Notification implements Parcelable |
| 56 | { |
| 57 | /** |
| 58 | * Use all default values (where applicable). |
| 59 | */ |
| 60 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 61 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 62 | /** |
| 63 | * Use the default notification sound. This will ignore any given |
| 64 | * {@link #sound}. |
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 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 68 | */ |
| 69 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 70 | public static final int DEFAULT_SOUND = 1; |
| 71 | |
| 72 | /** |
| 73 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 74 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 75 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 76 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 78 | */ |
| 79 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | public static final int DEFAULT_VIBRATE = 2; |
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 | /** |
| 83 | * Use the default notification lights. This will ignore the |
| 84 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 85 | * {@link #ledOnMS}. |
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 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 88 | */ |
| 89 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 90 | public static final int DEFAULT_LIGHTS = 4; |
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 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 93 | * A timestamp related to this notification, in milliseconds since the epoch. |
| 94 | * |
| 95 | * Default value: {@link System#currentTimeMillis() Now}. |
| 96 | * |
| 97 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 98 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 99 | * yet to occur but about which the user is being informed). Indefinite events should be |
| 100 | * timestamped according to when the activity began. |
| 101 | * |
| 102 | * Some examples: |
| 103 | * |
| 104 | * <ul> |
| 105 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 106 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 107 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 108 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 109 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 110 | * <li>Notification of an ongoing countdown timer should be stamped with the timer's end time. |
| 111 | * </ul> |
| 112 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 113 | */ |
| 114 | public long when; |
| 115 | |
| 116 | /** |
| 117 | * 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] | 118 | * 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] | 119 | */ |
| 120 | public int icon; |
| 121 | |
| 122 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 123 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 124 | * leave it at its default value of 0. |
| 125 | * |
| 126 | * @see android.widget.ImageView#setImageLevel |
| 127 | * @see android.graphics.drawable#setLevel |
| 128 | */ |
| 129 | public int iconLevel; |
| 130 | |
| 131 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 132 | * The number of events that this notification represents. For example, in a new mail |
| 133 | * notification, this could be the number of unread messages. |
| 134 | * |
| 135 | * The system may or may not use this field to modify the appearance of the notification. For |
| 136 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 137 | * superimposed over the icon in the status bar. Starting with |
| 138 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 139 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
| 140 | * |
| 141 | * 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] | 142 | */ |
| 143 | public int number; |
| 144 | |
| 145 | /** |
| 146 | * The intent to execute when the expanded status entry is clicked. If |
| 147 | * this is an activity, it must include the |
| 148 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 149 | * that you take care of task management as described in the |
| 150 | * <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] | 151 | * Stack</a> document. In particular, make sure to read the notification section |
| 152 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 153 | * Notifications</a> for the correct ways to launch an application from a |
| 154 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 155 | */ |
| 156 | public PendingIntent contentIntent; |
| 157 | |
| 158 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 159 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 160 | * the "Clear All" button or by swiping it away individually. |
| 161 | * |
| 162 | * This probably shouldn't be launching an activity since several of those will be sent |
| 163 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 164 | */ |
| 165 | public PendingIntent deleteIntent; |
| 166 | |
| 167 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 168 | * 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] | 169 | * |
| 170 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 171 | */ |
| 172 | public PendingIntent fullScreenIntent; |
| 173 | |
| 174 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 175 | * Text to scroll across the screen when this item is added to |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 176 | * the status bar on large and smaller devices. |
| 177 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 178 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | */ |
| 180 | public CharSequence tickerText; |
| 181 | |
| 182 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 183 | * The view to show as the ticker in the status bar when the notification |
| 184 | * is posted. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 185 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 186 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 187 | |
| 188 | /** |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 189 | * 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] | 190 | */ |
| 191 | public RemoteViews contentView; |
| 192 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 193 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 194 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 195 | * opportunity to show more detail. The system UI may choose to show this |
| 196 | * instead of the normal content view at its discretion. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 197 | */ |
| 198 | public RemoteViews bigContentView; |
| 199 | |
| 200 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 201 | * 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] | 202 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 203 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 204 | |
| 205 | /** |
| 206 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 207 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 208 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 209 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 210 | * </p> |
| 211 | */ |
| 212 | public Uri sound; |
| 213 | |
| 214 | /** |
| 215 | * Use this constant as the value for audioStreamType to request that |
| 216 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 217 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 218 | */ |
| 219 | public static final int STREAM_DEFAULT = -1; |
| 220 | |
| 221 | /** |
| 222 | * The audio stream type to use when playing the sound. |
| 223 | * Should be one of the STREAM_ constants from |
| 224 | * {@link android.media.AudioManager}. |
| 225 | */ |
| 226 | public int audioStreamType = STREAM_DEFAULT; |
| 227 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 229 | * The pattern with which to vibrate. |
| 230 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 231 | * <p> |
| 232 | * To vibrate the default pattern, see {@link #defaults}. |
| 233 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 234 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 235 | * @see android.os.Vibrator#vibrate(long[],int) |
| 236 | */ |
| 237 | public long[] vibrate; |
| 238 | |
| 239 | /** |
| 240 | * The color of the led. The hardware will do its best approximation. |
| 241 | * |
| 242 | * @see #FLAG_SHOW_LIGHTS |
| 243 | * @see #flags |
| 244 | */ |
| 245 | public int ledARGB; |
| 246 | |
| 247 | /** |
| 248 | * The number of milliseconds for the LED to be on while it's flashing. |
| 249 | * The hardware will do its best approximation. |
| 250 | * |
| 251 | * @see #FLAG_SHOW_LIGHTS |
| 252 | * @see #flags |
| 253 | */ |
| 254 | public int ledOnMS; |
| 255 | |
| 256 | /** |
| 257 | * The number of milliseconds for the LED to be off while it's flashing. |
| 258 | * The hardware will do its best approximation. |
| 259 | * |
| 260 | * @see #FLAG_SHOW_LIGHTS |
| 261 | * @see #flags |
| 262 | */ |
| 263 | public int ledOffMS; |
| 264 | |
| 265 | /** |
| 266 | * Specifies which values should be taken from the defaults. |
| 267 | * <p> |
| 268 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 269 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 270 | * values, use {@link #DEFAULT_ALL}. |
| 271 | * </p> |
| 272 | */ |
| 273 | public int defaults; |
| 274 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 275 | /** |
| 276 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 277 | * set if you want the LED on for this notification. |
| 278 | * <ul> |
| 279 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 280 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 281 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 282 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 283 | * be on and off to ledOnMS and ledOffMS.</li> |
| 284 | * </ul> |
| 285 | * <p> |
| 286 | * Since hardware varies, you are not guaranteed that any of the values |
| 287 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 288 | * because they will be set to values that work on any given hardware. |
| 289 | * <p> |
| 290 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 291 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 292 | */ |
| 293 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 294 | |
| 295 | /** |
| 296 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 297 | * set if this notification is in reference to something that is ongoing, |
| 298 | * like a phone call. It should not be set if this notification is in |
| 299 | * reference to something that happened at a particular point in time, |
| 300 | * like a missed phone call. |
| 301 | */ |
| 302 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 303 | |
| 304 | /** |
| 305 | * 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] | 306 | * the audio will be repeated until the notification is |
| 307 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 308 | */ |
| 309 | public static final int FLAG_INSISTENT = 0x00000004; |
| 310 | |
| 311 | /** |
| 312 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 313 | * set if you want the sound and/or vibration play each time the |
| 314 | * notification is sent, even if it has not been canceled before that. |
| 315 | */ |
| 316 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 317 | |
| 318 | /** |
| 319 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 320 | * 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] | 321 | * user. On tablets, the |
| 322 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 323 | */ |
| 324 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 325 | |
| 326 | /** |
| 327 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 328 | * set if the notification should not be canceled when the user clicks |
| 329 | * the Clear all button. |
| 330 | */ |
| 331 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 332 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 333 | /** |
| 334 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 335 | * set if this notification represents a currently running service. This |
| 336 | * will normally be set for you by {@link Service#startForeground}. |
| 337 | */ |
| 338 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 339 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 340 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 341 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
| 342 | * |
| 343 | * @deprecated Use {@link #priority} with a positive value. |
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 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | public int flags; |
| 348 | |
| 349 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 350 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 351 | * notifications, use this value for all notifications. |
| 352 | */ |
| 353 | public static final int PRIORITY_DEFAULT = 0; |
| 354 | |
| 355 | /** |
| 356 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 357 | * items smaller, or at a different position in the list, compared with your app's |
| 358 | * {@link #PRIORITY_DEFAULT} items. |
| 359 | */ |
| 360 | public static final int PRIORITY_LOW = -1; |
| 361 | |
| 362 | /** |
| 363 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 364 | * circumstances, such as detailed notification logs. |
| 365 | */ |
| 366 | public static final int PRIORITY_MIN = -2; |
| 367 | |
| 368 | /** |
| 369 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 370 | * show these items larger, or at a different position in notification lists, compared with |
| 371 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 372 | */ |
| 373 | public static final int PRIORITY_HIGH = 1; |
| 374 | |
| 375 | /** |
| 376 | * Highest {@link #priority}, for your application's most important items that require the |
| 377 | * user's prompt attention or input. |
| 378 | */ |
| 379 | public static final int PRIORITY_MAX = 2; |
| 380 | |
| 381 | /** |
| 382 | * Relative priority for this notification. |
| 383 | * |
| 384 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 385 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 386 | * situations, while the user might be interrupted for a higher-priority notification. The |
| 387 | * system will make a determination about how to interpret notification priority as described in |
| 388 | * MUMBLE MUMBLE. |
| 389 | */ |
| 390 | public int priority; |
| 391 | |
| 392 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 393 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 394 | * Notification type: incoming call (voice or video) or similar synchronous communication request. |
| 395 | */ |
| 396 | public static final String KIND_CALL = "android.call"; |
| 397 | |
| 398 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 399 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 400 | * Notification type: incoming direct message (SMS, instant message, etc.). |
| 401 | */ |
| 402 | public static final String KIND_MESSAGE = "android.message"; |
| 403 | |
| 404 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 405 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 406 | * Notification type: asynchronous bulk message (email). |
| 407 | */ |
| 408 | public static final String KIND_EMAIL = "android.email"; |
| 409 | |
| 410 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 411 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 422 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 423 | * If this notification matches of one or more special types (see the <code>KIND_*</code> |
| 424 | * constants), add them here, best match first. |
| 425 | */ |
| 426 | public String[] kind; |
| 427 | |
| 428 | /** |
| 429 | * Extra key for people values (type TBD). |
| 430 | * |
| 431 | * @hide |
| 432 | */ |
| 433 | public static final String EXTRA_PEOPLE = "android.people"; |
| 434 | |
| 435 | private Bundle extras; |
| 436 | |
| 437 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 438 | * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification. |
| 439 | * @hide |
| 440 | */ |
| 441 | private static class Action implements Parcelable { |
| 442 | public int icon; |
| 443 | public CharSequence title; |
| 444 | public PendingIntent actionIntent; |
| 445 | @SuppressWarnings("unused") |
| 446 | public Action() { } |
| 447 | private Action(Parcel in) { |
| 448 | icon = in.readInt(); |
| 449 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 450 | if (in.readInt() == 1) { |
| 451 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 452 | } |
| 453 | } |
| 454 | public Action(int icon_, CharSequence title_, PendingIntent intent_) { |
| 455 | this.icon = icon_; |
| 456 | this.title = title_; |
| 457 | this.actionIntent = intent_; |
| 458 | } |
| 459 | @Override |
| 460 | public Action clone() { |
| 461 | return new Action( |
| 462 | this.icon, |
| 463 | this.title.toString(), |
| 464 | this.actionIntent // safe to alias |
| 465 | ); |
| 466 | } |
| 467 | @Override |
| 468 | public int describeContents() { |
| 469 | return 0; |
| 470 | } |
| 471 | @Override |
| 472 | public void writeToParcel(Parcel out, int flags) { |
| 473 | out.writeInt(icon); |
| 474 | TextUtils.writeToParcel(title, out, flags); |
| 475 | if (actionIntent != null) { |
| 476 | out.writeInt(1); |
| 477 | actionIntent.writeToParcel(out, flags); |
| 478 | } else { |
| 479 | out.writeInt(0); |
| 480 | } |
| 481 | } |
| 482 | public static final Parcelable.Creator<Action> CREATOR |
| 483 | = new Parcelable.Creator<Action>() { |
| 484 | public Action createFromParcel(Parcel in) { |
| 485 | return new Action(in); |
| 486 | } |
| 487 | public Action[] newArray(int size) { |
| 488 | return new Action[size]; |
| 489 | } |
| 490 | }; |
| 491 | } |
| 492 | |
| 493 | private Action[] actions; |
| 494 | |
| 495 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 496 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 497 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 498 | */ |
| 499 | public Notification() |
| 500 | { |
| 501 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 502 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 506 | * @hide |
| 507 | */ |
| 508 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 509 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 510 | { |
| 511 | this.when = when; |
| 512 | this.icon = icon; |
| 513 | this.tickerText = tickerText; |
| 514 | setLatestEventInfo(context, contentTitle, contentText, |
| 515 | PendingIntent.getActivity(context, 0, contentIntent, 0)); |
| 516 | } |
| 517 | |
| 518 | /** |
| 519 | * Constructs a Notification object with the information needed to |
| 520 | * have a status bar icon without the standard expanded view. |
| 521 | * |
| 522 | * @param icon The resource id of the icon to put in the status bar. |
| 523 | * @param tickerText The text that flows by in the status bar when the notification first |
| 524 | * activates. |
| 525 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 526 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 527 | * |
| 528 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 529 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 530 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 531 | public Notification(int icon, CharSequence tickerText, long when) |
| 532 | { |
| 533 | this.icon = icon; |
| 534 | this.tickerText = tickerText; |
| 535 | this.when = when; |
| 536 | } |
| 537 | |
| 538 | /** |
| 539 | * Unflatten the notification from a parcel. |
| 540 | */ |
| 541 | public Notification(Parcel parcel) |
| 542 | { |
| 543 | int version = parcel.readInt(); |
| 544 | |
| 545 | when = parcel.readLong(); |
| 546 | icon = parcel.readInt(); |
| 547 | number = parcel.readInt(); |
| 548 | if (parcel.readInt() != 0) { |
| 549 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 550 | } |
| 551 | if (parcel.readInt() != 0) { |
| 552 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 553 | } |
| 554 | if (parcel.readInt() != 0) { |
| 555 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 556 | } |
| 557 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 558 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 559 | } |
| 560 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 561 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 562 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 563 | if (parcel.readInt() != 0) { |
| 564 | largeIcon = Bitmap.CREATOR.createFromParcel(parcel); |
| 565 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 566 | defaults = parcel.readInt(); |
| 567 | flags = parcel.readInt(); |
| 568 | if (parcel.readInt() != 0) { |
| 569 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 570 | } |
| 571 | |
| 572 | audioStreamType = parcel.readInt(); |
| 573 | vibrate = parcel.createLongArray(); |
| 574 | ledARGB = parcel.readInt(); |
| 575 | ledOnMS = parcel.readInt(); |
| 576 | ledOffMS = parcel.readInt(); |
| 577 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 578 | |
| 579 | if (parcel.readInt() != 0) { |
| 580 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 581 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 582 | |
| 583 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 584 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 585 | kind = parcel.createStringArray(); // may set kind to null |
| 586 | |
| 587 | if (parcel.readInt() != 0) { |
| 588 | extras = parcel.readBundle(); |
| 589 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 590 | |
| 591 | actions = parcel.createTypedArray(Action.CREATOR); |
| 592 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 593 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 594 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 597 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 598 | public Notification clone() { |
| 599 | Notification that = new Notification(); |
| 600 | |
| 601 | that.when = this.when; |
| 602 | that.icon = this.icon; |
| 603 | that.number = this.number; |
| 604 | |
| 605 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 606 | that.contentIntent = this.contentIntent; |
| 607 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 608 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 609 | |
| 610 | if (this.tickerText != null) { |
| 611 | that.tickerText = this.tickerText.toString(); |
| 612 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 613 | if (this.tickerView != null) { |
| 614 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 615 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 616 | if (this.contentView != null) { |
| 617 | that.contentView = this.contentView.clone(); |
| 618 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 619 | if (this.largeIcon != null) { |
| 620 | that.largeIcon = Bitmap.createBitmap(this.largeIcon); |
| 621 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 622 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 623 | that.sound = this.sound; // android.net.Uri is immutable |
| 624 | that.audioStreamType = this.audioStreamType; |
| 625 | |
| 626 | final long[] vibrate = this.vibrate; |
| 627 | if (vibrate != null) { |
| 628 | final int N = vibrate.length; |
| 629 | final long[] vib = that.vibrate = new long[N]; |
| 630 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 631 | } |
| 632 | |
| 633 | that.ledARGB = this.ledARGB; |
| 634 | that.ledOnMS = this.ledOnMS; |
| 635 | that.ledOffMS = this.ledOffMS; |
| 636 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 637 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 638 | that.flags = this.flags; |
| 639 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 640 | that.priority = this.priority; |
| 641 | |
| 642 | final String[] thiskind = this.kind; |
| 643 | if (thiskind != null) { |
| 644 | final int N = thiskind.length; |
| 645 | final String[] thatkind = that.kind = new String[N]; |
| 646 | System.arraycopy(thiskind, 0, thatkind, 0, N); |
| 647 | } |
| 648 | |
| 649 | if (this.extras != null) { |
| 650 | that.extras = new Bundle(this.extras); |
| 651 | |
| 652 | } |
| 653 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 654 | that.actions = new Action[this.actions.length]; |
| 655 | for(int i=0; i<this.actions.length; i++) { |
| 656 | that.actions[i] = this.actions[i].clone(); |
| 657 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 658 | if (this.bigContentView != null) { |
| 659 | that.bigContentView = this.bigContentView.clone(); |
| 660 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 661 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 662 | return that; |
| 663 | } |
| 664 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 665 | public int describeContents() { |
| 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | /** |
| 670 | * Flatten this notification from a parcel. |
| 671 | */ |
| 672 | public void writeToParcel(Parcel parcel, int flags) |
| 673 | { |
| 674 | parcel.writeInt(1); |
| 675 | |
| 676 | parcel.writeLong(when); |
| 677 | parcel.writeInt(icon); |
| 678 | parcel.writeInt(number); |
| 679 | if (contentIntent != null) { |
| 680 | parcel.writeInt(1); |
| 681 | contentIntent.writeToParcel(parcel, 0); |
| 682 | } else { |
| 683 | parcel.writeInt(0); |
| 684 | } |
| 685 | if (deleteIntent != null) { |
| 686 | parcel.writeInt(1); |
| 687 | deleteIntent.writeToParcel(parcel, 0); |
| 688 | } else { |
| 689 | parcel.writeInt(0); |
| 690 | } |
| 691 | if (tickerText != null) { |
| 692 | parcel.writeInt(1); |
| 693 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 694 | } else { |
| 695 | parcel.writeInt(0); |
| 696 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 697 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 698 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 699 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 700 | } else { |
| 701 | parcel.writeInt(0); |
| 702 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 703 | if (contentView != null) { |
| 704 | parcel.writeInt(1); |
| 705 | contentView.writeToParcel(parcel, 0); |
| 706 | } else { |
| 707 | parcel.writeInt(0); |
| 708 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 709 | if (largeIcon != null) { |
| 710 | parcel.writeInt(1); |
| 711 | largeIcon.writeToParcel(parcel, 0); |
| 712 | } else { |
| 713 | parcel.writeInt(0); |
| 714 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 715 | |
| 716 | parcel.writeInt(defaults); |
| 717 | parcel.writeInt(this.flags); |
| 718 | |
| 719 | if (sound != null) { |
| 720 | parcel.writeInt(1); |
| 721 | sound.writeToParcel(parcel, 0); |
| 722 | } else { |
| 723 | parcel.writeInt(0); |
| 724 | } |
| 725 | parcel.writeInt(audioStreamType); |
| 726 | parcel.writeLongArray(vibrate); |
| 727 | parcel.writeInt(ledARGB); |
| 728 | parcel.writeInt(ledOnMS); |
| 729 | parcel.writeInt(ledOffMS); |
| 730 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 731 | |
| 732 | if (fullScreenIntent != null) { |
| 733 | parcel.writeInt(1); |
| 734 | fullScreenIntent.writeToParcel(parcel, 0); |
| 735 | } else { |
| 736 | parcel.writeInt(0); |
| 737 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 738 | |
| 739 | parcel.writeInt(priority); |
| 740 | |
| 741 | parcel.writeStringArray(kind); // ok for null |
| 742 | |
| 743 | if (extras != null) { |
| 744 | parcel.writeInt(1); |
| 745 | extras.writeToParcel(parcel, 0); |
| 746 | } else { |
| 747 | parcel.writeInt(0); |
| 748 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 749 | |
| 750 | parcel.writeTypedArray(actions, 0); |
| 751 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 752 | if (bigContentView != null) { |
| 753 | parcel.writeInt(1); |
| 754 | bigContentView.writeToParcel(parcel, 0); |
| 755 | } else { |
| 756 | parcel.writeInt(0); |
| 757 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 758 | } |
| 759 | |
| 760 | /** |
| 761 | * Parcelable.Creator that instantiates Notification objects |
| 762 | */ |
| 763 | public static final Parcelable.Creator<Notification> CREATOR |
| 764 | = new Parcelable.Creator<Notification>() |
| 765 | { |
| 766 | public Notification createFromParcel(Parcel parcel) |
| 767 | { |
| 768 | return new Notification(parcel); |
| 769 | } |
| 770 | |
| 771 | public Notification[] newArray(int size) |
| 772 | { |
| 773 | return new Notification[size]; |
| 774 | } |
| 775 | }; |
| 776 | |
| 777 | /** |
| 778 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 779 | * layout. |
| 780 | * |
| 781 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 782 | * in the view.</p> |
| 783 | * @param context The context for your application / activity. |
| 784 | * @param contentTitle The title that goes in the expanded entry. |
| 785 | * @param contentText The text that goes in the expanded entry. |
| 786 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 787 | * If this is an activity, it must include the |
| 788 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 789 | * that you take care of task management as described in the |
| 790 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 791 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 792 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 793 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 794 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 795 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | public void setLatestEventInfo(Context context, |
| 797 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Daniel Sandler | cde8aae | 2012-04-04 23:40:22 -0400 | [diff] [blame] | 798 | // TODO: rewrite this to use Builder |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 799 | RemoteViews contentView = new RemoteViews(context.getPackageName(), |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 800 | R.layout.notification_template_base); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 801 | if (this.icon != 0) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 802 | contentView.setImageViewResource(R.id.icon, this.icon); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 803 | } |
Daniel Sandler | e95658c | 2012-05-10 00:33:54 -0400 | [diff] [blame] | 804 | if (priority < PRIORITY_LOW) { |
| 805 | contentView.setInt(R.id.icon, |
| 806 | "setBackgroundResource", R.drawable.notification_template_icon_low_bg); |
| 807 | contentView.setInt(R.id.status_bar_latest_event_content, |
| 808 | "setBackgroundResource", R.drawable.notification_bg_low); |
| 809 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 810 | if (contentTitle != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 811 | contentView.setTextViewText(R.id.title, contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 812 | } |
| 813 | if (contentText != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 814 | contentView.setTextViewText(R.id.text, contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 815 | } |
| 816 | if (this.when != 0) { |
Daniel Sandler | cde8aae | 2012-04-04 23:40:22 -0400 | [diff] [blame] | 817 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 818 | contentView.setLong(R.id.time, "setTime", when); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 819 | } |
Daniel Sandler | b4b2223 | 2012-04-30 10:38:31 -0400 | [diff] [blame] | 820 | if (this.number != 0) { |
| 821 | NumberFormat f = NumberFormat.getIntegerInstance(); |
| 822 | contentView.setTextViewText(R.id.info, f.format(this.number)); |
| 823 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 906 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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 | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 942 | private boolean mUseChronometer; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 943 | private Style mStyle; |
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 | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 985 | * Show the {@link Notification#when} field as a stopwatch. |
| 986 | * |
| 987 | * Instead of presenting <code>when</code> as a timestamp, the notification will show an |
| 988 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 989 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 990 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 991 | * |
| 992 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 993 | * @see Notification#when |
| 994 | */ |
| 995 | public Builder setUsesChronometer(boolean b) { |
| 996 | mUseChronometer = b; |
| 997 | return this; |
| 998 | } |
| 999 | |
| 1000 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1001 | * Set the small icon resource, which will be used to represent the notification in the |
| 1002 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1003 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1004 | |
| 1005 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 1006 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 1007 | * icon will be moved to the right-hand side. |
| 1008 | * |
| 1009 | |
| 1010 | * @param icon |
| 1011 | * A resource ID in the application's package of the drawable to use. |
| 1012 | * @see Notification#icon |
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) { |
| 1015 | mSmallIcon = icon; |
| 1016 | return this; |
| 1017 | } |
| 1018 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1019 | /** |
| 1020 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 1021 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 1022 | * LevelListDrawable}. |
| 1023 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1024 | * @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] | 1025 | * @param level The level to use for the icon. |
| 1026 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1027 | * @see Notification#icon |
| 1028 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1029 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1030 | public Builder setSmallIcon(int icon, int level) { |
| 1031 | mSmallIcon = icon; |
| 1032 | mSmallIconLevel = level; |
| 1033 | return this; |
| 1034 | } |
| 1035 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1036 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1037 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1038 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1039 | public Builder setContentTitle(CharSequence title) { |
| 1040 | mContentTitle = title; |
| 1041 | return this; |
| 1042 | } |
| 1043 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1044 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1045 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1046 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1047 | public Builder setContentText(CharSequence text) { |
| 1048 | mContentText = text; |
| 1049 | return this; |
| 1050 | } |
| 1051 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1052 | /** |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1053 | * Set the third line of text in the platform notification template. |
| 1054 | * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the same location in the standard template. |
| 1055 | */ |
| 1056 | public Builder setSubText(CharSequence text) { |
| 1057 | mSubText = text; |
| 1058 | return this; |
| 1059 | } |
| 1060 | |
| 1061 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1062 | * Set the large number at the right-hand side of the notification. This is |
| 1063 | * equivalent to setContentInfo, although it might show the number in a different |
| 1064 | * font size for readability. |
| 1065 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1066 | public Builder setNumber(int number) { |
| 1067 | mNumber = number; |
| 1068 | return this; |
| 1069 | } |
| 1070 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1071 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1072 | * A small piece of additional information pertaining to this notification. |
| 1073 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1074 | * The platform template will draw this on the last line of the notification, at the far |
| 1075 | * 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] | 1076 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1077 | public Builder setContentInfo(CharSequence info) { |
| 1078 | mContentInfo = info; |
| 1079 | return this; |
| 1080 | } |
| 1081 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1082 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1083 | * Set the progress this notification represents. |
| 1084 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1085 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1086 | */ |
| 1087 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 1088 | mProgressMax = max; |
| 1089 | mProgress = progress; |
| 1090 | mProgressIndeterminate = indeterminate; |
| 1091 | return this; |
| 1092 | } |
| 1093 | |
| 1094 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1095 | * Supply a custom RemoteViews to use instead of the platform template. |
| 1096 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1097 | * @see Notification#contentView |
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 setContent(RemoteViews views) { |
| 1100 | mContentView = views; |
| 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 be sent when the notification is clicked. |
| 1106 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1107 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 1108 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 1109 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1110 | * 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] | 1111 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1112 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1113 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1114 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1115 | public Builder setContentIntent(PendingIntent intent) { |
| 1116 | mContentIntent = intent; |
| 1117 | return this; |
| 1118 | } |
| 1119 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1120 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1121 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 1122 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1123 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1124 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1125 | public Builder setDeleteIntent(PendingIntent intent) { |
| 1126 | mDeleteIntent = intent; |
| 1127 | return this; |
| 1128 | } |
| 1129 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1130 | /** |
| 1131 | * An intent to launch instead of posting the notification to the status bar. |
| 1132 | * Only for use with extremely high-priority notifications demanding the user's |
| 1133 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 1134 | * alarm clock that the user has explicitly set to a particular time. |
| 1135 | * If this facility is used for something else, please give the user an option |
| 1136 | * to turn it off and use a normal notification, as this can be extremely |
| 1137 | * disruptive. |
| 1138 | * |
| 1139 | * @param intent The pending intent to launch. |
| 1140 | * @param highPriority Passing true will cause this notification to be sent |
| 1141 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1142 | * |
| 1143 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1144 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1145 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 1146 | mFullScreenIntent = intent; |
| 1147 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 1148 | return this; |
| 1149 | } |
| 1150 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1151 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1152 | * 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] | 1153 | * arrives. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1154 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1155 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1156 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1157 | public Builder setTicker(CharSequence tickerText) { |
| 1158 | mTickerText = tickerText; |
| 1159 | return this; |
| 1160 | } |
| 1161 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1162 | /** |
| 1163 | * Set the text that is displayed in the status bar when the notification first |
| 1164 | * arrives, and also a RemoteViews object that may be displayed instead on some |
| 1165 | * devices. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1166 | * |
| 1167 | * @see Notification#tickerText |
| 1168 | * @see Notification#tickerView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1169 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1170 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
| 1171 | mTickerText = tickerText; |
| 1172 | mTickerView = views; |
| 1173 | return this; |
| 1174 | } |
| 1175 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1176 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1177 | * Add a large icon to the notification (and the ticker on some devices). |
| 1178 | * |
| 1179 | * In the platform template, this image will be shown on the left of the notification view |
| 1180 | * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side). |
| 1181 | * |
| 1182 | * @see Notification#largeIcon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1183 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1184 | public Builder setLargeIcon(Bitmap icon) { |
| 1185 | mLargeIcon = icon; |
| 1186 | return this; |
| 1187 | } |
| 1188 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1189 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1190 | * Set the sound to play. |
| 1191 | * |
| 1192 | * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications. |
| 1193 | * |
| 1194 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1195 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 1196 | public Builder setSound(Uri sound) { |
| 1197 | mSound = sound; |
| 1198 | mAudioStreamType = STREAM_DEFAULT; |
| 1199 | return this; |
| 1200 | } |
| 1201 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1202 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1203 | * 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] | 1204 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1205 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 1206 | * |
| 1207 | * @see Notification#sound |
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 setSound(Uri sound, int streamType) { |
| 1210 | mSound = sound; |
| 1211 | mAudioStreamType = streamType; |
| 1212 | return this; |
| 1213 | } |
| 1214 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1215 | /** |
| 1216 | * Set the vibration pattern to use. |
| 1217 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1218 | |
| 1219 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 1220 | * <code>pattern</code> parameter. |
| 1221 | * |
| 1222 | |
| 1223 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1224 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1225 | public Builder setVibrate(long[] pattern) { |
| 1226 | mVibrate = pattern; |
| 1227 | return this; |
| 1228 | } |
| 1229 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1230 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1231 | * Set the desired color for the indicator LED on the device, as well as the |
| 1232 | * blink duty cycle (specified in milliseconds). |
| 1233 | * |
| 1234 | |
| 1235 | * Not all devices will honor all (or even any) of these values. |
| 1236 | * |
| 1237 | |
| 1238 | * @see Notification#ledARGB |
| 1239 | * @see Notification#ledOnMS |
| 1240 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1241 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1242 | public Builder setLights(int argb, int onMs, int offMs) { |
| 1243 | mLedArgb = argb; |
| 1244 | mLedOnMs = onMs; |
| 1245 | mLedOffMs = offMs; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1246 | return this; |
| 1247 | } |
| 1248 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1249 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1250 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1251 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1252 | |
| 1253 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 1254 | * must take care of canceling them. |
| 1255 | * |
| 1256 | |
| 1257 | * They are typically used to indicate a background task that the user is actively engaged |
| 1258 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 1259 | * (e.g., a file download, sync operation, active network connection). |
| 1260 | * |
| 1261 | |
| 1262 | * @see Notification#FLAG_ONGOING_EVENT |
| 1263 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1264 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1265 | public Builder setOngoing(boolean ongoing) { |
| 1266 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 1267 | return this; |
| 1268 | } |
| 1269 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1270 | /** |
| 1271 | * Set this flag if you would only like the sound, vibrate |
| 1272 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1273 | * |
| 1274 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1275 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1276 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 1277 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 1278 | return this; |
| 1279 | } |
| 1280 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1281 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1282 | * Make this notification automatically dismissed when the user touches it. The |
| 1283 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 1284 | * |
| 1285 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1286 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1287 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 1288 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1289 | return this; |
| 1290 | } |
| 1291 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1292 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1293 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1294 | * <p> |
| 1295 | * The value should be one or more of the following fields combined with |
| 1296 | * bitwise-or: |
| 1297 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 1298 | * <p> |
| 1299 | * For all default values, use {@link #DEFAULT_ALL}. |
| 1300 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1301 | public Builder setDefaults(int defaults) { |
| 1302 | mDefaults = defaults; |
| 1303 | return this; |
| 1304 | } |
| 1305 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1306 | /** |
| 1307 | * Set the priority of this notification. |
| 1308 | * |
| 1309 | * @see Notification#priority |
| 1310 | */ |
| 1311 | public Builder setPriority(int pri) { |
| 1312 | mPriority = pri; |
| 1313 | return this; |
| 1314 | } |
| 1315 | |
| 1316 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame^] | 1317 | * @hide |
| 1318 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1319 | * Add a kind (category) to this notification. Optional. |
| 1320 | * |
| 1321 | * @see Notification#kind |
| 1322 | */ |
| 1323 | public Builder addKind(String k) { |
| 1324 | mKindList.add(k); |
| 1325 | return this; |
| 1326 | } |
| 1327 | |
| 1328 | /** |
| 1329 | * Add metadata to this notification. |
| 1330 | * |
| 1331 | * 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] | 1332 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1333 | * called. |
| 1334 | * |
| 1335 | * @see Notification#extras |
| 1336 | * @hide |
| 1337 | */ |
| 1338 | public Builder setExtras(Bundle bag) { |
| 1339 | mExtras = bag; |
| 1340 | return this; |
| 1341 | } |
| 1342 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1343 | /** |
| 1344 | * Add an action to this notification. Actions are typically displayed by |
| 1345 | * the system as a button adjacent to the notification content. |
| 1346 | * |
| 1347 | * @param icon Resource ID of a drawable that represents the action. |
| 1348 | * @param title Text describing the action. |
| 1349 | * @param intent PendingIntent to be fired when the action is invoked. |
| 1350 | */ |
| 1351 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
| 1352 | mActions.add(new Action(icon, title, intent)); |
| 1353 | return this; |
| 1354 | } |
| 1355 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1356 | /** |
| 1357 | * Add a rich notification style to be applied at build time. |
| 1358 | * |
| 1359 | * @param style Object responsible for modifying the notification style. |
| 1360 | */ |
| 1361 | public Builder setStyle(Style style) { |
| 1362 | if (mStyle != style) { |
| 1363 | mStyle = style; |
| 1364 | mStyle.setBuilder(this); |
| 1365 | } |
| 1366 | return this; |
| 1367 | } |
| 1368 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1369 | private void setFlag(int mask, boolean value) { |
| 1370 | if (value) { |
| 1371 | mFlags |= mask; |
| 1372 | } else { |
| 1373 | mFlags &= ~mask; |
| 1374 | } |
| 1375 | } |
| 1376 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1377 | private RemoteViews applyStandardTemplate(int resId) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1378 | RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1379 | boolean hasLine3 = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1380 | boolean hasLine2 = false; |
| 1381 | int smallIconImageViewId = R.id.icon; |
| 1382 | if (mLargeIcon != null) { |
| 1383 | contentView.setImageViewBitmap(R.id.icon, mLargeIcon); |
| 1384 | smallIconImageViewId = R.id.right_icon; |
| 1385 | } |
Daniel Sandler | e95658c | 2012-05-10 00:33:54 -0400 | [diff] [blame] | 1386 | if (mPriority < PRIORITY_LOW) { |
| 1387 | contentView.setInt(R.id.icon, |
| 1388 | "setBackgroundResource", R.drawable.notification_template_icon_low_bg); |
| 1389 | contentView.setInt(R.id.status_bar_latest_event_content, |
| 1390 | "setBackgroundResource", R.drawable.notification_bg_low); |
| 1391 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1392 | if (mSmallIcon != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1393 | contentView.setImageViewResource(smallIconImageViewId, mSmallIcon); |
| 1394 | contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1395 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1396 | contentView.setViewVisibility(smallIconImageViewId, View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1397 | } |
| 1398 | if (mContentTitle != null) { |
| 1399 | contentView.setTextViewText(R.id.title, mContentTitle); |
| 1400 | } |
| 1401 | if (mContentText != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1402 | contentView.setTextViewText( |
| 1403 | (mSubText != null) ? R.id.text2 : R.id.text, |
| 1404 | mContentText); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1405 | hasLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1406 | } |
| 1407 | if (mContentInfo != null) { |
| 1408 | contentView.setTextViewText(R.id.info, mContentInfo); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1409 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
| 1410 | hasLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1411 | } else if (mNumber > 0) { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 1412 | final int tooBig = mContext.getResources().getInteger( |
| 1413 | R.integer.status_bar_notification_info_maxnum); |
| 1414 | if (mNumber > tooBig) { |
| 1415 | contentView.setTextViewText(R.id.info, mContext.getResources().getString( |
| 1416 | R.string.status_bar_notification_info_overflow)); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 1417 | } else { |
| 1418 | NumberFormat f = NumberFormat.getIntegerInstance(); |
| 1419 | contentView.setTextViewText(R.id.info, f.format(mNumber)); |
| 1420 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1421 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
| 1422 | hasLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1423 | } else { |
| 1424 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 1425 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1426 | |
| 1427 | if (mSubText != null) { |
| 1428 | contentView.setTextViewText(R.id.text, mSubText); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1429 | contentView.setViewVisibility(R.id.text2, |
| 1430 | mContentText != null ? View.VISIBLE : View.GONE); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1431 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1432 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 1433 | if (mProgressMax != 0 || mProgressIndeterminate) { |
| 1434 | contentView.setProgressBar( |
| 1435 | R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); |
| 1436 | contentView.setViewVisibility(R.id.progress, View.VISIBLE); |
| 1437 | } else { |
| 1438 | contentView.setViewVisibility(R.id.progress, View.GONE); |
| 1439 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1440 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1441 | if (mWhen != 0) { |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1442 | if (mUseChronometer) { |
| 1443 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 1444 | contentView.setLong(R.id.chronometer, "setBase", |
| 1445 | mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 1446 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 1447 | } else { |
| 1448 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 1449 | contentView.setLong(R.id.time, "setTime", mWhen); |
| 1450 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1451 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1452 | contentView.setViewVisibility(R.id.line3, hasLine3 ? View.VISIBLE : View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1453 | return contentView; |
| 1454 | } |
| 1455 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1456 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
| 1457 | RemoteViews big = applyStandardTemplate(layoutId); |
| 1458 | |
| 1459 | int N = mActions.size(); |
| 1460 | if (N > 0) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1461 | // Log.d("Notification", "has actions: " + mContentText); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1462 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
| 1463 | if (N>3) N=3; |
Chris Wren | 2c22eb0 | 2012-05-08 09:49:13 -0400 | [diff] [blame] | 1464 | big.removeAllViews(R.id.actions); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1465 | for (int i=0; i<N; i++) { |
| 1466 | final RemoteViews button = generateActionButton(mActions.get(i)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1467 | //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1468 | big.addView(R.id.actions, button); |
| 1469 | } |
| 1470 | } |
| 1471 | return big; |
| 1472 | } |
| 1473 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1474 | private RemoteViews makeContentView() { |
| 1475 | if (mContentView != null) { |
| 1476 | return mContentView; |
| 1477 | } else { |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1478 | return applyStandardTemplate(R.layout.notification_template_base); // no more special large_icon flavor |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1479 | } |
| 1480 | } |
| 1481 | |
| 1482 | private RemoteViews makeTickerView() { |
| 1483 | if (mTickerView != null) { |
| 1484 | return mTickerView; |
| 1485 | } else { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1486 | if (mContentView == null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1487 | return applyStandardTemplate(mLargeIcon == null |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1488 | ? R.layout.status_bar_latest_event_ticker |
| 1489 | : R.layout.status_bar_latest_event_ticker_large_icon); |
| 1490 | } else { |
| 1491 | return null; |
| 1492 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1493 | } |
| 1494 | } |
| 1495 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1496 | private RemoteViews makeBigContentView() { |
| 1497 | if (mActions.size() == 0) return null; |
| 1498 | |
Chris Wren | b023bf8 | 2012-04-23 16:05:42 -0400 | [diff] [blame] | 1499 | return applyStandardTemplateWithActions(R.layout.notification_template_big_base); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1500 | } |
| 1501 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1502 | private RemoteViews generateActionButton(Action action) { |
| 1503 | RemoteViews button = new RemoteViews(mContext.getPackageName(), R.layout.notification_action); |
| 1504 | button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0); |
| 1505 | button.setTextViewText(R.id.action0, action.title); |
| 1506 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 1507 | button.setContentDescription(R.id.action0, action.title); |
| 1508 | return button; |
| 1509 | } |
| 1510 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1511 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1512 | * Apply the unstyled operations and return a new {@link Notification} object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1513 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1514 | private Notification buildUnstyled() { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1515 | Notification n = new Notification(); |
| 1516 | n.when = mWhen; |
| 1517 | n.icon = mSmallIcon; |
| 1518 | n.iconLevel = mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1519 | n.number = mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1520 | n.contentView = makeContentView(); |
| 1521 | n.contentIntent = mContentIntent; |
| 1522 | n.deleteIntent = mDeleteIntent; |
| 1523 | n.fullScreenIntent = mFullScreenIntent; |
| 1524 | n.tickerText = mTickerText; |
| 1525 | n.tickerView = makeTickerView(); |
| 1526 | n.largeIcon = mLargeIcon; |
| 1527 | n.sound = mSound; |
| 1528 | n.audioStreamType = mAudioStreamType; |
| 1529 | n.vibrate = mVibrate; |
| 1530 | n.ledARGB = mLedArgb; |
| 1531 | n.ledOnMS = mLedOnMs; |
| 1532 | n.ledOffMS = mLedOffMs; |
| 1533 | n.defaults = mDefaults; |
| 1534 | n.flags = mFlags; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1535 | n.bigContentView = makeBigContentView(); |
Joe Onorato | 8d0b655 | 2010-11-22 16:09:29 -0800 | [diff] [blame] | 1536 | if (mLedOnMs != 0 && mLedOffMs != 0) { |
| 1537 | n.flags |= FLAG_SHOW_LIGHTS; |
| 1538 | } |
| 1539 | if ((mDefaults & DEFAULT_LIGHTS) != 0) { |
| 1540 | n.flags |= FLAG_SHOW_LIGHTS; |
| 1541 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1542 | if (mKindList.size() > 0) { |
| 1543 | n.kind = new String[mKindList.size()]; |
| 1544 | mKindList.toArray(n.kind); |
| 1545 | } else { |
| 1546 | n.kind = null; |
| 1547 | } |
| 1548 | n.priority = mPriority; |
| 1549 | n.extras = mExtras != null ? new Bundle(mExtras) : null; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1550 | if (mActions.size() > 0) { |
| 1551 | n.actions = new Action[mActions.size()]; |
| 1552 | mActions.toArray(n.actions); |
| 1553 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1554 | return n; |
| 1555 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1556 | |
| 1557 | /** |
| 1558 | * @deprecated Use {@link #build()} instead. |
| 1559 | */ |
| 1560 | @Deprecated |
| 1561 | public Notification getNotification() { |
| 1562 | return build(); |
| 1563 | } |
| 1564 | |
| 1565 | /** |
| 1566 | * Combine all of the options that have been set and return a new {@link Notification} |
| 1567 | * object. |
| 1568 | */ |
| 1569 | public Notification build() { |
| 1570 | if (mStyle != null) { |
| 1571 | return mStyle.build(); |
| 1572 | } else { |
| 1573 | return buildUnstyled(); |
| 1574 | } |
| 1575 | } |
| 1576 | } |
| 1577 | |
| 1578 | |
| 1579 | /** |
| 1580 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 1581 | * object. |
| 1582 | */ |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1583 | public static abstract class Style |
| 1584 | { |
| 1585 | private CharSequence mBigContentTitle; |
| 1586 | private CharSequence mSummaryText = null; |
| 1587 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1588 | protected Builder mBuilder; |
| 1589 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1590 | /** |
| 1591 | * Overrides ContentTitle in the big form of the template. |
| 1592 | * This defaults to the value passed to setContentTitle(). |
| 1593 | */ |
| 1594 | protected void internalSetBigContentTitle(CharSequence title) { |
| 1595 | mBigContentTitle = title; |
| 1596 | } |
| 1597 | |
| 1598 | /** |
| 1599 | * Set the first line of text after the detail section in the big form of the template. |
| 1600 | */ |
| 1601 | protected void internalSetSummaryText(CharSequence cs) { |
| 1602 | mSummaryText = cs; |
| 1603 | } |
| 1604 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1605 | public void setBuilder(Builder builder) { |
| 1606 | if (mBuilder != builder) { |
| 1607 | mBuilder = builder; |
| 1608 | mBuilder.setStyle(this); |
| 1609 | } |
| 1610 | } |
| 1611 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1612 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1613 | if (mBuilder == null) { |
| 1614 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 1615 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1616 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1617 | |
| 1618 | protected RemoteViews getStandardView(int layoutId) { |
| 1619 | checkBuilder(); |
| 1620 | |
| 1621 | if (mBigContentTitle != null) { |
| 1622 | mBuilder.setContentTitle(mBigContentTitle); |
| 1623 | } |
| 1624 | |
| 1625 | if (mBuilder.mSubText == null) { |
| 1626 | mBuilder.setContentText(null); |
| 1627 | } |
| 1628 | |
| 1629 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 1630 | |
| 1631 | if (mBuilder.mSubText == null) { |
| 1632 | contentView.setViewVisibility(R.id.line3, View.GONE); |
| 1633 | } |
| 1634 | |
| 1635 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 1636 | contentView.setViewVisibility(R.id.line1, View.GONE); |
| 1637 | } |
| 1638 | |
| 1639 | if (mSummaryText != null && !mSummaryText.equals("")) { |
| 1640 | contentView.setViewVisibility(R.id.overflow_title, View.VISIBLE); |
| 1641 | contentView.setTextViewText(R.id.overflow_title, mSummaryText); |
| 1642 | } |
| 1643 | |
| 1644 | return contentView; |
| 1645 | } |
| 1646 | |
| 1647 | public abstract Notification build(); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1648 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1649 | |
| 1650 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1651 | * Helper class for generating large-format notifications that include a large image attachment. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1652 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1653 | * 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] | 1654 | * <pre class="prettyprint"> |
| 1655 | * Notification noti = new Notification.BigPictureStyle( |
| 1656 | * new Notification.Builder() |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1657 | * .setContentTitle("New photo from " + sender.toString()) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1658 | * .setContentText(subject) |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1659 | * .setSmallIcon(R.drawable.new_post) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1660 | * .setLargeIcon(aBitmap)) |
| 1661 | * .bigPicture(aBigBitmap) |
| 1662 | * .build(); |
| 1663 | * </pre> |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1664 | * |
| 1665 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1666 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1667 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1668 | private Bitmap mPicture; |
| 1669 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1670 | public BigPictureStyle() { |
| 1671 | } |
| 1672 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1673 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1674 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1675 | } |
| 1676 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1677 | /** |
| 1678 | * Overrides ContentTitle in the big form of the template. |
| 1679 | * This defaults to the value passed to setContentTitle(). |
| 1680 | */ |
| 1681 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
| 1682 | internalSetBigContentTitle(title); |
| 1683 | return this; |
| 1684 | } |
| 1685 | |
| 1686 | /** |
| 1687 | * Set the first line of text after the detail section in the big form of the template. |
| 1688 | */ |
| 1689 | public BigPictureStyle setSummaryText(CharSequence cs) { |
| 1690 | internalSetSummaryText(cs); |
| 1691 | return this; |
| 1692 | } |
| 1693 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1694 | public BigPictureStyle bigPicture(Bitmap b) { |
| 1695 | mPicture = b; |
| 1696 | return this; |
| 1697 | } |
| 1698 | |
| 1699 | private RemoteViews makeBigContentView() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1700 | RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1701 | |
| 1702 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
| 1703 | |
| 1704 | return contentView; |
| 1705 | } |
| 1706 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1707 | @Override |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1708 | public Notification build() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1709 | checkBuilder(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1710 | Notification wip = mBuilder.buildUnstyled(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1711 | wip.bigContentView = makeBigContentView(); |
| 1712 | return wip; |
| 1713 | } |
| 1714 | } |
| 1715 | |
| 1716 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1717 | * Helper class for generating large-format notifications that include a lot of text. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1718 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1719 | * 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] | 1720 | * <pre class="prettyprint"> |
| 1721 | * Notification noti = new Notification.BigPictureStyle( |
| 1722 | * new Notification.Builder() |
| 1723 | * .setContentTitle("New mail from " + sender.toString()) |
| 1724 | * .setContentText(subject) |
| 1725 | * .setSmallIcon(R.drawable.new_mail) |
| 1726 | * .setLargeIcon(aBitmap)) |
| 1727 | * .bigText(aVeryLongString) |
| 1728 | * .build(); |
| 1729 | * </pre> |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1730 | * |
| 1731 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1732 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1733 | public static class BigTextStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1734 | private CharSequence mBigText; |
| 1735 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1736 | public BigTextStyle() { |
| 1737 | } |
| 1738 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1739 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1740 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1741 | } |
| 1742 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1743 | /** |
| 1744 | * Overrides ContentTitle in the big form of the template. |
| 1745 | * This defaults to the value passed to setContentTitle(). |
| 1746 | */ |
| 1747 | public BigTextStyle setBigContentTitle(CharSequence title) { |
| 1748 | internalSetBigContentTitle(title); |
| 1749 | return this; |
| 1750 | } |
| 1751 | |
| 1752 | /** |
| 1753 | * Set the first line of text after the detail section in the big form of the template. |
| 1754 | */ |
| 1755 | public BigTextStyle setSummaryText(CharSequence cs) { |
| 1756 | internalSetSummaryText(cs); |
| 1757 | return this; |
| 1758 | } |
| 1759 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1760 | public BigTextStyle bigText(CharSequence cs) { |
| 1761 | mBigText = cs; |
| 1762 | return this; |
| 1763 | } |
| 1764 | |
| 1765 | private RemoteViews makeBigContentView() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1766 | RemoteViews contentView = getStandardView(R.layout.notification_template_big_text); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1767 | contentView.setTextViewText(R.id.big_text, mBigText); |
| 1768 | contentView.setViewVisibility(R.id.big_text, View.VISIBLE); |
Chris Wren | 3c5f9243 | 2012-05-04 16:31:17 -0400 | [diff] [blame] | 1769 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1770 | |
| 1771 | return contentView; |
| 1772 | } |
| 1773 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1774 | @Override |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1775 | public Notification build() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1776 | checkBuilder(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1777 | Notification wip = mBuilder.buildUnstyled(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1778 | wip.bigContentView = makeBigContentView(); |
| 1779 | return wip; |
| 1780 | } |
| 1781 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1782 | |
| 1783 | /** |
| 1784 | * Helper class for generating large-format notifications that include a list of (up to 5) strings. |
| 1785 | * |
| 1786 | * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so: |
| 1787 | * <pre class="prettyprint"> |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1788 | * Notification noti = new Notification.InboxStyle( |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1789 | * new Notification.Builder() |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1790 | * .setContentTitle("5 New mails from " + sender.toString()) |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1791 | * .setContentText(subject) |
| 1792 | * .setSmallIcon(R.drawable.new_mail) |
| 1793 | * .setLargeIcon(aBitmap)) |
| 1794 | * .addLine(str1) |
| 1795 | * .addLine(str2) |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1796 | * .setContentTitle("") |
| 1797 | * .setSummaryText("+3 more") |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1798 | * .build(); |
| 1799 | * </pre> |
| 1800 | * |
| 1801 | * @see Notification#bigContentView |
| 1802 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1803 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1804 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 1805 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1806 | public InboxStyle() { |
| 1807 | } |
| 1808 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1809 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1810 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1811 | } |
| 1812 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1813 | /** |
| 1814 | * Overrides ContentTitle in the big form of the template. |
| 1815 | * This defaults to the value passed to setContentTitle(). |
| 1816 | */ |
| 1817 | public InboxStyle setBigContentTitle(CharSequence title) { |
| 1818 | internalSetBigContentTitle(title); |
| 1819 | return this; |
| 1820 | } |
| 1821 | |
| 1822 | /** |
| 1823 | * Set the first line of text after the detail section in the big form of the template. |
| 1824 | */ |
| 1825 | public InboxStyle setSummaryText(CharSequence cs) { |
| 1826 | internalSetSummaryText(cs); |
| 1827 | return this; |
| 1828 | } |
| 1829 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1830 | public InboxStyle addLine(CharSequence cs) { |
| 1831 | mTexts.add(cs); |
| 1832 | return this; |
| 1833 | } |
| 1834 | |
| 1835 | private RemoteViews makeBigContentView() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1836 | RemoteViews contentView = getStandardView(R.layout.notification_template_inbox); |
| 1837 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1838 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1839 | int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, |
| 1840 | R.id.inbox_text4}; |
| 1841 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1842 | int i=0; |
| 1843 | while (i < mTexts.size() && i < rowIds.length) { |
| 1844 | CharSequence str = mTexts.get(i); |
| 1845 | if (str != null && !str.equals("")) { |
| 1846 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
| 1847 | contentView.setTextViewText(rowIds[i], str); |
| 1848 | } |
| 1849 | i++; |
| 1850 | } |
| 1851 | |
| 1852 | return contentView; |
| 1853 | } |
| 1854 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1855 | @Override |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1856 | public Notification build() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1857 | checkBuilder(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1858 | Notification wip = mBuilder.buildUnstyled(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1859 | wip.bigContentView = makeBigContentView(); |
| 1860 | return wip; |
| 1861 | } |
| 1862 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1863 | } |