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