Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(438)

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/ntp/ContentSuggestionsNotificationHelper.java

Issue 2606753002: Post notification after fetching articles (Closed)
Patch Set: Add TODO. Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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.ntp; 5 package org.chromium.chrome.browser.ntp;
6 6
7 import android.app.NotificationManager;
8 import android.app.PendingIntent;
7 import android.content.Context; 9 import android.content.Context;
8 import android.content.Intent; 10 import android.content.Intent;
11 import android.graphics.Bitmap;
9 import android.net.Uri; 12 import android.net.Uri;
10 import android.provider.Browser; 13 import android.provider.Browser;
14 import android.support.v4.app.NotificationCompat;
11 15
12 import org.chromium.base.ContextUtils; 16 import org.chromium.base.ContextUtils;
13 import org.chromium.base.annotations.CalledByNative; 17 import org.chromium.base.annotations.CalledByNative;
18 import org.chromium.chrome.R;
14 import org.chromium.chrome.browser.IntentHandler; 19 import org.chromium.chrome.browser.IntentHandler;
15 import org.chromium.chrome.browser.ShortcutHelper; 20 import org.chromium.chrome.browser.ShortcutHelper;
16 import org.chromium.chrome.browser.document.ChromeLauncherActivity; 21 import org.chromium.chrome.browser.document.ChromeLauncherActivity;
17 22
18 /** 23 /**
19 * Provides functionality needed for content suggestion notifications. 24 * Provides functionality needed for content suggestion notifications.
20 * 25 *
21 * Exposes helper functions to native C++ code. 26 * Exposes helper functions to native C++ code.
22 */ 27 */
23 public class ContentSuggestionsNotificationHelper { 28 public class ContentSuggestionsNotificationHelper {
29 private static final String NOTIFICATION_TAG = "ContentSuggestionsNotificati on";
30 private static final int NOTIFICATION_ID = 0;
31
24 private ContentSuggestionsNotificationHelper() {} // Prevent instantiation 32 private ContentSuggestionsNotificationHelper() {} // Prevent instantiation
25 33
26 @CalledByNative 34 @CalledByNative
27 private static void openUrl(String url) { 35 private static void openUrl(String url) {
28 Context context = ContextUtils.getApplicationContext(); 36 Context context = ContextUtils.getApplicationContext();
29 Intent intent = new Intent(); 37 Intent intent = new Intent();
30 intent.setAction(Intent.ACTION_VIEW); 38 intent.setAction(Intent.ACTION_VIEW);
31 intent.setData(Uri.parse(url)); 39 intent.setData(Uri.parse(url));
32 intent.setClass(context, ChromeLauncherActivity.class); 40 intent.setClass(context, ChromeLauncherActivity.class);
33 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 41 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
34 intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName()); 42 intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
35 intent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true ); 43 intent.putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ELSE_NEW_TAB, true );
36 IntentHandler.addTrustedIntentExtras(intent, context); 44 IntentHandler.addTrustedIntentExtras(intent, context);
37 context.startActivity(intent); 45 context.startActivity(intent);
38 } 46 }
47
48 @CalledByNative
49 private static void showNotification(String url, String title, String text, Bitmap image) {
50 Context context = ContextUtils.getApplicationContext();
51 NotificationManager manager =
52 (NotificationManager) context.getSystemService(Context.NOTIFICAT ION_SERVICE);
53 Intent intent = new Intent()
54 .setAction(Intent.ACTION_VIEW)
55 .setData(Uri.parse(url))
56 .setClass(context, ChromeLauncherActivity.class)
57 .putExtra(ShortcutHelper.REUSE_URL_MATCHING_TAB_ ELSE_NEW_TAB, true)
58 .putExtra(Browser.EXTRA_APPLICATION_ID, context. getPackageName());
59 NotificationCompat.Builder builder =
60 new NotificationCompat.Builder(context)
61 .setAutoCancel(true)
62 .setContentIntent(PendingIntent.getActivity(context, 0, intent, 0))
63 .setContentTitle(title)
64 .setContentText(text)
65 .setLargeIcon(image)
66 .setSmallIcon(R.drawable.ic_chrome);
67 manager.notify(NOTIFICATION_TAG, NOTIFICATION_ID, builder.build());
68 }
69
70 @CalledByNative
71 private static void hideNotification() {
72 Context context = ContextUtils.getApplicationContext();
73 NotificationManager manager =
74 (NotificationManager) context.getSystemService(Context.NOTIFICAT ION_SERVICE);
75 manager.cancel(NOTIFICATION_TAG, NOTIFICATION_ID);
76 }
39 } 77 }
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/BUILD.gn » ('j') | chrome/browser/ntp_snippets/ntp_snippets_features.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698