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

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: Abstracting over Notification.Builder + NotificationCompat.Builder Created 3 years, 10 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 .getChromeNotificationBuilder(true, NotificationConstant s.TYPE_ID_GENERAL,
168 NotificationConstants.TYPE_NAME_GENERAL)
165 .setAutoCancel(false) 169 .setAutoCancel(false)
166 .setOngoing(true) 170 .setOngoing(true)
167 .setContentTitle(mContext.getString(R.string.app_name)) 171 .setContentTitle(mContext.getString(R.string.app_name))
168 .setSmallIcon(getNotificationIconId(mediaType)) 172 .setSmallIcon(getNotificationIconId(mediaType))
169 .setLocalOnly(true); 173 .setLocalOnly(true);
170 174
171 StringBuilder contentText = 175 StringBuilder contentText =
172 new StringBuilder(getNotificationContentText(mediaType, url)).ap pend('.'); 176 new StringBuilder(getNotificationContentText(mediaType, url)).ap pend('.');
173 Intent tabIntent = Tab.createBringTabToFrontIntent(notificationId); 177 Intent tabIntent = Tab.createBringTabToFrontIntent(notificationId);
174 if (tabIntent != null) { 178 if (tabIntent != null) {
175 PendingIntent contentIntent = PendingIntent.getActivity( 179 PendingIntent contentIntent = PendingIntent.getActivity(
176 mContext, notificationId, tabIntent, 0); 180 mContext, notificationId, tabIntent, 0);
177 builder.setContentIntent(contentIntent); 181 builder.setContentIntent(contentIntent);
178 if (mediaType == MEDIATYPE_SCREEN_CAPTURE) { 182 if (mediaType == MEDIATYPE_SCREEN_CAPTURE) {
179 // Add a "Stop" button to the screen capture notification and tu rn the notification 183 // Add a "Stop" button to the screen capture notification and tu rn the notification
180 // into a high priority one. 184 // into a high priority one.
181 builder.setPriority(Notification.PRIORITY_HIGH); 185 builder.setPriority(Notification.PRIORITY_HIGH);
182 builder.setVibrate(new long[0]); 186 builder.setVibrate(new long[0]);
183 builder.addAction(R.drawable.ic_stop_white_36dp, 187 builder.addAction(R.drawable.ic_stop_white_36dp,
184 mContext.getResources().getString(R.string.accessibility _stop), 188 mContext.getResources().getString(R.string.accessibility _stop),
185 buildStopCapturePendingIntent(notificationId)); 189 buildStopCapturePendingIntent(notificationId));
186 } else { 190 } else {
187 contentText.append(mContext.getResources().getString( 191 contentText.append(mContext.getResources().getString(
188 R.string.media_notification_link_text, url)); 192 R.string.media_notification_link_text, url));
189 } 193 }
190 } else { 194 } else {
191 contentText.append(" ").append(url); 195 contentText.append(" ").append(url);
192 } 196 }
193 builder.setContentText(contentText); 197 builder.setContentText(contentText.toString());
194 198
195 Notification notification = new NotificationCompat.BigTextStyle(builder) 199 Notification notification = builder.buildWithBigTextStyle(contentText.to String());
196 .bigText(contentText).build();
197 mNotificationManager.notify(NOTIFICATION_NAMESPACE, notificationId, noti fication); 200 mNotificationManager.notify(NOTIFICATION_NAMESPACE, notificationId, noti fication);
198 mNotifications.put(notificationId, mediaType); 201 mNotifications.put(notificationId, mediaType);
199 updateSharedPreferencesEntry(notificationId, false); 202 updateSharedPreferencesEntry(notificationId, false);
200 } 203 }
201 204
202 /** 205 /**
203 * Builds notification content text for the provided mediaType and url. 206 * Builds notification content text for the provided mediaType and url.
204 * @param mediaType Media type of the notification. 207 * @param mediaType Media type of the notification.
205 * @param url Url of the current webrtc call. 208 * @param url Url of the current webrtc call.
206 * @return A string builder initialized to the contents of the specified str ing. 209 * @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. 357 * Build PendingIntent for the actions of screen capture notification.
355 */ 358 */
356 private PendingIntent buildStopCapturePendingIntent(int notificationId) { 359 private PendingIntent buildStopCapturePendingIntent(int notificationId) {
357 Intent intent = new Intent(this, MediaCaptureNotificationService.class); 360 Intent intent = new Intent(this, MediaCaptureNotificationService.class);
358 intent.setAction(ACTION_SCREEN_CAPTURE_STOP); 361 intent.setAction(ACTION_SCREEN_CAPTURE_STOP);
359 intent.putExtra(NOTIFICATION_ID_EXTRA, notificationId); 362 intent.putExtra(NOTIFICATION_ID_EXTRA, notificationId);
360 return PendingIntent.getService( 363 return PendingIntent.getService(
361 mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURR ENT); 364 mContext, notificationId, intent, PendingIntent.FLAG_UPDATE_CURR ENT);
362 } 365 }
363 } 366 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698