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

Side by Side Diff: chrome/android/java/src/org/chromium/chrome/browser/media/MediaCaptureNotificationService.java

Issue 2699253003: Abstracting over Notification.Builder + NotificationCompat.Builder (Closed)
Patch Set: remove erroneously added methods from rebase Created 3 years, 9 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 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.media; 5 package org.chromium.chrome.browser.media;
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.app.Service; 10 import android.app.Service;
11 import android.content.Context; 11 import android.content.Context;
12 import android.content.Intent; 12 import android.content.Intent;
13 import android.content.SharedPreferences; 13 import android.content.SharedPreferences;
14 import android.os.IBinder; 14 import android.os.IBinder;
15 import android.support.v4.app.NotificationCompat;
16 import android.util.SparseIntArray; 15 import android.util.SparseIntArray;
17 16
18 import org.chromium.base.ContextUtils; 17 import org.chromium.base.ContextUtils;
19 import org.chromium.base.Log; 18 import org.chromium.base.Log;
20 import org.chromium.chrome.R; 19 import org.chromium.chrome.R;
20 import org.chromium.chrome.browser.ChromeApplication;
21 import org.chromium.chrome.browser.notifications.ChromeNotificationBuilder;
22 import org.chromium.chrome.browser.notifications.NotificationConstants;
21 import org.chromium.chrome.browser.tab.Tab; 23 import org.chromium.chrome.browser.tab.Tab;
22 import org.chromium.chrome.browser.tab.TabWebContentsDelegateAndroid; 24 import org.chromium.chrome.browser.tab.TabWebContentsDelegateAndroid;
23 25
24 import java.net.MalformedURLException; 26 import java.net.MalformedURLException;
25 import java.net.URL; 27 import java.net.URL;
26 import java.util.HashSet; 28 import java.util.HashSet;
27 import java.util.Iterator; 29 import java.util.Iterator;
28 import java.util.Set; 30 import java.util.Set;
29 31
30 /** 32 /**
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 155 }
154 } 156 }
155 157
156 /** 158 /**
157 * Creates a notification for the provided notificationId and mediaType. 159 * Creates a notification for the provided notificationId and mediaType.
158 * @param notificationId Unique id of the notification. 160 * @param notificationId Unique id of the notification.
159 * @param mediaType Media type of the notification. 161 * @param mediaType Media type of the notification.
160 * @param url Url of the current webrtc call. 162 * @param url Url of the current webrtc call.
161 */ 163 */
162 private void createNotification(int notificationId, int mediaType, String ur l) { 164 private void createNotification(int notificationId, int mediaType, String ur l) {
163 NotificationCompat.Builder builder = 165 ChromeNotificationBuilder builder =
164 new NotificationCompat.Builder(mContext) 166 ((ChromeApplication) mContext)
167 .createChromeNotificationBuilder(true /* preferCompat */ ,
168 NotificationConstants.CATEGORY_ID_BROWSER,
169 mContext.getString(R.string.notification_categor y_browser),
170 NotificationConstants.CATEGORY_GROUP_ID_GENERAL,
171 mContext.getString(R.string.notification_categor y_group_general))
165 .setAutoCancel(false) 172 .setAutoCancel(false)
166 .setOngoing(true) 173 .setOngoing(true)
167 .setContentTitle(mContext.getString(R.string.app_name)) 174 .setContentTitle(mContext.getString(R.string.app_name))
168 .setSmallIcon(getNotificationIconId(mediaType)) 175 .setSmallIcon(getNotificationIconId(mediaType))
169 .setLocalOnly(true); 176 .setLocalOnly(true);
170 177
171 StringBuilder contentText = 178 StringBuilder contentText =
172 new StringBuilder(getNotificationContentText(mediaType, url)).ap pend('.'); 179 new StringBuilder(getNotificationContentText(mediaType, url)).ap pend('.');
173 Intent tabIntent = Tab.createBringTabToFrontIntent(notificationId); 180 Intent tabIntent = Tab.createBringTabToFrontIntent(notificationId);
174 if (tabIntent != null) { 181 if (tabIntent != null) {
175 PendingIntent contentIntent = PendingIntent.getActivity( 182 PendingIntent contentIntent = PendingIntent.getActivity(
176 mContext, notificationId, tabIntent, 0); 183 mContext, notificationId, tabIntent, 0);
177 builder.setContentIntent(contentIntent); 184 builder.setContentIntent(contentIntent);
178 if (mediaType == MEDIATYPE_SCREEN_CAPTURE) { 185 if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
179 // Add a "Stop" button to the screen capture notification and tu rn the notification 186 // Add a "Stop" button to the screen capture notification and tu rn the notification
180 // into a high priority one. 187 // into a high priority one.
181 builder.setPriority(Notification.PRIORITY_HIGH); 188 builder.setPriority(Notification.PRIORITY_HIGH);
182 builder.setVibrate(new long[0]); 189 builder.setVibrate(new long[0]);
183 builder.addAction(R.drawable.ic_stop_white_36dp, 190 builder.addAction(R.drawable.ic_stop_white_36dp,
184 mContext.getResources().getString(R.string.accessibility _stop), 191 mContext.getResources().getString(R.string.accessibility _stop),
185 buildStopCapturePendingIntent(notificationId)); 192 buildStopCapturePendingIntent(notificationId));
186 } else { 193 } else {
187 contentText.append(mContext.getResources().getString( 194 contentText.append(mContext.getResources().getString(
188 R.string.media_notification_link_text, url)); 195 R.string.media_notification_link_text, url));
189 } 196 }
190 } else { 197 } else {
191 contentText.append(" ").append(url); 198 contentText.append(" ").append(url);
192 } 199 }
193 builder.setContentText(contentText); 200 builder.setContentText(contentText.toString());
194 201
195 Notification notification = new NotificationCompat.BigTextStyle(builder) 202 Notification notification = builder.buildWithBigTextStyle(contentText.to String());
196 .bigText(contentText).build();
197 mNotificationManager.notify(NOTIFICATION_NAMESPACE, notificationId, noti fication); 203 mNotificationManager.notify(NOTIFICATION_NAMESPACE, notificationId, noti fication);
198 mNotifications.put(notificationId, mediaType); 204 mNotifications.put(notificationId, mediaType);
199 updateSharedPreferencesEntry(notificationId, false); 205 updateSharedPreferencesEntry(notificationId, false);
200 } 206 }
201 207
202 /** 208 /**
203 * Builds notification content text for the provided mediaType and url. 209 * Builds notification content text for the provided mediaType and url.
204 * @param mediaType Media type of the notification. 210 * @param mediaType Media type of the notification.
205 * @param url Url of the current webrtc call. 211 * @param url Url of the current webrtc call.
206 * @return A string builder initialized to the contents of the specified str ing. 212 * @return A string builder initialized to the contents of the specified str ing.
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 * Build PendingIntent for the actions of screen capture notification. 360 * Build PendingIntent for the actions of screen capture notification.
355 */ 361 */
356 private PendingIntent buildStopCapturePendingIntent(int notificationId) { 362 private PendingIntent buildStopCapturePendingIntent(int notificationId) {
357 Intent intent = new Intent(this, MediaCaptureNotificationService.class); 363 Intent intent = new Intent(this, MediaCaptureNotificationService.class);
358 intent.setAction(ACTION_SCREEN_CAPTURE_STOP); 364 intent.setAction(ACTION_SCREEN_CAPTURE_STOP);
359 intent.putExtra(NOTIFICATION_ID_EXTRA, notificationId); 365 intent.putExtra(NOTIFICATION_ID_EXTRA, notificationId);
360 return PendingIntent.getService( 366 return PendingIntent.getService(
361 mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURR ENT); 367 mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURR ENT);
362 } 368 }
363 } 369 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698