Chromium Code Reviews| 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 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 296 * @param origin Full text of the origin, including the protocol, owning thi s notification. | 296 * @param origin Full text of the origin, including the protocol, owning thi s notification. |
| 297 * @param tag A string identifier for this notification. If the tag is not e mpty, the new | 297 * @param tag A string identifier for this notification. If the tag is not e mpty, the new |
| 298 * notification will replace the previous notification with the s ame tag and origin, | 298 * notification will replace the previous notification with the s ame tag and origin, |
| 299 * if present. If no matching previous notification is present, t he new one will just | 299 * if present. If no matching previous notification is present, t he new one will just |
| 300 * be added. | 300 * be added. |
| 301 * @param title Title to be displayed in the notification. | 301 * @param title Title to be displayed in the notification. |
| 302 * @param body Message to be displayed in the notification. Will be trimmed to one line of | 302 * @param body Message to be displayed in the notification. Will be trimmed to one line of |
| 303 * text by the Android notification system. | 303 * text by the Android notification system. |
| 304 * @param icon Icon to be displayed in the notification. When this isn't a v alid Bitmap, a | 304 * @param icon Icon to be displayed in the notification. When this isn't a v alid Bitmap, a |
| 305 * default icon will be generated instead. | 305 * default icon will be generated instead. |
| 306 * @param vibrate Vibration pattern for the Notification. A notification tha t vibrates is | |
|
Peter Beverloo
2015/04/26 23:26:41
nit: Remove the "A notification...heads-up notific
Sanghyun Park
2015/04/27 14:00:00
I missunderstood about this.
I'll add "@see https
| |
| 307 * more likely to be presented as a heads-up notification. | |
| 306 * @param silent Whether the default sound, vibration and lights should be s uppressed. | 308 * @param silent Whether the default sound, vibration and lights should be s uppressed. |
| 307 */ | 309 */ |
| 308 @CalledByNative | 310 @CalledByNative |
| 309 private void displayNotification(long persistentNotificationId, String origi n, String tag, | 311 private void displayNotification(long persistentNotificationId, String origi n, String tag, |
| 310 String title, String body, Bitmap icon, boolean silent) { | 312 String title, String body, Bitmap icon, int[] vibrate, boolean silen t) { |
| 311 if (icon == null || icon.getWidth() == 0) { | 313 if (icon == null || icon.getWidth() == 0) { |
| 312 icon = getIconGenerator().generateIconForUrl(origin, true); | 314 icon = getIconGenerator().generateIconForUrl(origin, true); |
| 313 } | 315 } |
| 314 | 316 |
| 315 Resources res = mAppContext.getResources(); | 317 Resources res = mAppContext.getResources(); |
| 316 | 318 |
| 317 // The data used to make each intent unique according to the rules of In tent#filterEquals. | 319 // The data used to make each intent unique according to the rules of In tent#filterEquals. |
| 318 // Without this, the pending intents derived from them may be reused, be cause extras are | 320 // Without this, the pending intents derived from them may be reused, be cause extras are |
| 319 // not taken into account for the filterEquals comparison. | 321 // not taken into account for the filterEquals comparison. |
| 320 Uri intentData = Uri.parse(origin).buildUpon().fragment( | 322 Uri intentData = Uri.parse(origin).buildUpon().fragment( |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 342 .setDeleteIntent(getPendingIntent( | 344 .setDeleteIntent(getPendingIntent( |
| 343 NotificationConstants.ACTION_CLOSE_NOTIFICATION, | 345 NotificationConstants.ACTION_CLOSE_NOTIFICATION, |
| 344 persistentNotificationId, origin, tag, intentData)) | 346 persistentNotificationId, origin, tag, intentData)) |
| 345 .addAction(R.drawable.settings_cog, | 347 .addAction(R.drawable.settings_cog, |
| 346 res.getString(R.string.page_info_site_settings_button ), | 348 res.getString(R.string.page_info_site_settings_button ), |
| 347 pendingSettingsIntent) | 349 pendingSettingsIntent) |
| 348 .setSubText(origin); | 350 .setSubText(origin); |
| 349 | 351 |
| 350 // Use the system's default ringtone, vibration and indicator lights unl ess the notification | 352 // Use the system's default ringtone, vibration and indicator lights unl ess the notification |
| 351 // has been marked as being silent, for example because it's low priorit y. | 353 // has been marked as being silent, for example because it's low priorit y. |
| 352 if (!silent) notificationBuilder.setDefaults(Notification.DEFAULT_ALL); | 354 // If a vibration pattern is set, the notification should use the provid ed pattern |
|
Peter Beverloo
2015/04/26 23:26:41
Could we perhaps extract this block to a separate
Sanghyun Park
2015/04/27 14:00:00
Sure, I'll make method and add testcase.
| |
| 355 // rather than the defaulting to system settings. | |
| 356 assert silent && vibrate.length == 0; | |
| 357 | |
| 358 int defaults = Notification.DEFAULT_ALL; | |
| 359 if (silent) defaults = 0; | |
| 360 | |
| 361 if (vibrate.length > 0) { | |
| 362 // In Android platform, the first value indicates the number of | |
| 363 // milliseconds to wait before turning the vibrator on unlike Blink. | |
| 364 // So, we need to insert any value at the beginning of vibrate value . | |
| 365 long[] pattern = new long[vibrate.length + 1]; | |
| 366 pattern[0] = 0; | |
| 367 for (int i = 0; i < vibrate.length; ++i) { | |
|
Peter Beverloo
2015/04/26 23:26:41
Check out System.arraycopy() :-)
Sanghyun Park
2015/04/27 14:00:00
Unfortunately, we cannot use "arraycopy()".
For us
| |
| 368 pattern[i + 1] = vibrate[i]; | |
| 369 } | |
| 370 defaults &= ~Notification.DEFAULT_VIBRATE; | |
|
Peter Beverloo
2015/04/26 23:26:41
nit: I'd have this line as the first line in the i
Sanghyun Park
2015/04/27 14:00:00
Done.
| |
| 371 notificationBuilder.setVibrate(pattern); | |
| 372 } | |
| 373 notificationBuilder.setDefaults(defaults); | |
| 353 | 374 |
| 354 String platformTag = makePlatformTag(persistentNotificationId, origin, t ag); | 375 String platformTag = makePlatformTag(persistentNotificationId, origin, t ag); |
| 355 mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilde r.build()); | 376 mNotificationManager.notify(platformTag, PLATFORM_ID, notificationBuilde r.build()); |
| 356 } | 377 } |
| 357 | 378 |
| 358 /** | 379 /** |
| 359 * Ensures the existance of an icon generator, which is created lazily. | 380 * Ensures the existance of an icon generator, which is created lazily. |
| 360 * | 381 * |
| 361 * @return The icon generator which can be used. | 382 * @return The icon generator which can be used. |
| 362 */ | 383 */ |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 436 origin, tag); | 457 origin, tag); |
| 437 } | 458 } |
| 438 | 459 |
| 439 private static native void nativeInitializeNotificationUIManager(); | 460 private static native void nativeInitializeNotificationUIManager(); |
| 440 | 461 |
| 441 private native boolean nativeOnNotificationClicked(long nativeNotificationUI ManagerAndroid, | 462 private native boolean nativeOnNotificationClicked(long nativeNotificationUI ManagerAndroid, |
| 442 long persistentNotificationId, String origin, String tag); | 463 long persistentNotificationId, String origin, String tag); |
| 443 private native boolean nativeOnNotificationClosed(long nativeNotificationUIM anagerAndroid, | 464 private native boolean nativeOnNotificationClosed(long nativeNotificationUIM anagerAndroid, |
| 444 long persistentNotificationId, String origin, String tag); | 465 long persistentNotificationId, String origin, String tag); |
| 445 } | 466 } |
| OLD | NEW |