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