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