[Media] Simplify how we get the background color for the media player.

The color was being passed down all the way from MediaDataManager to
ColorSchemeTransition when it doesn't need to be. This moves the
background color fetch to ColorSchemeTransition, which groups it with
all the other color fetching.

Bug: 228960370
Test: atest SystemUITests
Test: manual: verify media player still looks good
Change-Id: I0a542fd68847b942c3cb1e3c4576344068a06a07
This commit is contained in:
Caitlin Cassidy
2022-04-14 17:39:45 +00:00
parent f6453bc32f
commit f9c2af711f
9 changed files with 12 additions and 24 deletions

View File

@@ -85,12 +85,13 @@ typealias ColorTransitionFactory = (Int, (ColorScheme) -> Int, (Int) -> Unit) ->
*/
class ColorSchemeTransition internal constructor(
private val context: Context,
bgColor: Int,
mediaViewHolder: MediaViewHolder,
colorTransitionFactory: ColorTransitionFactory
) {
constructor(context: Context, bgColor: Int, mediaViewHolder: MediaViewHolder) :
this(context, bgColor, mediaViewHolder, ::ColorTransition)
constructor(context: Context, mediaViewHolder: MediaViewHolder) :
this(context, mediaViewHolder, ::ColorTransition)
val bgColor = context.getColor(com.android.systemui.R.color.material_dynamic_secondary95)
val surfaceColor = colorTransitionFactory(
bgColor,

View File

@@ -904,7 +904,6 @@ internal object MediaPlayerData {
private val EMPTY = MediaData(
userId = -1,
initialized = false,
backgroundColor = 0,
app = null,
appIcon = null,
artist = null,

View File

@@ -150,7 +150,6 @@ public class MediaControlPanel {
private MediaSession.Token mToken;
private MediaController mController;
private Lazy<MediaDataManager> mMediaDataManagerLazy;
private int mBackgroundColor;
// Uid for the media app.
protected int mUid = Process.INVALID_UID;
private int mSmartspaceMediaItemsCount;
@@ -343,8 +342,7 @@ public class MediaControlPanel {
AnimatorSet exit = loadAnimator(R.anim.media_metadata_exit,
Interpolators.EMPHASIZED_ACCELERATE, titleText, artistText);
mColorSchemeTransition = new ColorSchemeTransition(
mContext, mBackgroundColor, mMediaViewHolder);
mColorSchemeTransition = new ColorSchemeTransition(mContext, mMediaViewHolder);
mMetadataAnimationHandler = new MetadataAnimationHandler(exit, enter);
}
@@ -409,7 +407,6 @@ public class MediaControlPanel {
}
mInstanceId = data.getInstanceId();
mBackgroundColor = data.getBackgroundColor();
if (mToken == null || !mToken.equals(token)) {
mToken = token;
}
@@ -485,7 +482,7 @@ public class MediaControlPanel {
Drawable icon = device.getIcon();
if (icon instanceof AdaptiveIcon) {
AdaptiveIcon aIcon = (AdaptiveIcon) icon;
aIcon.setBackgroundColor(mBackgroundColor);
aIcon.setBackgroundColor(mColorSchemeTransition.getBgColor());
iconView.setImageDrawable(aIcon);
} else {
iconView.setImageDrawable(icon);
@@ -956,11 +953,11 @@ public class MediaControlPanel {
}
mSmartspaceId = SmallHash.hash(data.getTargetId());
mBackgroundColor = data.getBackgroundColor();
int backgroundColor = data.getBackgroundColor();
mPackageName = data.getPackageName();
mInstanceId = data.getInstanceId();
TransitionLayout recommendationCard = mRecommendationViewHolder.getRecommendations();
recommendationCard.setBackgroundTintList(ColorStateList.valueOf(mBackgroundColor));
recommendationCard.setBackgroundTintList(ColorStateList.valueOf(backgroundColor));
List<SmartspaceAction> mediaRecommendationList = data.getRecommendations();
if (mediaRecommendationList == null || mediaRecommendationList.isEmpty()) {

View File

@@ -27,7 +27,6 @@ import com.android.systemui.R
data class MediaData(
val userId: Int,
val initialized: Boolean = false,
val backgroundColor: Int,
/**
* App name that will be displayed on the player.
*/

View File

@@ -85,7 +85,6 @@ private const val EXTRAS_SMARTSPACE_DISMISS_INTENT_KEY = "dismiss_intent"
private val LOADING = MediaData(
userId = -1,
initialized = false,
backgroundColor = 0,
app = null,
appIcon = null,
artist = null,
@@ -177,7 +176,6 @@ class MediaDataManager(
private val themeText = com.android.settingslib.Utils.getColorAttr(context,
com.android.internal.R.attr.textColorPrimary).defaultColor
private val bgColor = context.getColor(R.color.material_dynamic_secondary95)
// Internal listeners are part of the internal pipeline. External listeners (those registered
// with [MediaDeviceManager.addListener]) receive events after they have propagated through
@@ -591,7 +589,7 @@ class MediaDataManager(
val mediaAction = getResumeMediaAction(resumeAction)
val lastActive = systemClock.elapsedRealtime()
foregroundExecutor.execute {
onMediaDataLoaded(packageName, null, MediaData(userId, true, bgColor, appName,
onMediaDataLoaded(packageName, null, MediaData(userId, true, appName,
null, desc.subtitle, desc.title, artworkIcon, listOf(mediaAction), listOf(0),
MediaButton(playOrPause = mediaAction), packageName, token, appIntent,
device = null, active = false,
@@ -713,7 +711,7 @@ class MediaDataManager(
val resumeAction: Runnable? = mediaEntries[key]?.resumeAction
val hasCheckedForResume = mediaEntries[key]?.hasCheckedForResume == true
val active = mediaEntries[key]?.active ?: true
onMediaDataLoaded(key, oldKey, MediaData(sbn.normalizedUserId, true, bgColor, app,
onMediaDataLoaded(key, oldKey, MediaData(sbn.normalizedUserId, true, app,
smallIcon, artist, song, artWorkIcon, actionIcons, actionsToShowCollapsed,
semanticActions, sbn.packageName, token, notif.contentIntent, device,
active, resumeAction = resumeAction, playbackLocation = playbackLocation,

View File

@@ -38,7 +38,6 @@ import org.mockito.junit.MockitoJUnit
private const val DEFAULT_COLOR = Color.RED
private const val TARGET_COLOR = Color.BLUE
private const val BG_COLOR = Color.GREEN
@SmallTest
@RunWith(AndroidTestingRunner::class)
@@ -66,8 +65,7 @@ class ColorSchemeTransitionTest : SysuiTestCase() {
transitionFactory = { default, extractColor, applyColor -> mockTransition }
whenever(extractColor.invoke(colorScheme)).thenReturn(TARGET_COLOR)
colorSchemeTransition = ColorSchemeTransition(context,
BG_COLOR, mediaViewHolder, transitionFactory)
colorSchemeTransition = ColorSchemeTransition(context, mediaViewHolder, transitionFactory)
colorTransition = object : ColorTransition(DEFAULT_COLOR, extractColor, applyColor) {
override fun buildAnimator(): ValueAnimator {

View File

@@ -90,7 +90,6 @@ import org.mockito.Mockito.verify
import org.mockito.junit.MockitoJUnit
private const val KEY = "TEST_KEY"
private const val BG_COLOR = Color.RED
private const val PACKAGE = "PKG"
private const val ARTIST = "ARTIST"
private const val TITLE = "TITLE"
@@ -247,7 +246,6 @@ public class MediaControlPanelTest : SysuiTestCase() {
session.setActive(true)
mediaData = MediaTestUtils.emptyMediaData.copy(
backgroundColor = BG_COLOR,
artist = ARTIST,
song = TITLE,
packageName = PACKAGE,

View File

@@ -57,7 +57,6 @@ public class MediaDataCombineLatestTest extends SysuiTestCase {
private static final String OLD_KEY = "TEST_KEY_OLD";
private static final String APP = "APP";
private static final String PACKAGE = "PKG";
private static final int BG_COLOR = Color.RED;
private static final String ARTIST = "ARTIST";
private static final String TITLE = "TITLE";
private static final String DEVICE_NAME = "DEVICE_NAME";
@@ -76,7 +75,7 @@ public class MediaDataCombineLatestTest extends SysuiTestCase {
mManager.addListener(mListener);
mMediaData = new MediaData(
USER_ID, true, BG_COLOR, APP, null, ARTIST, TITLE, null,
USER_ID, true, APP, null, ARTIST, TITLE, null,
new ArrayList<>(), new ArrayList<>(), null, PACKAGE, null, null, null, true, null,
MediaData.PLAYBACK_LOCAL, false, KEY, false, false, false, 0L,
InstanceId.fakeInstanceId(-1), -1);

View File

@@ -7,7 +7,6 @@ class MediaTestUtils {
val emptyMediaData = MediaData(
userId = 0,
initialized = true,
backgroundColor = 0,
app = null,
appIcon = null,
artist = null,