diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java index 3d638dd9e211e..2a9ba8395ee75 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java +++ b/packages/SystemUI/src/com/android/systemui/media/MediaControlPanel.java @@ -396,6 +396,8 @@ public class MediaControlPanel { // TODO: b/156036025 bring back media guts makeActive(); + mMediaNotifView.updateState(R.id.collapsed, collapsedSet); + mMediaNotifView.updateState(R.id.expanded, expandedSet); } private Drawable createRoundedBitmap(Icon icon) { @@ -753,16 +755,18 @@ public class MediaControlPanel { } } - public MediaMeasurementInput getLastMeasureInput() { - return mLastMeasureInput; - } - private void remeasureInternal(MediaMeasurementInput input) { - ConstraintSet expandedSet = mMediaNotifView.getConstraintSet(R.id.expanded); - ConstraintSet collapsedSet = mMediaNotifView.getConstraintSet(R.id.collapsed); int width = input.getWidth(); - collapsedSet.setGuidelineBegin(R.id.view_width, width); - expandedSet.setGuidelineBegin(R.id.view_width, width); + setPlayerWidth(width); mMediaNotifView.measure(input.getWidthMeasureSpec(), input.getHeightMeasureSpec()); } + + public void setPlayerWidth(int width) { + ConstraintSet expandedSet = mMediaNotifView.getConstraintSet(R.id.expanded); + ConstraintSet collapsedSet = mMediaNotifView.getConstraintSet(R.id.collapsed); + collapsedSet.setGuidelineBegin(R.id.view_width, width); + expandedSet.setGuidelineBegin(R.id.view_width, width); + mMediaNotifView.updateState(R.id.collapsed, collapsedSet); + mMediaNotifView.updateState(R.id.expanded, expandedSet); + } } diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt index 391b1124cd090..b4c0c334773e8 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaHierarchyManager.kt @@ -132,9 +132,21 @@ class MediaHierarchyManager @Inject constructor( return viewHost } - private fun createUniqueObjectHost(host: MediaState): UniqueObjectHostView { + private fun createUniqueObjectHost(host: MediaHost): UniqueObjectHostView { val viewHost = UniqueObjectHostView(context) viewHost.measurementCache = mediaMeasurementProvider.obtainCache(host) + viewHost.firstMeasureListener = { input -> + if (host.location == currentAttachmentLocation) { + // The first measurement of the attached view is happening, Let's make + // sure the player width is updated + val measuringInput = host.getMeasuringInput(input) + mediaViewManager.remeasureAllPlayers( + measuringInput, + animate = false, + duration = 0, + startDelay = 0) + } + } viewHost.addOnAttachStateChangeListener(object : View.OnAttachStateChangeListener { override fun onViewAttachedToWindow(p0: View?) { diff --git a/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt b/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt index 6dd978716a9e8..a364e6b73e60a 100644 --- a/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt +++ b/packages/SystemUI/src/com/android/systemui/media/MediaViewManager.kt @@ -63,6 +63,7 @@ class MediaViewManager @Inject constructor( removed?.apply { mediaContent.removeView(removed.view) removed.onDestroy() + updateMediaPaddings() } } }) @@ -106,8 +107,9 @@ class MediaViewManager @Inject constructor( } else { mediaContent.addView(existingPlayer.view) } + updatePlayerToCurrentState(existingPlayer) } else if (existingPlayer.isPlaying && - mediaContent.indexOfChild(existingPlayer.view) != 0) { + mediaContent.indexOfChild(existingPlayer.view) != 0) { if (visualStabilityManager.isReorderingAllowed) { mediaContent.removeView(existingPlayer.view) mediaContent.addView(existingPlayer.view, 0) @@ -116,9 +118,20 @@ class MediaViewManager @Inject constructor( } } existingPlayer.bind(data) + // Resetting the progress to make sure it's taken into account for the latest + // motion model + existingPlayer.view.progress = currentState?.expansion ?: 0.0f updateMediaPaddings() } + private fun updatePlayerToCurrentState(existingPlayer: MediaControlPanel) { + if (desiredState != null && desiredState!!.measurementInput != null) { + // make sure the player width is set to the current state + val measurementInput = desiredState!!.measurementInput!! + existingPlayer.setPlayerWidth(measurementInput.width) + } + } + private fun updateMediaPaddings() { val padding = context.resources.getDimensionPixelSize(R.dimen.qs_media_padding) val childCount = mediaContent.childCount @@ -153,9 +166,14 @@ class MediaViewManager @Inject constructor( // This is a hosting view, let's remeasure our players desiredState = targetState val measurementInput = targetState.measurementInput - for (mediaPlayer in mediaPlayers.values) { - mediaPlayer.remeasure(measurementInput, animate, duration, startDelay) - } + remeasureAllPlayers(measurementInput, animate, duration, startDelay) + } + } + + fun remeasureAllPlayers(measurementInput: MediaMeasurementInput?, + animate: Boolean, duration: Long, startDelay: Long) { + for (mediaPlayer in mediaPlayers.values) { + mediaPlayer.remeasure(measurementInput, animate, duration, startDelay) } } diff --git a/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt b/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt index 9c993aae443e1..376d09110d20e 100644 --- a/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt +++ b/packages/SystemUI/src/com/android/systemui/util/animation/UniqueObjectHostView.kt @@ -30,12 +30,10 @@ class UniqueObjectHostView( context: Context ) : FrameLayout(context) { lateinit var measurementCache : GuaranteedMeasurementCache + var firstMeasureListener: ((MeasurementInput) -> Unit)? = null @SuppressLint("DrawAllocation") override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { - if (isCurrentHost()) { - super.onMeasure(widthMeasureSpec, heightMeasureSpec) - } val paddingHorizontal = paddingStart + paddingEnd val paddingVertical = paddingTop + paddingBottom val width = MeasureSpec.getSize(widthMeasureSpec) - paddingHorizontal @@ -43,13 +41,18 @@ class UniqueObjectHostView( val height = MeasureSpec.getSize(heightMeasureSpec) - paddingVertical val heightSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.getMode(heightMeasureSpec)) val measurementInput = MeasurementInputData(widthSpec, heightSpec) - if (!isCurrentHost() || !measurementCache.contains(measurementInput)) { + firstMeasureListener?.apply { + invoke(measurementInput) + firstMeasureListener = null + } + if (!isCurrentHost()) { // We're not currently the host, let's get the dimension from our cache (this might - // perform a measuring if the cache doesn't have it yet + // perform a measuring if the cache doesn't have it yet) val (cachedWidth, cachedHeight) = measurementCache.obtainMeasurement(measurementInput) setMeasuredDimension(cachedWidth + paddingHorizontal, cachedHeight + paddingVertical) } else { - // Let's update what we have in the cache if it's present + super.onMeasure(widthMeasureSpec, heightMeasureSpec) + // Let's update our cache val child = getChildAt(0)!! val output = MeasurementOutput(child.measuredWidth, child.measuredHeight) measurementCache.putMeasurement(measurementInput, output)