diff options
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java | 31 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt | 8 |
2 files changed, 37 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java index 20417aff024c..03cdff05e642 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -48,6 +48,7 @@ import android.os.Process; import android.text.TextUtils; import android.util.Log; import android.util.Pair; +import android.view.Gravity; import android.view.View; import android.view.ViewGroup; import android.view.animation.Interpolator; @@ -619,6 +620,12 @@ public class MediaControlPanel { // the metadata changes). TransitionDrawable transitionDrawable = new TransitionDrawable( new Drawable[]{mPrevArtwork, artwork}); + + scaleTransitionDrawableLayer(transitionDrawable, 0, width, height); + scaleTransitionDrawableLayer(transitionDrawable, 1, width, height); + transitionDrawable.setLayerGravity(0, Gravity.CENTER); + transitionDrawable.setLayerGravity(1, Gravity.CENTER); + albumView.setImageDrawable(transitionDrawable); transitionDrawable.startTransition(isArtworkBound ? 333 : 80); } @@ -652,6 +659,30 @@ public class MediaControlPanel { }); } + private void scaleTransitionDrawableLayer(TransitionDrawable transitionDrawable, int layer, + int targetWidth, int targetHeight) { + Drawable drawable = transitionDrawable.getDrawable(layer); + if (drawable == null) { + return; + } + + int width = drawable.getIntrinsicWidth(); + int height = drawable.getIntrinsicHeight(); + if (width == 0 || height == 0 || targetWidth == 0 || targetHeight == 0) { + return; + } + + float scale; + if ((width / (float) height) > (targetWidth / (float) targetHeight)) { + // Drawable is wider than target view, scale to match height + scale = targetHeight / (float) height; + } else { + // Drawable is taller than target view, scale to match width + scale = targetWidth / (float) width; + } + transitionDrawable.setLayerSize(layer, (int) (scale * width), (int) (scale * height)); + } + private void bindActionButtons(MediaData data) { MediaButton semanticActions = data.getSemanticActions(); diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt index 94254da0d7de..d47bfe1fe59a 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/media/MediaControlPanelTest.kt @@ -34,6 +34,7 @@ import android.graphics.drawable.Drawable import android.graphics.drawable.GradientDrawable import android.graphics.drawable.Icon import android.graphics.drawable.RippleDrawable +import android.graphics.drawable.TransitionDrawable import android.media.MediaMetadata import android.media.session.MediaSession import android.media.session.PlaybackState @@ -74,6 +75,7 @@ import com.android.systemui.util.mockito.withArgCaptor import com.android.systemui.util.time.FakeSystemClock import com.google.common.truth.Truth.assertThat import dagger.Lazy +import junit.framework.Assert.assertTrue import org.junit.After import org.junit.Before import org.junit.Rule @@ -579,9 +581,11 @@ public class MediaControlPanelTest : SysuiTestCase() { player.bindPlayer(state1, PACKAGE) bgExecutor.runAllReady() mainExecutor.runAllReady() - verify(albumView, times(2)).setImageDrawable(any(Drawable::class.java)) + val drawableCaptor = argumentCaptor<Drawable>() + verify(albumView, times(2)).setImageDrawable(drawableCaptor.capture()) + assertTrue(drawableCaptor.allValues[1] is TransitionDrawable) - // Third binding does run transition or update background + // Third binding doesn't run transition or update background player.bindPlayer(state2, PACKAGE) bgExecutor.runAllReady() mainExecutor.runAllReady() |