OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.content.Context; | 8 import android.content.Context; |
9 import android.os.Build; | 9 import android.os.Build; |
10 | 10 |
| 11 import org.chromium.chrome.browser.ChromeApplication; |
| 12 |
11 /** | 13 /** |
12 * Builds a notification using the standard Notification.BigTextStyle layout. | 14 * Builds a notification using the standard Notification.BigTextStyle layout. |
13 */ | 15 */ |
14 public class StandardNotificationBuilder extends NotificationBuilderBase { | 16 public class StandardNotificationBuilder extends NotificationBuilderBase { |
15 private final Context mContext; | 17 private final Context mContext; |
16 | 18 |
17 public StandardNotificationBuilder(Context context) { | 19 public StandardNotificationBuilder(Context context) { |
18 super(context.getResources()); | 20 super(context.getResources()); |
19 mContext = context; | 21 mContext = context; |
20 } | 22 } |
21 | 23 |
22 @Override | 24 @Override |
23 public Notification build() { | 25 public Notification build() { |
24 // Note: this is not a NotificationCompat builder so be mindful of the | 26 // Note: this is not a NotificationCompat builder so be mindful of the |
25 // API level of methods you call on the builder. | 27 // API level of methods you call on the builder. |
26 Notification.Builder builder = new Notification.Builder(mContext); | 28 // TODO(crbug.com/697104) We should probably use a Compat builder. |
| 29 ChromeNotificationBuilder builder = |
| 30 ((ChromeApplication) mContext.getApplicationContext()) |
| 31 .createChromeNotificationBuilder(false /* preferCompat *
/, |
| 32 NotificationConstants.CATEGORY_ID_SITES, |
| 33 mContext.getString( |
| 34 org.chromium.chrome.R.string.notificatio
n_category_sites), |
| 35 NotificationConstants.CATEGORY_GROUP_ID_GENERAL, |
| 36 mContext.getString(org.chromium.chrome.R.string |
| 37 .notification_categor
y_group_general)); |
| 38 |
27 builder.setContentTitle(mTitle); | 39 builder.setContentTitle(mTitle); |
28 builder.setContentText(mBody); | 40 builder.setContentText(mBody); |
29 builder.setSubText(mOrigin); | 41 builder.setSubText(mOrigin); |
30 builder.setTicker(mTickerText); | 42 builder.setTicker(mTickerText); |
31 if (mImage != null) { | 43 if (mImage != null) { |
32 Notification.BigPictureStyle style = | 44 Notification.BigPictureStyle style = |
33 new Notification.BigPictureStyle().bigPicture(mImage); | 45 new Notification.BigPictureStyle().bigPicture(mImage); |
34 if (Build.VERSION.CODENAME.equals("N") | 46 if (Build.VERSION.CODENAME.equals("N") |
35 || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { | 47 || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { |
36 // Android N doesn't show content text when expanded, so duplica
te body text as a | 48 // Android N doesn't show content text when expanded, so duplica
te body text as a |
(...skipping 20 matching lines...) Expand all Loading... |
57 builder.setWhen(mTimestamp); | 69 builder.setWhen(mTimestamp); |
58 builder.setOnlyAlertOnce(!mRenotify); | 70 builder.setOnlyAlertOnce(!mRenotify); |
59 setGroupOnBuilder(builder, mOrigin); | 71 setGroupOnBuilder(builder, mOrigin); |
60 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 72 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
61 // Notification.Builder.setPublicVersion was added in Android L. | 73 // Notification.Builder.setPublicVersion was added in Android L. |
62 builder.setPublicVersion(createPublicNotification(mContext)); | 74 builder.setPublicVersion(createPublicNotification(mContext)); |
63 } | 75 } |
64 return builder.build(); | 76 return builder.build(); |
65 } | 77 } |
66 } | 78 } |
OLD | NEW |