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