Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit b28ec0a3 authored by Selim Cinek's avatar Selim Cinek
Browse files

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
parent 2d7be5f4
Loading
Loading
Loading
Loading
+9 −5
Original line number Diff line number Diff line
@@ -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) {
        int width = input.getWidth();
        setPlayerWidth(width);
        mMediaNotifView.measure(input.getWidthMeasureSpec(), input.getHeightMeasureSpec());
    }

    private void remeasureInternal(MediaMeasurementInput input) {
    public void setPlayerWidth(int width) {
        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);
        mMediaNotifView.measure(input.getWidthMeasureSpec(), input.getHeightMeasureSpec());
        mMediaNotifView.updateState(R.id.collapsed, collapsedSet);
        mMediaNotifView.updateState(R.id.expanded, expandedSet);
    }
}
+13 −1
Original line number Diff line number Diff line
@@ -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?) {
+22 −4
Original line number Diff line number Diff line
@@ -63,6 +63,7 @@ class MediaViewManager @Inject constructor(
                removed?.apply {
                    mediaContent.removeView(removed.view)
                    removed.onDestroy()
                    updateMediaPaddings()
                }
            }
        })
@@ -106,6 +107,7 @@ class MediaViewManager @Inject constructor(
            } else {
                mediaContent.addView(existingPlayer.view)
            }
            updatePlayerToCurrentState(existingPlayer)
        } else if (existingPlayer.isPlaying &&
                    mediaContent.indexOfChild(existingPlayer.view) != 0) {
            if (visualStabilityManager.isReorderingAllowed) {
@@ -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,11 +166,16 @@ class MediaViewManager @Inject constructor(
            // This is a hosting view, let's remeasure our players
            desiredState = targetState
            val measurementInput = targetState.measurementInput
            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)
        }
    }
    }

    /**
     * Get a measurement for the given input state. This measures the first player and returns
+9 −6
Original line number Diff line number Diff line
@@ -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)