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; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 23 | import android.content.res.Resources; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 24 | import android.graphics.Bitmap; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 25 | import android.media.AudioManager; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 26 | import android.net.Uri; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 27 | import android.os.Bundle; |
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; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 31 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 32 | import android.text.TextUtils; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 33 | import android.util.TypedValue; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 34 | import android.view.View; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 35 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 36 | import android.widget.RemoteViews; |
| 37 | |
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. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 94 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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 |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 100 | * timestamped according to when the activity began. |
| 101 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 102 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 103 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 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. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 134 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 140 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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 | 8aa9ae6 | 2012-12-04 23:31:47 -0500 | [diff] [blame] | 321 | * user. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 342 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 383 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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 |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 387 | * system will make a determination about how to interpret this priority when presenting |
| 388 | * the notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 389 | */ |
| 390 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 391 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 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 | /** |
Daniel Sandler | a90513d | 2012-06-04 02:11:17 -0400 | [diff] [blame] | 417 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 418 | * Notification type: promotion or advertisement. |
| 419 | */ |
| 420 | public static final String KIND_PROMO = "android.promo"; |
| 421 | |
| 422 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 423 | * @hide |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 424 | * If this notification matches of one or more special types (see the <code>KIND_*</code> |
| 425 | * constants), add them here, best match first. |
| 426 | */ |
| 427 | public String[] kind; |
| 428 | |
| 429 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 430 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 431 | * @hide |
| 432 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 433 | public Bundle extras = new Bundle(); |
| 434 | |
| 435 | // extras keys for Builder inputs |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 436 | /** @hide */ |
| 437 | public static final String EXTRA_TITLE = "android.title"; |
| 438 | /** @hide */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 439 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
| 440 | /** @hide */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 441 | public static final String EXTRA_TEXT = "android.text"; |
| 442 | /** @hide */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 443 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
| 444 | /** @hide */ |
| 445 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
| 446 | /** @hide */ |
| 447 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 448 | /** @hide */ |
| 449 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 450 | /** @hide */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 451 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
| 452 | /** @hide */ |
| 453 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
| 454 | /** @hide */ |
| 455 | public static final String EXTRA_PROGRESS = "android.progress"; |
| 456 | /** @hide */ |
| 457 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
| 458 | /** @hide */ |
| 459 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
| 460 | /** @hide */ |
| 461 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
| 462 | /** @hide */ |
| 463 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
| 464 | /** @hide from BigPictureStyle */ |
| 465 | public static final String EXTRA_PICTURE = "android.picture"; |
| 466 | /** @hide from InboxStyle */ |
| 467 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
| 468 | |
| 469 | // extras keys for other interesting pieces of information |
| 470 | /** @hide */ |
| 471 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 472 | |
| 473 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 474 | * Structure to encapsulate an "action", including title and icon, that can be attached to a Notification. |
| 475 | * @hide |
| 476 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 477 | public static class Action implements Parcelable { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 478 | public int icon; |
| 479 | public CharSequence title; |
| 480 | public PendingIntent actionIntent; |
| 481 | @SuppressWarnings("unused") |
| 482 | public Action() { } |
| 483 | private Action(Parcel in) { |
| 484 | icon = in.readInt(); |
| 485 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 486 | if (in.readInt() == 1) { |
| 487 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 488 | } |
| 489 | } |
| 490 | public Action(int icon_, CharSequence title_, PendingIntent intent_) { |
| 491 | this.icon = icon_; |
| 492 | this.title = title_; |
| 493 | this.actionIntent = intent_; |
| 494 | } |
| 495 | @Override |
| 496 | public Action clone() { |
| 497 | return new Action( |
| 498 | this.icon, |
| 499 | this.title.toString(), |
| 500 | this.actionIntent // safe to alias |
| 501 | ); |
| 502 | } |
| 503 | @Override |
| 504 | public int describeContents() { |
| 505 | return 0; |
| 506 | } |
| 507 | @Override |
| 508 | public void writeToParcel(Parcel out, int flags) { |
| 509 | out.writeInt(icon); |
| 510 | TextUtils.writeToParcel(title, out, flags); |
| 511 | if (actionIntent != null) { |
| 512 | out.writeInt(1); |
| 513 | actionIntent.writeToParcel(out, flags); |
| 514 | } else { |
| 515 | out.writeInt(0); |
| 516 | } |
| 517 | } |
| 518 | public static final Parcelable.Creator<Action> CREATOR |
| 519 | = new Parcelable.Creator<Action>() { |
| 520 | public Action createFromParcel(Parcel in) { |
| 521 | return new Action(in); |
| 522 | } |
| 523 | public Action[] newArray(int size) { |
| 524 | return new Action[size]; |
| 525 | } |
| 526 | }; |
| 527 | } |
| 528 | |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 529 | /** |
| 530 | * @hide |
| 531 | */ |
| 532 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 533 | |
| 534 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 535 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 536 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 537 | */ |
| 538 | public Notification() |
| 539 | { |
| 540 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 541 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 545 | * @hide |
| 546 | */ |
| 547 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 548 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 549 | { |
| 550 | this.when = when; |
| 551 | this.icon = icon; |
| 552 | this.tickerText = tickerText; |
| 553 | setLatestEventInfo(context, contentTitle, contentText, |
| 554 | PendingIntent.getActivity(context, 0, contentIntent, 0)); |
| 555 | } |
| 556 | |
| 557 | /** |
| 558 | * Constructs a Notification object with the information needed to |
| 559 | * have a status bar icon without the standard expanded view. |
| 560 | * |
| 561 | * @param icon The resource id of the icon to put in the status bar. |
| 562 | * @param tickerText The text that flows by in the status bar when the notification first |
| 563 | * activates. |
| 564 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 565 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 566 | * |
| 567 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 568 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 569 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 570 | public Notification(int icon, CharSequence tickerText, long when) |
| 571 | { |
| 572 | this.icon = icon; |
| 573 | this.tickerText = tickerText; |
| 574 | this.when = when; |
| 575 | } |
| 576 | |
| 577 | /** |
| 578 | * Unflatten the notification from a parcel. |
| 579 | */ |
| 580 | public Notification(Parcel parcel) |
| 581 | { |
| 582 | int version = parcel.readInt(); |
| 583 | |
| 584 | when = parcel.readLong(); |
| 585 | icon = parcel.readInt(); |
| 586 | number = parcel.readInt(); |
| 587 | if (parcel.readInt() != 0) { |
| 588 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 589 | } |
| 590 | if (parcel.readInt() != 0) { |
| 591 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 592 | } |
| 593 | if (parcel.readInt() != 0) { |
| 594 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 595 | } |
| 596 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 597 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 598 | } |
| 599 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 600 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 601 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 602 | if (parcel.readInt() != 0) { |
| 603 | largeIcon = Bitmap.CREATOR.createFromParcel(parcel); |
| 604 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 605 | defaults = parcel.readInt(); |
| 606 | flags = parcel.readInt(); |
| 607 | if (parcel.readInt() != 0) { |
| 608 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 609 | } |
| 610 | |
| 611 | audioStreamType = parcel.readInt(); |
| 612 | vibrate = parcel.createLongArray(); |
| 613 | ledARGB = parcel.readInt(); |
| 614 | ledOnMS = parcel.readInt(); |
| 615 | ledOffMS = parcel.readInt(); |
| 616 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 617 | |
| 618 | if (parcel.readInt() != 0) { |
| 619 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 620 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 621 | |
| 622 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 623 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 624 | kind = parcel.createStringArray(); // may set kind to null |
| 625 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 626 | extras = parcel.readBundle(); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 627 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 628 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 629 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 630 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 631 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 632 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 633 | } |
| 634 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 635 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 636 | public Notification clone() { |
| 637 | Notification that = new Notification(); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 638 | cloneInto(that); |
| 639 | return that; |
| 640 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 641 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 642 | private void cloneInto(Notification that) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 643 | that.when = this.when; |
| 644 | that.icon = this.icon; |
| 645 | that.number = this.number; |
| 646 | |
| 647 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 648 | that.contentIntent = this.contentIntent; |
| 649 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 650 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 651 | |
| 652 | if (this.tickerText != null) { |
| 653 | that.tickerText = this.tickerText.toString(); |
| 654 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 655 | if (this.tickerView != null) { |
| 656 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 657 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 658 | if (this.contentView != null) { |
| 659 | that.contentView = this.contentView.clone(); |
| 660 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 661 | if (this.largeIcon != null) { |
| 662 | that.largeIcon = Bitmap.createBitmap(this.largeIcon); |
| 663 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 664 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 665 | that.sound = this.sound; // android.net.Uri is immutable |
| 666 | that.audioStreamType = this.audioStreamType; |
| 667 | |
| 668 | final long[] vibrate = this.vibrate; |
| 669 | if (vibrate != null) { |
| 670 | final int N = vibrate.length; |
| 671 | final long[] vib = that.vibrate = new long[N]; |
| 672 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 673 | } |
| 674 | |
| 675 | that.ledARGB = this.ledARGB; |
| 676 | that.ledOnMS = this.ledOnMS; |
| 677 | that.ledOffMS = this.ledOffMS; |
| 678 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 679 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 680 | that.flags = this.flags; |
| 681 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 682 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 683 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 684 | final String[] thiskind = this.kind; |
| 685 | if (thiskind != null) { |
| 686 | final int N = thiskind.length; |
| 687 | final String[] thatkind = that.kind = new String[N]; |
| 688 | System.arraycopy(thiskind, 0, thatkind, 0, N); |
| 689 | } |
| 690 | |
| 691 | if (this.extras != null) { |
| 692 | that.extras = new Bundle(this.extras); |
| 693 | |
| 694 | } |
| 695 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 696 | if (this.actions != null) { |
| 697 | that.actions = new Action[this.actions.length]; |
| 698 | for(int i=0; i<this.actions.length; i++) { |
| 699 | that.actions[i] = this.actions[i].clone(); |
| 700 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 701 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 702 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 703 | if (this.bigContentView != null) { |
| 704 | that.bigContentView = this.bigContentView.clone(); |
| 705 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 706 | } |
| 707 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 708 | public int describeContents() { |
| 709 | return 0; |
| 710 | } |
| 711 | |
| 712 | /** |
| 713 | * Flatten this notification from a parcel. |
| 714 | */ |
| 715 | public void writeToParcel(Parcel parcel, int flags) |
| 716 | { |
| 717 | parcel.writeInt(1); |
| 718 | |
| 719 | parcel.writeLong(when); |
| 720 | parcel.writeInt(icon); |
| 721 | parcel.writeInt(number); |
| 722 | if (contentIntent != null) { |
| 723 | parcel.writeInt(1); |
| 724 | contentIntent.writeToParcel(parcel, 0); |
| 725 | } else { |
| 726 | parcel.writeInt(0); |
| 727 | } |
| 728 | if (deleteIntent != null) { |
| 729 | parcel.writeInt(1); |
| 730 | deleteIntent.writeToParcel(parcel, 0); |
| 731 | } else { |
| 732 | parcel.writeInt(0); |
| 733 | } |
| 734 | if (tickerText != null) { |
| 735 | parcel.writeInt(1); |
| 736 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 737 | } else { |
| 738 | parcel.writeInt(0); |
| 739 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 740 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 741 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 742 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 743 | } else { |
| 744 | parcel.writeInt(0); |
| 745 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 746 | if (contentView != null) { |
| 747 | parcel.writeInt(1); |
| 748 | contentView.writeToParcel(parcel, 0); |
| 749 | } else { |
| 750 | parcel.writeInt(0); |
| 751 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 752 | if (largeIcon != null) { |
| 753 | parcel.writeInt(1); |
| 754 | largeIcon.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 | parcel.writeInt(defaults); |
| 760 | parcel.writeInt(this.flags); |
| 761 | |
| 762 | if (sound != null) { |
| 763 | parcel.writeInt(1); |
| 764 | sound.writeToParcel(parcel, 0); |
| 765 | } else { |
| 766 | parcel.writeInt(0); |
| 767 | } |
| 768 | parcel.writeInt(audioStreamType); |
| 769 | parcel.writeLongArray(vibrate); |
| 770 | parcel.writeInt(ledARGB); |
| 771 | parcel.writeInt(ledOnMS); |
| 772 | parcel.writeInt(ledOffMS); |
| 773 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 774 | |
| 775 | if (fullScreenIntent != null) { |
| 776 | parcel.writeInt(1); |
| 777 | fullScreenIntent.writeToParcel(parcel, 0); |
| 778 | } else { |
| 779 | parcel.writeInt(0); |
| 780 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 781 | |
| 782 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 783 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 784 | parcel.writeStringArray(kind); // ok for null |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 785 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 786 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 787 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 788 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 789 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 790 | if (bigContentView != null) { |
| 791 | parcel.writeInt(1); |
| 792 | bigContentView.writeToParcel(parcel, 0); |
| 793 | } else { |
| 794 | parcel.writeInt(0); |
| 795 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 796 | } |
| 797 | |
| 798 | /** |
| 799 | * Parcelable.Creator that instantiates Notification objects |
| 800 | */ |
| 801 | public static final Parcelable.Creator<Notification> CREATOR |
| 802 | = new Parcelable.Creator<Notification>() |
| 803 | { |
| 804 | public Notification createFromParcel(Parcel parcel) |
| 805 | { |
| 806 | return new Notification(parcel); |
| 807 | } |
| 808 | |
| 809 | public Notification[] newArray(int size) |
| 810 | { |
| 811 | return new Notification[size]; |
| 812 | } |
| 813 | }; |
| 814 | |
| 815 | /** |
| 816 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 817 | * layout. |
| 818 | * |
| 819 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 820 | * in the view.</p> |
| 821 | * @param context The context for your application / activity. |
| 822 | * @param contentTitle The title that goes in the expanded entry. |
| 823 | * @param contentText The text that goes in the expanded entry. |
| 824 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 825 | * If this is an activity, it must include the |
| 826 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 827 | * that you take care of task management as described in the |
| 828 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 829 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 830 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 831 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 832 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 833 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 834 | public void setLatestEventInfo(Context context, |
| 835 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 836 | Notification.Builder builder = new Notification.Builder(context); |
| 837 | |
| 838 | // First, ensure that key pieces of information that may have been set directly |
| 839 | // are preserved |
| 840 | builder.setWhen(this.when); |
| 841 | builder.setSmallIcon(this.icon); |
| 842 | builder.setPriority(this.priority); |
| 843 | builder.setTicker(this.tickerText); |
| 844 | builder.setNumber(this.number); |
| 845 | builder.mFlags = this.flags; |
| 846 | builder.setSound(this.sound, this.audioStreamType); |
| 847 | builder.setDefaults(this.defaults); |
| 848 | builder.setVibrate(this.vibrate); |
| 849 | |
| 850 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 851 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 852 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 853 | } |
| 854 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 855 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 856 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 857 | builder.setContentIntent(contentIntent); |
| 858 | builder.buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | @Override |
| 862 | public String toString() { |
| 863 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 864 | sb.append("Notification(pri="); |
| 865 | sb.append(priority); |
| 866 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 867 | if (contentView != null) { |
| 868 | sb.append(contentView.getPackage()); |
| 869 | sb.append("/0x"); |
| 870 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 871 | } else { |
| 872 | sb.append("null"); |
| 873 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 874 | // 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] | 875 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 876 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 877 | sb.append("default"); |
| 878 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 879 | int N = this.vibrate.length-1; |
| 880 | sb.append("["); |
| 881 | for (int i=0; i<N; i++) { |
| 882 | sb.append(this.vibrate[i]); |
| 883 | sb.append(','); |
| 884 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 885 | if (N != -1) { |
| 886 | sb.append(this.vibrate[N]); |
| 887 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 888 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 889 | } else { |
| 890 | sb.append("null"); |
| 891 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 892 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 893 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 894 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 895 | } else if (this.sound != null) { |
| 896 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 897 | } else { |
| 898 | sb.append("null"); |
| 899 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 900 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 901 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 902 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 903 | sb.append(Integer.toHexString(this.flags)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 904 | sb.append(" kind=["); |
| 905 | if (this.kind == null) { |
| 906 | sb.append("null"); |
| 907 | } else { |
| 908 | for (int i=0; i<this.kind.length; i++) { |
| 909 | if (i>0) sb.append(","); |
| 910 | sb.append(this.kind[i]); |
| 911 | } |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 912 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 913 | sb.append("]"); |
| 914 | if (actions != null) { |
| 915 | sb.append(" "); |
| 916 | sb.append(actions.length); |
| 917 | sb.append(" action"); |
| 918 | if (actions.length > 1) sb.append("s"); |
| 919 | } |
| 920 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 921 | return sb.toString(); |
| 922 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 923 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 924 | /** {@hide} */ |
| 925 | public void setUser(UserHandle user) { |
Amith Yamasani | ecbd68b | 2012-11-02 12:17:19 -0700 | [diff] [blame] | 926 | if (user.getIdentifier() == UserHandle.USER_ALL) { |
| 927 | user = UserHandle.OWNER; |
| 928 | } |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 929 | if (tickerView != null) { |
| 930 | tickerView.setUser(user); |
| 931 | } |
| 932 | if (contentView != null) { |
| 933 | contentView.setUser(user); |
| 934 | } |
| 935 | if (bigContentView != null) { |
| 936 | bigContentView.setUser(user); |
| 937 | } |
| 938 | } |
| 939 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 940 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 941 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 942 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 943 | * Provides a convenient way to set the various fields of a {@link Notification} and generate |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 944 | * content views using the platform's notification layout template. If your app supports |
| 945 | * versions of Android as old as API level 4, you can instead use |
| 946 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 947 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 948 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 949 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 950 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 951 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 952 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 953 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 954 | * .setContentTitle("New mail from " + sender.toString()) |
| 955 | * .setContentText(subject) |
| 956 | * .setSmallIcon(R.drawable.new_mail) |
| 957 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 958 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 959 | * </pre> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 960 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 961 | public static class Builder { |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 962 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 963 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 964 | private Context mContext; |
| 965 | |
| 966 | private long mWhen; |
| 967 | private int mSmallIcon; |
| 968 | private int mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 969 | private int mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 970 | private CharSequence mContentTitle; |
| 971 | private CharSequence mContentText; |
| 972 | private CharSequence mContentInfo; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 973 | private CharSequence mSubText; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 974 | private PendingIntent mContentIntent; |
| 975 | private RemoteViews mContentView; |
| 976 | private PendingIntent mDeleteIntent; |
| 977 | private PendingIntent mFullScreenIntent; |
| 978 | private CharSequence mTickerText; |
| 979 | private RemoteViews mTickerView; |
| 980 | private Bitmap mLargeIcon; |
| 981 | private Uri mSound; |
| 982 | private int mAudioStreamType; |
| 983 | private long[] mVibrate; |
| 984 | private int mLedArgb; |
| 985 | private int mLedOnMs; |
| 986 | private int mLedOffMs; |
| 987 | private int mDefaults; |
| 988 | private int mFlags; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 989 | private int mProgressMax; |
| 990 | private int mProgress; |
| 991 | private boolean mProgressIndeterminate; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 992 | private ArrayList<String> mKindList = new ArrayList<String>(1); |
| 993 | private Bundle mExtras; |
| 994 | private int mPriority; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 995 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 996 | private boolean mUseChronometer; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 997 | private Style mStyle; |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 998 | private boolean mShowWhen = true; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 999 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1000 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1001 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1002 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1003 | |
| 1004 | * <table> |
| 1005 | * <tr><th align=right>priority</th> |
| 1006 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 1007 | * <tr><th align=right>when</th> |
| 1008 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 1009 | * <tr><th align=right>audio stream</th> |
| 1010 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 1011 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1012 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1013 | |
| 1014 | * @param context |
| 1015 | * A {@link Context} that will be used by the Builder to construct the |
| 1016 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 1017 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1018 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1019 | public Builder(Context context) { |
| 1020 | mContext = context; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1021 | |
| 1022 | // Set defaults to match the defaults of a Notification |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1023 | mWhen = System.currentTimeMillis(); |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1024 | mAudioStreamType = STREAM_DEFAULT; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1025 | mPriority = PRIORITY_DEFAULT; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1026 | } |
| 1027 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1028 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1029 | * Add a timestamp pertaining to the notification (usually the time the event occurred). |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1030 | * It will be shown in the notification content view by default; use |
| 1031 | * {@link Builder#setShowWhen(boolean) setShowWhen} to control this. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1032 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1033 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1034 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1035 | public Builder setWhen(long when) { |
| 1036 | mWhen = when; |
| 1037 | return this; |
| 1038 | } |
| 1039 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1040 | /** |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1041 | * Control whether the timestamp set with {@link Builder#setWhen(long) setWhen} is shown |
| 1042 | * in the content view. |
| 1043 | */ |
| 1044 | public Builder setShowWhen(boolean show) { |
| 1045 | mShowWhen = show; |
| 1046 | return this; |
| 1047 | } |
| 1048 | |
| 1049 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1050 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1051 | * |
| 1052 | * Instead of presenting <code>when</code> as a timestamp, the notification will show an |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1053 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1054 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1055 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 1056 | * |
| 1057 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1058 | * @see Notification#when |
| 1059 | */ |
| 1060 | public Builder setUsesChronometer(boolean b) { |
| 1061 | mUseChronometer = b; |
| 1062 | return this; |
| 1063 | } |
| 1064 | |
| 1065 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1066 | * Set the small icon resource, which will be used to represent the notification in the |
| 1067 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1068 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1069 | |
| 1070 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 1071 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 1072 | * icon will be moved to the right-hand side. |
| 1073 | * |
| 1074 | |
| 1075 | * @param icon |
| 1076 | * A resource ID in the application's package of the drawable to use. |
| 1077 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1078 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1079 | public Builder setSmallIcon(int icon) { |
| 1080 | mSmallIcon = icon; |
| 1081 | return this; |
| 1082 | } |
| 1083 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1084 | /** |
| 1085 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 1086 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 1087 | * LevelListDrawable}. |
| 1088 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1089 | * @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] | 1090 | * @param level The level to use for the icon. |
| 1091 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1092 | * @see Notification#icon |
| 1093 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1094 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1095 | public Builder setSmallIcon(int icon, int level) { |
| 1096 | mSmallIcon = icon; |
| 1097 | mSmallIconLevel = level; |
| 1098 | return this; |
| 1099 | } |
| 1100 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1101 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1102 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1103 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1104 | public Builder setContentTitle(CharSequence title) { |
| 1105 | mContentTitle = title; |
| 1106 | return this; |
| 1107 | } |
| 1108 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1109 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1110 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1111 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1112 | public Builder setContentText(CharSequence text) { |
| 1113 | mContentText = text; |
| 1114 | return this; |
| 1115 | } |
| 1116 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1117 | /** |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1118 | * Set the third line of text in the platform notification template. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1119 | * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the same location in the standard template. |
| 1120 | */ |
| 1121 | public Builder setSubText(CharSequence text) { |
| 1122 | mSubText = text; |
| 1123 | return this; |
| 1124 | } |
| 1125 | |
| 1126 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1127 | * Set the large number at the right-hand side of the notification. This is |
| 1128 | * equivalent to setContentInfo, although it might show the number in a different |
| 1129 | * font size for readability. |
| 1130 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1131 | public Builder setNumber(int number) { |
| 1132 | mNumber = number; |
| 1133 | return this; |
| 1134 | } |
| 1135 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1136 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1137 | * A small piece of additional information pertaining to this notification. |
| 1138 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1139 | * The platform template will draw this on the last line of the notification, at the far |
| 1140 | * 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] | 1141 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1142 | public Builder setContentInfo(CharSequence info) { |
| 1143 | mContentInfo = info; |
| 1144 | return this; |
| 1145 | } |
| 1146 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1147 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1148 | * Set the progress this notification represents. |
| 1149 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1150 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1151 | */ |
| 1152 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 1153 | mProgressMax = max; |
| 1154 | mProgress = progress; |
| 1155 | mProgressIndeterminate = indeterminate; |
| 1156 | return this; |
| 1157 | } |
| 1158 | |
| 1159 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1160 | * Supply a custom RemoteViews to use instead of the platform template. |
| 1161 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1162 | * @see Notification#contentView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1163 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1164 | public Builder setContent(RemoteViews views) { |
| 1165 | mContentView = views; |
| 1166 | return this; |
| 1167 | } |
| 1168 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1169 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1170 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 1171 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1172 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 1173 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 1174 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1175 | * 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] | 1176 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1177 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1178 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1179 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1180 | public Builder setContentIntent(PendingIntent intent) { |
| 1181 | mContentIntent = intent; |
| 1182 | return this; |
| 1183 | } |
| 1184 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1185 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1186 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 1187 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1188 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1189 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1190 | public Builder setDeleteIntent(PendingIntent intent) { |
| 1191 | mDeleteIntent = intent; |
| 1192 | return this; |
| 1193 | } |
| 1194 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1195 | /** |
| 1196 | * An intent to launch instead of posting the notification to the status bar. |
| 1197 | * Only for use with extremely high-priority notifications demanding the user's |
| 1198 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 1199 | * alarm clock that the user has explicitly set to a particular time. |
| 1200 | * If this facility is used for something else, please give the user an option |
| 1201 | * to turn it off and use a normal notification, as this can be extremely |
| 1202 | * disruptive. |
| 1203 | * |
| 1204 | * @param intent The pending intent to launch. |
| 1205 | * @param highPriority Passing true will cause this notification to be sent |
| 1206 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1207 | * |
| 1208 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1209 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1210 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 1211 | mFullScreenIntent = intent; |
| 1212 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 1213 | return this; |
| 1214 | } |
| 1215 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1216 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1217 | * 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] | 1218 | * arrives. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1219 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1220 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1221 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1222 | public Builder setTicker(CharSequence tickerText) { |
| 1223 | mTickerText = tickerText; |
| 1224 | return this; |
| 1225 | } |
| 1226 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1227 | /** |
| 1228 | * Set the text that is displayed in the status bar when the notification first |
| 1229 | * arrives, and also a RemoteViews object that may be displayed instead on some |
| 1230 | * devices. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1231 | * |
| 1232 | * @see Notification#tickerText |
| 1233 | * @see Notification#tickerView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1234 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1235 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
| 1236 | mTickerText = tickerText; |
| 1237 | mTickerView = views; |
| 1238 | return this; |
| 1239 | } |
| 1240 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1241 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1242 | * Add a large icon to the notification (and the ticker on some devices). |
| 1243 | * |
| 1244 | * In the platform template, this image will be shown on the left of the notification view |
| 1245 | * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side). |
| 1246 | * |
| 1247 | * @see Notification#largeIcon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1248 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1249 | public Builder setLargeIcon(Bitmap icon) { |
| 1250 | mLargeIcon = icon; |
| 1251 | return this; |
| 1252 | } |
| 1253 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1254 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1255 | * Set the sound to play. |
| 1256 | * |
| 1257 | * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications. |
| 1258 | * |
| 1259 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1260 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 1261 | public Builder setSound(Uri sound) { |
| 1262 | mSound = sound; |
| 1263 | mAudioStreamType = STREAM_DEFAULT; |
| 1264 | return this; |
| 1265 | } |
| 1266 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1267 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1268 | * 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] | 1269 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1270 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 1271 | * |
| 1272 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1273 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1274 | public Builder setSound(Uri sound, int streamType) { |
| 1275 | mSound = sound; |
| 1276 | mAudioStreamType = streamType; |
| 1277 | return this; |
| 1278 | } |
| 1279 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1280 | /** |
| 1281 | * Set the vibration pattern to use. |
| 1282 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1283 | |
| 1284 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 1285 | * <code>pattern</code> parameter. |
| 1286 | * |
| 1287 | |
| 1288 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1289 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1290 | public Builder setVibrate(long[] pattern) { |
| 1291 | mVibrate = pattern; |
| 1292 | return this; |
| 1293 | } |
| 1294 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1295 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1296 | * Set the desired color for the indicator LED on the device, as well as the |
| 1297 | * blink duty cycle (specified in milliseconds). |
| 1298 | * |
| 1299 | |
| 1300 | * Not all devices will honor all (or even any) of these values. |
| 1301 | * |
| 1302 | |
| 1303 | * @see Notification#ledARGB |
| 1304 | * @see Notification#ledOnMS |
| 1305 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1306 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1307 | public Builder setLights(int argb, int onMs, int offMs) { |
| 1308 | mLedArgb = argb; |
| 1309 | mLedOnMs = onMs; |
| 1310 | mLedOffMs = offMs; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1311 | return this; |
| 1312 | } |
| 1313 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1314 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1315 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1316 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1317 | |
| 1318 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 1319 | * must take care of canceling them. |
| 1320 | * |
| 1321 | |
| 1322 | * They are typically used to indicate a background task that the user is actively engaged |
| 1323 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 1324 | * (e.g., a file download, sync operation, active network connection). |
| 1325 | * |
| 1326 | |
| 1327 | * @see Notification#FLAG_ONGOING_EVENT |
| 1328 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1329 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1330 | public Builder setOngoing(boolean ongoing) { |
| 1331 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 1332 | return this; |
| 1333 | } |
| 1334 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1335 | /** |
| 1336 | * Set this flag if you would only like the sound, vibrate |
| 1337 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1338 | * |
| 1339 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1340 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1341 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 1342 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 1343 | return this; |
| 1344 | } |
| 1345 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1346 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1347 | * Make this notification automatically dismissed when the user touches it. The |
| 1348 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 1349 | * |
| 1350 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1351 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1352 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 1353 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1354 | return this; |
| 1355 | } |
| 1356 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1357 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1358 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1359 | * <p> |
| 1360 | * The value should be one or more of the following fields combined with |
| 1361 | * bitwise-or: |
| 1362 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 1363 | * <p> |
| 1364 | * For all default values, use {@link #DEFAULT_ALL}. |
| 1365 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1366 | public Builder setDefaults(int defaults) { |
| 1367 | mDefaults = defaults; |
| 1368 | return this; |
| 1369 | } |
| 1370 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1371 | /** |
| 1372 | * Set the priority of this notification. |
| 1373 | * |
| 1374 | * @see Notification#priority |
| 1375 | */ |
| 1376 | public Builder setPriority(int pri) { |
| 1377 | mPriority = pri; |
| 1378 | return this; |
| 1379 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1380 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1381 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1382 | * @hide |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1383 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1384 | * Add a kind (category) to this notification. Optional. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1385 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1386 | * @see Notification#kind |
| 1387 | */ |
| 1388 | public Builder addKind(String k) { |
| 1389 | mKindList.add(k); |
| 1390 | return this; |
| 1391 | } |
| 1392 | |
| 1393 | /** |
| 1394 | * Add metadata to this notification. |
| 1395 | * |
| 1396 | * 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] | 1397 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1398 | * called. |
| 1399 | * |
| 1400 | * @see Notification#extras |
| 1401 | * @hide |
| 1402 | */ |
| 1403 | public Builder setExtras(Bundle bag) { |
| 1404 | mExtras = bag; |
| 1405 | return this; |
| 1406 | } |
| 1407 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1408 | /** |
| 1409 | * Add an action to this notification. Actions are typically displayed by |
| 1410 | * the system as a button adjacent to the notification content. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1411 | * <br> |
| 1412 | * A notification displays up to 3 actions, from left to right in the order they were added. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1413 | * |
| 1414 | * @param icon Resource ID of a drawable that represents the action. |
| 1415 | * @param title Text describing the action. |
| 1416 | * @param intent PendingIntent to be fired when the action is invoked. |
| 1417 | */ |
| 1418 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
| 1419 | mActions.add(new Action(icon, title, intent)); |
| 1420 | return this; |
| 1421 | } |
| 1422 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1423 | /** |
| 1424 | * Add a rich notification style to be applied at build time. |
| 1425 | * |
| 1426 | * @param style Object responsible for modifying the notification style. |
| 1427 | */ |
| 1428 | public Builder setStyle(Style style) { |
| 1429 | if (mStyle != style) { |
| 1430 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 1431 | if (mStyle != null) { |
| 1432 | mStyle.setBuilder(this); |
| 1433 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1434 | } |
| 1435 | return this; |
| 1436 | } |
| 1437 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1438 | private void setFlag(int mask, boolean value) { |
| 1439 | if (value) { |
| 1440 | mFlags |= mask; |
| 1441 | } else { |
| 1442 | mFlags &= ~mask; |
| 1443 | } |
| 1444 | } |
| 1445 | |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1446 | private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1447 | RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1448 | boolean showLine3 = false; |
| 1449 | boolean showLine2 = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1450 | int smallIconImageViewId = R.id.icon; |
| 1451 | if (mLargeIcon != null) { |
| 1452 | contentView.setImageViewBitmap(R.id.icon, mLargeIcon); |
| 1453 | smallIconImageViewId = R.id.right_icon; |
| 1454 | } |
Daniel Sandler | e95658c | 2012-05-10 00:33:54 -0400 | [diff] [blame] | 1455 | if (mPriority < PRIORITY_LOW) { |
| 1456 | contentView.setInt(R.id.icon, |
| 1457 | "setBackgroundResource", R.drawable.notification_template_icon_low_bg); |
| 1458 | contentView.setInt(R.id.status_bar_latest_event_content, |
| 1459 | "setBackgroundResource", R.drawable.notification_bg_low); |
| 1460 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1461 | if (mSmallIcon != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1462 | contentView.setImageViewResource(smallIconImageViewId, mSmallIcon); |
| 1463 | contentView.setViewVisibility(smallIconImageViewId, View.VISIBLE); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1464 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1465 | contentView.setViewVisibility(smallIconImageViewId, View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1466 | } |
| 1467 | if (mContentTitle != null) { |
| 1468 | contentView.setTextViewText(R.id.title, mContentTitle); |
| 1469 | } |
| 1470 | if (mContentText != null) { |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1471 | contentView.setTextViewText(R.id.text, mContentText); |
| 1472 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1473 | } |
| 1474 | if (mContentInfo != null) { |
| 1475 | contentView.setTextViewText(R.id.info, mContentInfo); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1476 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1477 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1478 | } else if (mNumber > 0) { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 1479 | final int tooBig = mContext.getResources().getInteger( |
| 1480 | R.integer.status_bar_notification_info_maxnum); |
| 1481 | if (mNumber > tooBig) { |
| 1482 | contentView.setTextViewText(R.id.info, mContext.getResources().getString( |
| 1483 | R.string.status_bar_notification_info_overflow)); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 1484 | } else { |
| 1485 | NumberFormat f = NumberFormat.getIntegerInstance(); |
| 1486 | contentView.setTextViewText(R.id.info, f.format(mNumber)); |
| 1487 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1488 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1489 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1490 | } else { |
| 1491 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 1492 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1493 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1494 | // Need to show three lines? |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1495 | if (mSubText != null) { |
| 1496 | contentView.setTextViewText(R.id.text, mSubText); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1497 | if (mContentText != null) { |
| 1498 | contentView.setTextViewText(R.id.text2, mContentText); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1499 | contentView.setViewVisibility(R.id.text2, View.VISIBLE); |
| 1500 | showLine2 = true; |
| 1501 | } else { |
| 1502 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 1503 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1504 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1505 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 1506 | if (mProgressMax != 0 || mProgressIndeterminate) { |
| 1507 | contentView.setProgressBar( |
| 1508 | R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); |
| 1509 | contentView.setViewVisibility(R.id.progress, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1510 | showLine2 = true; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1511 | } else { |
| 1512 | contentView.setViewVisibility(R.id.progress, View.GONE); |
| 1513 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1514 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1515 | if (showLine2) { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1516 | if (fitIn1U) { |
| 1517 | // need to shrink all the type to make sure everything fits |
| 1518 | final Resources res = mContext.getResources(); |
| 1519 | final float subTextSize = res.getDimensionPixelSize( |
| 1520 | R.dimen.notification_subtext_size); |
| 1521 | contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); |
| 1522 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1523 | // vertical centering |
| 1524 | contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); |
| 1525 | } |
| 1526 | |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1527 | if (mWhen != 0 && mShowWhen) { |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1528 | if (mUseChronometer) { |
| 1529 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 1530 | contentView.setLong(R.id.chronometer, "setBase", |
| 1531 | mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 1532 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 1533 | } else { |
| 1534 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 1535 | contentView.setLong(R.id.time, "setTime", mWhen); |
| 1536 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1537 | } else { |
| 1538 | contentView.setViewVisibility(R.id.time, View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1539 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1540 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1541 | contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1542 | contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1543 | return contentView; |
| 1544 | } |
| 1545 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1546 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1547 | RemoteViews big = applyStandardTemplate(layoutId, false); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1548 | |
| 1549 | int N = mActions.size(); |
| 1550 | if (N > 0) { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1551 | // Log.d("Notification", "has actions: " + mContentText); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1552 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1553 | big.setViewVisibility(R.id.action_divider, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1554 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Chris Wren | 2c22eb0 | 2012-05-08 09:49:13 -0400 | [diff] [blame] | 1555 | big.removeAllViews(R.id.actions); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1556 | for (int i=0; i<N; i++) { |
| 1557 | final RemoteViews button = generateActionButton(mActions.get(i)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1558 | //Log.d("Notification", "adding action " + i + ": " + mActions.get(i).title); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1559 | big.addView(R.id.actions, button); |
| 1560 | } |
| 1561 | } |
| 1562 | return big; |
| 1563 | } |
| 1564 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1565 | private RemoteViews makeContentView() { |
| 1566 | if (mContentView != null) { |
| 1567 | return mContentView; |
| 1568 | } else { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1569 | return applyStandardTemplate(R.layout.notification_template_base, true); // no more special large_icon flavor |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | private RemoteViews makeTickerView() { |
| 1574 | if (mTickerView != null) { |
| 1575 | return mTickerView; |
| 1576 | } else { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1577 | if (mContentView == null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1578 | return applyStandardTemplate(mLargeIcon == null |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1579 | ? R.layout.status_bar_latest_event_ticker |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1580 | : R.layout.status_bar_latest_event_ticker_large_icon, true); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1581 | } else { |
| 1582 | return null; |
| 1583 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1584 | } |
| 1585 | } |
| 1586 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1587 | private RemoteViews makeBigContentView() { |
| 1588 | if (mActions.size() == 0) return null; |
| 1589 | |
Chris Wren | b023bf8 | 2012-04-23 16:05:42 -0400 | [diff] [blame] | 1590 | return applyStandardTemplateWithActions(R.layout.notification_template_big_base); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1591 | } |
| 1592 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1593 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1594 | final boolean tombstone = (action.actionIntent == null); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1595 | RemoteViews button = new RemoteViews(mContext.getPackageName(), |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1596 | tombstone ? R.layout.notification_action_tombstone |
| 1597 | : R.layout.notification_action); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1598 | button.setTextViewCompoundDrawables(R.id.action0, action.icon, 0, 0, 0); |
| 1599 | button.setTextViewText(R.id.action0, action.title); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1600 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 1601 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 1602 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1603 | button.setContentDescription(R.id.action0, action.title); |
| 1604 | return button; |
| 1605 | } |
| 1606 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1607 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1608 | * Apply the unstyled operations and return a new {@link Notification} object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1609 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1610 | private Notification buildUnstyled() { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1611 | Notification n = new Notification(); |
| 1612 | n.when = mWhen; |
| 1613 | n.icon = mSmallIcon; |
| 1614 | n.iconLevel = mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1615 | n.number = mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1616 | n.contentView = makeContentView(); |
| 1617 | n.contentIntent = mContentIntent; |
| 1618 | n.deleteIntent = mDeleteIntent; |
| 1619 | n.fullScreenIntent = mFullScreenIntent; |
| 1620 | n.tickerText = mTickerText; |
| 1621 | n.tickerView = makeTickerView(); |
| 1622 | n.largeIcon = mLargeIcon; |
| 1623 | n.sound = mSound; |
| 1624 | n.audioStreamType = mAudioStreamType; |
| 1625 | n.vibrate = mVibrate; |
| 1626 | n.ledARGB = mLedArgb; |
| 1627 | n.ledOnMS = mLedOnMs; |
| 1628 | n.ledOffMS = mLedOffMs; |
| 1629 | n.defaults = mDefaults; |
| 1630 | n.flags = mFlags; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 1631 | n.bigContentView = makeBigContentView(); |
Daniel Sandler | 26c1343 | 2013-04-04 11:01:04 -0400 | [diff] [blame] | 1632 | if (mLedOnMs != 0 || mLedOffMs != 0) { |
Joe Onorato | 8d0b655 | 2010-11-22 16:09:29 -0800 | [diff] [blame] | 1633 | n.flags |= FLAG_SHOW_LIGHTS; |
| 1634 | } |
| 1635 | if ((mDefaults & DEFAULT_LIGHTS) != 0) { |
| 1636 | n.flags |= FLAG_SHOW_LIGHTS; |
| 1637 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1638 | if (mKindList.size() > 0) { |
| 1639 | n.kind = new String[mKindList.size()]; |
| 1640 | mKindList.toArray(n.kind); |
| 1641 | } else { |
| 1642 | n.kind = null; |
| 1643 | } |
| 1644 | n.priority = mPriority; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1645 | if (mActions.size() > 0) { |
| 1646 | n.actions = new Action[mActions.size()]; |
| 1647 | mActions.toArray(n.actions); |
| 1648 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1649 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1650 | return n; |
| 1651 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1652 | |
| 1653 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1654 | * Capture, in the provided bundle, semantic information used in the construction of |
| 1655 | * this Notification object. |
| 1656 | * @hide |
| 1657 | */ |
| 1658 | public void addExtras(Bundle extras) { |
| 1659 | // Store original information used in the construction of this object |
| 1660 | extras.putCharSequence(EXTRA_TITLE, mContentTitle); |
| 1661 | extras.putCharSequence(EXTRA_TEXT, mContentText); |
| 1662 | extras.putCharSequence(EXTRA_SUB_TEXT, mSubText); |
| 1663 | extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo); |
| 1664 | extras.putInt(EXTRA_SMALL_ICON, mSmallIcon); |
| 1665 | extras.putInt(EXTRA_PROGRESS, mProgress); |
| 1666 | extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax); |
| 1667 | extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate); |
| 1668 | extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer); |
| 1669 | extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen); |
| 1670 | } |
| 1671 | |
| 1672 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1673 | * @deprecated Use {@link #build()} instead. |
| 1674 | */ |
| 1675 | @Deprecated |
| 1676 | public Notification getNotification() { |
| 1677 | return build(); |
| 1678 | } |
| 1679 | |
| 1680 | /** |
| 1681 | * Combine all of the options that have been set and return a new {@link Notification} |
| 1682 | * object. |
| 1683 | */ |
| 1684 | public Notification build() { |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1685 | final Notification n; |
| 1686 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1687 | if (mStyle != null) { |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1688 | n = mStyle.build(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1689 | } else { |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1690 | n = buildUnstyled(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1691 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1692 | |
| 1693 | n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle(); |
| 1694 | |
| 1695 | addExtras(n.extras); |
| 1696 | if (mStyle != null) { |
| 1697 | mStyle.addExtras(n.extras); |
| 1698 | } |
| 1699 | |
| 1700 | return n; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1701 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1702 | |
| 1703 | /** |
| 1704 | * Apply this Builder to an existing {@link Notification} object. |
| 1705 | * |
| 1706 | * @hide |
| 1707 | */ |
| 1708 | public Notification buildInto(Notification n) { |
| 1709 | build().cloneInto(n); |
| 1710 | return n; |
| 1711 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1712 | } |
| 1713 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1714 | /** |
| 1715 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 1716 | * object. |
| 1717 | */ |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1718 | public static abstract class Style |
| 1719 | { |
| 1720 | private CharSequence mBigContentTitle; |
| 1721 | private CharSequence mSummaryText = null; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 1722 | private boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1723 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1724 | protected Builder mBuilder; |
| 1725 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1726 | /** |
| 1727 | * Overrides ContentTitle in the big form of the template. |
| 1728 | * This defaults to the value passed to setContentTitle(). |
| 1729 | */ |
| 1730 | protected void internalSetBigContentTitle(CharSequence title) { |
| 1731 | mBigContentTitle = title; |
| 1732 | } |
| 1733 | |
| 1734 | /** |
| 1735 | * Set the first line of text after the detail section in the big form of the template. |
| 1736 | */ |
| 1737 | protected void internalSetSummaryText(CharSequence cs) { |
| 1738 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 1739 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1740 | } |
| 1741 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1742 | public void setBuilder(Builder builder) { |
| 1743 | if (mBuilder != builder) { |
| 1744 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 1745 | if (mBuilder != null) { |
| 1746 | mBuilder.setStyle(this); |
| 1747 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1748 | } |
| 1749 | } |
| 1750 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1751 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1752 | if (mBuilder == null) { |
| 1753 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 1754 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1755 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1756 | |
| 1757 | protected RemoteViews getStandardView(int layoutId) { |
| 1758 | checkBuilder(); |
| 1759 | |
| 1760 | if (mBigContentTitle != null) { |
| 1761 | mBuilder.setContentTitle(mBigContentTitle); |
| 1762 | } |
| 1763 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1764 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 1765 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1766 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 1767 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 1768 | } else { |
| 1769 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1770 | } |
| 1771 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 1772 | // The last line defaults to the subtext, but can be replaced by mSummaryText |
| 1773 | final CharSequence overflowText = |
| 1774 | mSummaryTextSet ? mSummaryText |
| 1775 | : mBuilder.mSubText; |
| 1776 | if (overflowText != null) { |
| 1777 | contentView.setTextViewText(R.id.text, overflowText); |
| 1778 | contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 1779 | contentView.setViewVisibility(R.id.line3, View.VISIBLE); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 1780 | } else { |
| 1781 | contentView.setViewVisibility(R.id.overflow_divider, View.GONE); |
| 1782 | contentView.setViewVisibility(R.id.line3, View.GONE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | return contentView; |
| 1786 | } |
| 1787 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1788 | /** |
| 1789 | * @hide |
| 1790 | */ |
| 1791 | public void addExtras(Bundle extras) { |
| 1792 | if (mSummaryTextSet) { |
| 1793 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 1794 | } |
| 1795 | if (mBigContentTitle != null) { |
| 1796 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 1797 | } |
| 1798 | } |
| 1799 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1800 | public abstract Notification build(); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1801 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1802 | |
| 1803 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1804 | * Helper class for generating large-format notifications that include a large image attachment. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1805 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1806 | * 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] | 1807 | * <pre class="prettyprint"> |
| 1808 | * Notification noti = new Notification.BigPictureStyle( |
| 1809 | * new Notification.Builder() |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1810 | * .setContentTitle("New photo from " + sender.toString()) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1811 | * .setContentText(subject) |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1812 | * .setSmallIcon(R.drawable.new_post) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1813 | * .setLargeIcon(aBitmap)) |
| 1814 | * .bigPicture(aBigBitmap) |
| 1815 | * .build(); |
| 1816 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1817 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1818 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1819 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1820 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1821 | private Bitmap mPicture; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 1822 | private Bitmap mBigLargeIcon; |
| 1823 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1824 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1825 | public BigPictureStyle() { |
| 1826 | } |
| 1827 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1828 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1829 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1830 | } |
| 1831 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1832 | /** |
| 1833 | * Overrides ContentTitle in the big form of the template. |
| 1834 | * This defaults to the value passed to setContentTitle(). |
| 1835 | */ |
| 1836 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
| 1837 | internalSetBigContentTitle(title); |
| 1838 | return this; |
| 1839 | } |
| 1840 | |
| 1841 | /** |
| 1842 | * Set the first line of text after the detail section in the big form of the template. |
| 1843 | */ |
| 1844 | public BigPictureStyle setSummaryText(CharSequence cs) { |
| 1845 | internalSetSummaryText(cs); |
| 1846 | return this; |
| 1847 | } |
| 1848 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 1849 | /** |
| 1850 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 1851 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1852 | public BigPictureStyle bigPicture(Bitmap b) { |
| 1853 | mPicture = b; |
| 1854 | return this; |
| 1855 | } |
| 1856 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 1857 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 1858 | * Override the large icon when the big notification is shown. |
| 1859 | */ |
| 1860 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
| 1861 | mBigLargeIconSet = true; |
| 1862 | mBigLargeIcon = b; |
| 1863 | return this; |
| 1864 | } |
| 1865 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1866 | private RemoteViews makeBigContentView() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1867 | RemoteViews contentView = getStandardView(R.layout.notification_template_big_picture); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1868 | |
| 1869 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
| 1870 | |
| 1871 | return contentView; |
| 1872 | } |
| 1873 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1874 | /** |
| 1875 | * @hide |
| 1876 | */ |
| 1877 | public void addExtras(Bundle extras) { |
| 1878 | super.addExtras(extras); |
| 1879 | |
| 1880 | if (mBigLargeIconSet) { |
| 1881 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 1882 | } |
| 1883 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 1884 | } |
| 1885 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1886 | @Override |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1887 | public Notification build() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1888 | checkBuilder(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1889 | Notification wip = mBuilder.buildUnstyled(); |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 1890 | if (mBigLargeIconSet ) { |
| 1891 | mBuilder.mLargeIcon = mBigLargeIcon; |
| 1892 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1893 | wip.bigContentView = makeBigContentView(); |
| 1894 | return wip; |
| 1895 | } |
| 1896 | } |
| 1897 | |
| 1898 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1899 | * Helper class for generating large-format notifications that include a lot of text. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1900 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1901 | * 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] | 1902 | * <pre class="prettyprint"> |
Daniel Sandler | 8768278 | 2012-11-07 14:04:42 -0500 | [diff] [blame] | 1903 | * Notification noti = new Notification.BigTextStyle( |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1904 | * new Notification.Builder() |
| 1905 | * .setContentTitle("New mail from " + sender.toString()) |
| 1906 | * .setContentText(subject) |
| 1907 | * .setSmallIcon(R.drawable.new_mail) |
| 1908 | * .setLargeIcon(aBitmap)) |
| 1909 | * .bigText(aVeryLongString) |
| 1910 | * .build(); |
| 1911 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1912 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 1913 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1914 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1915 | public static class BigTextStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1916 | private CharSequence mBigText; |
| 1917 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1918 | public BigTextStyle() { |
| 1919 | } |
| 1920 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1921 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1922 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1923 | } |
| 1924 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1925 | /** |
| 1926 | * Overrides ContentTitle in the big form of the template. |
| 1927 | * This defaults to the value passed to setContentTitle(). |
| 1928 | */ |
| 1929 | public BigTextStyle setBigContentTitle(CharSequence title) { |
| 1930 | internalSetBigContentTitle(title); |
| 1931 | return this; |
| 1932 | } |
| 1933 | |
| 1934 | /** |
| 1935 | * Set the first line of text after the detail section in the big form of the template. |
| 1936 | */ |
| 1937 | public BigTextStyle setSummaryText(CharSequence cs) { |
| 1938 | internalSetSummaryText(cs); |
| 1939 | return this; |
| 1940 | } |
| 1941 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 1942 | /** |
| 1943 | * Provide the longer text to be displayed in the big form of the |
| 1944 | * template in place of the content text. |
| 1945 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1946 | public BigTextStyle bigText(CharSequence cs) { |
| 1947 | mBigText = cs; |
| 1948 | return this; |
| 1949 | } |
| 1950 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 1951 | /** |
| 1952 | * @hide |
| 1953 | */ |
| 1954 | public void addExtras(Bundle extras) { |
| 1955 | super.addExtras(extras); |
| 1956 | |
| 1957 | extras.putCharSequence(EXTRA_TEXT, mBigText); |
| 1958 | } |
| 1959 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1960 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 1961 | // Remove the content text so line3 only shows if you have a summary |
| 1962 | final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 1963 | mBuilder.mContentText = null; |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 1964 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1965 | RemoteViews contentView = getStandardView(R.layout.notification_template_big_text); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1966 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 1967 | if (hadThreeLines) { |
| 1968 | // vertical centering |
| 1969 | contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); |
| 1970 | } |
| 1971 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1972 | contentView.setTextViewText(R.id.big_text, mBigText); |
| 1973 | contentView.setViewVisibility(R.id.big_text, View.VISIBLE); |
Chris Wren | 3c5f9243 | 2012-05-04 16:31:17 -0400 | [diff] [blame] | 1974 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1975 | |
| 1976 | return contentView; |
| 1977 | } |
| 1978 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1979 | @Override |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1980 | public Notification build() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1981 | checkBuilder(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1982 | Notification wip = mBuilder.buildUnstyled(); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1983 | wip.bigContentView = makeBigContentView(); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1984 | |
| 1985 | wip.extras.putCharSequence(EXTRA_TEXT, mBigText); |
| 1986 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1987 | return wip; |
| 1988 | } |
| 1989 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1990 | |
| 1991 | /** |
| 1992 | * Helper class for generating large-format notifications that include a list of (up to 5) strings. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1993 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1994 | * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so: |
| 1995 | * <pre class="prettyprint"> |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1996 | * Notification noti = new Notification.InboxStyle( |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1997 | * new Notification.Builder() |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 1998 | * .setContentTitle("5 New mails from " + sender.toString()) |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 1999 | * .setContentText(subject) |
| 2000 | * .setSmallIcon(R.drawable.new_mail) |
| 2001 | * .setLargeIcon(aBitmap)) |
| 2002 | * .addLine(str1) |
| 2003 | * .addLine(str2) |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2004 | * .setContentTitle("") |
| 2005 | * .setSummaryText("+3 more") |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2006 | * .build(); |
| 2007 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2008 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2009 | * @see Notification#bigContentView |
| 2010 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2011 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2012 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 2013 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2014 | public InboxStyle() { |
| 2015 | } |
| 2016 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2017 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2018 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2019 | } |
| 2020 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2021 | /** |
| 2022 | * Overrides ContentTitle in the big form of the template. |
| 2023 | * This defaults to the value passed to setContentTitle(). |
| 2024 | */ |
| 2025 | public InboxStyle setBigContentTitle(CharSequence title) { |
| 2026 | internalSetBigContentTitle(title); |
| 2027 | return this; |
| 2028 | } |
| 2029 | |
| 2030 | /** |
| 2031 | * Set the first line of text after the detail section in the big form of the template. |
| 2032 | */ |
| 2033 | public InboxStyle setSummaryText(CharSequence cs) { |
| 2034 | internalSetSummaryText(cs); |
| 2035 | return this; |
| 2036 | } |
| 2037 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 2038 | /** |
| 2039 | * Append a line to the digest section of the Inbox notification. |
| 2040 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2041 | public InboxStyle addLine(CharSequence cs) { |
| 2042 | mTexts.add(cs); |
| 2043 | return this; |
| 2044 | } |
| 2045 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame^] | 2046 | /** |
| 2047 | * @hide |
| 2048 | */ |
| 2049 | public void addExtras(Bundle extras) { |
| 2050 | super.addExtras(extras); |
| 2051 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 2052 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 2053 | } |
| 2054 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2055 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2056 | // Remove the content text so line3 disappears unless you have a summary |
| 2057 | mBuilder.mContentText = null; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2058 | RemoteViews contentView = getStandardView(R.layout.notification_template_inbox); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2059 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2060 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2061 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2062 | int[] rowIds = {R.id.inbox_text0, R.id.inbox_text1, R.id.inbox_text2, R.id.inbox_text3, |
Chris Wren | 29bb6d9 | 2012-05-17 18:09:42 -0400 | [diff] [blame] | 2063 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2064 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 2065 | // Make sure all rows are gone in case we reuse a view. |
| 2066 | for (int rowId : rowIds) { |
| 2067 | contentView.setViewVisibility(rowId, View.GONE); |
| 2068 | } |
| 2069 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 2070 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2071 | int i=0; |
| 2072 | while (i < mTexts.size() && i < rowIds.length) { |
| 2073 | CharSequence str = mTexts.get(i); |
| 2074 | if (str != null && !str.equals("")) { |
| 2075 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
| 2076 | contentView.setTextViewText(rowIds[i], str); |
| 2077 | } |
| 2078 | i++; |
| 2079 | } |
| 2080 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 2081 | contentView.setViewVisibility(R.id.inbox_end_pad, |
| 2082 | mTexts.size() > 0 ? View.VISIBLE : View.GONE); |
| 2083 | |
| 2084 | contentView.setViewVisibility(R.id.inbox_more, |
| 2085 | mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE); |
Chris Wren | 29bb6d9 | 2012-05-17 18:09:42 -0400 | [diff] [blame] | 2086 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2087 | return contentView; |
| 2088 | } |
| 2089 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2090 | @Override |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2091 | public Notification build() { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2092 | checkBuilder(); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2093 | Notification wip = mBuilder.buildUnstyled(); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2094 | wip.bigContentView = makeBigContentView(); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2095 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 2096 | return wip; |
| 2097 | } |
| 2098 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 2099 | } |