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; |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 } | 398 } |
399 return input; | 399 return input; |
400 } | 400 } |
401 | 401 |
402 /** | 402 /** |
403 * Sets the small icon on {@code builder} using a {@code Bitmap} if a non-nu
ll bitmap is | 403 * Sets the small icon on {@code builder} using a {@code Bitmap} if a non-nu
ll bitmap is |
404 * provided and the API level is high enough, otherwise the resource id is u
sed. | 404 * provided and the API level is high enough, otherwise the resource id is u
sed. |
405 */ | 405 */ |
406 @TargetApi(Build.VERSION_CODES.M) // For the Icon class. | 406 @TargetApi(Build.VERSION_CODES.M) // For the Icon class. |
407 protected static void setSmallIconOnBuilder( | 407 protected static void setSmallIconOnBuilder( |
408 Notification.Builder builder, int iconId, @Nullable Bitmap iconBitma
p) { | 408 ChromeNotificationBuilder builder, int iconId, @Nullable Bitmap icon
Bitmap) { |
409 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && iconBitmap != null
) { | 409 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && iconBitmap != null
) { |
410 builder.setSmallIcon(Icon.createWithBitmap(iconBitmap)); | 410 builder.setSmallIcon(Icon.createWithBitmap(iconBitmap)); |
411 } else { | 411 } else { |
412 builder.setSmallIcon(iconId); | 412 builder.setSmallIcon(iconId); |
413 } | 413 } |
414 } | 414 } |
415 | 415 |
416 /** | 416 /** |
417 * Adds an action to {@code builder} using a {@code Bitmap} if a bitmap is p
rovided and the API | 417 * Adds an action to {@code builder} using a {@code Bitmap} if a bitmap is p
rovided and the API |
418 * level is high enough, otherwise a resource id is used. | 418 * level is high enough, otherwise a resource id is used. |
419 */ | 419 */ |
420 @SuppressWarnings("deprecation") // For addAction(int, CharSequence, Pending
Intent) | 420 @SuppressWarnings("deprecation") // For addAction(int, CharSequence, Pending
Intent) |
421 protected static void addActionToBuilder(Notification.Builder builder, Actio
n action) { | 421 protected static void addActionToBuilder(ChromeNotificationBuilder builder,
Action action) { |
422 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { | 422 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) { |
423 // Notification.Action.Builder and RemoteInput were added in KITKAT_
WATCH. | 423 // Notification.Action.Builder and RemoteInput were added in KITKAT_
WATCH. |
424 Notification.Action.Builder actionBuilder = getActionBuilder(action)
; | 424 Notification.Action.Builder actionBuilder = getActionBuilder(action)
; |
425 if (action.type == Action.Type.TEXT) { | 425 if (action.type == Action.Type.TEXT) { |
426 assert action.placeholder != null; | 426 assert action.placeholder != null; |
427 actionBuilder.addRemoteInput( | 427 actionBuilder.addRemoteInput( |
428 new RemoteInput.Builder(NotificationConstants.KEY_TEXT_R
EPLY) | 428 new RemoteInput.Builder(NotificationConstants.KEY_TEXT_R
EPLY) |
429 .setLabel(action.placeholder) | 429 .setLabel(action.placeholder) |
430 .build()); | 430 .build()); |
431 } | 431 } |
432 builder.addAction(actionBuilder.build()); | 432 builder.addAction(actionBuilder.build()); |
433 } else { | 433 } else { |
434 builder.addAction(action.iconId, action.title, action.intent); | 434 builder.addAction(action.iconId, action.title, action.intent); |
435 } | 435 } |
436 } | 436 } |
437 | 437 |
438 /** | 438 /** |
439 * Sets the notification group for the builder, determined by the origin pro
vided. | 439 * Sets the notification group for the builder, determined by the origin pro
vided. |
440 * Note, after this notification is built and posted, a further summary noti
fication must be | 440 * Note, after this notification is built and posted, a further summary noti
fication must be |
441 * posted for notifications in the group to appear grouped in the notificati
on shade. | 441 * posted for notifications in the group to appear grouped in the notificati
on shade. |
442 */ | 442 */ |
443 @SuppressLint("NewApi") // For setGroup | 443 @SuppressLint("NewApi") // For setGroup |
444 static void setGroupOnBuilder(Notification.Builder builder, CharSequence ori
gin) { | 444 static void setGroupOnBuilder(ChromeNotificationBuilder builder, CharSequenc
e origin) { |
445 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH || origin =
= null) return; | 445 if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT_WATCH || origin =
= null) return; |
446 builder.setGroup(NotificationConstants.GROUP_WEB_PREFIX + origin); | 446 builder.setGroup(NotificationConstants.GROUP_WEB_PREFIX + origin); |
447 // TODO(crbug.com/674927) Post a group summary notification. | 447 // TODO(crbug.com/674927) Post a group summary notification. |
448 // Notifications with the same group will only actually be stacked if we
post a group | 448 // Notifications with the same group will only actually be stacked if we
post a group |
449 // summary notification. Calling setGroup at least prevents them being a
utobundled with | 449 // summary notification. Calling setGroup at least prevents them being a
utobundled with |
450 // all Chrome notifications on N though (see crbug.com/674015). | 450 // all Chrome notifications on N though (see crbug.com/674015). |
451 } | 451 } |
452 | 452 |
453 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // For Notification.Action.Buil
der | 453 @TargetApi(Build.VERSION_CODES.KITKAT_WATCH) // For Notification.Action.Buil
der |
454 @SuppressWarnings("deprecation") // For Builder(int, CharSequence, PendingIn
tent) | 454 @SuppressWarnings("deprecation") // For Builder(int, CharSequence, PendingIn
tent) |
(...skipping 27 matching lines...) Expand all Loading... |
482 int largeIconWidthPx = | 482 int largeIconWidthPx = |
483 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_width); | 483 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_width); |
484 int largeIconHeightPx = | 484 int largeIconHeightPx = |
485 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_height); | 485 resources.getDimensionPixelSize(android.R.dimen.notification_lar
ge_icon_height); |
486 float density = resources.getDisplayMetrics().density; | 486 float density = resources.getDisplayMetrics().density; |
487 int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2; | 487 int cornerRadiusPx = Math.min(largeIconWidthPx, largeIconHeightPx) / 2; |
488 return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cor
nerRadiusPx, | 488 return new RoundedIconGenerator(largeIconWidthPx, largeIconHeightPx, cor
nerRadiusPx, |
489 NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * den
sity); | 489 NOTIFICATION_ICON_BG_COLOR, NOTIFICATION_ICON_TEXT_SIZE_DP * den
sity); |
490 } | 490 } |
491 } | 491 } |
OLD | NEW |