Fixing some issues where view was too short when created

The view was always created too small because we didn't
set the constraints in the beginning

Test: add new media notification, not clipped off
Bug: 154137987
Change-Id: Ifb9c95ba41be7392ec4b61e2b801b7420b811d3a
This commit is contained in:
Selim Cinek
2020-05-01 15:07:42 -07:00
parent 2d7be5f40f
commit b28ec0a32f
4 changed files with 56 additions and 19 deletions

View File

@@ -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);
}
}

View File

@@ -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?) {

View File

@@ -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)
}
}

View File

@@ -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)