OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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.incognito; | 5 package org.chromium.chrome.browser.incognito; |
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.content.Context; | 9 import android.content.Context; |
10 import android.support.v4.app.NotificationCompat; | |
11 | 10 |
12 import org.chromium.base.ContextUtils; | 11 import org.chromium.base.ContextUtils; |
13 import org.chromium.chrome.R; | 12 import org.chromium.chrome.R; |
| 13 import org.chromium.chrome.browser.ChromeApplication; |
| 14 import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder; |
14 import org.chromium.chrome.browser.notifications.NotificationConstants; | 15 import org.chromium.chrome.browser.notifications.NotificationConstants; |
15 | 16 |
16 /** | 17 /** |
17 * Manages the notification indicating that there are incognito tabs opened in D
ocument mode. | 18 * Manages the notification indicating that there are incognito tabs opened in D
ocument mode. |
18 */ | 19 */ |
19 public class IncognitoNotificationManager { | 20 public class IncognitoNotificationManager { |
20 private static final String INCOGNITO_TABS_OPEN_TAG = "incognito_tabs_open"; | 21 private static final String INCOGNITO_TABS_OPEN_TAG = "incognito_tabs_open"; |
21 private static final int INCOGNITO_TABS_OPEN_ID = 100; | 22 private static final int INCOGNITO_TABS_OPEN_ID = 100; |
22 | 23 |
23 /** | 24 /** |
24 * Shows the close all incognito notification. | 25 * Shows the close all incognito notification. |
25 */ | 26 */ |
26 public static void showIncognitoNotification() { | 27 public static void showIncognitoNotification() { |
27 Context context = ContextUtils.getApplicationContext(); | 28 Context context = ContextUtils.getApplicationContext(); |
28 String actionMessage = | 29 String actionMessage = |
29 context.getResources().getString(R.string.close_all_incognito_no
tification); | 30 context.getResources().getString(R.string.close_all_incognito_no
tification); |
30 String title = context.getResources().getString(R.string.app_name); | 31 String title = context.getResources().getString(R.string.app_name); |
31 | 32 |
32 NotificationCompat.Builder builder = new NotificationCompat.Builder(cont
ext) | 33 ChromeNotificationBuilder builder = |
33 .setContentTitle(title) | 34 ((ChromeApplication) context) |
34 .setContentIntent( | 35 .createChromeNotificationBuilder(true /* preferCompat */
, |
35 IncognitoNotificationService.getRemoveAllIncognitoTabsIn
tent(context)) | 36 NotificationConstants.CATEGORY_ID_BROWSER, |
36 .setContentText(actionMessage) | 37 context.getString(R.string.notification_category
_browser), |
37 .setOngoing(true) | 38 NotificationConstants.CATEGORY_GROUP_ID_GENERAL, |
38 .setVisibility(Notification.VISIBILITY_SECRET) | 39 context.getString(R.string.notification_category
_group_general)) |
39 .setSmallIcon(R.drawable.incognito_statusbar) | 40 .setContentTitle(title) |
40 .setShowWhen(false) | 41 .setContentIntent( |
41 .setLocalOnly(true) | 42 IncognitoNotificationService.getRemoveAllIncogni
toTabsIntent( |
42 .setGroup(NotificationConstants.GROUP_INCOGNITO); | 43 context)) |
| 44 .setContentText(actionMessage) |
| 45 .setOngoing(true) |
| 46 .setVisibility(Notification.VISIBILITY_SECRET) |
| 47 .setSmallIcon(R.drawable.incognito_statusbar) |
| 48 .setShowWhen(false) |
| 49 .setLocalOnly(true) |
| 50 .setGroup(NotificationConstants.GROUP_INCOGNITO); |
43 NotificationManager nm = | 51 NotificationManager nm = |
44 (NotificationManager) context.getSystemService(Context.NOTIFICAT
ION_SERVICE); | 52 (NotificationManager) context.getSystemService(Context.NOTIFICAT
ION_SERVICE); |
45 nm.notify(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID, builder.build
()); | 53 nm.notify(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID, builder.build
()); |
46 } | 54 } |
47 | 55 |
48 /** | 56 /** |
49 * Dismisses the incognito notification. | 57 * Dismisses the incognito notification. |
50 */ | 58 */ |
51 public static void dismissIncognitoNotification() { | 59 public static void dismissIncognitoNotification() { |
52 Context context = ContextUtils.getApplicationContext(); | 60 Context context = ContextUtils.getApplicationContext(); |
53 NotificationManager nm = | 61 NotificationManager nm = |
54 (NotificationManager) context.getSystemService(Context.NOTIFIC
ATION_SERVICE); | 62 (NotificationManager) context.getSystemService(Context.NOTIFIC
ATION_SERVICE); |
55 nm.cancel(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID); | 63 nm.cancel(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID); |
56 } | 64 } |
57 } | 65 } |
OLD | NEW |