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

Commit 1d6d9bd1 authored by Julia Tuttle's avatar Julia Tuttle Committed by Android (Google) Code Review
Browse files

Merge "[AOD RONs] Fix FrameLayoutWithMaxHeight.onMeasure logic" into main

parents d38a8e79 c14db1c3
Loading
Loading
Loading
Loading
+23 −13
Original line number Diff line number Diff line
@@ -170,24 +170,35 @@ private class FrameLayoutWithMaxHeight(maxHeight: Int, context: Context) : Frame

    // This mirrors the logic in NotificationContentView.onMeasure.
    override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
        if (childCount < 1) {
            return
        if (childCount != 1) {
            Log.wtf(TAG, "Should contain exactly one child.")
            return super.onMeasure(widthMeasureSpec, heightMeasureSpec)
        }

        val child = getChildAt(0)
        val childLayoutHeight = child.layoutParams.height
        val childHeightSpec =
            if (childLayoutHeight >= 0) {
                makeMeasureSpec(maxHeight.coerceAtMost(childLayoutHeight), EXACTLY)
            } else {
                makeMeasureSpec(maxHeight, AT_MOST)
            }
        measureChildWithMargins(child, widthMeasureSpec, 0, childHeightSpec, 0)
        val childMeasuredHeight = child.measuredHeight
        val horizPadding = paddingStart + paddingEnd
        val vertPadding = paddingTop + paddingBottom

        val ownWidthSize = MeasureSpec.getSize(widthMeasureSpec)
        val ownHeightMode = MeasureSpec.getMode(heightMeasureSpec)
        val ownHeightSize = MeasureSpec.getSize(heightMeasureSpec)

        val availableHeight =
            if (ownHeightMode != UNSPECIFIED) {
                maxHeight.coerceAtMost(ownHeightSize)
            } else {
                maxHeight
            }

        val child = getChildAt(0)
        val childWidthSpec = makeMeasureSpec(ownWidthSize, EXACTLY)
        val childHeightSpec =
            child.layoutParams.height
                .takeIf { it >= 0 }
                ?.let { makeMeasureSpec(availableHeight.coerceAtMost(it), EXACTLY) }
                ?: run { makeMeasureSpec(availableHeight, AT_MOST) }
        measureChildWithMargins(child, childWidthSpec, horizPadding, childHeightSpec, vertPadding)
        val childMeasuredHeight = child.measuredHeight

        val ownMeasuredWidth = MeasureSpec.getSize(widthMeasureSpec)
        val ownMeasuredHeight =
            if (ownHeightMode != UNSPECIFIED) {
@@ -195,7 +206,6 @@ private class FrameLayoutWithMaxHeight(maxHeight: Int, context: Context) : Frame
            } else {
                childMeasuredHeight
            }

        setMeasuredDimension(ownMeasuredWidth, ownMeasuredHeight)
    }
}