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

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

Issue 1266023002: [MediaSession,Android] Use a badged notification icon for the Work profile (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: No canvas drawing into bitmap Created 5 years, 4 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
« no previous file with comments | « base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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.ui; 5 package org.chromium.chrome.browser.media.ui;
6 6
7 import android.app.PendingIntent; 7 import android.app.PendingIntent;
8 import android.app.Service; 8 import android.app.Service;
9 import android.content.Context; 9 import android.content.Context;
10 import android.content.Intent; 10 import android.content.Intent;
11 import android.graphics.Bitmap;
12 import android.graphics.drawable.BitmapDrawable;
13 import android.graphics.drawable.Drawable;
11 import android.os.IBinder; 14 import android.os.IBinder;
12 import android.provider.Browser; 15 import android.provider.Browser;
13 import android.support.v4.app.NotificationCompat; 16 import android.support.v4.app.NotificationCompat;
14 import android.widget.RemoteViews; 17 import android.widget.RemoteViews;
15 18
19 import org.chromium.base.ApiCompatibilityUtils;
16 import org.chromium.chrome.R; 20 import org.chromium.chrome.R;
17 import org.chromium.chrome.browser.IntentHandler.TabOpenType; 21 import org.chromium.chrome.browser.IntentHandler.TabOpenType;
18 22
19 /** 23 /**
20 * A class for notifications that provide information and optional media control s for a given media. 24 * A class for notifications that provide information and optional media control s for a given media.
21 * Internally implements a Service for transforming notification Intents into 25 * Internally implements a Service for transforming notification Intents into
22 * {@link MediaPlaybackListener} calls for all registered listeners. 26 * {@link MediaPlaybackListener} calls for all registered listeners.
23 */ 27 */
24 public class NotificationMediaPlaybackControls { 28 public class NotificationMediaPlaybackControls {
25 private static final Object LOCK = new Object(); 29 private static final Object LOCK = new Object();
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 148
145 // ListenerService running for the notification. Only non-null when showing. 149 // ListenerService running for the notification. Only non-null when showing.
146 private ListenerService mService; 150 private ListenerService mService;
147 151
148 private final String mPlayDescription; 152 private final String mPlayDescription;
149 153
150 private final String mPauseDescription; 154 private final String mPauseDescription;
151 155
152 private NotificationCompat.Builder mNotificationBuilder; 156 private NotificationCompat.Builder mNotificationBuilder;
153 157
158 private Bitmap mNotificationIconBitmap;
159
154 private MediaNotificationInfo mMediaNotificationInfo; 160 private MediaNotificationInfo mMediaNotificationInfo;
155 161
156 private NotificationMediaPlaybackControls(Context context) { 162 private NotificationMediaPlaybackControls(Context context) {
157 mContext = context; 163 mContext = context;
158 mPlayDescription = context.getResources().getString(R.string.accessibili ty_play); 164 mPlayDescription = context.getResources().getString(R.string.accessibili ty_play);
159 mPauseDescription = context.getResources().getString(R.string.accessibil ity_pause); 165 mPauseDescription = context.getResources().getString(R.string.accessibil ity_pause);
160 } 166 }
161 167
162 private void showNotification(MediaNotificationInfo mediaNotificationInfo) { 168 private void showNotification(MediaNotificationInfo mediaNotificationInfo) {
163 mContext.startService(new Intent(mContext, ListenerService.class)); 169 mContext.startService(new Intent(mContext, ListenerService.class));
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 233
228 private void updateNotification() { 234 private void updateNotification() {
229 if (mService == null) return; 235 if (mService == null) return;
230 236
231 if (mMediaNotificationInfo == null) { 237 if (mMediaNotificationInfo == null) {
232 // Notification was hidden before we could update it. 238 // Notification was hidden before we could update it.
233 assert mNotificationBuilder == null; 239 assert mNotificationBuilder == null;
234 return; 240 return;
235 } 241 }
236 242
243 // Android doesn't badge the icons for RemoteViews automatically when
244 // running the app under the Work profile.
245 if (mNotificationIconBitmap == null) {
246 Drawable notificationIconDrawable = ApiCompatibilityUtils.getUserBad gedIcon(
247 mContext, R.drawable.audio_playing);
248 mNotificationIconBitmap = drawableToBitmap(notificationIconDrawable) ;
249 }
250
237 if (mNotificationBuilder == null) { 251 if (mNotificationBuilder == null) {
238 mNotificationBuilder = new NotificationCompat.Builder(mContext) 252 mNotificationBuilder = new NotificationCompat.Builder(mContext)
239 .setSmallIcon(R.drawable.audio_playing) 253 .setSmallIcon(R.drawable.audio_playing)
240 .setAutoCancel(false) 254 .setAutoCancel(false)
241 .setOngoing(true); 255 .setOngoing(true);
242 } 256 }
243 mNotificationBuilder.setContentIntent(createContentIntent()); 257 mNotificationBuilder.setContentIntent(createContentIntent());
244 258
245 RemoteViews contentView = createContentView(); 259 RemoteViews contentView = createContentView();
246 260
247 contentView.setTextViewText(R.id.title, getTitle()); 261 contentView.setTextViewText(R.id.title, getTitle());
248 contentView.setTextViewText(R.id.status, getStatus()); 262 contentView.setTextViewText(R.id.status, getStatus());
249 contentView.setImageViewResource(R.id.icon, R.drawable.audio_playing); 263 if (mNotificationIconBitmap != null) {
264 contentView.setImageViewBitmap(R.id.icon, mNotificationIconBitmap);
265 } else {
266 contentView.setImageViewResource(R.id.icon, R.drawable.audio_playing );
267 }
250 268
251 if (mMediaNotificationInfo.isPaused) { 269 if (mMediaNotificationInfo.isPaused) {
252 contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidco ntrol_play); 270 contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidco ntrol_play);
253 contentView.setContentDescription(R.id.playpause, mPlayDescription); 271 contentView.setContentDescription(R.id.playpause, mPlayDescription);
254 contentView.setOnClickPendingIntent(R.id.playpause, 272 contentView.setOnClickPendingIntent(R.id.playpause,
255 mService.getPendingIntent(ListenerService.ACTION_PLAY)); 273 mService.getPendingIntent(ListenerService.ACTION_PLAY));
256 } else { 274 } else {
257 contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidco ntrol_pause); 275 contentView.setImageViewResource(R.id.playpause, R.drawable.ic_vidco ntrol_pause);
258 contentView.setContentDescription(R.id.playpause, mPauseDescription) ; 276 contentView.setContentDescription(R.id.playpause, mPauseDescription) ;
259 contentView.setOnClickPendingIntent(R.id.playpause, 277 contentView.setOnClickPendingIntent(R.id.playpause,
260 mService.getPendingIntent(ListenerService.ACTION_PAUSE)); 278 mService.getPendingIntent(ListenerService.ACTION_PAUSE));
261 } 279 }
262 280
263 mNotificationBuilder.setContent(contentView); 281 mNotificationBuilder.setContent(contentView);
264 mNotificationBuilder.setVisibility( 282 mNotificationBuilder.setVisibility(
265 mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY _PRIVATE 283 mMediaNotificationInfo.isPrivate ? NotificationCompat.VISIBILITY _PRIVATE
266 : NotificationCompat.VISIBILITY _PUBLIC); 284 : NotificationCompat.VISIBILITY _PUBLIC);
267 285
268 mService.startForeground(R.id.media_playback_notification, mNotification Builder.build()); 286 mService.startForeground(R.id.media_playback_notification, mNotification Builder.build());
269 } 287 }
288
289 private Bitmap drawableToBitmap(Drawable drawable) {
290 if (!(drawable instanceof BitmapDrawable)) return null;
291
292 BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
293 return bitmapDrawable.getBitmap();
294 }
270 } 295 }
OLDNEW
« no previous file with comments | « base/android/java/src/org/chromium/base/ApiCompatibilityUtils.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698