| 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.content.res.Resources; | 9 import android.content.res.Resources; |
| 10 import android.graphics.Bitmap; | 10 import android.graphics.Bitmap; |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 private static final int WORK_PROFILE_BADGE_SIZE_DP = 16; | 73 private static final int WORK_PROFILE_BADGE_SIZE_DP = 16; |
| 74 | 74 |
| 75 /** | 75 /** |
| 76 * Material Grey 600 - to be applied to action button icons in the Material
theme. | 76 * Material Grey 600 - to be applied to action button icons in the Material
theme. |
| 77 */ | 77 */ |
| 78 private static final int BUTTON_ICON_COLOR_MATERIAL = 0xff757575; | 78 private static final int BUTTON_ICON_COLOR_MATERIAL = 0xff757575; |
| 79 | 79 |
| 80 private final Context mContext; | 80 private final Context mContext; |
| 81 | 81 |
| 82 public CustomNotificationBuilder(Context context) { | 82 public CustomNotificationBuilder(Context context) { |
| 83 super(context.getResources()); | 83 // TODO(crbug.com/726340): Pass in the ChannelDefinition |
| 84 super(context.getResources(), ChannelDefinitions.CHANNEL_ID_SITES); |
| 84 mContext = context; | 85 mContext = context; |
| 85 } | 86 } |
| 86 | 87 |
| 87 @Override | 88 @Override |
| 88 public Notification build() { | 89 public Notification build() { |
| 89 // A note about RemoteViews and updating notifications. When a notificat
ion is passed to the | 90 // A note about RemoteViews and updating notifications. When a notificat
ion is passed to the |
| 90 // {@code NotificationManager} with the same tag and id as a previous no
tification, an | 91 // {@code NotificationManager} with the same tag and id as a previous no
tification, an |
| 91 // in-place update will be performed. In that case, the actions of all n
ew | 92 // in-place update will be performed. In that case, the actions of all n
ew |
| 92 // {@link RemoteViews} will be applied to the views of the old notificat
ion. This is safe | 93 // {@link RemoteViews} will be applied to the views of the old notificat
ion. This is safe |
| 93 // for actions that overwrite old values such as setting the text of a {
@code TextView}, but | 94 // for actions that overwrite old values such as setting the text of a {
@code TextView}, but |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 136 } |
| 136 } | 137 } |
| 137 addActionButtons(bigView); | 138 addActionButtons(bigView); |
| 138 configureSettingsButton(bigView); | 139 configureSettingsButton(bigView); |
| 139 | 140 |
| 140 // Note: under the hood this is not a NotificationCompat builder so be m
indful of the | 141 // Note: under the hood this is not a NotificationCompat builder so be m
indful of the |
| 141 // API level of methods you call on the builder. | 142 // API level of methods you call on the builder. |
| 142 // TODO(crbug.com/697104) We should probably use a Compat builder. | 143 // TODO(crbug.com/697104) We should probably use a Compat builder. |
| 143 ChromeNotificationBuilder builder = | 144 ChromeNotificationBuilder builder = |
| 144 NotificationBuilderFactory.createChromeNotificationBuilder( | 145 NotificationBuilderFactory.createChromeNotificationBuilder( |
| 145 false /* preferCompat */, ChannelDefinitions.CHANNEL_ID_
SITES); | 146 false /* preferCompat */, mChannelId); |
| 146 builder.setTicker(mTickerText); | 147 builder.setTicker(mTickerText); |
| 147 builder.setContentIntent(mContentIntent); | 148 builder.setContentIntent(mContentIntent); |
| 148 builder.setDeleteIntent(mDeleteIntent); | 149 builder.setDeleteIntent(mDeleteIntent); |
| 149 builder.setDefaults(mDefaults); | 150 builder.setPriority(mPriority); |
| 150 builder.setVibrate(mVibratePattern); | 151 // Browser channel uses silent notifications to avoid disrupting the use
r. |
| 152 if (!ChannelDefinitions.CHANNEL_ID_BROWSER.equals(mChannelId)) { |
| 153 builder.setDefaults(mDefaults); |
| 154 builder.setVibrate(mVibratePattern); |
| 155 } |
| 151 builder.setWhen(mTimestamp); | 156 builder.setWhen(mTimestamp); |
| 152 builder.setOnlyAlertOnce(!mRenotify); | 157 builder.setOnlyAlertOnce(!mRenotify); |
| 153 builder.setContent(compactView); | 158 builder.setContent(compactView); |
| 154 | 159 |
| 155 // Some things are duplicated in the builder to ensure the notification
shows correctly on | 160 // Some things are duplicated in the builder to ensure the notification
shows correctly on |
| 156 // Wear devices and custom lock screens. | 161 // Wear devices and custom lock screens. |
| 157 builder.setContentTitle(mTitle); | 162 builder.setContentTitle(mTitle); |
| 158 builder.setContentText(mBody); | 163 builder.setContentText(mBody); |
| 159 builder.setSubText(mOrigin); | 164 builder.setSubText(mOrigin); |
| 160 builder.setLargeIcon(getNormalizedLargeIcon()); | 165 builder.setLargeIcon(getNormalizedLargeIcon()); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 } | 328 } |
| 324 | 329 |
| 325 /** | 330 /** |
| 326 * Whether to use the Material look and feel or fall back to Holo. | 331 * Whether to use the Material look and feel or fall back to Holo. |
| 327 */ | 332 */ |
| 328 @VisibleForTesting | 333 @VisibleForTesting |
| 329 static boolean useMaterial() { | 334 static boolean useMaterial() { |
| 330 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; | 335 return Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP; |
| 331 } | 336 } |
| 332 } | 337 } |
| OLD | NEW |