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