| OLD | NEW |
| 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.media.remote; | 5 package org.chromium.chrome.browser.media.remote; |
| 6 | 6 |
| 7 import android.content.Context; | 7 import android.content.Context; |
| 8 import android.content.Intent; | 8 import android.content.Intent; |
| 9 import android.graphics.Bitmap; | 9 import android.graphics.Bitmap; |
| 10 import android.media.AudioManager; | 10 import android.media.AudioManager; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 /** | 75 /** |
| 76 * Sets the poster bitmap to display on the TransportControl. | 76 * Sets the poster bitmap to display on the TransportControl. |
| 77 */ | 77 */ |
| 78 public final void setPosterBitmap(Bitmap posterBitmap) { | 78 public final void setPosterBitmap(Bitmap posterBitmap) { |
| 79 if (mPosterBitmap == posterBitmap | 79 if (mPosterBitmap == posterBitmap |
| 80 || (mPosterBitmap != null && mPosterBitmap.sameAs(posterBitmap))
) { | 80 || (mPosterBitmap != null && mPosterBitmap.sameAs(posterBitmap))
) { |
| 81 return; | 81 return; |
| 82 } | 82 } |
| 83 mPosterBitmap = posterBitmap; | 83 mPosterBitmap = posterBitmap; |
| 84 if (mNotificationBuilder == null || mMediaRouteController == null) retur
n; | 84 if (mNotificationBuilder == null || mMediaRouteController == null) retur
n; |
| 85 mNotificationBuilder.setImage(mMediaRouteController.getPoster()); | 85 mNotificationBuilder.setLargeIcon(mMediaRouteController.getPoster()); |
| 86 updateNotification(); | 86 updateNotification(); |
| 87 } | 87 } |
| 88 | 88 |
| 89 public void hide() { | 89 public void hide() { |
| 90 mIsShowing = false; | 90 mIsShowing = false; |
| 91 MediaNotificationManager.hide(Tab.INVALID_TAB_ID, R.id.remote_notificati
on); | 91 MediaNotificationManager.hide(Tab.INVALID_TAB_ID, R.id.remote_notificati
on); |
| 92 mAudioManager.abandonAudioFocus(this); | 92 mAudioManager.abandonAudioFocus(this); |
| 93 mMediaRouteController.removeUiListener(this); | 93 mMediaRouteController.removeUiListener(this); |
| 94 } | 94 } |
| 95 | 95 |
| 96 public void show(PlayerState initialState) { | 96 public void show(PlayerState initialState) { |
| 97 mMediaRouteController.addUiListener(this); | 97 mMediaRouteController.addUiListener(this); |
| 98 // TODO(aberent): investigate why this is necessary, and whether we are
handling | 98 // TODO(aberent): investigate why this is necessary, and whether we are
handling |
| 99 // it correctly. Also add code to restore it when Chrome is resumed. | 99 // it correctly. Also add code to restore it when Chrome is resumed. |
| 100 mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TY
PE, | 100 mAudioManager.requestAudioFocus(this, AudioManager.USE_DEFAULT_STREAM_TY
PE, |
| 101 AudioManager.AUDIOFOCUS_GAIN); | 101 AudioManager.AUDIOFOCUS_GAIN); |
| 102 Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.c
lass); | 102 Intent contentIntent = new Intent(mContext, ExpandedControllerActivity.c
lass); |
| 103 mNotificationBuilder = new MediaNotificationInfo.Builder() | 103 mNotificationBuilder = new MediaNotificationInfo.Builder() |
| 104 .setPaused(false) | 104 .setPaused(false) |
| 105 .setPrivate(false) | 105 .setPrivate(false) |
| 106 .setIcon(R.drawable.ic_notification_media_route) | 106 .setIcon(R.drawable.ic_notification_media_route) |
| 107 .setContentIntent(contentIntent) | 107 .setContentIntent(contentIntent) |
| 108 .setImage(mMediaRouteController.getPoster()) | 108 .setLargeIcon(mMediaRouteController.getPoster()) |
| 109 .setId(R.id.remote_notification) | 109 .setId(R.id.remote_notification) |
| 110 .setListener(this); | 110 .setListener(this); |
| 111 mState = initialState; | 111 mState = initialState; |
| 112 updateNotification(); | 112 updateNotification(); |
| 113 mIsShowing = true; | 113 mIsShowing = true; |
| 114 } | 114 } |
| 115 | 115 |
| 116 public void setRouteController(MediaRouteController controller) { | 116 public void setRouteController(MediaRouteController controller) { |
| 117 mMediaRouteController = controller; | 117 mMediaRouteController = controller; |
| 118 } | 118 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 129 MediaNotificationManager.show(mContext, mNotificationBuilder.build()
); | 129 MediaNotificationManager.show(mContext, mNotificationBuilder.build()
); |
| 130 } else { | 130 } else { |
| 131 hide(); | 131 hide(); |
| 132 } | 132 } |
| 133 } | 133 } |
| 134 | 134 |
| 135 // TODO(aberent) at the moment this is only called from a test, but it shoul
d be called if the | 135 // TODO(aberent) at the moment this is only called from a test, but it shoul
d be called if the |
| 136 // poster changes. | 136 // poster changes. |
| 137 public void onPosterBitmapChanged() { | 137 public void onPosterBitmapChanged() { |
| 138 if (mNotificationBuilder == null || mMediaRouteController == null) retur
n; | 138 if (mNotificationBuilder == null || mMediaRouteController == null) retur
n; |
| 139 mNotificationBuilder.setImage(mMediaRouteController.getPoster()); | 139 mNotificationBuilder.setLargeIcon(mMediaRouteController.getPoster()); |
| 140 updateNotification(); | 140 updateNotification(); |
| 141 } | 141 } |
| 142 | 142 |
| 143 // MediaRouteController.UiListener implementation. | 143 // MediaRouteController.UiListener implementation. |
| 144 @Override | 144 @Override |
| 145 public void onPlaybackStateChanged(PlayerState newState) { | 145 public void onPlaybackStateChanged(PlayerState newState) { |
| 146 mState = newState; | 146 mState = newState; |
| 147 updateNotification(); | 147 updateNotification(); |
| 148 } | 148 } |
| 149 | 149 |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 203 @VisibleForTesting | 203 @VisibleForTesting |
| 204 static CastNotificationControl getForTests() { | 204 static CastNotificationControl getForTests() { |
| 205 return sInstance; | 205 return sInstance; |
| 206 } | 206 } |
| 207 | 207 |
| 208 @VisibleForTesting | 208 @VisibleForTesting |
| 209 boolean isShowingForTests() { | 209 boolean isShowingForTests() { |
| 210 return mIsShowing; | 210 return mIsShowing; |
| 211 } | 211 } |
| 212 } | 212 } |
| OLD | NEW |