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(awdf) We should probably use a Compat builder. |
29 ChromeNotificationBuilder builder = | |
30 ((ChromeApplication) mContext) | |
nyquist
2017/02/28 07:29:09
This seems unsafe. Could you use mContext.getAppli
awdf
2017/02/28 18:04:11
Done. (It should already be as NPB gets applicatio
| |
31 .createChromeNotificationBuilder(false /* preferCompat * /, | |
32 NotificationConstants.CATEGORY_ID_GENERAL, | |
33 mContext.getString(org.chromium.chrome.R.string | |
34 .notification_categor y_general)); | |
35 | |
27 builder.setContentTitle(mTitle); | 36 builder.setContentTitle(mTitle); |
28 builder.setContentText(mBody); | 37 builder.setContentText(mBody); |
29 builder.setSubText(mOrigin); | 38 builder.setSubText(mOrigin); |
30 builder.setTicker(mTickerText); | 39 builder.setTicker(mTickerText); |
31 if (mImage != null) { | 40 if (mImage != null) { |
32 Notification.BigPictureStyle style = | 41 Notification.BigPictureStyle style = |
33 new Notification.BigPictureStyle().bigPicture(mImage); | 42 new Notification.BigPictureStyle().bigPicture(mImage); |
34 if (Build.VERSION.CODENAME.equals("N") | 43 if (Build.VERSION.CODENAME.equals("N") |
35 || Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { | 44 || 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 | 45 // 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); | 66 builder.setWhen(mTimestamp); |
58 builder.setOnlyAlertOnce(!mRenotify); | 67 builder.setOnlyAlertOnce(!mRenotify); |
59 setGroupOnBuilder(builder, mOrigin); | 68 setGroupOnBuilder(builder, mOrigin); |
60 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 69 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
61 // Notification.Builder.setPublicVersion was added in Android L. | 70 // Notification.Builder.setPublicVersion was added in Android L. |
62 builder.setPublicVersion(createPublicNotification(mContext)); | 71 builder.setPublicVersion(createPublicNotification(mContext)); |
63 } | 72 } |
64 return builder.build(); | 73 return builder.build(); |
65 } | 74 } |
66 } | 75 } |
OLD | NEW |