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 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 19 | import android.annotation.IntDef; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.Intent; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 22 | import android.content.res.Resources; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 23 | import android.graphics.Bitmap; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 24 | import android.graphics.PorterDuff; |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 25 | import android.media.AudioManager; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 26 | import android.media.session.MediaSessionToken; |
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; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 29 | import android.os.Build; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 30 | import android.os.Bundle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 31 | import android.os.Parcel; |
| 32 | import android.os.Parcelable; |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 33 | import android.os.SystemClock; |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 34 | import android.os.UserHandle; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | import android.text.TextUtils; |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 36 | import android.util.Log; |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 37 | import android.util.TypedValue; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 38 | import android.view.Gravity; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 39 | import android.view.View; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 40 | import android.widget.ProgressBar; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 41 | import android.widget.RemoteViews; |
| 42 | |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 43 | import com.android.internal.R; |
Griff Hazen | c091ba8 | 2014-05-16 10:13:26 -0700 | [diff] [blame] | 44 | import com.android.internal.util.NotificationColorUtil; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 45 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 46 | import java.lang.annotation.Retention; |
| 47 | import java.lang.annotation.RetentionPolicy; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 48 | import java.text.NumberFormat; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 49 | import java.util.ArrayList; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 50 | import java.util.Arrays; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 51 | import java.util.Collections; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 52 | import java.util.List; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 53 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 54 | /** |
| 55 | * A class that represents how a persistent notification is to be presented to |
| 56 | * the user using the {@link android.app.NotificationManager}. |
| 57 | * |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 58 | * <p>The {@link Notification.Builder Notification.Builder} has been added to make it |
| 59 | * easier to construct Notifications.</p> |
| 60 | * |
Joe Fernandez | 558459f | 2011-10-13 16:47:36 -0700 | [diff] [blame] | 61 | * <div class="special reference"> |
| 62 | * <h3>Developer Guides</h3> |
| 63 | * <p>For a guide to creating notifications, read the |
| 64 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html">Status Bar Notifications</a> |
| 65 | * developer guide.</p> |
| 66 | * </div> |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 67 | */ |
| 68 | public class Notification implements Parcelable |
| 69 | { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 70 | private static final String TAG = "Notification"; |
| 71 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 72 | /** |
| 73 | * Use all default values (where applicable). |
| 74 | */ |
| 75 | public static final int DEFAULT_ALL = ~0; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 76 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 77 | /** |
| 78 | * Use the default notification sound. This will ignore any given |
| 79 | * {@link #sound}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 80 | * |
| 81 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 82 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 83 | */ |
| 84 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 85 | public static final int DEFAULT_SOUND = 1; |
| 86 | |
| 87 | /** |
| 88 | * Use the default notification vibrate. This will ignore any given |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 89 | * {@link #vibrate}. Using phone vibration requires the |
Scott Main | b8b3645 | 2009-04-26 15:50:49 -0700 | [diff] [blame] | 90 | * {@link android.Manifest.permission#VIBRATE VIBRATE} permission. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 91 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 92 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 93 | */ |
| 94 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 95 | public static final int DEFAULT_VIBRATE = 2; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 96 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 97 | /** |
| 98 | * Use the default notification lights. This will ignore the |
| 99 | * {@link #FLAG_SHOW_LIGHTS} bit, and {@link #ledARGB}, {@link #ledOffMS}, or |
| 100 | * {@link #ledOnMS}. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 101 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 102 | * @see #defaults |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 103 | */ |
| 104 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 105 | public static final int DEFAULT_LIGHTS = 4; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 106 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 107 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 108 | * A timestamp related to this notification, in milliseconds since the epoch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 109 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 110 | * Default value: {@link System#currentTimeMillis() Now}. |
| 111 | * |
| 112 | * Choose a timestamp that will be most relevant to the user. For most finite events, this |
| 113 | * corresponds to the time the event happened (or will happen, in the case of events that have |
| 114 | * 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] | 115 | * timestamped according to when the activity began. |
| 116 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 117 | * Some examples: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 118 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 119 | * <ul> |
| 120 | * <li>Notification of a new chat message should be stamped when the message was received.</li> |
| 121 | * <li>Notification of an ongoing file download (with a progress bar, for example) should be stamped when the download started.</li> |
| 122 | * <li>Notification of a completed file download should be stamped when the download finished.</li> |
| 123 | * <li>Notification of an upcoming meeting should be stamped with the time the meeting will begin (that is, in the future).</li> |
| 124 | * <li>Notification of an ongoing stopwatch (increasing timer) should be stamped with the watch's start time. |
| 125 | * <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] | 126 | * </ul> |
| 127 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 128 | */ |
| 129 | public long when; |
| 130 | |
| 131 | /** |
| 132 | * 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] | 133 | * 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] | 134 | */ |
| 135 | public int icon; |
| 136 | |
| 137 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 138 | * If the icon in the status bar is to have more than one level, you can set this. Otherwise, |
| 139 | * leave it at its default value of 0. |
| 140 | * |
| 141 | * @see android.widget.ImageView#setImageLevel |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 142 | * @see android.graphics.drawable.Drawable#setLevel |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 143 | */ |
| 144 | public int iconLevel; |
| 145 | |
| 146 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 147 | * The number of events that this notification represents. For example, in a new mail |
| 148 | * notification, this could be the number of unread messages. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 149 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 150 | * The system may or may not use this field to modify the appearance of the notification. For |
| 151 | * example, before {@link android.os.Build.VERSION_CODES#HONEYCOMB}, this number was |
| 152 | * superimposed over the icon in the status bar. Starting with |
| 153 | * {@link android.os.Build.VERSION_CODES#HONEYCOMB}, the template used by |
| 154 | * {@link Notification.Builder} has displayed the number in the expanded notification view. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 155 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 156 | * 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] | 157 | */ |
| 158 | public int number; |
| 159 | |
| 160 | /** |
| 161 | * The intent to execute when the expanded status entry is clicked. If |
| 162 | * this is an activity, it must include the |
| 163 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 164 | * that you take care of task management as described in the |
| 165 | * <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] | 166 | * Stack</a> document. In particular, make sure to read the notification section |
| 167 | * <a href="{@docRoot}guide/topics/ui/notifiers/notifications.html#HandlingNotifications">Handling |
| 168 | * Notifications</a> for the correct ways to launch an application from a |
| 169 | * notification. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 170 | */ |
| 171 | public PendingIntent contentIntent; |
| 172 | |
| 173 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 174 | * The intent to execute when the notification is explicitly dismissed by the user, either with |
| 175 | * the "Clear All" button or by swiping it away individually. |
| 176 | * |
| 177 | * This probably shouldn't be launching an activity since several of those will be sent |
| 178 | * at the same time. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 179 | */ |
| 180 | public PendingIntent deleteIntent; |
| 181 | |
| 182 | /** |
Dianne Hackborn | 170bae7 | 2010-09-03 15:14:28 -0700 | [diff] [blame] | 183 | * 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] | 184 | * |
| 185 | * @see Notification.Builder#setFullScreenIntent |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 186 | */ |
| 187 | public PendingIntent fullScreenIntent; |
| 188 | |
| 189 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 190 | * Text to scroll across the screen when this item is added to |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 191 | * the status bar on large and smaller devices. |
| 192 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 193 | * @see #tickerView |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 194 | */ |
| 195 | public CharSequence tickerText; |
| 196 | |
| 197 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 198 | * The view to show as the ticker in the status bar when the notification |
| 199 | * is posted. |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 200 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 201 | public RemoteViews tickerView; |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 202 | |
| 203 | /** |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 204 | * 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] | 205 | */ |
| 206 | public RemoteViews contentView; |
| 207 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 208 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 209 | * A large-format version of {@link #contentView}, giving the Notification an |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 210 | * opportunity to show more detail. The system UI may choose to show this |
| 211 | * instead of the normal content view at its discretion. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 212 | */ |
| 213 | public RemoteViews bigContentView; |
| 214 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 215 | |
| 216 | /** |
| 217 | * @hide |
| 218 | * A medium-format version of {@link #contentView}, giving the Notification an |
| 219 | * opportunity to add action buttons to contentView. The system UI may |
| 220 | * choose to show this as a popup notification at its discretion. |
| 221 | */ |
| 222 | public RemoteViews headsUpContentView; |
| 223 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 224 | /** |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 225 | * 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] | 226 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 227 | public Bitmap largeIcon; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 228 | |
| 229 | /** |
| 230 | * The sound to play. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 231 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 232 | * <p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 233 | * To play the default notification sound, see {@link #defaults}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 234 | * </p> |
| 235 | */ |
| 236 | public Uri sound; |
| 237 | |
| 238 | /** |
| 239 | * Use this constant as the value for audioStreamType to request that |
| 240 | * the default stream type for notifications be used. Currently the |
Jeff Sharkey | 098d580 | 2012-04-26 17:30:34 -0700 | [diff] [blame] | 241 | * default stream type is {@link AudioManager#STREAM_NOTIFICATION}. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 242 | */ |
| 243 | public static final int STREAM_DEFAULT = -1; |
| 244 | |
| 245 | /** |
| 246 | * The audio stream type to use when playing the sound. |
| 247 | * Should be one of the STREAM_ constants from |
| 248 | * {@link android.media.AudioManager}. |
| 249 | */ |
| 250 | public int audioStreamType = STREAM_DEFAULT; |
| 251 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 252 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 253 | * The pattern with which to vibrate. |
| 254 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 255 | * <p> |
| 256 | * To vibrate the default pattern, see {@link #defaults}. |
| 257 | * </p> |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 258 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 259 | * @see android.os.Vibrator#vibrate(long[],int) |
| 260 | */ |
| 261 | public long[] vibrate; |
| 262 | |
| 263 | /** |
| 264 | * The color of the led. The hardware will do its best approximation. |
| 265 | * |
| 266 | * @see #FLAG_SHOW_LIGHTS |
| 267 | * @see #flags |
| 268 | */ |
| 269 | public int ledARGB; |
| 270 | |
| 271 | /** |
| 272 | * The number of milliseconds for the LED to be on while it's flashing. |
| 273 | * The hardware will do its best approximation. |
| 274 | * |
| 275 | * @see #FLAG_SHOW_LIGHTS |
| 276 | * @see #flags |
| 277 | */ |
| 278 | public int ledOnMS; |
| 279 | |
| 280 | /** |
| 281 | * The number of milliseconds for the LED to be off while it's flashing. |
| 282 | * The hardware will do its best approximation. |
| 283 | * |
| 284 | * @see #FLAG_SHOW_LIGHTS |
| 285 | * @see #flags |
| 286 | */ |
| 287 | public int ledOffMS; |
| 288 | |
| 289 | /** |
| 290 | * Specifies which values should be taken from the defaults. |
| 291 | * <p> |
| 292 | * To set, OR the desired from {@link #DEFAULT_SOUND}, |
| 293 | * {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. For all default |
| 294 | * values, use {@link #DEFAULT_ALL}. |
| 295 | * </p> |
| 296 | */ |
| 297 | public int defaults; |
| 298 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 299 | /** |
| 300 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 301 | * set if you want the LED on for this notification. |
| 302 | * <ul> |
| 303 | * <li>To turn the LED off, pass 0 in the alpha channel for colorARGB |
| 304 | * or 0 for both ledOnMS and ledOffMS.</li> |
| 305 | * <li>To turn the LED on, pass 1 for ledOnMS and 0 for ledOffMS.</li> |
| 306 | * <li>To flash the LED, pass the number of milliseconds that it should |
| 307 | * be on and off to ledOnMS and ledOffMS.</li> |
| 308 | * </ul> |
| 309 | * <p> |
| 310 | * Since hardware varies, you are not guaranteed that any of the values |
| 311 | * you pass are honored exactly. Use the system defaults (TODO) if possible |
| 312 | * because they will be set to values that work on any given hardware. |
| 313 | * <p> |
| 314 | * The alpha channel must be set for forward compatibility. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 315 | * |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 316 | */ |
| 317 | public static final int FLAG_SHOW_LIGHTS = 0x00000001; |
| 318 | |
| 319 | /** |
| 320 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 321 | * set if this notification is in reference to something that is ongoing, |
| 322 | * like a phone call. It should not be set if this notification is in |
| 323 | * reference to something that happened at a particular point in time, |
| 324 | * like a missed phone call. |
| 325 | */ |
| 326 | public static final int FLAG_ONGOING_EVENT = 0x00000002; |
| 327 | |
| 328 | /** |
| 329 | * 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] | 330 | * the audio will be repeated until the notification is |
| 331 | * cancelled or the notification window is opened. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 332 | */ |
| 333 | public static final int FLAG_INSISTENT = 0x00000004; |
| 334 | |
| 335 | /** |
| 336 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
Griff Hazen | 293977b | 2014-04-28 08:37:20 -0700 | [diff] [blame] | 337 | * set if you would only like the sound, vibrate and ticker to be played |
| 338 | * if the notification was not already showing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 339 | */ |
| 340 | public static final int FLAG_ONLY_ALERT_ONCE = 0x00000008; |
| 341 | |
| 342 | /** |
| 343 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 344 | * 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] | 345 | * user. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 346 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 347 | */ |
| 348 | public static final int FLAG_AUTO_CANCEL = 0x00000010; |
| 349 | |
| 350 | /** |
| 351 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 352 | * set if the notification should not be canceled when the user clicks |
| 353 | * the Clear all button. |
| 354 | */ |
| 355 | public static final int FLAG_NO_CLEAR = 0x00000020; |
| 356 | |
Dianne Hackborn | d8a43f6 | 2009-08-17 23:33:56 -0700 | [diff] [blame] | 357 | /** |
| 358 | * Bit to be bitwise-ored into the {@link #flags} field that should be |
| 359 | * set if this notification represents a currently running service. This |
| 360 | * will normally be set for you by {@link Service#startForeground}. |
| 361 | */ |
| 362 | public static final int FLAG_FOREGROUND_SERVICE = 0x00000040; |
| 363 | |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 364 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 365 | * Obsolete flag indicating high-priority notifications; use the priority field instead. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 366 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 367 | * @deprecated Use {@link #priority} with a positive value. |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 368 | */ |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 369 | public static final int FLAG_HIGH_PRIORITY = 0x00000080; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 370 | |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 371 | /** |
| 372 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 373 | * set if this notification is relevant to the current device only |
| 374 | * and it is not recommended that it bridge to other devices. |
| 375 | */ |
| 376 | public static final int FLAG_LOCAL_ONLY = 0x00000100; |
| 377 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 378 | /** |
| 379 | * Bit to be bitswise-ored into the {@link #flags} field that should be |
| 380 | * set if this notification is the group summary for a group of notifications. |
| 381 | * Grouped notifications may display in a cluster or stack on devices which |
| 382 | * support such rendering. Requires a group key also be set using {@link Builder#setGroup}. |
| 383 | */ |
| 384 | public static final int FLAG_GROUP_SUMMARY = 0x00000200; |
| 385 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 386 | public int flags; |
| 387 | |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 388 | /** @hide */ |
| 389 | @IntDef({PRIORITY_DEFAULT,PRIORITY_LOW,PRIORITY_MIN,PRIORITY_HIGH,PRIORITY_MAX}) |
| 390 | @Retention(RetentionPolicy.SOURCE) |
| 391 | public @interface Priority {} |
| 392 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 393 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 394 | * Default notification {@link #priority}. If your application does not prioritize its own |
| 395 | * notifications, use this value for all notifications. |
| 396 | */ |
| 397 | public static final int PRIORITY_DEFAULT = 0; |
| 398 | |
| 399 | /** |
| 400 | * Lower {@link #priority}, for items that are less important. The UI may choose to show these |
| 401 | * items smaller, or at a different position in the list, compared with your app's |
| 402 | * {@link #PRIORITY_DEFAULT} items. |
| 403 | */ |
| 404 | public static final int PRIORITY_LOW = -1; |
| 405 | |
| 406 | /** |
| 407 | * Lowest {@link #priority}; these items might not be shown to the user except under special |
| 408 | * circumstances, such as detailed notification logs. |
| 409 | */ |
| 410 | public static final int PRIORITY_MIN = -2; |
| 411 | |
| 412 | /** |
| 413 | * Higher {@link #priority}, for more important notifications or alerts. The UI may choose to |
| 414 | * show these items larger, or at a different position in notification lists, compared with |
| 415 | * your app's {@link #PRIORITY_DEFAULT} items. |
| 416 | */ |
| 417 | public static final int PRIORITY_HIGH = 1; |
| 418 | |
| 419 | /** |
| 420 | * Highest {@link #priority}, for your application's most important items that require the |
| 421 | * user's prompt attention or input. |
| 422 | */ |
| 423 | public static final int PRIORITY_MAX = 2; |
| 424 | |
| 425 | /** |
| 426 | * Relative priority for this notification. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 427 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 428 | * Priority is an indication of how much of the user's valuable attention should be consumed by |
| 429 | * this notification. Low-priority notifications may be hidden from the user in certain |
| 430 | * 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] | 431 | * system will make a determination about how to interpret this priority when presenting |
| 432 | * the notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 433 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 434 | @Priority |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 435 | public int priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 436 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 437 | /** |
| 438 | * Accent color (an ARGB integer like the constants in {@link android.graphics.Color}) |
| 439 | * to be applied by the standard Style templates when presenting this notification. |
| 440 | * |
| 441 | * The current template design constructs a colorful header image by overlaying the |
| 442 | * {@link #icon} image (stenciled in white) atop a field of this color. Alpha components are |
| 443 | * ignored. |
| 444 | */ |
| 445 | public int color = COLOR_DEFAULT; |
| 446 | |
| 447 | /** |
| 448 | * Special value of {@link #color} telling the system not to decorate this notification with |
| 449 | * any special color but instead use default colors when presenting this notification. |
| 450 | */ |
| 451 | public static final int COLOR_DEFAULT = 0; // AKA Color.TRANSPARENT |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 452 | |
| 453 | /** |
| 454 | * Sphere of visibility of this notification, which affects how and when the SystemUI reveals |
| 455 | * the notification's presence and contents in untrusted situations (namely, on the secure |
| 456 | * lockscreen). |
| 457 | * |
| 458 | * The default level, {@link #VISIBILITY_PRIVATE}, behaves exactly as notifications have always |
| 459 | * done on Android: The notification's {@link #icon} and {@link #tickerText} (if available) are |
| 460 | * shown in all situations, but the contents are only available if the device is unlocked for |
| 461 | * the appropriate user. |
| 462 | * |
| 463 | * A more permissive policy can be expressed by {@link #VISIBILITY_PUBLIC}; such a notification |
| 464 | * can be read even in an "insecure" context (that is, above a secure lockscreen). |
| 465 | * To modify the public version of this notification—for example, to redact some portions—see |
| 466 | * {@link Builder#setPublicVersion(Notification)}. |
| 467 | * |
| 468 | * Finally, a notification can be made {@link #VISIBILITY_SECRET}, which will suppress its icon |
| 469 | * and ticker until the user has bypassed the lockscreen. |
| 470 | */ |
| 471 | public int visibility; |
| 472 | |
| 473 | public static final int VISIBILITY_PUBLIC = 1; |
| 474 | public static final int VISIBILITY_PRIVATE = 0; |
| 475 | public static final int VISIBILITY_SECRET = -1; |
| 476 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 477 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 478 | * Notification category: incoming call (voice or video) or similar synchronous communication request. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 479 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 480 | public static final String CATEGORY_CALL = "call"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 481 | |
| 482 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 483 | * Notification category: incoming direct message (SMS, instant message, etc.). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 484 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 485 | public static final String CATEGORY_MESSAGE = "msg"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 486 | |
| 487 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 488 | * Notification category: asynchronous bulk message (email). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 489 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 490 | public static final String CATEGORY_EMAIL = "email"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 491 | |
| 492 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 493 | * Notification category: calendar event. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 494 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 495 | public static final String CATEGORY_EVENT = "event"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 496 | |
| 497 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 498 | * Notification category: promotion or advertisement. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 499 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 500 | public static final String CATEGORY_PROMO = "promo"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 501 | |
| 502 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 503 | * Notification category: alarm or timer. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 504 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 505 | public static final String CATEGORY_ALARM = "alarm"; |
| 506 | |
| 507 | /** |
| 508 | * Notification category: progress of a long-running background operation. |
| 509 | */ |
| 510 | public static final String CATEGORY_PROGRESS = "progress"; |
| 511 | |
| 512 | /** |
| 513 | * Notification category: social network or sharing update. |
| 514 | */ |
| 515 | public static final String CATEGORY_SOCIAL = "social"; |
| 516 | |
| 517 | /** |
| 518 | * Notification category: error in background operation or authentication status. |
| 519 | */ |
| 520 | public static final String CATEGORY_ERROR = "err"; |
| 521 | |
| 522 | /** |
| 523 | * Notification category: media transport control for playback. |
| 524 | */ |
| 525 | public static final String CATEGORY_TRANSPORT = "transport"; |
| 526 | |
| 527 | /** |
| 528 | * Notification category: system or device status update. Reserved for system use. |
| 529 | */ |
| 530 | public static final String CATEGORY_SYSTEM = "sys"; |
| 531 | |
| 532 | /** |
| 533 | * Notification category: indication of running background service. |
| 534 | */ |
| 535 | public static final String CATEGORY_SERVICE = "service"; |
| 536 | |
| 537 | /** |
John Spurlock | 0a69c8c | 2014-03-21 13:30:57 -0400 | [diff] [blame] | 538 | * Notification category: a specific, timely recommendation for a single thing. |
| 539 | * For example, a news app might want to recommend a news story it believes the user will |
| 540 | * want to read next. |
| 541 | */ |
| 542 | public static final String CATEGORY_RECOMMENDATION = "recommendation"; |
| 543 | |
| 544 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 545 | * Notification category: ongoing information about device or contextual status. |
| 546 | */ |
| 547 | public static final String CATEGORY_STATUS = "status"; |
| 548 | |
| 549 | /** |
| 550 | * One of the predefined notification categories (see the <code>CATEGORY_*</code> constants) |
| 551 | * that best describes this Notification. May be used by the system for ranking and filtering. |
| 552 | */ |
| 553 | public String category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 554 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 555 | private String mGroupKey; |
| 556 | |
| 557 | /** |
| 558 | * Get the key used to group this notification into a cluster or stack |
| 559 | * with other notifications on devices which support such rendering. |
| 560 | */ |
| 561 | public String getGroup() { |
| 562 | return mGroupKey; |
| 563 | } |
| 564 | |
| 565 | private String mSortKey; |
| 566 | |
| 567 | /** |
| 568 | * Get a sort key that orders this notification among other notifications from the |
| 569 | * same package. This can be useful if an external sort was already applied and an app |
| 570 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 571 | * value, although providing different priorities in addition to providing sort key may |
| 572 | * cause this value to be ignored. |
| 573 | * |
| 574 | * <p>This sort key can also be used to order members of a notification group. See |
| 575 | * {@link Builder#setGroup}. |
| 576 | * |
| 577 | * @see String#compareTo(String) |
| 578 | */ |
| 579 | public String getSortKey() { |
| 580 | return mSortKey; |
| 581 | } |
| 582 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 583 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 584 | * Additional semantic data to be carried around with this Notification. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 585 | * <p> |
| 586 | * The extras keys defined here are intended to capture the original inputs to {@link Builder} |
| 587 | * APIs, and are intended to be used by |
| 588 | * {@link android.service.notification.NotificationListenerService} implementations to extract |
| 589 | * detailed information from notification objects. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 590 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 591 | public Bundle extras = new Bundle(); |
| 592 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 593 | /** |
| 594 | * {@link #extras} key: this is the title of the notification, |
| 595 | * as supplied to {@link Builder#setContentTitle(CharSequence)}. |
| 596 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 597 | public static final String EXTRA_TITLE = "android.title"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 598 | |
| 599 | /** |
| 600 | * {@link #extras} key: this is the title of the notification when shown in expanded form, |
| 601 | * e.g. as supplied to {@link BigTextStyle#setBigContentTitle(CharSequence)}. |
| 602 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 603 | public static final String EXTRA_TITLE_BIG = EXTRA_TITLE + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 604 | |
| 605 | /** |
| 606 | * {@link #extras} key: this is the main text payload, as supplied to |
| 607 | * {@link Builder#setContentText(CharSequence)}. |
| 608 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 609 | public static final String EXTRA_TEXT = "android.text"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 610 | |
| 611 | /** |
| 612 | * {@link #extras} key: this is a third line of text, as supplied to |
| 613 | * {@link Builder#setSubText(CharSequence)}. |
| 614 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 615 | public static final String EXTRA_SUB_TEXT = "android.subText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 616 | |
| 617 | /** |
| 618 | * {@link #extras} key: this is a small piece of additional text as supplied to |
| 619 | * {@link Builder#setContentInfo(CharSequence)}. |
| 620 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 621 | public static final String EXTRA_INFO_TEXT = "android.infoText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 622 | |
| 623 | /** |
| 624 | * {@link #extras} key: this is a line of summary information intended to be shown |
| 625 | * alongside expanded notifications, as supplied to (e.g.) |
| 626 | * {@link BigTextStyle#setSummaryText(CharSequence)}. |
| 627 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 628 | public static final String EXTRA_SUMMARY_TEXT = "android.summaryText"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 629 | |
| 630 | /** |
| 631 | * {@link #extras} key: this is the resource ID of the notification's main small icon, as |
| 632 | * supplied to {@link Builder#setSmallIcon(int)}. |
| 633 | */ |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 634 | public static final String EXTRA_SMALL_ICON = "android.icon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 635 | |
| 636 | /** |
| 637 | * {@link #extras} key: this is a bitmap to be used instead of the small icon when showing the |
| 638 | * notification payload, as |
| 639 | * supplied to {@link Builder#setLargeIcon(android.graphics.Bitmap)}. |
| 640 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 641 | public static final String EXTRA_LARGE_ICON = "android.largeIcon"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 642 | |
| 643 | /** |
| 644 | * {@link #extras} key: this is a bitmap to be used instead of the one from |
| 645 | * {@link Builder#setLargeIcon(android.graphics.Bitmap)} when the notification is |
| 646 | * shown in its expanded form, as supplied to |
| 647 | * {@link BigPictureStyle#bigLargeIcon(android.graphics.Bitmap)}. |
| 648 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 649 | public static final String EXTRA_LARGE_ICON_BIG = EXTRA_LARGE_ICON + ".big"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 650 | |
| 651 | /** |
| 652 | * {@link #extras} key: this is the progress value supplied to |
| 653 | * {@link Builder#setProgress(int, int, boolean)}. |
| 654 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 655 | public static final String EXTRA_PROGRESS = "android.progress"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 656 | |
| 657 | /** |
| 658 | * {@link #extras} key: this is the maximum value supplied to |
| 659 | * {@link Builder#setProgress(int, int, boolean)}. |
| 660 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 661 | public static final String EXTRA_PROGRESS_MAX = "android.progressMax"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 662 | |
| 663 | /** |
| 664 | * {@link #extras} key: whether the progress bar is indeterminate, supplied to |
| 665 | * {@link Builder#setProgress(int, int, boolean)}. |
| 666 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 667 | public static final String EXTRA_PROGRESS_INDETERMINATE = "android.progressIndeterminate"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 668 | |
| 669 | /** |
| 670 | * {@link #extras} key: whether {@link #when} should be shown as a count-up timer (specifically |
| 671 | * a {@link android.widget.Chronometer}) instead of a timestamp, as supplied to |
| 672 | * {@link Builder#setUsesChronometer(boolean)}. |
| 673 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 674 | public static final String EXTRA_SHOW_CHRONOMETER = "android.showChronometer"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 675 | |
| 676 | /** |
| 677 | * {@link #extras} key: whether {@link #when} should be shown, |
| 678 | * as supplied to {@link Builder#setShowWhen(boolean)}. |
| 679 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 680 | public static final String EXTRA_SHOW_WHEN = "android.showWhen"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 681 | |
| 682 | /** |
| 683 | * {@link #extras} key: this is a bitmap to be shown in {@link BigPictureStyle} expanded |
| 684 | * notifications, supplied to {@link BigPictureStyle#bigPicture(android.graphics.Bitmap)}. |
| 685 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 686 | public static final String EXTRA_PICTURE = "android.picture"; |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 687 | |
| 688 | /** |
| 689 | * {@link #extras} key: An array of CharSequences to show in {@link InboxStyle} expanded |
| 690 | * notifications, each of which was supplied to {@link InboxStyle#addLine(CharSequence)}. |
| 691 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 692 | public static final String EXTRA_TEXT_LINES = "android.textLines"; |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 693 | |
| 694 | /** |
| 695 | * {@link #extras} key: A string representing the name of the specific |
| 696 | * {@link android.app.Notification.Style} used to create this notification. |
| 697 | */ |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 698 | public static final String EXTRA_TEMPLATE = "android.template"; |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 699 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 700 | /** |
| 701 | * {@link #extras} key: An array of people that this notification relates to, specified |
| 702 | * by contacts provider contact URI. |
| 703 | */ |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 704 | public static final String EXTRA_PEOPLE = "android.people"; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 705 | |
| 706 | /** |
Scott Greenwald | 9a05b31 | 2013-06-28 00:37:54 -0400 | [diff] [blame] | 707 | * @hide |
Chris Wren | f953664 | 2014-04-17 10:01:54 -0400 | [diff] [blame] | 708 | * Extra added by NotificationManagerService to indicate whether |
| 709 | * the Notifications's score has been modified. |
Scott Greenwald | 9a05b31 | 2013-06-28 00:37:54 -0400 | [diff] [blame] | 710 | */ |
| 711 | public static final String EXTRA_SCORE_MODIFIED = "android.scoreModified"; |
| 712 | |
| 713 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 714 | * Not used. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 715 | * @hide |
| 716 | */ |
| 717 | public static final String EXTRA_AS_HEADS_UP = "headsup"; |
| 718 | |
| 719 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 720 | * Allow certain system-generated notifications to appear before the device is provisioned. |
| 721 | * Only available to notifications coming from the android package. |
| 722 | * @hide |
| 723 | */ |
| 724 | public static final String EXTRA_ALLOW_DURING_SETUP = "android.allowDuringSetup"; |
| 725 | |
| 726 | /** |
Jose Lima | e9e3b3b | 2014-05-18 23:44:50 -0700 | [diff] [blame] | 727 | * {@link #extras} key: A |
| 728 | * {@link android.content.ContentUris content URI} pointing to an image that can be displayed |
| 729 | * in the background when the notification is selected. The URI must point to an image stream |
| 730 | * suitable for passing into |
| 731 | * {@link android.graphics.BitmapFactory#decodeStream(java.io.InputStream) |
| 732 | * BitmapFactory.decodeStream}; all other content types will be ignored. The content provider |
| 733 | * URI used for this purpose must require no permissions to read the image data. |
| 734 | */ |
| 735 | public static final String EXTRA_BACKGROUND_IMAGE_URI = "android.backgroundImageUri"; |
| 736 | |
| 737 | /** |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 738 | * {@link #extras} key: A |
| 739 | * {@link android.media.session.MediaSessionToken} associated with a |
| 740 | * {@link android.app.Notification.MediaStyle} notification. |
| 741 | */ |
| 742 | public static final String EXTRA_MEDIA_SESSION = "android.mediaSession"; |
| 743 | |
| 744 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 745 | * Value for {@link #EXTRA_AS_HEADS_UP}. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 746 | * @hide |
| 747 | */ |
| 748 | public static final int HEADS_UP_NEVER = 0; |
| 749 | |
| 750 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 751 | * Default value for {@link #EXTRA_AS_HEADS_UP}. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 752 | * @hide |
| 753 | */ |
| 754 | public static final int HEADS_UP_ALLOWED = 1; |
| 755 | |
| 756 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 757 | * Value for {@link #EXTRA_AS_HEADS_UP}. |
Chris Wren | 51c7510 | 2013-07-16 20:49:17 -0400 | [diff] [blame] | 758 | * @hide |
| 759 | */ |
| 760 | public static final int HEADS_UP_REQUESTED = 2; |
| 761 | |
| 762 | /** |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 763 | * Structure to encapsulate a named action that can be shown as part of this notification. |
| 764 | * It must include an icon, a label, and a {@link PendingIntent} to be fired when the action is |
| 765 | * selected by the user. |
| 766 | * <p> |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 767 | * Apps should use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)} |
| 768 | * or {@link Notification.Builder#addAction(Notification.Action)} |
| 769 | * to attach actions. |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 770 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 771 | public static class Action implements Parcelable { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 772 | private final Bundle mExtras; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 773 | private final RemoteInput[] mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 774 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 775 | /** |
| 776 | * Small icon representing the action. |
| 777 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 778 | public int icon; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 779 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 780 | /** |
| 781 | * Title of the action. |
| 782 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 783 | public CharSequence title; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 784 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 785 | /** |
| 786 | * Intent to send when the user invokes this action. May be null, in which case the action |
| 787 | * may be rendered in a disabled presentation by the system UI. |
| 788 | */ |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 789 | public PendingIntent actionIntent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 790 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 791 | private Action(Parcel in) { |
| 792 | icon = in.readInt(); |
| 793 | title = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(in); |
| 794 | if (in.readInt() == 1) { |
| 795 | actionIntent = PendingIntent.CREATOR.createFromParcel(in); |
| 796 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 797 | mExtras = in.readBundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 798 | mRemoteInputs = in.createTypedArray(RemoteInput.CREATOR); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 799 | } |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 800 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 801 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 802 | * Use {@link Notification.Builder#addAction(int, CharSequence, PendingIntent)}. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 803 | */ |
| 804 | public Action(int icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 805 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 806 | } |
| 807 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 808 | private Action(int icon, CharSequence title, PendingIntent intent, Bundle extras, |
| 809 | RemoteInput[] remoteInputs) { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 810 | this.icon = icon; |
| 811 | this.title = title; |
| 812 | this.actionIntent = intent; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 813 | this.mExtras = extras != null ? extras : new Bundle(); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 814 | this.mRemoteInputs = remoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 815 | } |
| 816 | |
| 817 | /** |
| 818 | * Get additional metadata carried around with this Action. |
| 819 | */ |
| 820 | public Bundle getExtras() { |
| 821 | return mExtras; |
| 822 | } |
| 823 | |
| 824 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 825 | * Get the list of inputs to be collected from the user when this action is sent. |
| 826 | * May return null if no remote inputs were added. |
| 827 | */ |
| 828 | public RemoteInput[] getRemoteInputs() { |
| 829 | return mRemoteInputs; |
| 830 | } |
| 831 | |
| 832 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 833 | * Builder class for {@link Action} objects. |
| 834 | */ |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 835 | public static final class Builder { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 836 | private final int mIcon; |
| 837 | private final CharSequence mTitle; |
| 838 | private final PendingIntent mIntent; |
| 839 | private final Bundle mExtras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 840 | private ArrayList<RemoteInput> mRemoteInputs; |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 841 | |
| 842 | /** |
| 843 | * Construct a new builder for {@link Action} object. |
| 844 | * @param icon icon to show for this action |
| 845 | * @param title the title of the action |
| 846 | * @param intent the {@link PendingIntent} to fire when users trigger this action |
| 847 | */ |
| 848 | public Builder(int icon, CharSequence title, PendingIntent intent) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 849 | this(icon, title, intent, new Bundle(), null); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | /** |
| 853 | * Construct a new builder for {@link Action} object using the fields from an |
| 854 | * {@link Action}. |
| 855 | * @param action the action to read fields from. |
| 856 | */ |
| 857 | public Builder(Action action) { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 858 | this(action.icon, action.title, action.actionIntent, new Bundle(action.mExtras), |
| 859 | action.getRemoteInputs()); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 860 | } |
| 861 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 862 | private Builder(int icon, CharSequence title, PendingIntent intent, Bundle extras, |
| 863 | RemoteInput[] remoteInputs) { |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 864 | mIcon = icon; |
| 865 | mTitle = title; |
| 866 | mIntent = intent; |
| 867 | mExtras = extras; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 868 | if (remoteInputs != null) { |
| 869 | mRemoteInputs = new ArrayList<RemoteInput>(remoteInputs.length); |
| 870 | Collections.addAll(mRemoteInputs, remoteInputs); |
| 871 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 872 | } |
| 873 | |
| 874 | /** |
| 875 | * Merge additional metadata into this builder. |
| 876 | * |
| 877 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 878 | * |
| 879 | * @see Notification.Action#extras |
| 880 | */ |
| 881 | public Builder addExtras(Bundle extras) { |
| 882 | if (extras != null) { |
| 883 | mExtras.putAll(extras); |
| 884 | } |
| 885 | return this; |
| 886 | } |
| 887 | |
| 888 | /** |
| 889 | * Get the metadata Bundle used by this Builder. |
| 890 | * |
| 891 | * <p>The returned Bundle is shared with this Builder. |
| 892 | */ |
| 893 | public Bundle getExtras() { |
| 894 | return mExtras; |
| 895 | } |
| 896 | |
| 897 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 898 | * Add an input to be collected from the user when this action is sent. |
| 899 | * Response values can be retrieved from the fired intent by using the |
| 900 | * {@link RemoteInput#getResultsFromIntent} function. |
| 901 | * @param remoteInput a {@link RemoteInput} to add to the action |
| 902 | * @return this object for method chaining |
| 903 | */ |
| 904 | public Builder addRemoteInput(RemoteInput remoteInput) { |
| 905 | if (mRemoteInputs == null) { |
| 906 | mRemoteInputs = new ArrayList<RemoteInput>(); |
| 907 | } |
| 908 | mRemoteInputs.add(remoteInput); |
| 909 | return this; |
| 910 | } |
| 911 | |
| 912 | /** |
| 913 | * Apply an extender to this action builder. Extenders may be used to add |
| 914 | * metadata or change options on this builder. |
| 915 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 916 | public Builder extend(Extender extender) { |
| 917 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 918 | return this; |
| 919 | } |
| 920 | |
| 921 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 922 | * Combine all of the options that have been set and return a new {@link Action} |
| 923 | * object. |
| 924 | * @return the built action |
| 925 | */ |
| 926 | public Action build() { |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 927 | RemoteInput[] remoteInputs = mRemoteInputs != null |
| 928 | ? mRemoteInputs.toArray(new RemoteInput[mRemoteInputs.size()]) : null; |
| 929 | return new Action(mIcon, mTitle, mIntent, mExtras, remoteInputs); |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 930 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 931 | } |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 932 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 933 | @Override |
| 934 | public Action clone() { |
| 935 | return new Action( |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 936 | icon, |
| 937 | title, |
| 938 | actionIntent, // safe to alias |
| 939 | new Bundle(mExtras), |
| 940 | getRemoteInputs()); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 941 | } |
| 942 | @Override |
| 943 | public int describeContents() { |
| 944 | return 0; |
| 945 | } |
| 946 | @Override |
| 947 | public void writeToParcel(Parcel out, int flags) { |
| 948 | out.writeInt(icon); |
| 949 | TextUtils.writeToParcel(title, out, flags); |
| 950 | if (actionIntent != null) { |
| 951 | out.writeInt(1); |
| 952 | actionIntent.writeToParcel(out, flags); |
| 953 | } else { |
| 954 | out.writeInt(0); |
| 955 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 956 | out.writeBundle(mExtras); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 957 | out.writeTypedArray(mRemoteInputs, flags); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 958 | } |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 959 | public static final Parcelable.Creator<Action> CREATOR = |
| 960 | new Parcelable.Creator<Action>() { |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 961 | public Action createFromParcel(Parcel in) { |
| 962 | return new Action(in); |
| 963 | } |
| 964 | public Action[] newArray(int size) { |
| 965 | return new Action[size]; |
| 966 | } |
| 967 | }; |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 968 | |
| 969 | /** |
| 970 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 971 | * metadata or change options on an action builder. |
| 972 | */ |
| 973 | public interface Extender { |
| 974 | /** |
| 975 | * Apply this extender to a notification action builder. |
| 976 | * @param builder the builder to be modified. |
| 977 | * @return the build object for chaining. |
| 978 | */ |
| 979 | public Builder extend(Builder builder); |
| 980 | } |
| 981 | |
| 982 | /** |
| 983 | * Wearable extender for notification actions. To add extensions to an action, |
| 984 | * create a new {@link android.app.Notification.Action.WearableExtender} object using |
| 985 | * the {@code WearableExtender()} constructor and apply it to a |
| 986 | * {@link android.app.Notification.Action.Builder} using |
| 987 | * {@link android.app.Notification.Action.Builder#extend}. |
| 988 | * |
| 989 | * <pre class="prettyprint"> |
| 990 | * Notification.Action action = new Notification.Action.Builder( |
| 991 | * R.drawable.archive_all, "Archive all", actionIntent) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame^] | 992 | * .extend(new Notification.Action.WearableExtender() |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 993 | * .setAvailableOffline(false)) |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame^] | 994 | * .build();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 995 | */ |
| 996 | public static final class WearableExtender implements Extender { |
| 997 | /** Notification action extra which contains wearable extensions */ |
| 998 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 999 | |
| 1000 | private static final String KEY_FLAGS = "flags"; |
| 1001 | |
| 1002 | // Flags bitwise-ored to mFlags |
| 1003 | private static final int FLAG_AVAILABLE_OFFLINE = 0x1; |
| 1004 | |
| 1005 | // Default value for flags integer |
| 1006 | private static final int DEFAULT_FLAGS = FLAG_AVAILABLE_OFFLINE; |
| 1007 | |
| 1008 | private int mFlags = DEFAULT_FLAGS; |
| 1009 | |
| 1010 | /** |
| 1011 | * Create a {@link android.app.Notification.Action.WearableExtender} with default |
| 1012 | * options. |
| 1013 | */ |
| 1014 | public WearableExtender() { |
| 1015 | } |
| 1016 | |
| 1017 | /** |
| 1018 | * Create a {@link android.app.Notification.Action.WearableExtender} by reading |
| 1019 | * wearable options present in an existing notification action. |
| 1020 | * @param action the notification action to inspect. |
| 1021 | */ |
| 1022 | public WearableExtender(Action action) { |
| 1023 | Bundle wearableBundle = action.getExtras().getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 1024 | if (wearableBundle != null) { |
| 1025 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 1026 | } |
| 1027 | } |
| 1028 | |
| 1029 | /** |
| 1030 | * Apply wearable extensions to a notification action that is being built. This is |
| 1031 | * typically called by the {@link android.app.Notification.Action.Builder#extend} |
| 1032 | * method of {@link android.app.Notification.Action.Builder}. |
| 1033 | */ |
| 1034 | @Override |
| 1035 | public Action.Builder extend(Action.Builder builder) { |
| 1036 | Bundle wearableBundle = new Bundle(); |
| 1037 | |
| 1038 | if (mFlags != DEFAULT_FLAGS) { |
| 1039 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 1040 | } |
| 1041 | |
| 1042 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 1043 | return builder; |
| 1044 | } |
| 1045 | |
| 1046 | @Override |
| 1047 | public WearableExtender clone() { |
| 1048 | WearableExtender that = new WearableExtender(); |
| 1049 | that.mFlags = this.mFlags; |
| 1050 | return that; |
| 1051 | } |
| 1052 | |
| 1053 | /** |
| 1054 | * Set whether this action is available when the wearable device is not connected to |
| 1055 | * a companion device. The user can still trigger this action when the wearable device is |
| 1056 | * offline, but a visual hint will indicate that the action may not be available. |
| 1057 | * Defaults to true. |
| 1058 | */ |
| 1059 | public WearableExtender setAvailableOffline(boolean availableOffline) { |
| 1060 | setFlag(FLAG_AVAILABLE_OFFLINE, availableOffline); |
| 1061 | return this; |
| 1062 | } |
| 1063 | |
| 1064 | /** |
| 1065 | * Get whether this action is available when the wearable device is not connected to |
| 1066 | * a companion device. The user can still trigger this action when the wearable device is |
| 1067 | * offline, but a visual hint will indicate that the action may not be available. |
| 1068 | * Defaults to true. |
| 1069 | */ |
| 1070 | public boolean isAvailableOffline() { |
| 1071 | return (mFlags & FLAG_AVAILABLE_OFFLINE) != 0; |
| 1072 | } |
| 1073 | |
| 1074 | private void setFlag(int mask, boolean value) { |
| 1075 | if (value) { |
| 1076 | mFlags |= mask; |
| 1077 | } else { |
| 1078 | mFlags &= ~mask; |
| 1079 | } |
| 1080 | } |
| 1081 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1082 | } |
| 1083 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 1084 | /** |
| 1085 | * Array of all {@link Action} structures attached to this notification by |
| 1086 | * {@link Builder#addAction(int, CharSequence, PendingIntent)}. Mostly useful for instances of |
| 1087 | * {@link android.service.notification.NotificationListenerService} that provide an alternative |
| 1088 | * interface for invoking actions. |
| 1089 | */ |
Daniel Sandler | ea2a317 | 2013-02-20 22:24:20 -0500 | [diff] [blame] | 1090 | public Action[] actions; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1091 | |
| 1092 | /** |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1093 | * Replacement version of this notification whose content will be shown |
| 1094 | * in an insecure context such as atop a secure keyguard. See {@link #visibility} |
| 1095 | * and {@link #VISIBILITY_PUBLIC}. |
| 1096 | */ |
| 1097 | public Notification publicVersion; |
| 1098 | |
| 1099 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1100 | * Constructs a Notification object with default values. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1101 | * You might want to consider using {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1102 | */ |
| 1103 | public Notification() |
| 1104 | { |
| 1105 | this.when = System.currentTimeMillis(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1106 | this.priority = PRIORITY_DEFAULT; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1107 | } |
| 1108 | |
| 1109 | /** |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1110 | * @hide |
| 1111 | */ |
| 1112 | public Notification(Context context, int icon, CharSequence tickerText, long when, |
| 1113 | CharSequence contentTitle, CharSequence contentText, Intent contentIntent) |
| 1114 | { |
| 1115 | this.when = when; |
| 1116 | this.icon = icon; |
| 1117 | this.tickerText = tickerText; |
| 1118 | setLatestEventInfo(context, contentTitle, contentText, |
| 1119 | PendingIntent.getActivity(context, 0, contentIntent, 0)); |
| 1120 | } |
| 1121 | |
| 1122 | /** |
| 1123 | * Constructs a Notification object with the information needed to |
| 1124 | * have a status bar icon without the standard expanded view. |
| 1125 | * |
| 1126 | * @param icon The resource id of the icon to put in the status bar. |
| 1127 | * @param tickerText The text that flows by in the status bar when the notification first |
| 1128 | * activates. |
| 1129 | * @param when The time to show in the time field. In the System.currentTimeMillis |
| 1130 | * timebase. |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1131 | * |
| 1132 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1133 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1134 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1135 | public Notification(int icon, CharSequence tickerText, long when) |
| 1136 | { |
| 1137 | this.icon = icon; |
| 1138 | this.tickerText = tickerText; |
| 1139 | this.when = when; |
| 1140 | } |
| 1141 | |
| 1142 | /** |
| 1143 | * Unflatten the notification from a parcel. |
| 1144 | */ |
| 1145 | public Notification(Parcel parcel) |
| 1146 | { |
| 1147 | int version = parcel.readInt(); |
| 1148 | |
| 1149 | when = parcel.readLong(); |
| 1150 | icon = parcel.readInt(); |
| 1151 | number = parcel.readInt(); |
| 1152 | if (parcel.readInt() != 0) { |
| 1153 | contentIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1154 | } |
| 1155 | if (parcel.readInt() != 0) { |
| 1156 | deleteIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1157 | } |
| 1158 | if (parcel.readInt() != 0) { |
| 1159 | tickerText = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(parcel); |
| 1160 | } |
| 1161 | if (parcel.readInt() != 0) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1162 | tickerView = RemoteViews.CREATOR.createFromParcel(parcel); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1163 | } |
| 1164 | if (parcel.readInt() != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1165 | contentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1166 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1167 | if (parcel.readInt() != 0) { |
| 1168 | largeIcon = Bitmap.CREATOR.createFromParcel(parcel); |
| 1169 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1170 | defaults = parcel.readInt(); |
| 1171 | flags = parcel.readInt(); |
| 1172 | if (parcel.readInt() != 0) { |
| 1173 | sound = Uri.CREATOR.createFromParcel(parcel); |
| 1174 | } |
| 1175 | |
| 1176 | audioStreamType = parcel.readInt(); |
| 1177 | vibrate = parcel.createLongArray(); |
| 1178 | ledARGB = parcel.readInt(); |
| 1179 | ledOnMS = parcel.readInt(); |
| 1180 | ledOffMS = parcel.readInt(); |
| 1181 | iconLevel = parcel.readInt(); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1182 | |
| 1183 | if (parcel.readInt() != 0) { |
| 1184 | fullScreenIntent = PendingIntent.CREATOR.createFromParcel(parcel); |
| 1185 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1186 | |
| 1187 | priority = parcel.readInt(); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1188 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1189 | category = parcel.readString(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1190 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1191 | mGroupKey = parcel.readString(); |
| 1192 | |
| 1193 | mSortKey = parcel.readString(); |
| 1194 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1195 | extras = parcel.readBundle(); // may be null |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1196 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1197 | actions = parcel.createTypedArray(Action.CREATOR); // may be null |
| 1198 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1199 | if (parcel.readInt() != 0) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1200 | bigContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1201 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1202 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1203 | if (parcel.readInt() != 0) { |
| 1204 | headsUpContentView = RemoteViews.CREATOR.createFromParcel(parcel); |
| 1205 | } |
| 1206 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1207 | visibility = parcel.readInt(); |
| 1208 | |
| 1209 | if (parcel.readInt() != 0) { |
| 1210 | publicVersion = Notification.CREATOR.createFromParcel(parcel); |
| 1211 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1212 | |
| 1213 | color = parcel.readInt(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1214 | } |
| 1215 | |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1216 | @Override |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1217 | public Notification clone() { |
| 1218 | Notification that = new Notification(); |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1219 | cloneInto(that, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1220 | return that; |
| 1221 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1222 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1223 | /** |
| 1224 | * Copy all (or if heavy is false, all except Bitmaps and RemoteViews) members |
| 1225 | * of this into that. |
| 1226 | * @hide |
| 1227 | */ |
| 1228 | public void cloneInto(Notification that, boolean heavy) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1229 | that.when = this.when; |
| 1230 | that.icon = this.icon; |
| 1231 | that.number = this.number; |
| 1232 | |
| 1233 | // PendingIntents are global, so there's no reason (or way) to clone them. |
| 1234 | that.contentIntent = this.contentIntent; |
| 1235 | that.deleteIntent = this.deleteIntent; |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1236 | that.fullScreenIntent = this.fullScreenIntent; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1237 | |
| 1238 | if (this.tickerText != null) { |
| 1239 | that.tickerText = this.tickerText.toString(); |
| 1240 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1241 | if (heavy && this.tickerView != null) { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1242 | that.tickerView = this.tickerView.clone(); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1243 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1244 | if (heavy && this.contentView != null) { |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1245 | that.contentView = this.contentView.clone(); |
| 1246 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1247 | if (heavy && this.largeIcon != null) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1248 | that.largeIcon = Bitmap.createBitmap(this.largeIcon); |
| 1249 | } |
Jozef BABJAK | a8b9183 | 2011-02-22 08:05:08 +0100 | [diff] [blame] | 1250 | that.iconLevel = this.iconLevel; |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1251 | that.sound = this.sound; // android.net.Uri is immutable |
| 1252 | that.audioStreamType = this.audioStreamType; |
| 1253 | |
| 1254 | final long[] vibrate = this.vibrate; |
| 1255 | if (vibrate != null) { |
| 1256 | final int N = vibrate.length; |
| 1257 | final long[] vib = that.vibrate = new long[N]; |
| 1258 | System.arraycopy(vibrate, 0, vib, 0, N); |
| 1259 | } |
| 1260 | |
| 1261 | that.ledARGB = this.ledARGB; |
| 1262 | that.ledOnMS = this.ledOnMS; |
| 1263 | that.ledOffMS = this.ledOffMS; |
| 1264 | that.defaults = this.defaults; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1265 | |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1266 | that.flags = this.flags; |
| 1267 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1268 | that.priority = this.priority; |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1269 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1270 | that.category = this.category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1271 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1272 | that.mGroupKey = this.mGroupKey; |
| 1273 | |
| 1274 | that.mSortKey = this.mSortKey; |
| 1275 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1276 | if (this.extras != null) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1277 | try { |
| 1278 | that.extras = new Bundle(this.extras); |
| 1279 | // will unparcel |
| 1280 | that.extras.size(); |
| 1281 | } catch (BadParcelableException e) { |
| 1282 | Log.e(TAG, "could not unparcel extras from notification: " + this, e); |
| 1283 | that.extras = null; |
| 1284 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1285 | } |
| 1286 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1287 | if (this.actions != null) { |
| 1288 | that.actions = new Action[this.actions.length]; |
| 1289 | for(int i=0; i<this.actions.length; i++) { |
| 1290 | that.actions[i] = this.actions[i].clone(); |
| 1291 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1292 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1293 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1294 | if (heavy && this.bigContentView != null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1295 | that.bigContentView = this.bigContentView.clone(); |
| 1296 | } |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1297 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1298 | if (heavy && this.headsUpContentView != null) { |
| 1299 | that.headsUpContentView = this.headsUpContentView.clone(); |
| 1300 | } |
| 1301 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1302 | that.visibility = this.visibility; |
| 1303 | |
| 1304 | if (this.publicVersion != null) { |
| 1305 | that.publicVersion = new Notification(); |
| 1306 | this.publicVersion.cloneInto(that.publicVersion, heavy); |
| 1307 | } |
| 1308 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1309 | that.color = this.color; |
| 1310 | |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1311 | if (!heavy) { |
| 1312 | that.lightenPayload(); // will clean out extras |
| 1313 | } |
| 1314 | } |
| 1315 | |
| 1316 | /** |
| 1317 | * Removes heavyweight parts of the Notification object for archival or for sending to |
| 1318 | * listeners when the full contents are not necessary. |
| 1319 | * @hide |
| 1320 | */ |
| 1321 | public final void lightenPayload() { |
| 1322 | tickerView = null; |
| 1323 | contentView = null; |
| 1324 | bigContentView = null; |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1325 | headsUpContentView = null; |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 1326 | largeIcon = null; |
| 1327 | if (extras != null) { |
| 1328 | extras.remove(Notification.EXTRA_LARGE_ICON); |
| 1329 | extras.remove(Notification.EXTRA_LARGE_ICON_BIG); |
| 1330 | extras.remove(Notification.EXTRA_PICTURE); |
| 1331 | } |
Joe Onorato | 18e69df | 2010-05-17 22:26:12 -0700 | [diff] [blame] | 1332 | } |
| 1333 | |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1334 | /** |
| 1335 | * Make sure this CharSequence is safe to put into a bundle, which basically |
| 1336 | * means it had better not be some custom Parcelable implementation. |
| 1337 | * @hide |
| 1338 | */ |
| 1339 | public static CharSequence safeCharSequence(CharSequence cs) { |
| 1340 | if (cs instanceof Parcelable) { |
| 1341 | Log.e(TAG, "warning: " + cs.getClass().getCanonicalName() |
| 1342 | + " instance is a custom Parcelable and not allowed in Notification"); |
| 1343 | return cs.toString(); |
| 1344 | } |
| 1345 | |
| 1346 | return cs; |
| 1347 | } |
| 1348 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1349 | public int describeContents() { |
| 1350 | return 0; |
| 1351 | } |
| 1352 | |
| 1353 | /** |
| 1354 | * Flatten this notification from a parcel. |
| 1355 | */ |
| 1356 | public void writeToParcel(Parcel parcel, int flags) |
| 1357 | { |
| 1358 | parcel.writeInt(1); |
| 1359 | |
| 1360 | parcel.writeLong(when); |
| 1361 | parcel.writeInt(icon); |
| 1362 | parcel.writeInt(number); |
| 1363 | if (contentIntent != null) { |
| 1364 | parcel.writeInt(1); |
| 1365 | contentIntent.writeToParcel(parcel, 0); |
| 1366 | } else { |
| 1367 | parcel.writeInt(0); |
| 1368 | } |
| 1369 | if (deleteIntent != null) { |
| 1370 | parcel.writeInt(1); |
| 1371 | deleteIntent.writeToParcel(parcel, 0); |
| 1372 | } else { |
| 1373 | parcel.writeInt(0); |
| 1374 | } |
| 1375 | if (tickerText != null) { |
| 1376 | parcel.writeInt(1); |
| 1377 | TextUtils.writeToParcel(tickerText, parcel, flags); |
| 1378 | } else { |
| 1379 | parcel.writeInt(0); |
| 1380 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1381 | if (tickerView != null) { |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1382 | parcel.writeInt(1); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1383 | tickerView.writeToParcel(parcel, 0); |
Joe Onorato | ef1e776 | 2010-09-17 18:38:38 -0400 | [diff] [blame] | 1384 | } else { |
| 1385 | parcel.writeInt(0); |
| 1386 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1387 | if (contentView != null) { |
| 1388 | parcel.writeInt(1); |
| 1389 | contentView.writeToParcel(parcel, 0); |
| 1390 | } else { |
| 1391 | parcel.writeInt(0); |
| 1392 | } |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 1393 | if (largeIcon != null) { |
| 1394 | parcel.writeInt(1); |
| 1395 | largeIcon.writeToParcel(parcel, 0); |
| 1396 | } else { |
| 1397 | parcel.writeInt(0); |
| 1398 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1399 | |
| 1400 | parcel.writeInt(defaults); |
| 1401 | parcel.writeInt(this.flags); |
| 1402 | |
| 1403 | if (sound != null) { |
| 1404 | parcel.writeInt(1); |
| 1405 | sound.writeToParcel(parcel, 0); |
| 1406 | } else { |
| 1407 | parcel.writeInt(0); |
| 1408 | } |
| 1409 | parcel.writeInt(audioStreamType); |
| 1410 | parcel.writeLongArray(vibrate); |
| 1411 | parcel.writeInt(ledARGB); |
| 1412 | parcel.writeInt(ledOnMS); |
| 1413 | parcel.writeInt(ledOffMS); |
| 1414 | parcel.writeInt(iconLevel); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1415 | |
| 1416 | if (fullScreenIntent != null) { |
| 1417 | parcel.writeInt(1); |
| 1418 | fullScreenIntent.writeToParcel(parcel, 0); |
| 1419 | } else { |
| 1420 | parcel.writeInt(0); |
| 1421 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1422 | |
| 1423 | parcel.writeInt(priority); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1424 | |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1425 | parcel.writeString(category); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1426 | |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1427 | parcel.writeString(mGroupKey); |
| 1428 | |
| 1429 | parcel.writeString(mSortKey); |
| 1430 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1431 | parcel.writeBundle(extras); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1432 | |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1433 | parcel.writeTypedArray(actions, 0); // null ok |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1434 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1435 | if (bigContentView != null) { |
| 1436 | parcel.writeInt(1); |
| 1437 | bigContentView.writeToParcel(parcel, 0); |
| 1438 | } else { |
| 1439 | parcel.writeInt(0); |
| 1440 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1441 | |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1442 | if (headsUpContentView != null) { |
| 1443 | parcel.writeInt(1); |
| 1444 | headsUpContentView.writeToParcel(parcel, 0); |
| 1445 | } else { |
| 1446 | parcel.writeInt(0); |
| 1447 | } |
| 1448 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1449 | parcel.writeInt(visibility); |
| 1450 | |
| 1451 | if (publicVersion != null) { |
| 1452 | parcel.writeInt(1); |
| 1453 | publicVersion.writeToParcel(parcel, 0); |
| 1454 | } else { |
| 1455 | parcel.writeInt(0); |
| 1456 | } |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1457 | |
| 1458 | parcel.writeInt(color); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1459 | } |
| 1460 | |
| 1461 | /** |
| 1462 | * Parcelable.Creator that instantiates Notification objects |
| 1463 | */ |
| 1464 | public static final Parcelable.Creator<Notification> CREATOR |
| 1465 | = new Parcelable.Creator<Notification>() |
| 1466 | { |
| 1467 | public Notification createFromParcel(Parcel parcel) |
| 1468 | { |
| 1469 | return new Notification(parcel); |
| 1470 | } |
| 1471 | |
| 1472 | public Notification[] newArray(int size) |
| 1473 | { |
| 1474 | return new Notification[size]; |
| 1475 | } |
| 1476 | }; |
| 1477 | |
| 1478 | /** |
| 1479 | * Sets the {@link #contentView} field to be a view with the standard "Latest Event" |
| 1480 | * layout. |
| 1481 | * |
| 1482 | * <p>Uses the {@link #icon} and {@link #when} fields to set the icon and time fields |
| 1483 | * in the view.</p> |
| 1484 | * @param context The context for your application / activity. |
| 1485 | * @param contentTitle The title that goes in the expanded entry. |
| 1486 | * @param contentText The text that goes in the expanded entry. |
| 1487 | * @param contentIntent The intent to launch when the user clicks the expanded notification. |
| 1488 | * If this is an activity, it must include the |
| 1489 | * {@link android.content.Intent#FLAG_ACTIVITY_NEW_TASK} flag, which requires |
Scott Main | 7aee61f | 2011-02-08 11:25:01 -0800 | [diff] [blame] | 1490 | * that you take care of task management as described in the |
| 1491 | * <a href="{@docRoot}guide/topics/fundamentals/tasks-and-back-stack.html">Tasks and Back |
| 1492 | * Stack</a> document. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1493 | * |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1494 | * @deprecated Use {@link Builder} instead. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1495 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1496 | @Deprecated |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1497 | public void setLatestEventInfo(Context context, |
| 1498 | CharSequence contentTitle, CharSequence contentText, PendingIntent contentIntent) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1499 | Notification.Builder builder = new Notification.Builder(context); |
| 1500 | |
| 1501 | // First, ensure that key pieces of information that may have been set directly |
| 1502 | // are preserved |
| 1503 | builder.setWhen(this.when); |
| 1504 | builder.setSmallIcon(this.icon); |
| 1505 | builder.setPriority(this.priority); |
| 1506 | builder.setTicker(this.tickerText); |
| 1507 | builder.setNumber(this.number); |
| 1508 | builder.mFlags = this.flags; |
| 1509 | builder.setSound(this.sound, this.audioStreamType); |
| 1510 | builder.setDefaults(this.defaults); |
| 1511 | builder.setVibrate(this.vibrate); |
| 1512 | |
| 1513 | // now apply the latestEventInfo fields |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1514 | if (contentTitle != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1515 | builder.setContentTitle(contentTitle); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1516 | } |
| 1517 | if (contentText != null) { |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1518 | builder.setContentText(contentText); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1519 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 1520 | builder.setContentIntent(contentIntent); |
| 1521 | builder.buildInto(this); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1522 | } |
| 1523 | |
| 1524 | @Override |
| 1525 | public String toString() { |
| 1526 | StringBuilder sb = new StringBuilder(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1527 | sb.append("Notification(pri="); |
| 1528 | sb.append(priority); |
| 1529 | sb.append(" contentView="); |
Joe Onorato | c9596d6 | 2011-01-12 17:03:11 -0800 | [diff] [blame] | 1530 | if (contentView != null) { |
| 1531 | sb.append(contentView.getPackage()); |
| 1532 | sb.append("/0x"); |
| 1533 | sb.append(Integer.toHexString(contentView.getLayoutId())); |
| 1534 | } else { |
| 1535 | sb.append("null"); |
| 1536 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1537 | // 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] | 1538 | sb.append(" vibrate="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1539 | if ((this.defaults & DEFAULT_VIBRATE) != 0) { |
| 1540 | sb.append("default"); |
| 1541 | } else if (this.vibrate != null) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1542 | int N = this.vibrate.length-1; |
| 1543 | sb.append("["); |
| 1544 | for (int i=0; i<N; i++) { |
| 1545 | sb.append(this.vibrate[i]); |
| 1546 | sb.append(','); |
| 1547 | } |
Simon Schoar | 8cf97d9 | 2009-06-10 22:08:37 +0200 | [diff] [blame] | 1548 | if (N != -1) { |
| 1549 | sb.append(this.vibrate[N]); |
| 1550 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1551 | sb.append("]"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1552 | } else { |
| 1553 | sb.append("null"); |
| 1554 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1555 | sb.append(" sound="); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1556 | if ((this.defaults & DEFAULT_SOUND) != 0) { |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1557 | sb.append("default"); |
Daniel Sandler | 6738eee | 2012-11-16 12:03:32 -0500 | [diff] [blame] | 1558 | } else if (this.sound != null) { |
| 1559 | sb.append(this.sound.toString()); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1560 | } else { |
| 1561 | sb.append("null"); |
| 1562 | } |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1563 | sb.append(" defaults=0x"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1564 | sb.append(Integer.toHexString(this.defaults)); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1565 | sb.append(" flags=0x"); |
Daniel Sandler | e46cbd3 | 2010-06-17 10:35:26 -0400 | [diff] [blame] | 1566 | sb.append(Integer.toHexString(this.flags)); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1567 | sb.append(String.format(" color=0x%08x", this.color)); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1568 | if (this.category != null) { |
| 1569 | sb.append(" category="); |
| 1570 | sb.append(this.category); |
| 1571 | } |
| 1572 | if (this.mGroupKey != null) { |
| 1573 | sb.append(" groupKey="); |
| 1574 | sb.append(this.mGroupKey); |
| 1575 | } |
| 1576 | if (this.mSortKey != null) { |
| 1577 | sb.append(" sortKey="); |
| 1578 | sb.append(this.mSortKey); |
| 1579 | } |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 1580 | if (actions != null) { |
| 1581 | sb.append(" "); |
| 1582 | sb.append(actions.length); |
| 1583 | sb.append(" action"); |
| 1584 | if (actions.length > 1) sb.append("s"); |
| 1585 | } |
| 1586 | sb.append(")"); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1587 | return sb.toString(); |
| 1588 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1589 | |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1590 | /** {@hide} */ |
| 1591 | public void setUser(UserHandle user) { |
Amith Yamasani | ecbd68b | 2012-11-02 12:17:19 -0700 | [diff] [blame] | 1592 | if (user.getIdentifier() == UserHandle.USER_ALL) { |
| 1593 | user = UserHandle.OWNER; |
| 1594 | } |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1595 | if (tickerView != null) { |
| 1596 | tickerView.setUser(user); |
| 1597 | } |
| 1598 | if (contentView != null) { |
| 1599 | contentView.setUser(user); |
| 1600 | } |
| 1601 | if (bigContentView != null) { |
| 1602 | bigContentView.setUser(user); |
| 1603 | } |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 1604 | if (headsUpContentView != null) { |
| 1605 | headsUpContentView.setUser(user); |
| 1606 | } |
Jeff Sharkey | 6d51571 | 2012-09-20 16:06:08 -0700 | [diff] [blame] | 1607 | } |
| 1608 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1609 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1610 | * Builder class for {@link Notification} objects. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1611 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1612 | * 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] | 1613 | * content views using the platform's notification layout template. If your app supports |
| 1614 | * versions of Android as old as API level 4, you can instead use |
| 1615 | * {@link android.support.v4.app.NotificationCompat.Builder NotificationCompat.Builder}, |
| 1616 | * available in the <a href="{@docRoot}tools/extras/support-library.html">Android Support |
| 1617 | * library</a>. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1618 | * |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1619 | * <p>Example: |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1620 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1621 | * <pre class="prettyprint"> |
Scott Main | 183bf11 | 2012-08-13 19:12:13 -0700 | [diff] [blame] | 1622 | * Notification noti = new Notification.Builder(mContext) |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1623 | * .setContentTitle("New mail from " + sender.toString()) |
| 1624 | * .setContentText(subject) |
| 1625 | * .setSmallIcon(R.drawable.new_mail) |
| 1626 | * .setLargeIcon(aBitmap) |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1627 | * .build(); |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1628 | * </pre> |
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 static class Builder { |
Daniel Sandler | 602ad1c | 2012-06-12 16:06:27 -0400 | [diff] [blame] | 1631 | private static final int MAX_ACTION_BUTTONS = 3; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1632 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1633 | private Context mContext; |
| 1634 | |
| 1635 | private long mWhen; |
| 1636 | private int mSmallIcon; |
| 1637 | private int mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1638 | private int mNumber; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1639 | private CharSequence mContentTitle; |
| 1640 | private CharSequence mContentText; |
| 1641 | private CharSequence mContentInfo; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1642 | private CharSequence mSubText; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1643 | private PendingIntent mContentIntent; |
| 1644 | private RemoteViews mContentView; |
| 1645 | private PendingIntent mDeleteIntent; |
| 1646 | private PendingIntent mFullScreenIntent; |
| 1647 | private CharSequence mTickerText; |
| 1648 | private RemoteViews mTickerView; |
| 1649 | private Bitmap mLargeIcon; |
| 1650 | private Uri mSound; |
| 1651 | private int mAudioStreamType; |
| 1652 | private long[] mVibrate; |
| 1653 | private int mLedArgb; |
| 1654 | private int mLedOnMs; |
| 1655 | private int mLedOffMs; |
| 1656 | private int mDefaults; |
| 1657 | private int mFlags; |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1658 | private int mProgressMax; |
| 1659 | private int mProgress; |
| 1660 | private boolean mProgressIndeterminate; |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 1661 | private String mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 1662 | private String mGroupKey; |
| 1663 | private String mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1664 | private Bundle mExtras; |
| 1665 | private int mPriority; |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 1666 | private ArrayList<Action> mActions = new ArrayList<Action>(MAX_ACTION_BUTTONS); |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1667 | private boolean mUseChronometer; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 1668 | private Style mStyle; |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1669 | private boolean mShowWhen = true; |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 1670 | private int mVisibility = VISIBILITY_PRIVATE; |
| 1671 | private Notification mPublicVersion = null; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1672 | private final NotificationColorUtil mColorUtil; |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 1673 | private ArrayList<String> mPeople; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1674 | private boolean mPreQuantum; |
| 1675 | private int mColor = COLOR_DEFAULT; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1676 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1677 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1678 | * Constructs a new Builder with the defaults: |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1679 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1680 | |
| 1681 | * <table> |
| 1682 | * <tr><th align=right>priority</th> |
| 1683 | * <td>{@link #PRIORITY_DEFAULT}</td></tr> |
| 1684 | * <tr><th align=right>when</th> |
| 1685 | * <td>now ({@link System#currentTimeMillis()})</td></tr> |
| 1686 | * <tr><th align=right>audio stream</th> |
| 1687 | * <td>{@link #STREAM_DEFAULT}</td></tr> |
| 1688 | * </table> |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1689 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1690 | |
| 1691 | * @param context |
| 1692 | * A {@link Context} that will be used by the Builder to construct the |
| 1693 | * RemoteViews. The Context will not be held past the lifetime of this Builder |
| 1694 | * object. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1695 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1696 | public Builder(Context context) { |
| 1697 | mContext = context; |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1698 | |
| 1699 | // Set defaults to match the defaults of a Notification |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1700 | mWhen = System.currentTimeMillis(); |
Andy Stadler | 110988c | 2010-12-03 14:29:16 -0800 | [diff] [blame] | 1701 | mAudioStreamType = STREAM_DEFAULT; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1702 | mPriority = PRIORITY_DEFAULT; |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 1703 | mPeople = new ArrayList<String>(); |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 1704 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 1705 | mPreQuantum = context.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.L; |
| 1706 | mColorUtil = NotificationColorUtil.getInstance(); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1707 | } |
| 1708 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1709 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1710 | * 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] | 1711 | * It will be shown in the notification content view by default; use |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 1712 | * {@link #setShowWhen(boolean) setShowWhen} to control this. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1713 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1714 | * @see Notification#when |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1715 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1716 | public Builder setWhen(long when) { |
| 1717 | mWhen = when; |
| 1718 | return this; |
| 1719 | } |
| 1720 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1721 | /** |
Griff Hazen | 50c1165 | 2014-05-16 09:46:31 -0700 | [diff] [blame] | 1722 | * Control whether the timestamp set with {@link #setWhen(long) setWhen} is shown |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 1723 | * in the content view. |
| 1724 | */ |
| 1725 | public Builder setShowWhen(boolean show) { |
| 1726 | mShowWhen = show; |
| 1727 | return this; |
| 1728 | } |
| 1729 | |
| 1730 | /** |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1731 | * Show the {@link Notification#when} field as a stopwatch. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1732 | * |
| 1733 | * 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] | 1734 | * automatically updating display of the minutes and seconds since <code>when</code>. |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1735 | * |
Daniel Sandler | d33b803 | 2012-05-10 11:41:48 -0400 | [diff] [blame] | 1736 | * Useful when showing an elapsed time (like an ongoing phone call). |
| 1737 | * |
| 1738 | * @see android.widget.Chronometer |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 1739 | * @see Notification#when |
| 1740 | */ |
| 1741 | public Builder setUsesChronometer(boolean b) { |
| 1742 | mUseChronometer = b; |
| 1743 | return this; |
| 1744 | } |
| 1745 | |
| 1746 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1747 | * Set the small icon resource, which will be used to represent the notification in the |
| 1748 | * status bar. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1749 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1750 | |
| 1751 | * The platform template for the expanded view will draw this icon in the left, unless a |
| 1752 | * {@link #setLargeIcon(Bitmap) large icon} has also been specified, in which case the small |
| 1753 | * icon will be moved to the right-hand side. |
| 1754 | * |
| 1755 | |
| 1756 | * @param icon |
| 1757 | * A resource ID in the application's package of the drawable to use. |
| 1758 | * @see Notification#icon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1759 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1760 | public Builder setSmallIcon(int icon) { |
| 1761 | mSmallIcon = icon; |
| 1762 | return this; |
| 1763 | } |
| 1764 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1765 | /** |
| 1766 | * A variant of {@link #setSmallIcon(int) setSmallIcon(int)} that takes an additional |
| 1767 | * level parameter for when the icon is a {@link android.graphics.drawable.LevelListDrawable |
| 1768 | * LevelListDrawable}. |
| 1769 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1770 | * @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] | 1771 | * @param level The level to use for the icon. |
| 1772 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1773 | * @see Notification#icon |
| 1774 | * @see Notification#iconLevel |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1775 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1776 | public Builder setSmallIcon(int icon, int level) { |
| 1777 | mSmallIcon = icon; |
| 1778 | mSmallIconLevel = level; |
| 1779 | return this; |
| 1780 | } |
| 1781 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1782 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1783 | * Set the first line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1784 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1785 | public Builder setContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1786 | mContentTitle = safeCharSequence(title); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1787 | return this; |
| 1788 | } |
| 1789 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1790 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1791 | * Set the second line of text in the platform notification template. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1792 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1793 | public Builder setContentText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1794 | mContentText = safeCharSequence(text); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1795 | return this; |
| 1796 | } |
| 1797 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1798 | /** |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 1799 | * Set the third line of text in the platform notification template. |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1800 | * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the |
| 1801 | * same location in the standard template. |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1802 | */ |
| 1803 | public Builder setSubText(CharSequence text) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1804 | mSubText = safeCharSequence(text); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 1805 | return this; |
| 1806 | } |
| 1807 | |
| 1808 | /** |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1809 | * Set the large number at the right-hand side of the notification. This is |
| 1810 | * equivalent to setContentInfo, although it might show the number in a different |
| 1811 | * font size for readability. |
| 1812 | */ |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 1813 | public Builder setNumber(int number) { |
| 1814 | mNumber = number; |
| 1815 | return this; |
| 1816 | } |
| 1817 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1818 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1819 | * A small piece of additional information pertaining to this notification. |
| 1820 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1821 | * The platform template will draw this on the last line of the notification, at the far |
| 1822 | * 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] | 1823 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1824 | public Builder setContentInfo(CharSequence info) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1825 | mContentInfo = safeCharSequence(info); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1826 | return this; |
| 1827 | } |
| 1828 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1829 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1830 | * Set the progress this notification represents. |
| 1831 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1832 | * The platform template will represent this using a {@link ProgressBar}. |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 1833 | */ |
| 1834 | public Builder setProgress(int max, int progress, boolean indeterminate) { |
| 1835 | mProgressMax = max; |
| 1836 | mProgress = progress; |
| 1837 | mProgressIndeterminate = indeterminate; |
| 1838 | return this; |
| 1839 | } |
| 1840 | |
| 1841 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1842 | * Supply a custom RemoteViews to use instead of the platform template. |
| 1843 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1844 | * @see Notification#contentView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1845 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1846 | public Builder setContent(RemoteViews views) { |
| 1847 | mContentView = views; |
| 1848 | return this; |
| 1849 | } |
| 1850 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1851 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1852 | * Supply a {@link PendingIntent} to be sent when the notification is clicked. |
| 1853 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1854 | * As of {@link android.os.Build.VERSION_CODES#HONEYCOMB}, if this field is unset and you |
| 1855 | * have specified a custom RemoteViews with {@link #setContent(RemoteViews)}, you can use |
| 1856 | * {@link RemoteViews#setOnClickPendingIntent RemoteViews.setOnClickPendingIntent(int,PendingIntent)} |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1857 | * 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] | 1858 | * clickable buttons inside the notification view). |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1859 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1860 | * @see Notification#contentIntent Notification.contentIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1861 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1862 | public Builder setContentIntent(PendingIntent intent) { |
| 1863 | mContentIntent = intent; |
| 1864 | return this; |
| 1865 | } |
| 1866 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1867 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1868 | * Supply a {@link PendingIntent} to send when the notification is cleared explicitly by the user. |
| 1869 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1870 | * @see Notification#deleteIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1871 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1872 | public Builder setDeleteIntent(PendingIntent intent) { |
| 1873 | mDeleteIntent = intent; |
| 1874 | return this; |
| 1875 | } |
| 1876 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1877 | /** |
| 1878 | * An intent to launch instead of posting the notification to the status bar. |
| 1879 | * Only for use with extremely high-priority notifications demanding the user's |
| 1880 | * <strong>immediate</strong> attention, such as an incoming phone call or |
| 1881 | * alarm clock that the user has explicitly set to a particular time. |
| 1882 | * If this facility is used for something else, please give the user an option |
| 1883 | * to turn it off and use a normal notification, as this can be extremely |
| 1884 | * disruptive. |
| 1885 | * |
| 1886 | * @param intent The pending intent to launch. |
| 1887 | * @param highPriority Passing true will cause this notification to be sent |
| 1888 | * even if other notifications are suppressed. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1889 | * |
| 1890 | * @see Notification#fullScreenIntent |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1891 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1892 | public Builder setFullScreenIntent(PendingIntent intent, boolean highPriority) { |
| 1893 | mFullScreenIntent = intent; |
| 1894 | setFlag(FLAG_HIGH_PRIORITY, highPriority); |
| 1895 | return this; |
| 1896 | } |
| 1897 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1898 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1899 | * 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] | 1900 | * arrives. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1901 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1902 | * @see Notification#tickerText |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1903 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1904 | public Builder setTicker(CharSequence tickerText) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1905 | mTickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1906 | return this; |
| 1907 | } |
| 1908 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1909 | /** |
| 1910 | * Set the text that is displayed in the status bar when the notification first |
| 1911 | * arrives, and also a RemoteViews object that may be displayed instead on some |
| 1912 | * devices. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1913 | * |
| 1914 | * @see Notification#tickerText |
| 1915 | * @see Notification#tickerView |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1916 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1917 | public Builder setTicker(CharSequence tickerText, RemoteViews views) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 1918 | mTickerText = safeCharSequence(tickerText); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1919 | mTickerView = views; |
| 1920 | return this; |
| 1921 | } |
| 1922 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1923 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1924 | * Add a large icon to the notification (and the ticker on some devices). |
| 1925 | * |
| 1926 | * In the platform template, this image will be shown on the left of the notification view |
| 1927 | * in place of the {@link #setSmallIcon(int) small icon} (which will move to the right side). |
| 1928 | * |
| 1929 | * @see Notification#largeIcon |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1930 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1931 | public Builder setLargeIcon(Bitmap icon) { |
| 1932 | mLargeIcon = icon; |
| 1933 | return this; |
| 1934 | } |
| 1935 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1936 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1937 | * Set the sound to play. |
| 1938 | * |
| 1939 | * It will be played on the {@link #STREAM_DEFAULT default stream} for notifications. |
| 1940 | * |
| 1941 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1942 | */ |
Joe Onorato | 52f80cd | 2010-11-21 15:34:48 -0800 | [diff] [blame] | 1943 | public Builder setSound(Uri sound) { |
| 1944 | mSound = sound; |
| 1945 | mAudioStreamType = STREAM_DEFAULT; |
| 1946 | return this; |
| 1947 | } |
| 1948 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1949 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1950 | * 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] | 1951 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1952 | * See {@link android.media.AudioManager} for the <code>STREAM_</code> constants. |
| 1953 | * |
| 1954 | * @see Notification#sound |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1955 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1956 | public Builder setSound(Uri sound, int streamType) { |
| 1957 | mSound = sound; |
| 1958 | mAudioStreamType = streamType; |
| 1959 | return this; |
| 1960 | } |
| 1961 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1962 | /** |
| 1963 | * Set the vibration pattern to use. |
| 1964 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1965 | |
| 1966 | * See {@link android.os.Vibrator#vibrate(long[], int)} for a discussion of the |
| 1967 | * <code>pattern</code> parameter. |
| 1968 | * |
| 1969 | |
| 1970 | * @see Notification#vibrate |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1971 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1972 | public Builder setVibrate(long[] pattern) { |
| 1973 | mVibrate = pattern; |
| 1974 | return this; |
| 1975 | } |
| 1976 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1977 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1978 | * Set the desired color for the indicator LED on the device, as well as the |
| 1979 | * blink duty cycle (specified in milliseconds). |
| 1980 | * |
| 1981 | |
| 1982 | * Not all devices will honor all (or even any) of these values. |
| 1983 | * |
| 1984 | |
| 1985 | * @see Notification#ledARGB |
| 1986 | * @see Notification#ledOnMS |
| 1987 | * @see Notification#ledOffMS |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1988 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1989 | public Builder setLights(int argb, int onMs, int offMs) { |
| 1990 | mLedArgb = argb; |
| 1991 | mLedOnMs = onMs; |
| 1992 | mLedOffMs = offMs; |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 1993 | return this; |
| 1994 | } |
| 1995 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1996 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1997 | * Set whether this is an "ongoing" notification. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 1998 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 1999 | |
| 2000 | * Ongoing notifications cannot be dismissed by the user, so your application or service |
| 2001 | * must take care of canceling them. |
| 2002 | * |
| 2003 | |
| 2004 | * They are typically used to indicate a background task that the user is actively engaged |
| 2005 | * with (e.g., playing music) or is pending in some way and therefore occupying the device |
| 2006 | * (e.g., a file download, sync operation, active network connection). |
| 2007 | * |
| 2008 | |
| 2009 | * @see Notification#FLAG_ONGOING_EVENT |
| 2010 | * @see Service#setForeground(boolean) |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2011 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2012 | public Builder setOngoing(boolean ongoing) { |
| 2013 | setFlag(FLAG_ONGOING_EVENT, ongoing); |
| 2014 | return this; |
| 2015 | } |
| 2016 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2017 | /** |
| 2018 | * Set this flag if you would only like the sound, vibrate |
| 2019 | * and ticker to be played if the notification is not already showing. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2020 | * |
| 2021 | * @see Notification#FLAG_ONLY_ALERT_ONCE |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2022 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2023 | public Builder setOnlyAlertOnce(boolean onlyAlertOnce) { |
| 2024 | setFlag(FLAG_ONLY_ALERT_ONCE, onlyAlertOnce); |
| 2025 | return this; |
| 2026 | } |
| 2027 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2028 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2029 | * Make this notification automatically dismissed when the user touches it. The |
| 2030 | * PendingIntent set with {@link #setDeleteIntent} will be sent when this happens. |
| 2031 | * |
| 2032 | * @see Notification#FLAG_AUTO_CANCEL |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2033 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2034 | public Builder setAutoCancel(boolean autoCancel) { |
Joe Onorato | 281d83f | 2011-01-04 17:13:10 -0800 | [diff] [blame] | 2035 | setFlag(FLAG_AUTO_CANCEL, autoCancel); |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2036 | return this; |
| 2037 | } |
| 2038 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2039 | /** |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2040 | * Set whether or not this notification should not bridge to other devices. |
| 2041 | * |
| 2042 | * <p>Some notifications can be bridged to other devices for remote display. |
| 2043 | * This hint can be set to recommend this notification not be bridged. |
| 2044 | */ |
| 2045 | public Builder setLocalOnly(boolean localOnly) { |
| 2046 | setFlag(FLAG_LOCAL_ONLY, localOnly); |
| 2047 | return this; |
| 2048 | } |
| 2049 | |
| 2050 | /** |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2051 | * Set which notification properties will be inherited from system defaults. |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2052 | * <p> |
| 2053 | * The value should be one or more of the following fields combined with |
| 2054 | * bitwise-or: |
| 2055 | * {@link #DEFAULT_SOUND}, {@link #DEFAULT_VIBRATE}, {@link #DEFAULT_LIGHTS}. |
| 2056 | * <p> |
| 2057 | * For all default values, use {@link #DEFAULT_ALL}. |
| 2058 | */ |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2059 | public Builder setDefaults(int defaults) { |
| 2060 | mDefaults = defaults; |
| 2061 | return this; |
| 2062 | } |
| 2063 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2064 | /** |
| 2065 | * Set the priority of this notification. |
| 2066 | * |
| 2067 | * @see Notification#priority |
| 2068 | */ |
Tor Norbye | d9273d6 | 2013-05-30 15:59:53 -0700 | [diff] [blame] | 2069 | public Builder setPriority(@Priority int pri) { |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2070 | mPriority = pri; |
| 2071 | return this; |
| 2072 | } |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2073 | |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2074 | /** |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2075 | * Set the notification category. |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2076 | * |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2077 | * @see Notification#category |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2078 | */ |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2079 | public Builder setCategory(String category) { |
| 2080 | mCategory = category; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2081 | return this; |
| 2082 | } |
| 2083 | |
| 2084 | /** |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2085 | * Add a person that is relevant to this notification. |
| 2086 | * |
| 2087 | * @see Notification#EXTRA_PEOPLE |
| 2088 | */ |
| 2089 | public Builder addPerson(String handle) { |
| 2090 | mPeople.add(handle); |
| 2091 | return this; |
| 2092 | } |
| 2093 | |
| 2094 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2095 | * Set this notification to be part of a group of notifications sharing the same key. |
| 2096 | * Grouped notifications may display in a cluster or stack on devices which |
| 2097 | * support such rendering. |
| 2098 | * |
| 2099 | * <p>To make this notification the summary for its group, also call |
| 2100 | * {@link #setGroupSummary}. A sort order can be specified for group members by using |
| 2101 | * {@link #setSortKey}. |
| 2102 | * @param groupKey The group key of the group. |
| 2103 | * @return this object for method chaining |
| 2104 | */ |
| 2105 | public Builder setGroup(String groupKey) { |
| 2106 | mGroupKey = groupKey; |
| 2107 | return this; |
| 2108 | } |
| 2109 | |
| 2110 | /** |
| 2111 | * Set this notification to be the group summary for a group of notifications. |
| 2112 | * Grouped notifications may display in a cluster or stack on devices which |
| 2113 | * support such rendering. Requires a group key also be set using {@link #setGroup}. |
| 2114 | * @param isGroupSummary Whether this notification should be a group summary. |
| 2115 | * @return this object for method chaining |
| 2116 | */ |
| 2117 | public Builder setGroupSummary(boolean isGroupSummary) { |
| 2118 | setFlag(FLAG_GROUP_SUMMARY, isGroupSummary); |
| 2119 | return this; |
| 2120 | } |
| 2121 | |
| 2122 | /** |
| 2123 | * Set a sort key that orders this notification among other notifications from the |
| 2124 | * same package. This can be useful if an external sort was already applied and an app |
| 2125 | * would like to preserve this. Notifications will be sorted lexicographically using this |
| 2126 | * value, although providing different priorities in addition to providing sort key may |
| 2127 | * cause this value to be ignored. |
| 2128 | * |
| 2129 | * <p>This sort key can also be used to order members of a notification group. See |
Griff Hazen | 9e1379f | 2014-05-20 12:50:51 -0700 | [diff] [blame] | 2130 | * {@link #setGroup}. |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2131 | * |
| 2132 | * @see String#compareTo(String) |
| 2133 | */ |
| 2134 | public Builder setSortKey(String sortKey) { |
| 2135 | mSortKey = sortKey; |
| 2136 | return this; |
| 2137 | } |
| 2138 | |
| 2139 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2140 | * Merge additional metadata into this notification. |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2141 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2142 | * <p>Values within the Bundle will replace existing extras values in this Builder. |
| 2143 | * |
| 2144 | * @see Notification#extras |
| 2145 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2146 | public Builder addExtras(Bundle extras) { |
| 2147 | if (extras != null) { |
| 2148 | if (mExtras == null) { |
| 2149 | mExtras = new Bundle(extras); |
| 2150 | } else { |
| 2151 | mExtras.putAll(extras); |
| 2152 | } |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2153 | } |
| 2154 | return this; |
| 2155 | } |
| 2156 | |
| 2157 | /** |
| 2158 | * Set metadata for this notification. |
| 2159 | * |
| 2160 | * <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] | 2161 | * current contents are copied into the Notification each time {@link #build()} is |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2162 | * called. |
| 2163 | * |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2164 | * <p>Replaces any existing extras values with those from the provided Bundle. |
| 2165 | * Use {@link #addExtras} to merge in metadata instead. |
| 2166 | * |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2167 | * @see Notification#extras |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2168 | */ |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2169 | public Builder setExtras(Bundle extras) { |
| 2170 | mExtras = extras; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2171 | return this; |
| 2172 | } |
| 2173 | |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2174 | /** |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2175 | * Get the current metadata Bundle used by this notification Builder. |
| 2176 | * |
| 2177 | * <p>The returned Bundle is shared with this Builder. |
| 2178 | * |
| 2179 | * <p>The current contents of this Bundle are copied into the Notification each time |
| 2180 | * {@link #build()} is called. |
| 2181 | * |
| 2182 | * @see Notification#extras |
| 2183 | */ |
| 2184 | public Bundle getExtras() { |
| 2185 | if (mExtras == null) { |
| 2186 | mExtras = new Bundle(); |
| 2187 | } |
| 2188 | return mExtras; |
| 2189 | } |
| 2190 | |
| 2191 | /** |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2192 | * Add an action to this notification. Actions are typically displayed by |
| 2193 | * the system as a button adjacent to the notification content. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2194 | * <p> |
| 2195 | * Every action must have an icon (32dp square and matching the |
| 2196 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2197 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2198 | * <p> |
| 2199 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2200 | * the order they were added. Actions will not be displayed when the notification is |
| 2201 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2202 | * 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] | 2203 | * |
| 2204 | * @param icon Resource ID of a drawable that represents the action. |
| 2205 | * @param title Text describing the action. |
| 2206 | * @param intent PendingIntent to be fired when the action is invoked. |
| 2207 | */ |
| 2208 | public Builder addAction(int icon, CharSequence title, PendingIntent intent) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2209 | mActions.add(new Action(icon, safeCharSequence(title), intent)); |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2210 | return this; |
| 2211 | } |
| 2212 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2213 | /** |
Griff Hazen | 959591e | 2014-05-15 22:26:18 -0700 | [diff] [blame] | 2214 | * Add an action to this notification. Actions are typically displayed by |
| 2215 | * the system as a button adjacent to the notification content. |
| 2216 | * <p> |
| 2217 | * Every action must have an icon (32dp square and matching the |
| 2218 | * <a href="{@docRoot}design/style/iconography.html#action-bar">Holo |
| 2219 | * Dark action bar</a> visual style), a textual label, and a {@link PendingIntent}. |
| 2220 | * <p> |
| 2221 | * A notification in its expanded form can display up to 3 actions, from left to right in |
| 2222 | * the order they were added. Actions will not be displayed when the notification is |
| 2223 | * collapsed, however, so be sure that any essential functions may be accessed by the user |
| 2224 | * in some other way (for example, in the Activity pointed to by {@link #contentIntent}). |
| 2225 | * |
| 2226 | * @param action The action to add. |
| 2227 | */ |
| 2228 | public Builder addAction(Action action) { |
| 2229 | mActions.add(action); |
| 2230 | return this; |
| 2231 | } |
| 2232 | |
| 2233 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2234 | * Add a rich notification style to be applied at build time. |
| 2235 | * |
| 2236 | * @param style Object responsible for modifying the notification style. |
| 2237 | */ |
| 2238 | public Builder setStyle(Style style) { |
| 2239 | if (mStyle != style) { |
| 2240 | mStyle = style; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2241 | if (mStyle != null) { |
| 2242 | mStyle.setBuilder(this); |
| 2243 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2244 | } |
| 2245 | return this; |
| 2246 | } |
| 2247 | |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2248 | /** |
| 2249 | * Specify the value of {@link #visibility}. |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2250 | * |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2251 | * @param visibility One of {@link #VISIBILITY_PRIVATE} (the default), |
| 2252 | * {@link #VISIBILITY_SECRET}, or {@link #VISIBILITY_PUBLIC}. |
| 2253 | * |
| 2254 | * @return The same Builder. |
| 2255 | */ |
| 2256 | public Builder setVisibility(int visibility) { |
| 2257 | mVisibility = visibility; |
| 2258 | return this; |
| 2259 | } |
| 2260 | |
| 2261 | /** |
| 2262 | * Supply a replacement Notification whose contents should be shown in insecure contexts |
| 2263 | * (i.e. atop the secure lockscreen). See {@link #visibility} and {@link #VISIBILITY_PUBLIC}. |
| 2264 | * @param n A replacement notification, presumably with some or all info redacted. |
| 2265 | * @return The same Builder. |
| 2266 | */ |
| 2267 | public Builder setPublicVersion(Notification n) { |
| 2268 | mPublicVersion = n; |
| 2269 | return this; |
| 2270 | } |
| 2271 | |
Griff Hazen | b720abe | 2014-05-20 13:15:30 -0700 | [diff] [blame] | 2272 | /** |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2273 | * Apply an extender to this notification builder. Extenders may be used to add |
| 2274 | * metadata or change options on this builder. |
| 2275 | */ |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 2276 | public Builder extend(Extender extender) { |
| 2277 | extender.extend(this); |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2278 | return this; |
| 2279 | } |
| 2280 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2281 | private void setFlag(int mask, boolean value) { |
| 2282 | if (value) { |
| 2283 | mFlags |= mask; |
| 2284 | } else { |
| 2285 | mFlags &= ~mask; |
| 2286 | } |
| 2287 | } |
| 2288 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2289 | /** |
| 2290 | * Sets {@link Notification#color}. |
| 2291 | * |
| 2292 | * @param argb The accent color to use |
| 2293 | * |
| 2294 | * @return The same Builder. |
| 2295 | */ |
| 2296 | public Builder setColor(int argb) { |
| 2297 | mColor = argb; |
| 2298 | return this; |
| 2299 | } |
| 2300 | |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2301 | private RemoteViews applyStandardTemplate(int resId, boolean fitIn1U) { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2302 | RemoteViews contentView = new RemoteViews(mContext.getPackageName(), resId); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2303 | boolean showLine3 = false; |
| 2304 | boolean showLine2 = false; |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2305 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2306 | if (mPriority < PRIORITY_LOW) { |
| 2307 | // TODO: Low priority presentation |
Daniel Sandler | e95658c | 2012-05-10 00:33:54 -0400 | [diff] [blame] | 2308 | } |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2309 | if (mLargeIcon != null) { |
| 2310 | contentView.setImageViewBitmap(R.id.icon, mLargeIcon); |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2311 | processLargeIcon(mLargeIcon, contentView); |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2312 | contentView.setImageViewResource(R.id.right_icon, mSmallIcon); |
| 2313 | contentView.setViewVisibility(R.id.right_icon, View.VISIBLE); |
| 2314 | processSmallRightIcon(mSmallIcon, contentView); |
| 2315 | } else { // small icon at left |
| 2316 | contentView.setImageViewResource(R.id.icon, mSmallIcon); |
| 2317 | contentView.setViewVisibility(R.id.icon, View.VISIBLE); |
| 2318 | processSmallIconAsLarge(mSmallIcon, contentView); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2319 | } |
| 2320 | if (mContentTitle != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2321 | contentView.setTextViewText(R.id.title, processLegacyText(mContentTitle)); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2322 | } |
| 2323 | if (mContentText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2324 | contentView.setTextViewText(R.id.text, processLegacyText(mContentText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2325 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2326 | } |
| 2327 | if (mContentInfo != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2328 | contentView.setTextViewText(R.id.info, processLegacyText(mContentInfo)); |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2329 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2330 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2331 | } else if (mNumber > 0) { |
Daniel Sandler | ebce011 | 2011-06-16 16:44:51 -0400 | [diff] [blame] | 2332 | final int tooBig = mContext.getResources().getInteger( |
| 2333 | R.integer.status_bar_notification_info_maxnum); |
| 2334 | if (mNumber > tooBig) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2335 | contentView.setTextViewText(R.id.info, processLegacyText( |
| 2336 | mContext.getResources().getString( |
| 2337 | R.string.status_bar_notification_info_overflow))); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 2338 | } else { |
| 2339 | NumberFormat f = NumberFormat.getIntegerInstance(); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2340 | contentView.setTextViewText(R.id.info, processLegacyText(f.format(mNumber))); |
Joe Onorato | 059a2f8 | 2011-01-04 10:27:01 -0800 | [diff] [blame] | 2341 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2342 | contentView.setViewVisibility(R.id.info, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2343 | showLine3 = true; |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2344 | } else { |
| 2345 | contentView.setViewVisibility(R.id.info, View.GONE); |
| 2346 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2347 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2348 | // Need to show three lines? |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2349 | if (mSubText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2350 | contentView.setTextViewText(R.id.text, processLegacyText(mSubText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2351 | if (mContentText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2352 | contentView.setTextViewText(R.id.text2, processLegacyText(mContentText)); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2353 | contentView.setViewVisibility(R.id.text2, View.VISIBLE); |
| 2354 | showLine2 = true; |
| 2355 | } else { |
| 2356 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2357 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2358 | } else { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2359 | contentView.setViewVisibility(R.id.text2, View.GONE); |
| 2360 | if (mProgressMax != 0 || mProgressIndeterminate) { |
| 2361 | contentView.setProgressBar( |
| 2362 | R.id.progress, mProgressMax, mProgress, mProgressIndeterminate); |
| 2363 | contentView.setViewVisibility(R.id.progress, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2364 | showLine2 = true; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2365 | } else { |
| 2366 | contentView.setViewVisibility(R.id.progress, View.GONE); |
| 2367 | } |
Jeff Sharkey | 1c40013 | 2011-08-05 14:50:13 -0700 | [diff] [blame] | 2368 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2369 | if (showLine2) { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2370 | if (fitIn1U) { |
| 2371 | // need to shrink all the type to make sure everything fits |
| 2372 | final Resources res = mContext.getResources(); |
| 2373 | final float subTextSize = res.getDimensionPixelSize( |
| 2374 | R.dimen.notification_subtext_size); |
| 2375 | contentView.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, subTextSize); |
| 2376 | } |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2377 | // vertical centering |
| 2378 | contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); |
| 2379 | } |
| 2380 | |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2381 | if (mWhen != 0 && mShowWhen) { |
Daniel Sandler | a2985ed | 2012-04-03 16:42:00 -0400 | [diff] [blame] | 2382 | if (mUseChronometer) { |
| 2383 | contentView.setViewVisibility(R.id.chronometer, View.VISIBLE); |
| 2384 | contentView.setLong(R.id.chronometer, "setBase", |
| 2385 | mWhen + (SystemClock.elapsedRealtime() - System.currentTimeMillis())); |
| 2386 | contentView.setBoolean(R.id.chronometer, "setStarted", true); |
| 2387 | } else { |
| 2388 | contentView.setViewVisibility(R.id.time, View.VISIBLE); |
| 2389 | contentView.setLong(R.id.time, "setTime", mWhen); |
| 2390 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2391 | } else { |
| 2392 | contentView.setViewVisibility(R.id.time, View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2393 | } |
Daniel Sandler | 0c89049 | 2012-09-12 17:23:10 -0700 | [diff] [blame] | 2394 | |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2395 | contentView.setViewVisibility(R.id.line3, showLine3 ? View.VISIBLE : View.GONE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2396 | contentView.setViewVisibility(R.id.overflow_divider, showLine3 ? View.VISIBLE : View.GONE); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2397 | return contentView; |
| 2398 | } |
| 2399 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2400 | private RemoteViews applyStandardTemplateWithActions(int layoutId) { |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2401 | RemoteViews big = applyStandardTemplate(layoutId, false); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2402 | |
| 2403 | int N = mActions.size(); |
| 2404 | if (N > 0) { |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2405 | big.setViewVisibility(R.id.actions, View.VISIBLE); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2406 | big.setViewVisibility(R.id.action_divider, View.VISIBLE); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2407 | if (N>MAX_ACTION_BUTTONS) N=MAX_ACTION_BUTTONS; |
Chris Wren | 2c22eb0 | 2012-05-08 09:49:13 -0400 | [diff] [blame] | 2408 | big.removeAllViews(R.id.actions); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2409 | for (int i=0; i<N; i++) { |
| 2410 | final RemoteViews button = generateActionButton(mActions.get(i)); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2411 | big.addView(R.id.actions, button); |
| 2412 | } |
| 2413 | } |
| 2414 | return big; |
| 2415 | } |
| 2416 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2417 | private RemoteViews makeContentView() { |
| 2418 | if (mContentView != null) { |
| 2419 | return mContentView; |
| 2420 | } else { |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2421 | return applyStandardTemplate(getBaseLayoutResource(), true); // no more special large_icon flavor |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2422 | } |
| 2423 | } |
| 2424 | |
| 2425 | private RemoteViews makeTickerView() { |
| 2426 | if (mTickerView != null) { |
| 2427 | return mTickerView; |
| 2428 | } else { |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2429 | if (mContentView == null) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2430 | return applyStandardTemplate(mLargeIcon == null |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2431 | ? R.layout.status_bar_latest_event_ticker |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2432 | : R.layout.status_bar_latest_event_ticker_large_icon, true); |
Joe Onorato | 561d385 | 2010-11-20 18:09:34 -0800 | [diff] [blame] | 2433 | } else { |
| 2434 | return null; |
| 2435 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2436 | } |
| 2437 | } |
| 2438 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2439 | private RemoteViews makeBigContentView() { |
| 2440 | if (mActions.size() == 0) return null; |
| 2441 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2442 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2443 | } |
| 2444 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2445 | private RemoteViews makeHeadsUpContentView() { |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2446 | if (mActions.size() == 0) return null; |
| 2447 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2448 | return applyStandardTemplateWithActions(getBigBaseLayoutResource()); |
Chris Wren | 8fd39ec | 2014-02-27 17:43:26 -0500 | [diff] [blame] | 2449 | } |
| 2450 | |
| 2451 | |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2452 | private RemoteViews generateActionButton(Action action) { |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2453 | final boolean tombstone = (action.actionIntent == null); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2454 | RemoteViews button = new RemoteViews(mContext.getPackageName(), |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2455 | tombstone ? getActionTombstoneLayoutResource() |
| 2456 | : getActionLayoutResource()); |
Chris Wren | 8749ac8a | 2013-12-03 14:31:01 -0500 | [diff] [blame] | 2457 | button.setTextViewCompoundDrawablesRelative(R.id.action0, action.icon, 0, 0, 0); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2458 | button.setTextViewText(R.id.action0, processLegacyText(action.title)); |
Daniel Sandler | 8680bf8 | 2012-05-15 16:52:52 -0400 | [diff] [blame] | 2459 | if (!tombstone) { |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 2460 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
Daniel Sandler | e551884 | 2012-05-10 16:20:40 -0400 | [diff] [blame] | 2461 | } |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2462 | button.setContentDescription(R.id.action0, action.title); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2463 | processLegacyAction(action, button); |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2464 | return button; |
| 2465 | } |
| 2466 | |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2467 | /** |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2468 | * @return Whether we are currently building a notification from a legacy (an app that |
| 2469 | * doesn't create quantum notifications by itself) app. |
| 2470 | */ |
| 2471 | private boolean isLegacy() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2472 | return mColorUtil != null; |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2473 | } |
| 2474 | |
| 2475 | private void processLegacyAction(Action action, RemoteViews button) { |
| 2476 | if (isLegacy()) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2477 | if (mColorUtil.isGrayscale(mContext, action.icon)) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2478 | button.setTextViewCompoundDrawablesRelativeColorFilter(R.id.action0, 0, |
| 2479 | mContext.getResources().getColor( |
| 2480 | R.color.notification_action_legacy_color_filter), |
| 2481 | PorterDuff.Mode.MULTIPLY); |
| 2482 | } |
| 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | private CharSequence processLegacyText(CharSequence charSequence) { |
| 2487 | if (isLegacy()) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2488 | return mColorUtil.invertCharSequenceColors(charSequence); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2489 | } else { |
| 2490 | return charSequence; |
| 2491 | } |
| 2492 | } |
| 2493 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2494 | /** |
| 2495 | * Apply any necessary background to smallIcons being used in the largeIcon spot. |
| 2496 | */ |
| 2497 | private void processSmallIconAsLarge(int largeIconId, RemoteViews contentView) { |
| 2498 | if (!isLegacy() || mColorUtil.isGrayscale(mContext, largeIconId)) { |
| 2499 | applyLargeIconBackground(contentView); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2500 | } |
| 2501 | } |
| 2502 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2503 | /** |
| 2504 | * Apply any necessary background to a largeIcon if it's a fake smallIcon (that is, |
| 2505 | * if it's grayscale). |
| 2506 | */ |
| 2507 | // TODO: also check bounds, transparency, that sort of thing. |
| 2508 | private void processLargeIcon(Bitmap largeIcon, RemoteViews contentView) { |
| 2509 | if (!isLegacy() || mColorUtil.isGrayscale(largeIcon)) { |
| 2510 | applyLargeIconBackground(contentView); |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2511 | } else { |
| 2512 | removeLargeIconBackground(contentView); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2513 | } |
| 2514 | } |
| 2515 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2516 | /** |
| 2517 | * Add a colored circle behind the largeIcon slot. |
| 2518 | */ |
| 2519 | private void applyLargeIconBackground(RemoteViews contentView) { |
| 2520 | contentView.setInt(R.id.icon, "setBackgroundResource", |
| 2521 | R.drawable.notification_icon_legacy_bg_inset); |
| 2522 | |
| 2523 | contentView.setDrawableParameters( |
| 2524 | R.id.icon, |
| 2525 | true, |
| 2526 | -1, |
| 2527 | mColor, |
| 2528 | PorterDuff.Mode.SRC_ATOP, |
| 2529 | -1); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2530 | } |
| 2531 | |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2532 | private void removeLargeIconBackground(RemoteViews contentView) { |
| 2533 | contentView.setInt(R.id.icon, "setBackgroundResource", 0); |
| 2534 | } |
| 2535 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2536 | /** |
| 2537 | * Recolor small icons when used in the R.id.right_icon slot. |
| 2538 | */ |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2539 | private void processSmallRightIcon(int smallIconDrawableId, |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2540 | RemoteViews contentView) { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2541 | if (!isLegacy() || mColorUtil.isGrayscale(mContext, smallIconDrawableId)) { |
Dan Sandler | 190d58d | 2014-05-15 09:33:39 -0400 | [diff] [blame] | 2542 | contentView.setDrawableParameters(R.id.right_icon, false, -1, |
| 2543 | 0xFFFFFFFF, |
| 2544 | PorterDuff.Mode.SRC_ATOP, -1); |
| 2545 | |
| 2546 | contentView.setInt(R.id.right_icon, |
| 2547 | "setBackgroundResource", |
| 2548 | R.drawable.notification_icon_legacy_bg); |
| 2549 | |
| 2550 | contentView.setDrawableParameters( |
| 2551 | R.id.right_icon, |
| 2552 | true, |
| 2553 | -1, |
| 2554 | mColor, |
| 2555 | PorterDuff.Mode.SRC_ATOP, |
| 2556 | -1); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2557 | } |
| 2558 | } |
| 2559 | |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2560 | private int resolveColor() { |
| 2561 | if (mColor == COLOR_DEFAULT) { |
| 2562 | mColor = mContext.getResources().getColor(R.color.notification_icon_bg_color); |
| 2563 | } else { |
| 2564 | mColor |= 0xFF000000; // no alpha for custom colors |
| 2565 | } |
| 2566 | return mColor; |
| 2567 | } |
| 2568 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2569 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2570 | * Apply the unstyled operations and return a new {@link Notification} object. |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2571 | * @hide |
Joe Onorato | cb109a0 | 2011-01-18 17:57:41 -0800 | [diff] [blame] | 2572 | */ |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2573 | public Notification buildUnstyled() { |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2574 | Notification n = new Notification(); |
| 2575 | n.when = mWhen; |
| 2576 | n.icon = mSmallIcon; |
| 2577 | n.iconLevel = mSmallIconLevel; |
Joe Onorato | 8595a3d | 2010-11-19 18:12:07 -0800 | [diff] [blame] | 2578 | n.number = mNumber; |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2579 | |
| 2580 | n.color = resolveColor(); |
| 2581 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2582 | n.contentView = makeContentView(); |
| 2583 | n.contentIntent = mContentIntent; |
| 2584 | n.deleteIntent = mDeleteIntent; |
| 2585 | n.fullScreenIntent = mFullScreenIntent; |
| 2586 | n.tickerText = mTickerText; |
| 2587 | n.tickerView = makeTickerView(); |
| 2588 | n.largeIcon = mLargeIcon; |
| 2589 | n.sound = mSound; |
| 2590 | n.audioStreamType = mAudioStreamType; |
| 2591 | n.vibrate = mVibrate; |
| 2592 | n.ledARGB = mLedArgb; |
| 2593 | n.ledOnMS = mLedOnMs; |
| 2594 | n.ledOffMS = mLedOffMs; |
| 2595 | n.defaults = mDefaults; |
| 2596 | n.flags = mFlags; |
Daniel Sandler | 96fd7c1 | 2012-03-30 16:37:36 -0400 | [diff] [blame] | 2597 | n.bigContentView = makeBigContentView(); |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2598 | n.headsUpContentView = makeHeadsUpContentView(); |
Daniel Sandler | 26c1343 | 2013-04-04 11:01:04 -0400 | [diff] [blame] | 2599 | if (mLedOnMs != 0 || mLedOffMs != 0) { |
Joe Onorato | 8d0b655 | 2010-11-22 16:09:29 -0800 | [diff] [blame] | 2600 | n.flags |= FLAG_SHOW_LIGHTS; |
| 2601 | } |
| 2602 | if ((mDefaults & DEFAULT_LIGHTS) != 0) { |
| 2603 | n.flags |= FLAG_SHOW_LIGHTS; |
| 2604 | } |
John Spurlock | fd7f1e0 | 2014-03-18 16:41:57 -0400 | [diff] [blame] | 2605 | n.category = mCategory; |
Griff Hazen | 5cadc3b | 2014-05-20 09:55:39 -0700 | [diff] [blame] | 2606 | n.mGroupKey = mGroupKey; |
| 2607 | n.mSortKey = mSortKey; |
Daniel Sandler | 2561b0b | 2012-02-13 21:04:12 -0500 | [diff] [blame] | 2608 | n.priority = mPriority; |
Daniel Sandler | a0a938c | 2012-03-15 08:42:37 -0400 | [diff] [blame] | 2609 | if (mActions.size() > 0) { |
| 2610 | n.actions = new Action[mActions.size()]; |
| 2611 | mActions.toArray(n.actions); |
| 2612 | } |
Dan Sandler | 0bf2ed8 | 2013-12-21 23:33:41 -0600 | [diff] [blame] | 2613 | n.visibility = mVisibility; |
| 2614 | |
| 2615 | if (mPublicVersion != null) { |
| 2616 | n.publicVersion = new Notification(); |
| 2617 | mPublicVersion.cloneInto(n.publicVersion, true); |
| 2618 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2619 | |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2620 | return n; |
| 2621 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2622 | |
| 2623 | /** |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2624 | * Capture, in the provided bundle, semantic information used in the construction of |
| 2625 | * this Notification object. |
| 2626 | * @hide |
| 2627 | */ |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2628 | public void populateExtras(Bundle extras) { |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2629 | // Store original information used in the construction of this object |
| 2630 | extras.putCharSequence(EXTRA_TITLE, mContentTitle); |
| 2631 | extras.putCharSequence(EXTRA_TEXT, mContentText); |
| 2632 | extras.putCharSequence(EXTRA_SUB_TEXT, mSubText); |
| 2633 | extras.putCharSequence(EXTRA_INFO_TEXT, mContentInfo); |
| 2634 | extras.putInt(EXTRA_SMALL_ICON, mSmallIcon); |
| 2635 | extras.putInt(EXTRA_PROGRESS, mProgress); |
| 2636 | extras.putInt(EXTRA_PROGRESS_MAX, mProgressMax); |
| 2637 | extras.putBoolean(EXTRA_PROGRESS_INDETERMINATE, mProgressIndeterminate); |
| 2638 | extras.putBoolean(EXTRA_SHOW_CHRONOMETER, mUseChronometer); |
| 2639 | extras.putBoolean(EXTRA_SHOW_WHEN, mShowWhen); |
John Spurlock | ac08a47 | 2013-06-10 11:37:08 -0400 | [diff] [blame] | 2640 | if (mLargeIcon != null) { |
| 2641 | extras.putParcelable(EXTRA_LARGE_ICON, mLargeIcon); |
| 2642 | } |
Chris Wren | dde7530 | 2014-03-26 17:24:15 -0400 | [diff] [blame] | 2643 | if (!mPeople.isEmpty()) { |
| 2644 | extras.putStringArray(EXTRA_PEOPLE, mPeople.toArray(new String[mPeople.size()])); |
| 2645 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2646 | } |
| 2647 | |
| 2648 | /** |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2649 | * @deprecated Use {@link #build()} instead. |
| 2650 | */ |
| 2651 | @Deprecated |
| 2652 | public Notification getNotification() { |
| 2653 | return build(); |
| 2654 | } |
| 2655 | |
| 2656 | /** |
| 2657 | * Combine all of the options that have been set and return a new {@link Notification} |
| 2658 | * object. |
| 2659 | */ |
| 2660 | public Notification build() { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2661 | Notification n = buildUnstyled(); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2662 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2663 | if (mStyle != null) { |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2664 | n = mStyle.buildStyled(n); |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2665 | } |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2666 | |
| 2667 | n.extras = mExtras != null ? new Bundle(mExtras) : new Bundle(); |
| 2668 | |
Griff Hazen | 720042b | 2014-02-24 15:46:56 -0800 | [diff] [blame] | 2669 | populateExtras(n.extras); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2670 | if (mStyle != null) { |
| 2671 | mStyle.addExtras(n.extras); |
| 2672 | } |
| 2673 | |
| 2674 | return n; |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2675 | } |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2676 | |
| 2677 | /** |
| 2678 | * Apply this Builder to an existing {@link Notification} object. |
| 2679 | * |
| 2680 | * @hide |
| 2681 | */ |
| 2682 | public Notification buildInto(Notification n) { |
Daniel Sandler | 1a497d3 | 2013-04-18 14:52:45 -0400 | [diff] [blame] | 2683 | build().cloneInto(n, true); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 2684 | return n; |
| 2685 | } |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2686 | |
| 2687 | |
| 2688 | private int getBaseLayoutResource() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2689 | return R.layout.notification_template_quantum_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2690 | } |
| 2691 | |
| 2692 | private int getBigBaseLayoutResource() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2693 | return R.layout.notification_template_quantum_big_base; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2694 | } |
| 2695 | |
| 2696 | private int getBigPictureLayoutResource() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2697 | return R.layout.notification_template_quantum_big_picture; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2698 | } |
| 2699 | |
| 2700 | private int getBigTextLayoutResource() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2701 | return R.layout.notification_template_quantum_big_text; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2702 | } |
| 2703 | |
| 2704 | private int getInboxLayoutResource() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2705 | return R.layout.notification_template_quantum_inbox; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2706 | } |
| 2707 | |
| 2708 | private int getActionLayoutResource() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2709 | return R.layout.notification_quantum_action; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2710 | } |
| 2711 | |
| 2712 | private int getActionTombstoneLayoutResource() { |
Dan Sandler | 26e81cf | 2014-05-06 10:01:27 -0400 | [diff] [blame] | 2713 | return R.layout.notification_quantum_action_tombstone; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2714 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2715 | } |
| 2716 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2717 | /** |
| 2718 | * An object that can apply a rich notification style to a {@link Notification.Builder} |
| 2719 | * object. |
| 2720 | */ |
Griff Hazen | dfcb080 | 2014-02-11 12:00:00 -0800 | [diff] [blame] | 2721 | public static abstract class Style { |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2722 | private CharSequence mBigContentTitle; |
| 2723 | private CharSequence mSummaryText = null; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2724 | private boolean mSummaryTextSet = false; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2725 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2726 | protected Builder mBuilder; |
| 2727 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2728 | /** |
| 2729 | * Overrides ContentTitle in the big form of the template. |
| 2730 | * This defaults to the value passed to setContentTitle(). |
| 2731 | */ |
| 2732 | protected void internalSetBigContentTitle(CharSequence title) { |
| 2733 | mBigContentTitle = title; |
| 2734 | } |
| 2735 | |
| 2736 | /** |
| 2737 | * Set the first line of text after the detail section in the big form of the template. |
| 2738 | */ |
| 2739 | protected void internalSetSummaryText(CharSequence cs) { |
| 2740 | mSummaryText = cs; |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2741 | mSummaryTextSet = true; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2742 | } |
| 2743 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2744 | public void setBuilder(Builder builder) { |
| 2745 | if (mBuilder != builder) { |
| 2746 | mBuilder = builder; |
Daniel Sandler | c08dea2 | 2012-06-28 08:35:24 -0700 | [diff] [blame] | 2747 | if (mBuilder != null) { |
| 2748 | mBuilder.setStyle(this); |
| 2749 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2750 | } |
| 2751 | } |
| 2752 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2753 | protected void checkBuilder() { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2754 | if (mBuilder == null) { |
| 2755 | throw new IllegalArgumentException("Style requires a valid Builder object"); |
| 2756 | } |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2757 | } |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2758 | |
| 2759 | protected RemoteViews getStandardView(int layoutId) { |
| 2760 | checkBuilder(); |
| 2761 | |
| 2762 | if (mBigContentTitle != null) { |
| 2763 | mBuilder.setContentTitle(mBigContentTitle); |
| 2764 | } |
| 2765 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2766 | RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(layoutId); |
| 2767 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2768 | if (mBigContentTitle != null && mBigContentTitle.equals("")) { |
| 2769 | contentView.setViewVisibility(R.id.line1, View.GONE); |
Chris Wren | 67dc9a0 | 2012-05-16 01:03:20 -0400 | [diff] [blame] | 2770 | } else { |
| 2771 | contentView.setViewVisibility(R.id.line1, View.VISIBLE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2772 | } |
| 2773 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2774 | // The last line defaults to the subtext, but can be replaced by mSummaryText |
| 2775 | final CharSequence overflowText = |
| 2776 | mSummaryTextSet ? mSummaryText |
| 2777 | : mBuilder.mSubText; |
| 2778 | if (overflowText != null) { |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2779 | contentView.setTextViewText(R.id.text, mBuilder.processLegacyText(overflowText)); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2780 | contentView.setViewVisibility(R.id.overflow_divider, View.VISIBLE); |
Daniel Sandler | 9f7936a | 2012-05-21 16:14:28 -0400 | [diff] [blame] | 2781 | contentView.setViewVisibility(R.id.line3, View.VISIBLE); |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 2782 | } else { |
| 2783 | contentView.setViewVisibility(R.id.overflow_divider, View.GONE); |
| 2784 | contentView.setViewVisibility(R.id.line3, View.GONE); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2785 | } |
| 2786 | |
| 2787 | return contentView; |
| 2788 | } |
| 2789 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2790 | /** |
| 2791 | * @hide |
| 2792 | */ |
| 2793 | public void addExtras(Bundle extras) { |
| 2794 | if (mSummaryTextSet) { |
| 2795 | extras.putCharSequence(EXTRA_SUMMARY_TEXT, mSummaryText); |
| 2796 | } |
| 2797 | if (mBigContentTitle != null) { |
| 2798 | extras.putCharSequence(EXTRA_TITLE_BIG, mBigContentTitle); |
| 2799 | } |
Chris Wren | 91ad563 | 2013-06-05 15:05:57 -0400 | [diff] [blame] | 2800 | extras.putString(EXTRA_TEMPLATE, this.getClass().getName()); |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2801 | } |
| 2802 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2803 | /** |
| 2804 | * @hide |
| 2805 | */ |
| 2806 | public abstract Notification buildStyled(Notification wip); |
| 2807 | |
| 2808 | /** |
| 2809 | * Calls {@link android.app.Notification.Builder#build()} on the Builder this Style is |
| 2810 | * attached to. |
| 2811 | * |
| 2812 | * @return the fully constructed Notification. |
| 2813 | */ |
| 2814 | public Notification build() { |
| 2815 | checkBuilder(); |
| 2816 | return mBuilder.build(); |
| 2817 | } |
Joe Onorato | 46439ce | 2010-11-19 13:56:21 -0800 | [diff] [blame] | 2818 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2819 | |
| 2820 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2821 | * 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] | 2822 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2823 | * 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] | 2824 | * <pre class="prettyprint"> |
| 2825 | * Notification noti = new Notification.BigPictureStyle( |
| 2826 | * new Notification.Builder() |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2827 | * .setContentTitle("New photo from " + sender.toString()) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2828 | * .setContentText(subject) |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2829 | * .setSmallIcon(R.drawable.new_post) |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2830 | * .setLargeIcon(aBitmap)) |
| 2831 | * .bigPicture(aBigBitmap) |
| 2832 | * .build(); |
| 2833 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2834 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2835 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2836 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2837 | public static class BigPictureStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2838 | private Bitmap mPicture; |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2839 | private Bitmap mBigLargeIcon; |
| 2840 | private boolean mBigLargeIconSet = false; |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2841 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2842 | public BigPictureStyle() { |
| 2843 | } |
| 2844 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2845 | public BigPictureStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2846 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2847 | } |
| 2848 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2849 | /** |
| 2850 | * Overrides ContentTitle in the big form of the template. |
| 2851 | * This defaults to the value passed to setContentTitle(). |
| 2852 | */ |
| 2853 | public BigPictureStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2854 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2855 | return this; |
| 2856 | } |
| 2857 | |
| 2858 | /** |
| 2859 | * Set the first line of text after the detail section in the big form of the template. |
| 2860 | */ |
| 2861 | public BigPictureStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2862 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2863 | return this; |
| 2864 | } |
| 2865 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 2866 | /** |
| 2867 | * Provide the bitmap to be used as the payload for the BigPicture notification. |
| 2868 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2869 | public BigPictureStyle bigPicture(Bitmap b) { |
| 2870 | mPicture = b; |
| 2871 | return this; |
| 2872 | } |
| 2873 | |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2874 | /** |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2875 | * Override the large icon when the big notification is shown. |
| 2876 | */ |
| 2877 | public BigPictureStyle bigLargeIcon(Bitmap b) { |
| 2878 | mBigLargeIconSet = true; |
| 2879 | mBigLargeIcon = b; |
| 2880 | return this; |
| 2881 | } |
| 2882 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2883 | private RemoteViews makeBigContentView() { |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2884 | RemoteViews contentView = getStandardView(mBuilder.getBigPictureLayoutResource()); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2885 | |
| 2886 | contentView.setImageViewBitmap(R.id.big_picture, mPicture); |
| 2887 | |
| 2888 | return contentView; |
| 2889 | } |
| 2890 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2891 | /** |
| 2892 | * @hide |
| 2893 | */ |
| 2894 | public void addExtras(Bundle extras) { |
| 2895 | super.addExtras(extras); |
| 2896 | |
| 2897 | if (mBigLargeIconSet) { |
| 2898 | extras.putParcelable(EXTRA_LARGE_ICON_BIG, mBigLargeIcon); |
| 2899 | } |
| 2900 | extras.putParcelable(EXTRA_PICTURE, mPicture); |
| 2901 | } |
| 2902 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2903 | /** |
| 2904 | * @hide |
| 2905 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2906 | @Override |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2907 | public Notification buildStyled(Notification wip) { |
Chris Wren | 3745a3d | 2012-05-22 15:11:52 -0400 | [diff] [blame] | 2908 | if (mBigLargeIconSet ) { |
| 2909 | mBuilder.mLargeIcon = mBigLargeIcon; |
| 2910 | } |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2911 | wip.bigContentView = makeBigContentView(); |
| 2912 | return wip; |
| 2913 | } |
| 2914 | } |
| 2915 | |
| 2916 | /** |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2917 | * 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] | 2918 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2919 | * 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] | 2920 | * <pre class="prettyprint"> |
Daniel Sandler | 8768278 | 2012-11-07 14:04:42 -0500 | [diff] [blame] | 2921 | * Notification noti = new Notification.BigTextStyle( |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2922 | * new Notification.Builder() |
| 2923 | * .setContentTitle("New mail from " + sender.toString()) |
| 2924 | * .setContentText(subject) |
| 2925 | * .setSmallIcon(R.drawable.new_mail) |
| 2926 | * .setLargeIcon(aBitmap)) |
| 2927 | * .bigText(aVeryLongString) |
| 2928 | * .build(); |
| 2929 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2930 | * |
Daniel Sandler | 4dfbe83 | 2012-04-11 14:51:46 -0400 | [diff] [blame] | 2931 | * @see Notification#bigContentView |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2932 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2933 | public static class BigTextStyle extends Style { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2934 | private CharSequence mBigText; |
| 2935 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2936 | public BigTextStyle() { |
| 2937 | } |
| 2938 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2939 | public BigTextStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 2940 | setBuilder(builder); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2941 | } |
| 2942 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2943 | /** |
| 2944 | * Overrides ContentTitle in the big form of the template. |
| 2945 | * This defaults to the value passed to setContentTitle(). |
| 2946 | */ |
| 2947 | public BigTextStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2948 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2949 | return this; |
| 2950 | } |
| 2951 | |
| 2952 | /** |
| 2953 | * Set the first line of text after the detail section in the big form of the template. |
| 2954 | */ |
| 2955 | public BigTextStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2956 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 2957 | return this; |
| 2958 | } |
| 2959 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 2960 | /** |
| 2961 | * Provide the longer text to be displayed in the big form of the |
| 2962 | * template in place of the content text. |
| 2963 | */ |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2964 | public BigTextStyle bigText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 2965 | mBigText = safeCharSequence(cs); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2966 | return this; |
| 2967 | } |
| 2968 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 2969 | /** |
| 2970 | * @hide |
| 2971 | */ |
| 2972 | public void addExtras(Bundle extras) { |
| 2973 | super.addExtras(extras); |
| 2974 | |
| 2975 | extras.putCharSequence(EXTRA_TEXT, mBigText); |
| 2976 | } |
| 2977 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2978 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2979 | // Remove the content text so line3 only shows if you have a summary |
| 2980 | final boolean hadThreeLines = (mBuilder.mContentText != null && mBuilder.mSubText != null); |
Daniel Sandler | 6387d2f | 2012-05-22 13:44:09 -0400 | [diff] [blame] | 2981 | mBuilder.mContentText = null; |
Daniel Sandler | 916ad91 | 2012-06-13 12:17:07 -0400 | [diff] [blame] | 2982 | |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 2983 | RemoteViews contentView = getStandardView(mBuilder.getBigTextLayoutResource()); |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 2984 | |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 2985 | if (hadThreeLines) { |
| 2986 | // vertical centering |
| 2987 | contentView.setViewPadding(R.id.line1, 0, 0, 0, 0); |
| 2988 | } |
| 2989 | |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 2990 | contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText)); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2991 | contentView.setViewVisibility(R.id.big_text, View.VISIBLE); |
Chris Wren | 3c5f9243 | 2012-05-04 16:31:17 -0400 | [diff] [blame] | 2992 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 2993 | |
| 2994 | return contentView; |
| 2995 | } |
| 2996 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 2997 | /** |
| 2998 | * @hide |
| 2999 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3000 | @Override |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3001 | public Notification buildStyled(Notification wip) { |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3002 | wip.bigContentView = makeBigContentView(); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3003 | |
| 3004 | wip.extras.putCharSequence(EXTRA_TEXT, mBigText); |
| 3005 | |
Daniel Sandler | f3b7343 | 2012-03-27 15:01:25 -0400 | [diff] [blame] | 3006 | return wip; |
| 3007 | } |
| 3008 | } |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3009 | |
| 3010 | /** |
| 3011 | * 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] | 3012 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3013 | * This class is a "rebuilder": It consumes a Builder object and modifies its behavior, like so: |
| 3014 | * <pre class="prettyprint"> |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3015 | * Notification noti = new Notification.InboxStyle( |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3016 | * new Notification.Builder() |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3017 | * .setContentTitle("5 New mails from " + sender.toString()) |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3018 | * .setContentText(subject) |
| 3019 | * .setSmallIcon(R.drawable.new_mail) |
| 3020 | * .setLargeIcon(aBitmap)) |
| 3021 | * .addLine(str1) |
| 3022 | * .addLine(str2) |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3023 | * .setContentTitle("") |
| 3024 | * .setSummaryText("+3 more") |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3025 | * .build(); |
| 3026 | * </pre> |
Joe Malin | 8d40d04 | 2012-11-05 11:36:40 -0800 | [diff] [blame] | 3027 | * |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3028 | * @see Notification#bigContentView |
| 3029 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3030 | public static class InboxStyle extends Style { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3031 | private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5); |
| 3032 | |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3033 | public InboxStyle() { |
| 3034 | } |
| 3035 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3036 | public InboxStyle(Builder builder) { |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3037 | setBuilder(builder); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3038 | } |
| 3039 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3040 | /** |
| 3041 | * Overrides ContentTitle in the big form of the template. |
| 3042 | * This defaults to the value passed to setContentTitle(). |
| 3043 | */ |
| 3044 | public InboxStyle setBigContentTitle(CharSequence title) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3045 | internalSetBigContentTitle(safeCharSequence(title)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3046 | return this; |
| 3047 | } |
| 3048 | |
| 3049 | /** |
| 3050 | * Set the first line of text after the detail section in the big form of the template. |
| 3051 | */ |
| 3052 | public InboxStyle setSummaryText(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3053 | internalSetSummaryText(safeCharSequence(cs)); |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3054 | return this; |
| 3055 | } |
| 3056 | |
Chris Wren | 0bd664d | 2012-08-01 13:56:56 -0400 | [diff] [blame] | 3057 | /** |
| 3058 | * Append a line to the digest section of the Inbox notification. |
| 3059 | */ |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3060 | public InboxStyle addLine(CharSequence cs) { |
Daniel Sandler | dcbaf66 | 2013-04-26 16:23:09 -0400 | [diff] [blame] | 3061 | mTexts.add(safeCharSequence(cs)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3062 | return this; |
| 3063 | } |
| 3064 | |
Daniel Sandler | f45564e | 2013-04-15 15:05:08 -0400 | [diff] [blame] | 3065 | /** |
| 3066 | * @hide |
| 3067 | */ |
| 3068 | public void addExtras(Bundle extras) { |
| 3069 | super.addExtras(extras); |
| 3070 | CharSequence[] a = new CharSequence[mTexts.size()]; |
| 3071 | extras.putCharSequenceArray(EXTRA_TEXT_LINES, mTexts.toArray(a)); |
| 3072 | } |
| 3073 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3074 | private RemoteViews makeBigContentView() { |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3075 | // Remove the content text so line3 disappears unless you have a summary |
| 3076 | mBuilder.mContentText = null; |
Jorim Jaggi | 39fa59f | 2014-02-25 15:38:45 +0100 | [diff] [blame] | 3077 | RemoteViews contentView = getStandardView(mBuilder.getInboxLayoutResource()); |
Daniel Sandler | 619738c | 2012-06-07 16:33:08 -0400 | [diff] [blame] | 3078 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3079 | contentView.setViewVisibility(R.id.text2, View.GONE); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3080 | |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3081 | 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] | 3082 | R.id.inbox_text4, R.id.inbox_text5, R.id.inbox_text6}; |
Chris Wren | d6297db | 2012-05-03 16:20:13 -0400 | [diff] [blame] | 3083 | |
Chris Wren | 4ed80d5 | 2012-05-17 09:30:03 -0400 | [diff] [blame] | 3084 | // Make sure all rows are gone in case we reuse a view. |
| 3085 | for (int rowId : rowIds) { |
| 3086 | contentView.setViewVisibility(rowId, View.GONE); |
| 3087 | } |
| 3088 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 3089 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3090 | int i=0; |
| 3091 | while (i < mTexts.size() && i < rowIds.length) { |
| 3092 | CharSequence str = mTexts.get(i); |
| 3093 | if (str != null && !str.equals("")) { |
| 3094 | contentView.setViewVisibility(rowIds[i], View.VISIBLE); |
Jorim Jaggi | 5c2d846 | 2014-03-21 17:37:00 +0100 | [diff] [blame] | 3095 | contentView.setTextViewText(rowIds[i], mBuilder.processLegacyText(str)); |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3096 | } |
| 3097 | i++; |
| 3098 | } |
| 3099 | |
Chris Wren | 683ab00 | 2012-09-20 10:35:54 -0400 | [diff] [blame] | 3100 | contentView.setViewVisibility(R.id.inbox_end_pad, |
| 3101 | mTexts.size() > 0 ? View.VISIBLE : View.GONE); |
| 3102 | |
| 3103 | contentView.setViewVisibility(R.id.inbox_more, |
| 3104 | mTexts.size() > rowIds.length ? View.VISIBLE : View.GONE); |
Chris Wren | 29bb6d9 | 2012-05-17 18:09:42 -0400 | [diff] [blame] | 3105 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3106 | return contentView; |
| 3107 | } |
| 3108 | |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3109 | /** |
| 3110 | * @hide |
| 3111 | */ |
Chris Wren | fbd96ba | 2012-05-01 12:03:58 -0400 | [diff] [blame] | 3112 | @Override |
Daniel Sandler | cf1d39b | 2013-09-23 13:35:35 -0400 | [diff] [blame] | 3113 | public Notification buildStyled(Notification wip) { |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3114 | wip.bigContentView = makeBigContentView(); |
Daniel Sandler | be6e7e0 | 2013-02-01 17:49:11 -0500 | [diff] [blame] | 3115 | |
Daniel Sandler | 879c5e0 | 2012-04-17 16:46:51 -0400 | [diff] [blame] | 3116 | return wip; |
| 3117 | } |
| 3118 | } |
Dan Sandler | 842dd77 | 2014-05-15 09:36:47 -0400 | [diff] [blame] | 3119 | |
| 3120 | /** |
| 3121 | * Notification style for media playback notifications. |
| 3122 | * |
| 3123 | * In the expanded form, {@link Notification#bigContentView}, up to 5 |
| 3124 | * {@link Notification.Action}s specified with |
| 3125 | * {@link Notification.Builder#addAction(int, CharSequence, PendingIntent) addAction} will be |
| 3126 | * shown as icon-only pushbuttons, suitable for transport controls. The Bitmap given to |
| 3127 | * {@link Notification.Builder#setLargeIcon(android.graphics.Bitmap) setLargeIcon()} will be |
| 3128 | * treated as album artwork. |
| 3129 | * |
| 3130 | * Unlike the other styles provided here, MediaStyle can also modify the standard-size |
| 3131 | * {@link Notification#contentView}; by providing action indices to |
| 3132 | * {@link #setShowActionsInCompactView(int...)} you can promote up to 2 actions to be displayed |
| 3133 | * in the standard view alongside the usual content. |
| 3134 | * |
| 3135 | * Finally, if you attach a {@link android.media.session.MediaSessionToken} using |
| 3136 | * {@link android.app.Notification.MediaStyle#setMediaSession(MediaSessionToken)}, |
| 3137 | * the System UI can identify this as a notification representing an active media session |
| 3138 | * and respond accordingly (by showing album artwork in the lockscreen, for example). |
| 3139 | * |
| 3140 | * To use this style with your Notification, feed it to |
| 3141 | * {@link Notification.Builder#setStyle(android.app.Notification.Style)} like so: |
| 3142 | * <pre class="prettyprint"> |
| 3143 | * Notification noti = new Notification.Builder() |
| 3144 | * .setSmallIcon(R.drawable.ic_stat_player) |
| 3145 | * .setContentTitle("Track title") // these three lines are optional |
| 3146 | * .setContentText("Artist - Album") // if you use |
| 3147 | * .setLargeIcon(albumArtBitmap)) // setMediaSession(token, true) |
| 3148 | * .setMediaSession(mySession, true) |
| 3149 | * .setStyle(<b>new Notification.MediaStyle()</b>) |
| 3150 | * .build(); |
| 3151 | * </pre> |
| 3152 | * |
| 3153 | * @see Notification#bigContentView |
| 3154 | */ |
| 3155 | public static class MediaStyle extends Style { |
| 3156 | static final int MAX_MEDIA_BUTTONS_IN_COMPACT = 2; |
| 3157 | static final int MAX_MEDIA_BUTTONS = 5; |
| 3158 | |
| 3159 | private int[] mActionsToShowInCompact = null; |
| 3160 | private MediaSessionToken mToken; |
| 3161 | |
| 3162 | public MediaStyle() { |
| 3163 | } |
| 3164 | |
| 3165 | public MediaStyle(Builder builder) { |
| 3166 | setBuilder(builder); |
| 3167 | } |
| 3168 | |
| 3169 | /** |
| 3170 | * Request up to 2 actions (by index in the order of addition) to be shown in the compact |
| 3171 | * notification view. |
| 3172 | */ |
| 3173 | public MediaStyle setShowActionsInCompactView(int...actions) { |
| 3174 | mActionsToShowInCompact = actions; |
| 3175 | return this; |
| 3176 | } |
| 3177 | |
| 3178 | /** |
| 3179 | * Attach a {@link android.media.session.MediaSessionToken} to this Notification to provide |
| 3180 | * additional playback information and control to the SystemUI. |
| 3181 | */ |
| 3182 | public MediaStyle setMediaSession(MediaSessionToken token) { |
| 3183 | mToken = token; |
| 3184 | return this; |
| 3185 | } |
| 3186 | |
| 3187 | @Override |
| 3188 | public Notification buildStyled(Notification wip) { |
| 3189 | wip.contentView = makeMediaContentView(); |
| 3190 | wip.bigContentView = makeMediaBigContentView(); |
| 3191 | |
| 3192 | return wip; |
| 3193 | } |
| 3194 | |
| 3195 | /** @hide */ |
| 3196 | @Override |
| 3197 | public void addExtras(Bundle extras) { |
| 3198 | super.addExtras(extras); |
| 3199 | |
| 3200 | if (mToken != null) { |
| 3201 | extras.putParcelable(EXTRA_MEDIA_SESSION, mToken); |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | private RemoteViews generateMediaActionButton(Action action) { |
| 3206 | final boolean tombstone = (action.actionIntent == null); |
| 3207 | RemoteViews button = new RemoteViews(mBuilder.mContext.getPackageName(), |
| 3208 | R.layout.notification_quantum_media_action); |
| 3209 | button.setImageViewResource(R.id.action0, action.icon); |
| 3210 | if (!tombstone) { |
| 3211 | button.setOnClickPendingIntent(R.id.action0, action.actionIntent); |
| 3212 | } |
| 3213 | button.setContentDescription(R.id.action0, action.title); |
| 3214 | return button; |
| 3215 | } |
| 3216 | |
| 3217 | private RemoteViews makeMediaContentView() { |
| 3218 | RemoteViews view = mBuilder.applyStandardTemplate( |
| 3219 | R.layout.notification_template_quantum_media, true /* 1U */); |
| 3220 | |
| 3221 | final int numActions = mBuilder.mActions.size(); |
| 3222 | final int N = mActionsToShowInCompact == null |
| 3223 | ? 0 |
| 3224 | : Math.min(mActionsToShowInCompact.length, MAX_MEDIA_BUTTONS_IN_COMPACT); |
| 3225 | if (N > 0) { |
| 3226 | view.removeAllViews(R.id.actions); |
| 3227 | for (int i = 0; i < N; i++) { |
| 3228 | if (i >= numActions) { |
| 3229 | throw new IllegalArgumentException(String.format( |
| 3230 | "setShowActionsInCompactView: action %d out of bounds (max %d)", |
| 3231 | i, numActions - 1)); |
| 3232 | } |
| 3233 | |
| 3234 | final Action action = mBuilder.mActions.get(mActionsToShowInCompact[i]); |
| 3235 | final RemoteViews button = generateMediaActionButton(action); |
| 3236 | view.addView(R.id.actions, button); |
| 3237 | } |
| 3238 | } |
| 3239 | return view; |
| 3240 | } |
| 3241 | |
| 3242 | private RemoteViews makeMediaBigContentView() { |
| 3243 | RemoteViews big = mBuilder.applyStandardTemplate( |
| 3244 | R.layout.notification_template_quantum_big_media, false); |
| 3245 | |
| 3246 | final int N = Math.min(mBuilder.mActions.size(), MAX_MEDIA_BUTTONS); |
| 3247 | if (N > 0) { |
| 3248 | big.removeAllViews(R.id.actions); |
| 3249 | for (int i=0; i<N; i++) { |
| 3250 | final RemoteViews button = generateMediaActionButton(mBuilder.mActions.get(i)); |
| 3251 | big.addView(R.id.actions, button); |
| 3252 | } |
| 3253 | } |
| 3254 | return big; |
| 3255 | } |
| 3256 | } |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3257 | |
| 3258 | /** |
| 3259 | * Extender interface for use with {@link Builder#extend}. Extenders may be used to add |
| 3260 | * metadata or change options on a notification builder. |
| 3261 | */ |
| 3262 | public interface Extender { |
| 3263 | /** |
| 3264 | * Apply this extender to a notification builder. |
| 3265 | * @param builder the builder to be modified. |
| 3266 | * @return the build object for chaining. |
| 3267 | */ |
| 3268 | public Builder extend(Builder builder); |
| 3269 | } |
| 3270 | |
| 3271 | /** |
| 3272 | * Helper class to add wearable extensions to notifications. |
| 3273 | * <p class="note"> See |
| 3274 | * <a href="{@docRoot}wear/notifications/creating.html">Creating Notifications |
| 3275 | * for Android Wear</a> for more information on how to use this class. |
| 3276 | * <p> |
| 3277 | * To create a notification with wearable extensions: |
| 3278 | * <ol> |
| 3279 | * <li>Create a {@link android.app.Notification.Builder}, setting any desired |
| 3280 | * properties. |
| 3281 | * <li>Create a {@link android.app.Notification.WearableExtender}. |
| 3282 | * <li>Set wearable-specific properties using the |
| 3283 | * {@code add} and {@code set} methods of {@link android.app.Notification.WearableExtender}. |
| 3284 | * <li>Call {@link android.app.Notification.Builder#extend} to apply the extensions to a |
| 3285 | * notification. |
| 3286 | * <li>Post the notification to the notification system with the |
| 3287 | * {@code NotificationManager.notify(...)} methods. |
| 3288 | * </ol> |
| 3289 | * |
| 3290 | * <pre class="prettyprint"> |
| 3291 | * Notification notif = new Notification.Builder(mContext) |
| 3292 | * .setContentTitle("New mail from " + sender.toString()) |
| 3293 | * .setContentText(subject) |
| 3294 | * .setSmallIcon(R.drawable.new_mail) |
| 3295 | * .extend(new Notification.WearableExtender() |
| 3296 | * .setContentIcon(R.drawable.new_mail)) |
| 3297 | * .build(); |
| 3298 | * NotificationManager notificationManger = |
| 3299 | * (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); |
| 3300 | * notificationManger.notify(0, notif);</pre> |
| 3301 | * |
| 3302 | * <p>Wearable extensions can be accessed on an existing notification by using the |
| 3303 | * {@code WearableExtender(Notification)} constructor, |
| 3304 | * and then using the {@code get} methods to access values. |
| 3305 | * |
| 3306 | * <pre class="prettyprint"> |
| 3307 | * Notification.WearableExtender wearableExtender = new Notification.WearableExtender( |
| 3308 | * notification); |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame^] | 3309 | * List<Notification> pages = wearableExtender.getPages();</pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3310 | */ |
| 3311 | public static final class WearableExtender implements Extender { |
| 3312 | /** |
| 3313 | * Sentinel value for an action index that is unset. |
| 3314 | */ |
| 3315 | public static final int UNSET_ACTION_INDEX = -1; |
| 3316 | |
| 3317 | /** |
| 3318 | * Size value for use with {@link #setCustomSizePreset} to show this notification with |
| 3319 | * default sizing. |
| 3320 | * <p>For custom display notifications created using {@link #setDisplayIntent}, |
| 3321 | * the default is {@link #SIZE_LARGE}. All other notifications size automatically based |
| 3322 | * on their content. |
| 3323 | */ |
| 3324 | public static final int SIZE_DEFAULT = 0; |
| 3325 | |
| 3326 | /** |
| 3327 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 3328 | * with an extra small size. |
| 3329 | * <p>This value is only applicable for custom display notifications created using |
| 3330 | * {@link #setDisplayIntent}. |
| 3331 | */ |
| 3332 | public static final int SIZE_XSMALL = 1; |
| 3333 | |
| 3334 | /** |
| 3335 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 3336 | * with a small size. |
| 3337 | * <p>This value is only applicable for custom display notifications created using |
| 3338 | * {@link #setDisplayIntent}. |
| 3339 | */ |
| 3340 | public static final int SIZE_SMALL = 2; |
| 3341 | |
| 3342 | /** |
| 3343 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 3344 | * with a medium size. |
| 3345 | * <p>This value is only applicable for custom display notifications created using |
| 3346 | * {@link #setDisplayIntent}. |
| 3347 | */ |
| 3348 | public static final int SIZE_MEDIUM = 3; |
| 3349 | |
| 3350 | /** |
| 3351 | * Size value for use with {@link #setCustomSizePreset} to show this notification |
| 3352 | * with a large size. |
| 3353 | * <p>This value is only applicable for custom display notifications created using |
| 3354 | * {@link #setDisplayIntent}. |
| 3355 | */ |
| 3356 | public static final int SIZE_LARGE = 4; |
| 3357 | |
| 3358 | /** Notification extra which contains wearable extensions */ |
| 3359 | private static final String EXTRA_WEARABLE_EXTENSIONS = "android.wearable.EXTENSIONS"; |
| 3360 | |
| 3361 | // Keys within EXTRA_WEARABLE_OPTIONS for wearable options. |
| 3362 | private static final String KEY_ACTIONS = "actions"; |
| 3363 | private static final String KEY_FLAGS = "flags"; |
| 3364 | private static final String KEY_DISPLAY_INTENT = "displayIntent"; |
| 3365 | private static final String KEY_PAGES = "pages"; |
| 3366 | private static final String KEY_BACKGROUND = "background"; |
| 3367 | private static final String KEY_CONTENT_ICON = "contentIcon"; |
| 3368 | private static final String KEY_CONTENT_ICON_GRAVITY = "contentIconGravity"; |
| 3369 | private static final String KEY_CONTENT_ACTION_INDEX = "contentActionIndex"; |
| 3370 | private static final String KEY_CUSTOM_SIZE_PRESET = "customSizePreset"; |
| 3371 | private static final String KEY_CUSTOM_CONTENT_HEIGHT = "customContentHeight"; |
| 3372 | private static final String KEY_GRAVITY = "gravity"; |
| 3373 | |
| 3374 | // Flags bitwise-ored to mFlags |
| 3375 | private static final int FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE = 0x1; |
| 3376 | private static final int FLAG_HINT_HIDE_ICON = 1 << 1; |
| 3377 | private static final int FLAG_HINT_SHOW_BACKGROUND_ONLY = 1 << 2; |
| 3378 | private static final int FLAG_START_SCROLL_BOTTOM = 1 << 3; |
| 3379 | |
| 3380 | // Default value for flags integer |
| 3381 | private static final int DEFAULT_FLAGS = FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE; |
| 3382 | |
| 3383 | private static final int DEFAULT_CONTENT_ICON_GRAVITY = Gravity.END; |
| 3384 | private static final int DEFAULT_GRAVITY = Gravity.BOTTOM; |
| 3385 | |
| 3386 | private ArrayList<Action> mActions = new ArrayList<Action>(); |
| 3387 | private int mFlags = DEFAULT_FLAGS; |
| 3388 | private PendingIntent mDisplayIntent; |
| 3389 | private ArrayList<Notification> mPages = new ArrayList<Notification>(); |
| 3390 | private Bitmap mBackground; |
| 3391 | private int mContentIcon; |
| 3392 | private int mContentIconGravity = DEFAULT_CONTENT_ICON_GRAVITY; |
| 3393 | private int mContentActionIndex = UNSET_ACTION_INDEX; |
| 3394 | private int mCustomSizePreset = SIZE_DEFAULT; |
| 3395 | private int mCustomContentHeight; |
| 3396 | private int mGravity = DEFAULT_GRAVITY; |
| 3397 | |
| 3398 | /** |
| 3399 | * Create a {@link android.app.Notification.WearableExtender} with default |
| 3400 | * options. |
| 3401 | */ |
| 3402 | public WearableExtender() { |
| 3403 | } |
| 3404 | |
| 3405 | public WearableExtender(Notification notif) { |
| 3406 | Bundle wearableBundle = notif.extras.getBundle(EXTRA_WEARABLE_EXTENSIONS); |
| 3407 | if (wearableBundle != null) { |
| 3408 | List<Action> actions = wearableBundle.getParcelableArrayList(KEY_ACTIONS); |
| 3409 | if (actions != null) { |
| 3410 | mActions.addAll(actions); |
| 3411 | } |
| 3412 | |
| 3413 | mFlags = wearableBundle.getInt(KEY_FLAGS, DEFAULT_FLAGS); |
| 3414 | mDisplayIntent = wearableBundle.getParcelable(KEY_DISPLAY_INTENT); |
| 3415 | |
| 3416 | Notification[] pages = getNotificationArrayFromBundle( |
| 3417 | wearableBundle, KEY_PAGES); |
| 3418 | if (pages != null) { |
| 3419 | Collections.addAll(mPages, pages); |
| 3420 | } |
| 3421 | |
| 3422 | mBackground = wearableBundle.getParcelable(KEY_BACKGROUND); |
| 3423 | mContentIcon = wearableBundle.getInt(KEY_CONTENT_ICON); |
| 3424 | mContentIconGravity = wearableBundle.getInt(KEY_CONTENT_ICON_GRAVITY, |
| 3425 | DEFAULT_CONTENT_ICON_GRAVITY); |
| 3426 | mContentActionIndex = wearableBundle.getInt(KEY_CONTENT_ACTION_INDEX, |
| 3427 | UNSET_ACTION_INDEX); |
| 3428 | mCustomSizePreset = wearableBundle.getInt(KEY_CUSTOM_SIZE_PRESET, |
| 3429 | SIZE_DEFAULT); |
| 3430 | mCustomContentHeight = wearableBundle.getInt(KEY_CUSTOM_CONTENT_HEIGHT); |
| 3431 | mGravity = wearableBundle.getInt(KEY_GRAVITY, DEFAULT_GRAVITY); |
| 3432 | } |
| 3433 | } |
| 3434 | |
| 3435 | /** |
| 3436 | * Apply wearable extensions to a notification that is being built. This is typically |
| 3437 | * called by the {@link android.app.Notification.Builder#extend} method of |
| 3438 | * {@link android.app.Notification.Builder}. |
| 3439 | */ |
| 3440 | @Override |
| 3441 | public Notification.Builder extend(Notification.Builder builder) { |
| 3442 | Bundle wearableBundle = new Bundle(); |
| 3443 | |
| 3444 | if (!mActions.isEmpty()) { |
| 3445 | wearableBundle.putParcelableArrayList(KEY_ACTIONS, mActions); |
| 3446 | } |
| 3447 | if (mFlags != DEFAULT_FLAGS) { |
| 3448 | wearableBundle.putInt(KEY_FLAGS, mFlags); |
| 3449 | } |
| 3450 | if (mDisplayIntent != null) { |
| 3451 | wearableBundle.putParcelable(KEY_DISPLAY_INTENT, mDisplayIntent); |
| 3452 | } |
| 3453 | if (!mPages.isEmpty()) { |
| 3454 | wearableBundle.putParcelableArray(KEY_PAGES, mPages.toArray( |
| 3455 | new Notification[mPages.size()])); |
| 3456 | } |
| 3457 | if (mBackground != null) { |
| 3458 | wearableBundle.putParcelable(KEY_BACKGROUND, mBackground); |
| 3459 | } |
| 3460 | if (mContentIcon != 0) { |
| 3461 | wearableBundle.putInt(KEY_CONTENT_ICON, mContentIcon); |
| 3462 | } |
| 3463 | if (mContentIconGravity != DEFAULT_CONTENT_ICON_GRAVITY) { |
| 3464 | wearableBundle.putInt(KEY_CONTENT_ICON_GRAVITY, mContentIconGravity); |
| 3465 | } |
| 3466 | if (mContentActionIndex != UNSET_ACTION_INDEX) { |
| 3467 | wearableBundle.putInt(KEY_CONTENT_ACTION_INDEX, |
| 3468 | mContentActionIndex); |
| 3469 | } |
| 3470 | if (mCustomSizePreset != SIZE_DEFAULT) { |
| 3471 | wearableBundle.putInt(KEY_CUSTOM_SIZE_PRESET, mCustomSizePreset); |
| 3472 | } |
| 3473 | if (mCustomContentHeight != 0) { |
| 3474 | wearableBundle.putInt(KEY_CUSTOM_CONTENT_HEIGHT, mCustomContentHeight); |
| 3475 | } |
| 3476 | if (mGravity != DEFAULT_GRAVITY) { |
| 3477 | wearableBundle.putInt(KEY_GRAVITY, mGravity); |
| 3478 | } |
| 3479 | |
| 3480 | builder.getExtras().putBundle(EXTRA_WEARABLE_EXTENSIONS, wearableBundle); |
| 3481 | return builder; |
| 3482 | } |
| 3483 | |
| 3484 | @Override |
| 3485 | public WearableExtender clone() { |
| 3486 | WearableExtender that = new WearableExtender(); |
| 3487 | that.mActions = new ArrayList<Action>(this.mActions); |
| 3488 | that.mFlags = this.mFlags; |
| 3489 | that.mDisplayIntent = this.mDisplayIntent; |
| 3490 | that.mPages = new ArrayList<Notification>(this.mPages); |
| 3491 | that.mBackground = this.mBackground; |
| 3492 | that.mContentIcon = this.mContentIcon; |
| 3493 | that.mContentIconGravity = this.mContentIconGravity; |
| 3494 | that.mContentActionIndex = this.mContentActionIndex; |
| 3495 | that.mCustomSizePreset = this.mCustomSizePreset; |
| 3496 | that.mCustomContentHeight = this.mCustomContentHeight; |
| 3497 | that.mGravity = this.mGravity; |
| 3498 | return that; |
| 3499 | } |
| 3500 | |
| 3501 | /** |
| 3502 | * Add a wearable action to this notification. |
| 3503 | * |
| 3504 | * <p>When wearable actions are added using this method, the set of actions that |
| 3505 | * show on a wearable device splits from devices that only show actions added |
| 3506 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 3507 | * of which actions display on different devices. |
| 3508 | * |
| 3509 | * @param action the action to add to this notification |
| 3510 | * @return this object for method chaining |
| 3511 | * @see android.app.Notification.Action |
| 3512 | */ |
| 3513 | public WearableExtender addAction(Action action) { |
| 3514 | mActions.add(action); |
| 3515 | return this; |
| 3516 | } |
| 3517 | |
| 3518 | /** |
| 3519 | * Adds wearable actions to this notification. |
| 3520 | * |
| 3521 | * <p>When wearable actions are added using this method, the set of actions that |
| 3522 | * show on a wearable device splits from devices that only show actions added |
| 3523 | * using {@link android.app.Notification.Builder#addAction}. This allows for customization |
| 3524 | * of which actions display on different devices. |
| 3525 | * |
| 3526 | * @param actions the actions to add to this notification |
| 3527 | * @return this object for method chaining |
| 3528 | * @see android.app.Notification.Action |
| 3529 | */ |
| 3530 | public WearableExtender addActions(List<Action> actions) { |
| 3531 | mActions.addAll(actions); |
| 3532 | return this; |
| 3533 | } |
| 3534 | |
| 3535 | /** |
| 3536 | * Clear all wearable actions present on this builder. |
| 3537 | * @return this object for method chaining. |
| 3538 | * @see #addAction |
| 3539 | */ |
| 3540 | public WearableExtender clearActions() { |
| 3541 | mActions.clear(); |
| 3542 | return this; |
| 3543 | } |
| 3544 | |
| 3545 | /** |
| 3546 | * Get the wearable actions present on this notification. |
| 3547 | */ |
| 3548 | public List<Action> getActions() { |
| 3549 | return mActions; |
| 3550 | } |
| 3551 | |
| 3552 | /** |
| 3553 | * Set an intent to launch inside of an activity view when displaying |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame^] | 3554 | * this notification. The {@link PendingIntent} provided should be for an activity. |
| 3555 | * |
| 3556 | * <pre class="prettyprint"> |
| 3557 | * Intent displayIntent = new Intent(context, MyDisplayActivity.class); |
| 3558 | * PendingIntent displayPendingIntent = PendingIntent.getActivity(context, |
| 3559 | * 0, displayIntent, PendingIntent.FLAG_UPDATE_CURRENT); |
| 3560 | * Notification notif = new Notification.Builder(context) |
| 3561 | * .extend(new Notification.WearableExtender() |
| 3562 | * .setDisplayIntent(displayPendingIntent) |
| 3563 | * .setCustomSizePreset(Notification.WearableExtender.SIZE_MEDIUM)) |
| 3564 | * .build();</pre> |
| 3565 | * |
| 3566 | * <p>The activity to launch needs to allow embedding, must be exported, and |
| 3567 | * should have an empty task affinity. |
| 3568 | * |
| 3569 | * <p>Example AndroidManifest.xml entry: |
| 3570 | * <pre class="prettyprint"> |
| 3571 | * <activity android:name="com.example.MyDisplayActivity" |
| 3572 | * android:exported="true" |
| 3573 | * android:allowEmbedded="true" |
| 3574 | * android:taskAffinity="" /></pre> |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3575 | * |
| 3576 | * @param intent the {@link PendingIntent} for an activity |
| 3577 | * @return this object for method chaining |
| 3578 | * @see android.app.Notification.WearableExtender#getDisplayIntent |
| 3579 | */ |
| 3580 | public WearableExtender setDisplayIntent(PendingIntent intent) { |
| 3581 | mDisplayIntent = intent; |
| 3582 | return this; |
| 3583 | } |
| 3584 | |
| 3585 | /** |
| 3586 | * Get the intent to launch inside of an activity view when displaying this |
| 3587 | * notification. This {@code PendingIntent} should be for an activity. |
| 3588 | */ |
| 3589 | public PendingIntent getDisplayIntent() { |
| 3590 | return mDisplayIntent; |
| 3591 | } |
| 3592 | |
| 3593 | /** |
| 3594 | * Add an additional page of content to display with this notification. The current |
| 3595 | * notification forms the first page, and pages added using this function form |
| 3596 | * subsequent pages. This field can be used to separate a notification into multiple |
| 3597 | * sections. |
| 3598 | * |
| 3599 | * @param page the notification to add as another page |
| 3600 | * @return this object for method chaining |
| 3601 | * @see android.app.Notification.WearableExtender#getPages |
| 3602 | */ |
| 3603 | public WearableExtender addPage(Notification page) { |
| 3604 | mPages.add(page); |
| 3605 | return this; |
| 3606 | } |
| 3607 | |
| 3608 | /** |
| 3609 | * Add additional pages of content to display with this notification. The current |
| 3610 | * notification forms the first page, and pages added using this function form |
| 3611 | * subsequent pages. This field can be used to separate a notification into multiple |
| 3612 | * sections. |
| 3613 | * |
| 3614 | * @param pages a list of notifications |
| 3615 | * @return this object for method chaining |
| 3616 | * @see android.app.Notification.WearableExtender#getPages |
| 3617 | */ |
| 3618 | public WearableExtender addPages(List<Notification> pages) { |
| 3619 | mPages.addAll(pages); |
| 3620 | return this; |
| 3621 | } |
| 3622 | |
| 3623 | /** |
| 3624 | * Clear all additional pages present on this builder. |
| 3625 | * @return this object for method chaining. |
| 3626 | * @see #addPage |
| 3627 | */ |
| 3628 | public WearableExtender clearPages() { |
| 3629 | mPages.clear(); |
| 3630 | return this; |
| 3631 | } |
| 3632 | |
| 3633 | /** |
| 3634 | * Get the array of additional pages of content for displaying this notification. The |
| 3635 | * current notification forms the first page, and elements within this array form |
| 3636 | * subsequent pages. This field can be used to separate a notification into multiple |
| 3637 | * sections. |
| 3638 | * @return the pages for this notification |
| 3639 | */ |
| 3640 | public List<Notification> getPages() { |
| 3641 | return mPages; |
| 3642 | } |
| 3643 | |
| 3644 | /** |
| 3645 | * Set a background image to be displayed behind the notification content. |
| 3646 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 3647 | * will work with any notification style. |
| 3648 | * |
| 3649 | * @param background the background bitmap |
| 3650 | * @return this object for method chaining |
| 3651 | * @see android.app.Notification.WearableExtender#getBackground |
| 3652 | */ |
| 3653 | public WearableExtender setBackground(Bitmap background) { |
| 3654 | mBackground = background; |
| 3655 | return this; |
| 3656 | } |
| 3657 | |
| 3658 | /** |
| 3659 | * Get a background image to be displayed behind the notification content. |
| 3660 | * Contrary to the {@link android.app.Notification.BigPictureStyle}, this background |
| 3661 | * will work with any notification style. |
| 3662 | * |
| 3663 | * @return the background image |
| 3664 | * @see android.app.Notification.WearableExtender#setBackground |
| 3665 | */ |
| 3666 | public Bitmap getBackground() { |
| 3667 | return mBackground; |
| 3668 | } |
| 3669 | |
| 3670 | /** |
| 3671 | * Set an icon that goes with the content of this notification. |
| 3672 | */ |
| 3673 | public WearableExtender setContentIcon(int icon) { |
| 3674 | mContentIcon = icon; |
| 3675 | return this; |
| 3676 | } |
| 3677 | |
| 3678 | /** |
| 3679 | * Get an icon that goes with the content of this notification. |
| 3680 | */ |
| 3681 | public int getContentIcon() { |
| 3682 | return mContentIcon; |
| 3683 | } |
| 3684 | |
| 3685 | /** |
| 3686 | * Set the gravity that the content icon should have within the notification display. |
| 3687 | * Supported values include {@link android.view.Gravity#START} and |
| 3688 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 3689 | * @see #setContentIcon |
| 3690 | */ |
| 3691 | public WearableExtender setContentIconGravity(int contentIconGravity) { |
| 3692 | mContentIconGravity = contentIconGravity; |
| 3693 | return this; |
| 3694 | } |
| 3695 | |
| 3696 | /** |
| 3697 | * Get the gravity that the content icon should have within the notification display. |
| 3698 | * Supported values include {@link android.view.Gravity#START} and |
| 3699 | * {@link android.view.Gravity#END}. The default value is {@link android.view.Gravity#END}. |
| 3700 | * @see #getContentIcon |
| 3701 | */ |
| 3702 | public int getContentIconGravity() { |
| 3703 | return mContentIconGravity; |
| 3704 | } |
| 3705 | |
| 3706 | /** |
| 3707 | * Set an action from this notification's actions to be clickable with the content of |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame^] | 3708 | * this notification. This action will no longer display separately from the |
| 3709 | * notification's content. |
| 3710 | * |
| 3711 | * <p>For notifications with multiple pages, child pages can also have content action's |
| 3712 | * set, although the list of available actions comes from the main notification and not |
| 3713 | * from the child page's notification. |
| 3714 | * |
| 3715 | * @param actionIndex The index of the action to hoist onto the current notification page. |
| 3716 | * If wearable actions were added to the main notification, this index |
| 3717 | * will apply to that list, otherwise it will apply to the regular |
| 3718 | * actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3719 | */ |
| 3720 | public WearableExtender setContentAction(int actionIndex) { |
| 3721 | mContentActionIndex = actionIndex; |
| 3722 | return this; |
| 3723 | } |
| 3724 | |
| 3725 | /** |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame^] | 3726 | * Get the action index from this notification's actions to be clickable with the |
| 3727 | * content of this notification. This action will no longer display separately |
| 3728 | * from the notification's content. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3729 | * |
Griff Hazen | 14f5799 | 2014-05-26 09:07:14 -0700 | [diff] [blame^] | 3730 | * <p>For notifications with multiple pages, child pages can also have content action's |
| 3731 | * set, although the list of available actions comes from the main notification and not |
| 3732 | * from the child page's notification. |
| 3733 | * |
| 3734 | * <p>If wearable specific actions were added to the main notification, this index will |
| 3735 | * apply to that list, otherwise it will apply to the regular actions list. |
Griff Hazen | 61a9e86 | 2014-05-22 16:05:19 -0700 | [diff] [blame] | 3736 | */ |
| 3737 | public int getContentAction() { |
| 3738 | return mContentActionIndex; |
| 3739 | } |
| 3740 | |
| 3741 | /** |
| 3742 | * Set the gravity that this notification should have within the available viewport space. |
| 3743 | * Supported values include {@link android.view.Gravity#TOP}, |
| 3744 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 3745 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 3746 | */ |
| 3747 | public WearableExtender setGravity(int gravity) { |
| 3748 | mGravity = gravity; |
| 3749 | return this; |
| 3750 | } |
| 3751 | |
| 3752 | /** |
| 3753 | * Get the gravity that this notification should have within the available viewport space. |
| 3754 | * Supported values include {@link android.view.Gravity#TOP}, |
| 3755 | * {@link android.view.Gravity#CENTER_VERTICAL} and {@link android.view.Gravity#BOTTOM}. |
| 3756 | * The default value is {@link android.view.Gravity#BOTTOM}. |
| 3757 | */ |
| 3758 | public int getGravity() { |
| 3759 | return mGravity; |
| 3760 | } |
| 3761 | |
| 3762 | /** |
| 3763 | * Set the custom size preset for the display of this notification out of the available |
| 3764 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 3765 | * {@link #SIZE_LARGE}. |
| 3766 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 3767 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. Check the |
| 3768 | * documentation for the preset in question. See also |
| 3769 | * {@link #setCustomContentHeight} and {@link #getCustomSizePreset}. |
| 3770 | */ |
| 3771 | public WearableExtender setCustomSizePreset(int sizePreset) { |
| 3772 | mCustomSizePreset = sizePreset; |
| 3773 | return this; |
| 3774 | } |
| 3775 | |
| 3776 | /** |
| 3777 | * Get the custom size preset for the display of this notification out of the available |
| 3778 | * presets found in {@link android.app.Notification.WearableExtender}, e.g. |
| 3779 | * {@link #SIZE_LARGE}. |
| 3780 | * <p>Some custom size presets are only applicable for custom display notifications created |
| 3781 | * using {@link #setDisplayIntent}. Check the documentation for the preset in question. |
| 3782 | * See also {@link #setCustomContentHeight} and {@link #setCustomSizePreset}. |
| 3783 | */ |
| 3784 | public int getCustomSizePreset() { |
| 3785 | return mCustomSizePreset; |
| 3786 | } |
| 3787 | |
| 3788 | /** |
| 3789 | * Set the custom height in pixels for the display of this notification's content. |
| 3790 | * <p>This option is only available for custom display notifications created |
| 3791 | * using {@link android.app.Notification.WearableExtender#setDisplayIntent}. See also |
| 3792 | * {@link android.app.Notification.WearableExtender#setCustomSizePreset} and |
| 3793 | * {@link #getCustomContentHeight}. |
| 3794 | */ |
| 3795 | public WearableExtender setCustomContentHeight(int height) { |
| 3796 | mCustomContentHeight = height; |
| 3797 | return this; |
| 3798 | } |
| 3799 | |
| 3800 | /** |
| 3801 | * Get the custom height in pixels for the display of this notification's content. |
| 3802 | * <p>This option is only available for custom display notifications created |
| 3803 | * using {@link #setDisplayIntent}. See also {@link #setCustomSizePreset} and |
| 3804 | * {@link #setCustomContentHeight}. |
| 3805 | */ |
| 3806 | public int getCustomContentHeight() { |
| 3807 | return mCustomContentHeight; |
| 3808 | } |
| 3809 | |
| 3810 | /** |
| 3811 | * Set whether the scrolling position for the contents of this notification should start |
| 3812 | * at the bottom of the contents instead of the top when the contents are too long to |
| 3813 | * display within the screen. Default is false (start scroll at the top). |
| 3814 | */ |
| 3815 | public WearableExtender setStartScrollBottom(boolean startScrollBottom) { |
| 3816 | setFlag(FLAG_START_SCROLL_BOTTOM, startScrollBottom); |
| 3817 | return this; |
| 3818 | } |
| 3819 | |
| 3820 | /** |
| 3821 | * Get whether the scrolling position for the contents of this notification should start |
| 3822 | * at the bottom of the contents instead of the top when the contents are too long to |
| 3823 | * display within the screen. Default is false (start scroll at the top). |
| 3824 | */ |
| 3825 | public boolean getStartScrollBottom() { |
| 3826 | return (mFlags & FLAG_START_SCROLL_BOTTOM) != 0; |
| 3827 | } |
| 3828 | |
| 3829 | /** |
| 3830 | * Set whether the content intent is available when the wearable device is not connected |
| 3831 | * to a companion device. The user can still trigger this intent when the wearable device |
| 3832 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 3833 | * Defaults to true. |
| 3834 | */ |
| 3835 | public WearableExtender setContentIntentAvailableOffline( |
| 3836 | boolean contentIntentAvailableOffline) { |
| 3837 | setFlag(FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE, contentIntentAvailableOffline); |
| 3838 | return this; |
| 3839 | } |
| 3840 | |
| 3841 | /** |
| 3842 | * Get whether the content intent is available when the wearable device is not connected |
| 3843 | * to a companion device. The user can still trigger this intent when the wearable device |
| 3844 | * is offline, but a visual hint will indicate that the content intent may not be available. |
| 3845 | * Defaults to true. |
| 3846 | */ |
| 3847 | public boolean getContentIntentAvailableOffline() { |
| 3848 | return (mFlags & FLAG_CONTENT_INTENT_AVAILABLE_OFFLINE) != 0; |
| 3849 | } |
| 3850 | |
| 3851 | /** |
| 3852 | * Set a hint that this notification's icon should not be displayed. |
| 3853 | * @param hintHideIcon {@code true} to hide the icon, {@code false} otherwise. |
| 3854 | * @return this object for method chaining |
| 3855 | */ |
| 3856 | public WearableExtender setHintHideIcon(boolean hintHideIcon) { |
| 3857 | setFlag(FLAG_HINT_HIDE_ICON, hintHideIcon); |
| 3858 | return this; |
| 3859 | } |
| 3860 | |
| 3861 | /** |
| 3862 | * Get a hint that this notification's icon should not be displayed. |
| 3863 | * @return {@code true} if this icon should not be displayed, false otherwise. |
| 3864 | * The default value is {@code false} if this was never set. |
| 3865 | */ |
| 3866 | public boolean getHintHideIcon() { |
| 3867 | return (mFlags & FLAG_HINT_HIDE_ICON) != 0; |
| 3868 | } |
| 3869 | |
| 3870 | /** |
| 3871 | * Set a visual hint that only the background image of this notification should be |
| 3872 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 3873 | * to sub-pages added using {@link #addPage}. |
| 3874 | */ |
| 3875 | public WearableExtender setHintShowBackgroundOnly(boolean hintShowBackgroundOnly) { |
| 3876 | setFlag(FLAG_HINT_SHOW_BACKGROUND_ONLY, hintShowBackgroundOnly); |
| 3877 | return this; |
| 3878 | } |
| 3879 | |
| 3880 | /** |
| 3881 | * Get a visual hint that only the background image of this notification should be |
| 3882 | * displayed, and other semantic content should be hidden. This hint is only applicable |
| 3883 | * to sub-pages added using {@link android.app.Notification.WearableExtender#addPage}. |
| 3884 | */ |
| 3885 | public boolean getHintShowBackgroundOnly() { |
| 3886 | return (mFlags & FLAG_HINT_SHOW_BACKGROUND_ONLY) != 0; |
| 3887 | } |
| 3888 | |
| 3889 | private void setFlag(int mask, boolean value) { |
| 3890 | if (value) { |
| 3891 | mFlags |= mask; |
| 3892 | } else { |
| 3893 | mFlags &= ~mask; |
| 3894 | } |
| 3895 | } |
| 3896 | } |
| 3897 | |
| 3898 | /** |
| 3899 | * Get an array of Notification objects from a parcelable array bundle field. |
| 3900 | * Update the bundle to have a typed array so fetches in the future don't need |
| 3901 | * to do an array copy. |
| 3902 | */ |
| 3903 | private static Notification[] getNotificationArrayFromBundle(Bundle bundle, String key) { |
| 3904 | Parcelable[] array = bundle.getParcelableArray(key); |
| 3905 | if (array instanceof Notification[] || array == null) { |
| 3906 | return (Notification[]) array; |
| 3907 | } |
| 3908 | Notification[] typedArray = Arrays.copyOf(array, array.length, |
| 3909 | Notification[].class); |
| 3910 | bundle.putParcelableArray(key, typedArray); |
| 3911 | return typedArray; |
| 3912 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 3913 | } |