| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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.app.NotificationManager; | 8 import android.app.NotificationManager; |
| 9 import android.app.PendingIntent; | 9 import android.app.PendingIntent; |
| 10 import android.content.Context; | 10 import android.content.Context; |
| (...skipping 402 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 413 * if present. If no matching previous notification is present, t
he new one will just | 413 * if present. If no matching previous notification is present, t
he new one will just |
| 414 * be added. | 414 * be added. |
| 415 * @param title Title to be displayed in the notification. | 415 * @param title Title to be displayed in the notification. |
| 416 * @param body Message to be displayed in the notification. Will be trimmed
to one line of | 416 * @param body Message to be displayed in the notification. Will be trimmed
to one line of |
| 417 * text by the Android notification system. | 417 * text by the Android notification system. |
| 418 * @param icon Icon to be displayed in the notification. Valid Bitmap icons
will be scaled to | 418 * @param icon Icon to be displayed in the notification. Valid Bitmap icons
will be scaled to |
| 419 * the platforms, whereas a default icon will be generated for i
nvalid Bitmaps. | 419 * the platforms, whereas a default icon will be generated for i
nvalid Bitmaps. |
| 420 * @param vibrationPattern Vibration pattern following the Web Vibration syn
tax. | 420 * @param vibrationPattern Vibration pattern following the Web Vibration syn
tax. |
| 421 * @param silent Whether the default sound, vibration and lights should be s
uppressed. | 421 * @param silent Whether the default sound, vibration and lights should be s
uppressed. |
| 422 * @param actionTitles Titles of actions to display alongside the notificati
on. | 422 * @param actionTitles Titles of actions to display alongside the notificati
on. |
| 423 * @param actionIcons Icons of actions to display alongside the notification
. |
| 423 * @see https://developer.android.com/reference/android/app/Notification.htm
l | 424 * @see https://developer.android.com/reference/android/app/Notification.htm
l |
| 424 */ | 425 */ |
| 425 @CalledByNative | 426 @CalledByNative |
| 426 private void displayNotification(long persistentNotificationId, String origi
n, String profileId, | 427 private void displayNotification(long persistentNotificationId, String origi
n, String profileId, |
| 427 boolean incognito, String tag, String title, String body, Bitmap ico
n, | 428 boolean incognito, String tag, String title, String body, Bitmap ico
n, |
| 428 int[] vibrationPattern, boolean silent, String[] actionTitles) { | 429 int[] vibrationPattern, boolean silent, String[] actionTitles, Bitma
p[] actionIcons) { |
| 430 if (actionTitles.length != actionIcons.length) { |
| 431 throw new IllegalStateException("The number of action titles and ico
ns must match."); |
| 432 } |
| 433 |
| 429 Resources res = mAppContext.getResources(); | 434 Resources res = mAppContext.getResources(); |
| 430 | 435 |
| 431 // Record whether it's known whether notifications can be shown to the u
ser at all. | 436 // Record whether it's known whether notifications can be shown to the u
ser at all. |
| 432 RecordHistogram.recordEnumeratedHistogram( | 437 RecordHistogram.recordEnumeratedHistogram( |
| 433 "Notifications.AppNotificationStatus", | 438 "Notifications.AppNotificationStatus", |
| 434 NotificationSystemStatusUtil.determineAppNotificationStatus(mApp
Context), | 439 NotificationSystemStatusUtil.determineAppNotificationStatus(mApp
Context), |
| 435 NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_BOUNDARY); | 440 NotificationSystemStatusUtil.APP_NOTIFICATIONS_STATUS_BOUNDARY); |
| 436 | 441 |
| 437 // Set up a pending intent for going to the settings screen for |origin|
. | 442 // Set up a pending intent for going to the settings screen for |origin|
. |
| 438 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( | 443 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 457 .setTitle(title) | 462 .setTitle(title) |
| 458 .setBody(body) | 463 .setBody(body) |
| 459 .setLargeIcon(ensureNormalizedIcon(icon, origin)) | 464 .setLargeIcon(ensureNormalizedIcon(icon, origin)) |
| 460 .setSmallIcon(R.drawable.ic_chrome) | 465 .setSmallIcon(R.drawable.ic_chrome) |
| 461 .setContentIntent(clickIntent) | 466 .setContentIntent(clickIntent) |
| 462 .setDeleteIntent(closeIntent) | 467 .setDeleteIntent(closeIntent) |
| 463 .setTicker(createTickerText(title, body)) | 468 .setTicker(createTickerText(title, body)) |
| 464 .setOrigin(UrlUtilities.formatUrlForSecurityDisplay( | 469 .setOrigin(UrlUtilities.formatUrlForSecurityDisplay( |
| 465 origin, false /* showScheme */)); | 470 origin, false /* showScheme */)); |
| 466 | 471 |
| 467 for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex
++) { | 472 // TODO: handle bitmaps for standard notifications as well. |
| 468 notificationBuilder.addAction(0 /* actionIcon */, actionTitles[actio
nIndex], | 473 if (useCustomLayouts()) { |
| 469 makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFIC
ATION, | 474 CustomNotificationBuilder customBuilder = |
| 470 persistentNotificationId, orig
in, profileId, | 475 (CustomNotificationBuilder) notificationBuilder; |
| 471 incognito, tag, actionIndex)); | 476 for (int actionIndex = 0; actionIndex < actionTitles.length; actionI
ndex++) { |
| 477 customBuilder.addAction(actionIcons[actionIndex], actionTitles[a
ctionIndex], |
| 478 makePendingIntent(NotificationConstants.ACTION_CLICK_NOT
IFICATION, |
| 479 persistentNotificationId, origin
, profileId, |
| 480 incognito, tag, actionIndex)); |
| 481 } |
| 472 } | 482 } |
| 473 | 483 |
| 474 // If action buttons are displayed, there isn't room for the full Site S
ettings button | 484 // If action buttons are displayed, there isn't room for the full Site S
ettings button |
| 475 // label and icon, so abbreviate it. This has the unfortunate side-effec
t of unnecessarily | 485 // label and icon, so abbreviate it. This has the unfortunate side-effec
t of unnecessarily |
| 476 // abbreviating it on Android Wear also (crbug.com/576656). If custom la
youts are enabled, | 486 // abbreviating it on Android Wear also (crbug.com/576656). If custom la
youts are enabled, |
| 477 // the label and icon provided here only affect Android Wear, so don't a
bbreviate them. | 487 // the label and icon provided here only affect Android Wear, so don't a
bbreviate them. |
| 478 boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLa
youts(); | 488 boolean abbreviateSiteSettings = actionTitles.length > 0 && !useCustomLa
youts(); |
| 479 int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_co
g; | 489 int settingsIconId = abbreviateSiteSettings ? 0 : R.drawable.settings_co
g; |
| 480 CharSequence settingsTitle = abbreviateSiteSettings | 490 CharSequence settingsTitle = abbreviateSiteSettings |
| 481 ? res.getString(R.string.notification_site_
settings_button) | 491 ? res.getString(R.string.notification_site_
settings_button) |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 645 | 655 |
| 646 private static native void nativeInitializeNotificationUIManager(); | 656 private static native void nativeInitializeNotificationUIManager(); |
| 647 | 657 |
| 648 private native void nativeOnNotificationClicked(long nativeNotificationUIMan
agerAndroid, | 658 private native void nativeOnNotificationClicked(long nativeNotificationUIMan
agerAndroid, |
| 649 long persistentNotificationId, String origin, String profileId, bool
ean incognito, | 659 long persistentNotificationId, String origin, String profileId, bool
ean incognito, |
| 650 String tag, int actionIndex); | 660 String tag, int actionIndex); |
| 651 private native void nativeOnNotificationClosed(long nativeNotificationUIMana
gerAndroid, | 661 private native void nativeOnNotificationClosed(long nativeNotificationUIMana
gerAndroid, |
| 652 long persistentNotificationId, String origin, String profileId, bool
ean incognito, | 662 long persistentNotificationId, String origin, String profileId, bool
ean incognito, |
| 653 String tag, boolean byUser); | 663 String tag, boolean byUser); |
| 654 } | 664 } |
| OLD | NEW |