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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
429 * @param incognito if the session of the profile is an off the record one. | 429 * @param incognito if the session of the profile is an off the record one. |
430 * @param tag A string identifier for this notification. If the tag is not e mpty, the new | 430 * @param tag A string identifier for this notification. If the tag is not e mpty, the new |
431 * notification will replace the previous notification with the s ame tag and origin, | 431 * notification will replace the previous notification with the s ame tag and origin, |
432 * if present. If no matching previous notification is present, t he new one will just | 432 * if present. If no matching previous notification is present, t he new one will just |
433 * be added. | 433 * be added. |
434 * @param title Title to be displayed in the notification. | 434 * @param title Title to be displayed in the notification. |
435 * @param body Message to be displayed in the notification. Will be trimmed to one line of | 435 * @param body Message to be displayed in the notification. Will be trimmed to one line of |
436 * text by the Android notification system. | 436 * text by the Android notification system. |
437 * @param icon Icon to be displayed in the notification. Valid Bitmap icons will be scaled to | 437 * @param icon Icon to be displayed in the notification. Valid Bitmap icons will be scaled to |
438 * the platforms, whereas a default icon will be generated for i nvalid Bitmaps. | 438 * the platforms, whereas a default icon will be generated for i nvalid Bitmaps. |
439 * @param smallIcon Icon to represent the notification in places where there is not enough space | |
440 * to display the whole notification. It may also be displa yed inside the | |
Peter Beverloo
2016/03/03 17:55:38
Let's explicitly call out the status bar?
Michael van Ouwerkerk
2016/03/09 18:28:25
Right, we're in Android code here.
| |
441 * notification. | |
439 * @param vibrationPattern Vibration pattern following the Web Vibration syn tax. | 442 * @param vibrationPattern Vibration pattern following the Web Vibration syn tax. |
440 * @param timestamp The timestamp of the event for which the notification is being shown. | 443 * @param timestamp The timestamp of the event for which the notification is being shown. |
441 * @param renotify Whether the sound, vibration, and lights should be replay ed if the | 444 * @param renotify Whether the sound, vibration, and lights should be replay ed if the |
442 * notification is replacing another notification. | 445 * notification is replacing another notification. |
443 * @param silent Whether the default sound, vibration and lights should be s uppressed. | 446 * @param silent Whether the default sound, vibration and lights should be s uppressed. |
444 * @param actionTitles Titles of actions to display alongside the notificati on. | 447 * @param actionTitles Titles of actions to display alongside the notificati on. |
445 * @param actionIcons Icons of actions to display alongside the notification . | 448 * @param actionIcons Icons of actions to display alongside the notification . |
446 * @see https://developer.android.com/reference/android/app/Notification.htm l | 449 * @see https://developer.android.com/reference/android/app/Notification.htm l |
447 */ | 450 */ |
448 @CalledByNative | 451 @CalledByNative |
449 private void displayNotification(long persistentNotificationId, String origi n, String profileId, | 452 private void displayNotification(long persistentNotificationId, String origi n, String profileId, |
450 boolean incognito, String tag, String title, String body, Bitmap ico n, | 453 boolean incognito, String tag, String title, String body, Bitmap ico n, Bitmap smallIcon, |
451 int[] vibrationPattern, long timestamp, boolean renotify, boolean si lent, | 454 int[] vibrationPattern, long timestamp, boolean renotify, boolean si lent, |
452 String[] actionTitles, Bitmap[] actionIcons) { | 455 String[] actionTitles, Bitmap[] actionIcons) { |
453 if (actionTitles.length != actionIcons.length) { | 456 if (actionTitles.length != actionIcons.length) { |
454 throw new IllegalArgumentException("The number of action titles and icons must match."); | 457 throw new IllegalArgumentException("The number of action titles and icons must match."); |
455 } | 458 } |
456 | 459 |
457 Resources res = mAppContext.getResources(); | 460 Resources res = mAppContext.getResources(); |
458 | 461 |
459 // Record whether it's known whether notifications can be shown to the u ser at all. | 462 // Record whether it's known whether notifications can be shown to the u ser at all. |
460 RecordHistogram.recordEnumeratedHistogram( | 463 RecordHistogram.recordEnumeratedHistogram( |
(...skipping 18 matching lines...) Expand all Loading... | |
479 PendingIntent closeIntent = makePendingIntent( | 482 PendingIntent closeIntent = makePendingIntent( |
480 NotificationConstants.ACTION_CLOSE_NOTIFICATION, persistentNotif icationId, origin, | 483 NotificationConstants.ACTION_CLOSE_NOTIFICATION, persistentNotif icationId, origin, |
481 profileId, incognito, tag, -1 /* actionIndex */); | 484 profileId, incognito, tag, -1 /* actionIndex */); |
482 | 485 |
483 NotificationBuilderBase notificationBuilder = | 486 NotificationBuilderBase notificationBuilder = |
484 createNotificationBuilder() | 487 createNotificationBuilder() |
485 .setTitle(title) | 488 .setTitle(title) |
486 .setBody(body) | 489 .setBody(body) |
487 .setLargeIcon(ensureNormalizedIcon(icon, origin)) | 490 .setLargeIcon(ensureNormalizedIcon(icon, origin)) |
488 .setSmallIcon(R.drawable.ic_chrome) | 491 .setSmallIcon(R.drawable.ic_chrome) |
492 .setSmallIcon(smallIcon) | |
489 .setContentIntent(clickIntent) | 493 .setContentIntent(clickIntent) |
490 .setDeleteIntent(closeIntent) | 494 .setDeleteIntent(closeIntent) |
491 .setTicker(createTickerText(title, body)) | 495 .setTicker(createTickerText(title, body)) |
492 .setTimestamp(timestamp) | 496 .setTimestamp(timestamp) |
493 .setRenotify(renotify) | 497 .setRenotify(renotify) |
494 .setOrigin(UrlUtilities.formatUrlForSecurityDisplay( | 498 .setOrigin(UrlUtilities.formatUrlForSecurityDisplay( |
495 origin, false /* showScheme */)); | 499 origin, false /* showScheme */)); |
496 | 500 |
497 for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex ++) { | 501 for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex ++) { |
498 notificationBuilder.addAction(actionIcons[actionIndex], actionTitles [actionIndex], | 502 notificationBuilder.addAction(actionIcons[actionIndex], actionTitles [actionIndex], |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
678 | 682 |
679 private static native void nativeInitializeNotificationUIManager(); | 683 private static native void nativeInitializeNotificationUIManager(); |
680 | 684 |
681 private native void nativeOnNotificationClicked(long nativeNotificationUIMan agerAndroid, | 685 private native void nativeOnNotificationClicked(long nativeNotificationUIMan agerAndroid, |
682 long persistentNotificationId, String origin, String profileId, bool ean incognito, | 686 long persistentNotificationId, String origin, String profileId, bool ean incognito, |
683 String tag, int actionIndex); | 687 String tag, int actionIndex); |
684 private native void nativeOnNotificationClosed(long nativeNotificationUIMana gerAndroid, | 688 private native void nativeOnNotificationClosed(long nativeNotificationUIMana gerAndroid, |
685 long persistentNotificationId, String origin, String profileId, bool ean incognito, | 689 long persistentNotificationId, String origin, String profileId, bool ean incognito, |
686 String tag, boolean byUser); | 690 String tag, boolean byUser); |
687 } | 691 } |
OLD | NEW |