Merge "Replace RoundedCornerBitmap with outline clipping" into rvc-dev am: 5a7e06187d
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/11893819 Change-Id: I0c8ec576bf3ec6a43b86b58d0c25dff969004560
This commit is contained in:
@@ -20,9 +20,8 @@ import android.app.PendingIntent;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Outline;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.graphics.drawable.GradientDrawable;
|
import android.graphics.drawable.GradientDrawable;
|
||||||
@@ -33,6 +32,7 @@ import android.media.session.MediaSession;
|
|||||||
import android.media.session.PlaybackState;
|
import android.media.session.PlaybackState;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.view.ViewOutlineProvider;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@@ -41,8 +41,6 @@ import androidx.annotation.NonNull;
|
|||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.UiThread;
|
import androidx.annotation.UiThread;
|
||||||
import androidx.constraintlayout.widget.ConstraintSet;
|
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.Utils;
|
||||||
import com.android.settingslib.media.MediaOutputSliceConstants;
|
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.plugins.ActivityStarter;
|
||||||
import com.android.systemui.util.animation.TransitionLayout;
|
import com.android.systemui.util.animation.TransitionLayout;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
@@ -87,6 +83,8 @@ public class MediaControlPanel {
|
|||||||
private int mBackgroundColor;
|
private int mBackgroundColor;
|
||||||
private int mAlbumArtSize;
|
private int mAlbumArtSize;
|
||||||
private int mAlbumArtRadius;
|
private int mAlbumArtRadius;
|
||||||
|
// This will provide the corners for the album art.
|
||||||
|
private final ViewOutlineProvider mViewOutlineProvider;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize a new control panel
|
* Initialize a new control panel
|
||||||
@@ -104,6 +102,13 @@ public class MediaControlPanel {
|
|||||||
mSeekBarViewModel = seekBarViewModel;
|
mSeekBarViewModel = seekBarViewModel;
|
||||||
mMediaViewController = mediaViewController;
|
mMediaViewController = mediaViewController;
|
||||||
loadDimens();
|
loadDimens();
|
||||||
|
|
||||||
|
mViewOutlineProvider = new ViewOutlineProvider() {
|
||||||
|
@Override
|
||||||
|
public void getOutline(View view, Outline outline) {
|
||||||
|
outline.setRoundRect(0, 0, mAlbumArtSize, mAlbumArtSize, mAlbumArtRadius);
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
@@ -162,6 +167,11 @@ public class MediaControlPanel {
|
|||||||
public void attach(PlayerViewHolder vh) {
|
public void attach(PlayerViewHolder vh) {
|
||||||
mViewHolder = vh;
|
mViewHolder = vh;
|
||||||
TransitionLayout player = vh.getPlayer();
|
TransitionLayout player = vh.getPlayer();
|
||||||
|
|
||||||
|
ImageView albumView = vh.getAlbumView();
|
||||||
|
albumView.setOutlineProvider(mViewOutlineProvider);
|
||||||
|
albumView.setClipToOutline(true);
|
||||||
|
|
||||||
mSeekBarObserver = new SeekBarObserver(vh);
|
mSeekBarObserver = new SeekBarObserver(vh);
|
||||||
mSeekBarViewModel.getProgress().observeForever(mSeekBarObserver);
|
mSeekBarViewModel.getProgress().observeForever(mSeekBarObserver);
|
||||||
mSeekBarViewModel.attachTouchHandlers(vh.getSeekBar());
|
mSeekBarViewModel.attachTouchHandlers(vh.getSeekBar());
|
||||||
@@ -171,7 +181,7 @@ public class MediaControlPanel {
|
|||||||
/**
|
/**
|
||||||
* Bind this view based on the data given
|
* Bind this view based on the data given
|
||||||
*/
|
*/
|
||||||
public void bind(@NotNull MediaData data) {
|
public void bind(@NonNull MediaData data) {
|
||||||
if (mViewHolder == null) {
|
if (mViewHolder == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -202,11 +212,9 @@ public class MediaControlPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ImageView albumView = mViewHolder.getAlbumView();
|
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;
|
boolean hasArtwork = data.getArtwork() != null;
|
||||||
if (hasArtwork) {
|
if (hasArtwork) {
|
||||||
Drawable artwork = createRoundedBitmap(data.getArtwork());
|
Drawable artwork = scaleDrawable(data.getArtwork());
|
||||||
albumView.setImageDrawable(artwork);
|
albumView.setImageDrawable(artwork);
|
||||||
}
|
}
|
||||||
setVisibleAndAlpha(collapsedSet, R.id.album_art, hasArtwork);
|
setVisibleAndAlpha(collapsedSet, R.id.album_art, hasArtwork);
|
||||||
@@ -334,7 +342,7 @@ public class MediaControlPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@UiThread
|
@UiThread
|
||||||
private Drawable createRoundedBitmap(Icon icon) {
|
private Drawable scaleDrawable(Icon icon) {
|
||||||
if (icon == null) {
|
if (icon == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -355,14 +363,7 @@ public class MediaControlPanel {
|
|||||||
bounds.offset((int) -offsetX,(int) -offsetY);
|
bounds.offset((int) -offsetX,(int) -offsetY);
|
||||||
}
|
}
|
||||||
drawable.setBounds(bounds);
|
drawable.setBounds(bounds);
|
||||||
Bitmap scaled = Bitmap.createBitmap(mAlbumArtSize, mAlbumArtSize,
|
return drawable;
|
||||||
Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas canvas = new Canvas(scaled);
|
|
||||||
drawable.draw(canvas);
|
|
||||||
RoundedBitmapDrawable artwork = RoundedBitmapDrawableFactory.create(
|
|
||||||
mContext.getResources(), scaled);
|
|
||||||
artwork.setCornerRadius(mAlbumArtRadius);
|
|
||||||
return artwork;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user