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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 * @param tag A string identifier for this notification. If the tag is not e
mpty, the new | 390 * @param tag A string identifier for this notification. If the tag is not e
mpty, the new |
391 * notification will replace the previous notification with the s
ame tag and origin, | 391 * notification will replace the previous notification with the s
ame tag and origin, |
392 * if present. If no matching previous notification is present, t
he new one will just | 392 * if present. If no matching previous notification is present, t
he new one will just |
393 * be added. | 393 * be added. |
394 * @param title Title to be displayed in the notification. | 394 * @param title Title to be displayed in the notification. |
395 * @param body Message to be displayed in the notification. Will be trimmed
to one line of | 395 * @param body Message to be displayed in the notification. Will be trimmed
to one line of |
396 * text by the Android notification system. | 396 * text by the Android notification system. |
397 * @param icon Icon to be displayed in the notification. Valid Bitmap icons
will be scaled to | 397 * @param icon Icon to be displayed in the notification. Valid Bitmap icons
will be scaled to |
398 * the platforms, whereas a default icon will be generated for i
nvalid Bitmaps. | 398 * the platforms, whereas a default icon will be generated for i
nvalid Bitmaps. |
399 * @param vibrationPattern Vibration pattern following the Web Vibration syn
tax. | 399 * @param vibrationPattern Vibration pattern following the Web Vibration syn
tax. |
| 400 * @param timestamp The timestamp of the event for which the notification is
being shown. |
400 * @param silent Whether the default sound, vibration and lights should be s
uppressed. | 401 * @param silent Whether the default sound, vibration and lights should be s
uppressed. |
401 * @param actionTitles Titles of actions to display alongside the notificati
on. | 402 * @param actionTitles Titles of actions to display alongside the notificati
on. |
402 * @see https://developer.android.com/reference/android/app/Notification.htm
l | 403 * @see https://developer.android.com/reference/android/app/Notification.htm
l |
403 */ | 404 */ |
404 @CalledByNative | 405 @CalledByNative |
405 private void displayNotification(long persistentNotificationId, String origi
n, String tag, | 406 private void displayNotification(long persistentNotificationId, String origi
n, String tag, |
406 String title, String body, Bitmap icon, int[] vibrationPattern, bool
ean silent, | 407 String title, String body, Bitmap icon, int[] vibrationPattern, long
timestamp, |
407 String[] actionTitles) { | 408 boolean silent, String[] actionTitles) { |
408 Resources res = mAppContext.getResources(); | 409 Resources res = mAppContext.getResources(); |
409 | 410 |
410 // Set up a pending intent for going to the settings screen for |origin|
. | 411 // Set up a pending intent for going to the settings screen for |origin|
. |
411 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( | 412 Intent settingsIntent = PreferencesLauncher.createIntentForSettingsPage( |
412 mAppContext, SingleWebsitePreferences.class.getName()); | 413 mAppContext, SingleWebsitePreferences.class.getName()); |
413 settingsIntent.setData(makeIntentData(persistentNotificationId, origin, | 414 settingsIntent.setData(makeIntentData(persistentNotificationId, origin, |
414 -1 /* actionIndex */)); | 415 -1 /* actionIndex */)); |
415 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, | 416 settingsIntent.putExtra(Preferences.EXTRA_SHOW_FRAGMENT_ARGUMENTS, |
416 SingleWebsitePreferences.createFragmentArgsForSite(origin)); | 417 SingleWebsitePreferences.createFragmentArgsForSite(origin)); |
417 | 418 |
418 PendingIntent pendingSettingsIntent = PendingIntent.getActivity(mAppCont
ext, | 419 PendingIntent pendingSettingsIntent = PendingIntent.getActivity(mAppCont
ext, |
419 PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_
UPDATE_CURRENT); | 420 PENDING_INTENT_REQUEST_CODE, settingsIntent, PendingIntent.FLAG_
UPDATE_CURRENT); |
420 | 421 |
421 NotificationCompat.Builder notificationBuilder = new NotificationCompat.
Builder(mAppContext) | 422 NotificationCompat.Builder notificationBuilder = new NotificationCompat.
Builder(mAppContext) |
422 .setContentTitle(title) | 423 .setContentTitle(title) |
423 .setContentText(body) | 424 .setContentText(body) |
424 .setStyle(new NotificationCompat.BigTextStyle().bigText(body)) | 425 .setStyle(new NotificationCompat.BigTextStyle().bigText(body)) |
425 .setLargeIcon(ensureNormalizedIcon(icon, origin)) | 426 .setLargeIcon(ensureNormalizedIcon(icon, origin)) |
426 .setSmallIcon(R.drawable.ic_chrome) | 427 .setSmallIcon(R.drawable.ic_chrome) |
427 .setContentIntent(makePendingIntent( | 428 .setContentIntent(makePendingIntent( |
428 NotificationConstants.ACTION_CLICK_NOTIFICATION, | 429 NotificationConstants.ACTION_CLICK_NOTIFICATION, |
429 persistentNotificationId, origin, tag, -1 /* actionIndex
*/)) | 430 persistentNotificationId, origin, tag, -1 /* actionIndex
*/)) |
430 .setDeleteIntent(makePendingIntent( | 431 .setDeleteIntent(makePendingIntent( |
431 NotificationConstants.ACTION_CLOSE_NOTIFICATION, | 432 NotificationConstants.ACTION_CLOSE_NOTIFICATION, |
432 persistentNotificationId, origin, tag, -1 /* actionIndex
*/)) | 433 persistentNotificationId, origin, tag, -1 /* actionIndex
*/)) |
433 .setTicker(createTickerText(title, body)) | 434 .setTicker(createTickerText(title, body)) |
| 435 .setWhen(timestamp) |
434 .setSubText(origin); | 436 .setSubText(origin); |
435 | 437 |
436 for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex
++) { | 438 for (int actionIndex = 0; actionIndex < actionTitles.length; actionIndex
++) { |
437 notificationBuilder.addAction( | 439 notificationBuilder.addAction( |
438 0 /* actionIcon */, actionTitles[actionIndex], | 440 0 /* actionIcon */, actionTitles[actionIndex], |
439 makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFIC
ATION, | 441 makePendingIntent(NotificationConstants.ACTION_CLICK_NOTIFIC
ATION, |
440 persistentNotificationId, origin, tag, act
ionIndex)); | 442 persistentNotificationId, origin, tag, act
ionIndex)); |
441 } | 443 } |
442 // Site settings button is always the last action button. | 444 // Site settings button is always the last action button. |
443 notificationBuilder.addAction(R.drawable.settings_cog, | 445 notificationBuilder.addAction(R.drawable.settings_cog, |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
565 origin, tag); | 567 origin, tag); |
566 } | 568 } |
567 | 569 |
568 private static native void nativeInitializeNotificationUIManager(); | 570 private static native void nativeInitializeNotificationUIManager(); |
569 | 571 |
570 private native boolean nativeOnNotificationClicked(long nativeNotificationUI
ManagerAndroid, | 572 private native boolean nativeOnNotificationClicked(long nativeNotificationUI
ManagerAndroid, |
571 long persistentNotificationId, String origin, String tag, int action
Index); | 573 long persistentNotificationId, String origin, String tag, int action
Index); |
572 private native boolean nativeOnNotificationClosed(long nativeNotificationUIM
anagerAndroid, | 574 private native boolean nativeOnNotificationClosed(long nativeNotificationUIM
anagerAndroid, |
573 long persistentNotificationId, String origin, String tag); | 575 long persistentNotificationId, String origin, String tag); |
574 } | 576 } |
OLD | NEW |