OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.notifications; | 5 package org.chromium.chrome.browser.notifications; |
6 | 6 |
7 import android.app.Notification; | 7 import android.app.Notification; |
8 import android.app.PendingIntent; | 8 import android.app.PendingIntent; |
9 import android.content.Context; | 9 import android.content.Context; |
10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
11 import android.graphics.drawable.Icon; | 11 import android.graphics.drawable.Icon; |
| 12 import android.media.session.MediaSession; |
12 import android.os.Build; | 13 import android.os.Build; |
| 14 import android.support.v4.media.session.MediaSessionCompat; |
13 import android.widget.RemoteViews; | 15 import android.widget.RemoteViews; |
14 | 16 |
15 /** | 17 /** |
16 * Wraps a Notification.Builder object. | 18 * Wraps a Notification.Builder object. |
17 */ | 19 */ |
18 public class NotificationBuilder implements ChromeNotificationBuilder { | 20 public class NotificationBuilder implements ChromeNotificationBuilder { |
19 protected final Notification.Builder mBuilder; | 21 protected final Notification.Builder mBuilder; |
20 | 22 |
21 public NotificationBuilder(Context context) { | 23 public NotificationBuilder(Context context) { |
22 mBuilder = new Notification.Builder(context); | 24 mBuilder = new Notification.Builder(context); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 return this; | 216 return this; |
215 } | 217 } |
216 | 218 |
217 @Override | 219 @Override |
218 public ChromeNotificationBuilder setStyle(Notification.BigTextStyle style) { | 220 public ChromeNotificationBuilder setStyle(Notification.BigTextStyle style) { |
219 mBuilder.setStyle(style); | 221 mBuilder.setStyle(style); |
220 return this; | 222 return this; |
221 } | 223 } |
222 | 224 |
223 @Override | 225 @Override |
| 226 public ChromeNotificationBuilder setMediaStyle(MediaSessionCompat session, i
nt[] actions, |
| 227 PendingIntent intent, boolean showCancelButton) { |
| 228 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 229 Notification.MediaStyle style = new Notification.MediaStyle(); |
| 230 style.setMediaSession(((MediaSession) session.getMediaSession()).get
SessionToken()); |
| 231 style.setShowActionsInCompactView(actions); |
| 232 mBuilder.setStyle(style); |
| 233 } |
| 234 return this; |
| 235 } |
| 236 |
| 237 @Override |
224 public Notification buildWithBigContentView(RemoteViews view) { | 238 public Notification buildWithBigContentView(RemoteViews view) { |
225 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 239 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
226 return mBuilder.setCustomBigContentView(view).build(); | 240 return mBuilder.setCustomBigContentView(view).build(); |
227 } else { | 241 } else { |
228 Notification notification = mBuilder.build(); | 242 Notification notification = mBuilder.build(); |
229 notification.bigContentView = view; | 243 notification.bigContentView = view; |
230 return notification; | 244 return notification; |
231 } | 245 } |
232 } | 246 } |
233 | 247 |
234 @Override | 248 @Override |
235 public Notification buildWithBigTextStyle(String bigText) { | 249 public Notification buildWithBigTextStyle(String bigText) { |
236 Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(m
Builder); | 250 Notification.BigTextStyle bigTextStyle = new Notification.BigTextStyle(m
Builder); |
237 bigTextStyle.bigText(bigText); | 251 bigTextStyle.bigText(bigText); |
238 return bigTextStyle.build(); | 252 return bigTextStyle.build(); |
239 } | 253 } |
240 | 254 |
241 @Override | 255 @Override |
242 public Notification build() { | 256 public Notification build() { |
243 return mBuilder.build(); | 257 return mBuilder.build(); |
244 } | 258 } |
245 } | 259 } |
OLD | NEW |