OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.annotation.SuppressLint; | 7 import android.annotation.SuppressLint; |
8 import android.annotation.TargetApi; | 8 import android.annotation.TargetApi; |
9 import android.app.Notification; | 9 import android.app.Notification; |
10 import android.app.PendingIntent; | 10 import android.app.PendingIntent; |
11 import android.app.RemoteInput; | 11 import android.app.RemoteInput; |
12 import android.content.Context; | 12 import android.content.Context; |
13 import android.content.res.Resources; | 13 import android.content.res.Resources; |
14 import android.graphics.Bitmap; | 14 import android.graphics.Bitmap; |
15 import android.graphics.Canvas; | 15 import android.graphics.Canvas; |
16 import android.graphics.Color; | 16 import android.graphics.Color; |
17 import android.graphics.Paint; | 17 import android.graphics.Paint; |
18 import android.graphics.PorterDuff; | 18 import android.graphics.PorterDuff; |
19 import android.graphics.PorterDuffColorFilter; | 19 import android.graphics.PorterDuffColorFilter; |
20 import android.graphics.drawable.Icon; | 20 import android.graphics.drawable.Icon; |
21 import android.os.Build; | 21 import android.os.Build; |
22 | 22 |
23 import org.chromium.base.VisibleForTesting; | 23 import org.chromium.base.VisibleForTesting; |
| 24 import org.chromium.chrome.browser.notifications.channels.ChannelDefinitions; |
24 import org.chromium.chrome.browser.widget.RoundedIconGenerator; | 25 import org.chromium.chrome.browser.widget.RoundedIconGenerator; |
25 | 26 |
26 import java.util.ArrayList; | 27 import java.util.ArrayList; |
27 import java.util.Arrays; | 28 import java.util.Arrays; |
28 import java.util.List; | 29 import java.util.List; |
29 | 30 |
30 import javax.annotation.Nullable; | 31 import javax.annotation.Nullable; |
31 | 32 |
32 /** | 33 /** |
33 * Abstract base class for building a notification. Stores all given arguments f
or later use. | 34 * Abstract base class for building a notification. Stores all given arguments f
or later use. |
(...skipping 317 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 352 } |
352 return icon; | 353 return icon; |
353 } | 354 } |
354 | 355 |
355 /** | 356 /** |
356 * Creates a public version of the notification to be displayed in sensitive
contexts, such as | 357 * Creates a public version of the notification to be displayed in sensitive
contexts, such as |
357 * on the lockscreen, displaying just the site origin and badge or generated
icon. | 358 * on the lockscreen, displaying just the site origin and badge or generated
icon. |
358 */ | 359 */ |
359 @TargetApi(Build.VERSION_CODES.LOLLIPOP) | 360 @TargetApi(Build.VERSION_CODES.LOLLIPOP) |
360 protected Notification createPublicNotification(Context context) { | 361 protected Notification createPublicNotification(Context context) { |
361 // Use Android's Notification.Builder because we want the default small
icon behaviour. | 362 // Use a non-compat builder because we want the default small icon behav
iour. |
362 Notification.Builder builder = | 363 ChromeNotificationBuilder builder = |
363 new Notification.Builder(context) | 364 NotificationBuilderFactory |
| 365 .createChromeNotificationBuilder( |
| 366 false /* preferCompat */, ChannelDefinitions.CHA
NNEL_ID_SITES) |
364 .setContentText(context.getString( | 367 .setContentText(context.getString( |
365 org.chromium.chrome.R.string.notification_hidden
_text)) | 368 org.chromium.chrome.R.string.notification_hidden
_text)) |
366 .setSmallIcon(org.chromium.chrome.R.drawable.ic_chrome); | 369 .setSmallIcon(org.chromium.chrome.R.drawable.ic_chrome); |
367 | 370 |
368 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { | 371 if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) { |
369 // On N, 'subtext' displays at the top of the notification and this
looks better. | 372 // On N, 'subtext' displays at the top of the notification and this
looks better. |
370 builder.setSubText(mOrigin); | 373 builder.setSubText(mOrigin); |
371 } else { | 374 } else { |
372 // Set origin as title on L & M, because they look odd without one. | 375 // Set origin as title on L & M, because they look odd without one. |
373 builder.setContentTitle(mOrigin); | 376 builder.setContentTitle(mOrigin); |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 int largeIconWidthPx = | 485 int largeIconWidthPx = |
483 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_width); | 486 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_width); |
484 int largeIconHeightPx = | 487 int largeIconHeightPx = |
485 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_height); | 488 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_height); |
486 float density = resources.getDisplayMetrics().density; | 489 float density = resources.getDisplayMetrics().density; |
487 int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2; | 490 int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2; |
488 return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cor
nerRadiusPx, | 491 return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cor
nerRadiusPx, |
489 NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * den
sity); | 492 NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * den
sity); |
490 } | 493 } |
491 } | 494 } |
OLD | NEW |