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_GENERAL, |
36 .setContentText(actionMessage) | 37 context.getString(R.string.notification_category
_general)) |
37 .setOngoing(true) | 38 .setContentTitle(title) |
38 .setVisibility(Notification.VISIBILITY_SECRET) | 39 .setContentIntent( |
39 .setSmallIcon(R.drawable.incognito_statusbar) | 40 IncognitoNotificationService.getRemoveAllIncogni
toTabsIntent( |
40 .setShowWhen(false) | 41 context)) |
41 .setLocalOnly(true) | 42 .setContentText(actionMessage) |
42 .setGroup(NotificationConstants.GROUP_INCOGNITO); | 43 .setOngoing(true) |
| 44 .setVisibility(Notification.VISIBILITY_SECRET) |
| 45 .setSmallIcon(R.drawable.incognito_statusbar) |
| 46 .setShowWhen(false) |
| 47 .setLocalOnly(true) |
| 48 .setGroup(NotificationConstants.GROUP_INCOGNITO); |
43 NotificationManager nm = | 49 NotificationManager nm = |
44 (NotificationManager) context.getSystemService(Context.NOTIFICAT
ION_SERVICE); | 50 (NotificationManager) context.getSystemService(Context.NOTIFICAT
ION_SERVICE); |
45 nm.notify(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID, builder.build
()); | 51 nm.notify(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID, builder.build
()); |
46 } | 52 } |
47 | 53 |
48 /** | 54 /** |
49 * Dismisses the incognito notification. | 55 * Dismisses the incognito notification. |
50 */ | 56 */ |
51 public static void dismissIncognitoNotification() { | 57 public static void dismissIncognitoNotification() { |
52 Context context = ContextUtils.getApplicationContext(); | 58 Context context = ContextUtils.getApplicationContext(); |
53 NotificationManager nm = | 59 NotificationManager nm = |
54 (NotificationManager) context.getSystemService(Context.NOTIFIC
ATION_SERVICE); | 60 (NotificationManager) context.getSystemService(Context.NOTIFIC
ATION_SERVICE); |
55 nm.cancel(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID); | 61 nm.cancel(INCOGNITO_TABS_OPEN_TAG, INCOGNITO_TABS_OPEN_ID); |
56 } | 62 } |
57 } | 63 } |
OLD | NEW |