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