Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c2bf0a6c authored by Hawkwood Glazier's avatar Hawkwood Glazier
Browse files

Fix Squashing Issue on UMO Background

Manually set each layer size in the TransitionDrawable. This
fills the available space in the view without stretching.

Test: Manual
Fixes: 230903077
Change-Id: I79fab11c9ce93c188c1c6f2636b00dff75debfa7
parent f37b7bf3
Loading
Loading
Loading
Loading
+31 −0
Original line number Diff line number Diff line
@@ -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();

+6 −2
Original line number Diff line number Diff line
@@ -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()