summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java39
1 files changed, 20 insertions, 19 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
index 2df0507a8864..d5c92f26e12b 100644
--- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
+++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java
@@ -20,9 +20,8 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.res.ColorStateList;
-import android.graphics.Bitmap;
-import android.graphics.Canvas;
import android.graphics.Color;
+import android.graphics.Outline;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
@@ -33,6 +32,7 @@ import android.media.session.MediaSession;
import android.media.session.PlaybackState;
import android.util.Log;
import android.view.View;
+import android.view.ViewOutlineProvider;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;
@@ -41,8 +41,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.constraintlayout.widget.ConstraintSet;
-import androidx.core.graphics.drawable.RoundedBitmapDrawable;
-import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
import com.android.settingslib.Utils;
import com.android.settingslib.media.MediaOutputSliceConstants;
@@ -52,8 +50,6 @@ import com.android.systemui.dagger.qualifiers.Background;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.util.animation.TransitionLayout;
-import org.jetbrains.annotations.NotNull;
-
import java.util.List;
import java.util.concurrent.Executor;
@@ -87,6 +83,8 @@ public class MediaControlPanel {
private int mBackgroundColor;
private int mAlbumArtSize;
private int mAlbumArtRadius;
+ // This will provide the corners for the album art.
+ private final ViewOutlineProvider mViewOutlineProvider;
/**
* Initialize a new control panel
@@ -104,6 +102,13 @@ public class MediaControlPanel {
mSeekBarViewModel = seekBarViewModel;
mMediaViewController = mediaViewController;
loadDimens();
+
+ mViewOutlineProvider = new ViewOutlineProvider() {
+ @Override
+ public void getOutline(View view, Outline outline) {
+ outline.setRoundRect(0, 0, mAlbumArtSize, mAlbumArtSize, mAlbumArtRadius);
+ }
+ };
}
public void onDestroy() {
@@ -162,6 +167,11 @@ public class MediaControlPanel {
public void attach(PlayerViewHolder vh) {
mViewHolder = vh;
TransitionLayout player = vh.getPlayer();
+
+ ImageView albumView = vh.getAlbumView();
+ albumView.setOutlineProvider(mViewOutlineProvider);
+ albumView.setClipToOutline(true);
+
mSeekBarObserver = new SeekBarObserver(vh);
mSeekBarViewModel.getProgress().observeForever(mSeekBarObserver);
mSeekBarViewModel.attachTouchHandlers(vh.getSeekBar());
@@ -171,7 +181,7 @@ public class MediaControlPanel {
/**
* Bind this view based on the data given
*/
- public void bind(@NotNull MediaData data) {
+ public void bind(@NonNull MediaData data) {
if (mViewHolder == null) {
return;
}
@@ -202,11 +212,9 @@ public class MediaControlPanel {
}
ImageView albumView = mViewHolder.getAlbumView();
- // TODO: migrate this to a view with rounded corners instead of baking the rounding
- // into the bitmap
boolean hasArtwork = data.getArtwork() != null;
if (hasArtwork) {
- Drawable artwork = createRoundedBitmap(data.getArtwork());
+ Drawable artwork = scaleDrawable(data.getArtwork());
albumView.setImageDrawable(artwork);
}
setVisibleAndAlpha(collapsedSet, R.id.album_art, hasArtwork);
@@ -334,7 +342,7 @@ public class MediaControlPanel {
}
@UiThread
- private Drawable createRoundedBitmap(Icon icon) {
+ private Drawable scaleDrawable(Icon icon) {
if (icon == null) {
return null;
}
@@ -355,14 +363,7 @@ public class MediaControlPanel {
bounds.offset((int) -offsetX,(int) -offsetY);
}
drawable.setBounds(bounds);
- Bitmap scaled = Bitmap.createBitmap(mAlbumArtSize, mAlbumArtSize,
- Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(scaled);
- drawable.draw(canvas);
- RoundedBitmapDrawable artwork = RoundedBitmapDrawableFactory.create(
- mContext.getResources(), scaled);
- artwork.setCornerRadius(mAlbumArtRadius);
- return artwork;
+ return drawable;
}
/**