| 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.notifications.channels.ChannelDefinitions; | 11 import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; |
| 12 | 12 |
| 13 /** | 13 /** |
| 14 * Builds a notification using the standard Notification.BigTextStyle layout. | 14 * Builds a notification using the standard Notification.BigTextStyle layout. |
| 15 */ | 15 */ |
| 16 public class StandardNotificationBuilder extends NotificationBuilderBase { | 16 public class StandardNotificationBuilder extends NotificationBuilderBase { |
| 17 private final Context mContext; | 17 private final Context mContext; |
| 18 | 18 |
| 19 public StandardNotificationBuilder(Context context) { | 19 public StandardNotificationBuilder( |
| 20 super(context.getResources()); | 20 Context context, @ChannelDefinitions.ChannelId String channelId) { |
| 21 super(context.getResources(), channelId); |
| 21 mContext = context; | 22 mContext = context; |
| 22 } | 23 } |
| 23 | 24 |
| 24 @Override | 25 @Override |
| 25 public Notification build() { | 26 public Notification build() { |
| 26 // Note: this is not a NotificationCompat builder so be mindful of the | 27 // Note: this is not a NotificationCompat builder so be mindful of the |
| 27 // API level of methods you call on the builder. | 28 // API level of methods you call on the builder. |
| 28 // TODO(crbug.com/697104) We should probably use a Compat builder. | 29 // TODO(crbug.com/697104) We should probably use a Compat builder. |
| 29 ChromeNotificationBuilder builder = | 30 ChromeNotificationBuilder builder = |
| 30 NotificationBuilderFactory.createChromeNotificationBuilder( | 31 NotificationBuilderFactory.createChromeNotificationBuilder( |
| 31 false /* preferCompat */, ChannelDefinitions.CHANNEL_ID_
SITES); | 32 false /* preferCompat */, mChannelId); |
| 32 | 33 |
| 33 builder.setContentTitle(mTitle); | 34 builder.setContentTitle(mTitle); |
| 34 builder.setContentText(mBody); | 35 builder.setContentText(mBody); |
| 35 builder.setSubText(mOrigin); | 36 builder.setSubText(mOrigin); |
| 36 builder.setTicker(mTickerText); | 37 builder.setTicker(mTickerText); |
| 37 if (mImage != null) { | 38 if (mImage != null) { |
| 38 Notification.BigPictureStyle style = | 39 Notification.BigPictureStyle style = |
| 39 new Notification.BigPictureStyle().bigPicture(mImage); | 40 new Notification.BigPictureStyle().bigPicture(mImage); |
| 40 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | 41 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { |
| 41 // Android N doesn't show content text when expanded, so duplica
te body text as a | 42 // Android N doesn't show content text when expanded, so duplica
te body text as a |
| 42 // summary for the big picture. | 43 // summary for the big picture. |
| 43 style.setSummaryText(mBody); | 44 style.setSummaryText(mBody); |
| 44 } | 45 } |
| 45 builder.setStyle(style); | 46 builder.setStyle(style); |
| 46 } else { | 47 } else { |
| 47 // If there is no image, let the body text wrap only multiple lines
when expanded. | 48 // If there is no image, let the body text wrap only multiple lines
when expanded. |
| 48 builder.setStyle(new Notification.BigTextStyle().bigText(mBody)); | 49 builder.setStyle(new Notification.BigTextStyle().bigText(mBody)); |
| 49 } | 50 } |
| 50 builder.setLargeIcon(getNormalizedLargeIcon()); | 51 builder.setLargeIcon(getNormalizedLargeIcon()); |
| 51 setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap); | 52 setSmallIconOnBuilder(builder, mSmallIconId, mSmallIconBitmap); |
| 52 builder.setContentIntent(mContentIntent); | 53 builder.setContentIntent(mContentIntent); |
| 53 builder.setDeleteIntent(mDeleteIntent); | 54 builder.setDeleteIntent(mDeleteIntent); |
| 54 for (Action action : mActions) { | 55 for (Action action : mActions) { |
| 55 addActionToBuilder(builder, action); | 56 addActionToBuilder(builder, action); |
| 56 } | 57 } |
| 57 if (mSettingsAction != null) { | 58 if (mSettingsAction != null) { |
| 58 addActionToBuilder(builder, mSettingsAction); | 59 addActionToBuilder(builder, mSettingsAction); |
| 59 } | 60 } |
| 60 builder.setDefaults(mDefaults); | 61 builder.setPriority(mPriority); |
| 61 builder.setVibrate(mVibratePattern); | 62 // Browser channel uses silent notifications to avoid disrupting the use
r. |
| 63 if (!ChannelDefinitions.CHANNEL_ID_BROWSER.equals(mChannelId)) { |
| 64 builder.setDefaults(mDefaults); |
| 65 builder.setVibrate(mVibratePattern); |
| 66 } |
| 62 builder.setWhen(mTimestamp); | 67 builder.setWhen(mTimestamp); |
| 63 builder.setOnlyAlertOnce(!mRenotify); | 68 builder.setOnlyAlertOnce(!mRenotify); |
| 64 setGroupOnBuilder(builder, mOrigin); | 69 setGroupOnBuilder(builder, mOrigin); |
| 65 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | 70 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| 66 // Public versions only supported since L, and createPublicNotificat
ion requires L+. | 71 // Public versions only supported since L, and createPublicNotificat
ion requires L+. |
| 67 builder.setPublicVersion(createPublicNotification(mContext)); | 72 builder.setPublicVersion(createPublicNotification(mContext)); |
| 68 } | 73 } |
| 69 return builder.build(); | 74 return builder.build(); |
| 70 } | 75 } |
| 71 } | 76 } |
| OLD | NEW |