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

Commit ab1ab2ef authored by Michael Mikhail's avatar Michael Mikhail Committed by Android (Google) Code Review
Browse files

Merge "Update media frame size along with media carousel" into main

parents 67322bf9 680aabce
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -1312,6 +1312,16 @@ flag {
    }
}

flag {
    name:"media_frame_dimensions_fix"
    namespace: "systemui"
    description: "measure and layout media frame when the desired location of media carousel changes"
    bug: "417204970"
    metadata {
      purpose: PURPOSE_BUGFIX
    }
}

flag {
  namespace: "systemui"
  name: "enable_view_capture_tracing"
+30 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import com.android.keyguard.KeyguardUpdateMonitorCallback
import com.android.systemui.Dumpable
import com.android.systemui.Flags
import com.android.systemui.Flags.enableSuggestedDeviceUi
import com.android.systemui.Flags.mediaFrameDimensionsFix
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.dagger.qualifiers.Application
import com.android.systemui.dagger.qualifiers.Background
@@ -1261,13 +1262,40 @@ constructor(
            // Let's remeasure the carousel
            val widthSpec = desiredHostState?.measurementInput?.widthMeasureSpec ?: 0
            val heightSpec = desiredHostState?.measurementInput?.heightMeasureSpec ?: 0
            mediaCarousel.measure(widthSpec, heightSpec)
            mediaCarousel.layout(0, 0, width, mediaCarousel.measuredHeight)
            mediaCarousel.measureAndLayout(
                widthSpec,
                heightSpec,
                width,
                mediaCarousel.measuredHeight,
            )
            if (mediaFrameDimensionsFix()) {
                debugLogger.logMediaCarouselDimensions(
                    reason = "update carousel size",
                    mediaCarousel.boundsOnScreen,
                    desiredLocation,
                )
                mediaFrame.measureAndLayout(
                    widthSpec,
                    heightSpec,
                    width,
                    mediaCarousel.measuredHeight,
                )
            }
            // Update the padding after layout; view widths are used in RTL to calculate scrollX
            mediaCarouselScrollHandler.playerWidthPlusPadding = playerWidthPlusPadding
        }
    }

    private fun ViewGroup.measureAndLayout(
        widthSpec: Int,
        heightSpec: Int,
        width: Int,
        height: Int,
    ) {
        measure(widthSpec, heightSpec)
        layout(0, 0, width, height)
    }

    fun onCarouselVisibleToUser() {
        if (
            !enableSuggestedDeviceUi() ||
+14 −0
Original line number Diff line number Diff line
@@ -95,6 +95,20 @@ constructor(@MediaCarouselControllerLog private val buffer: LogBuffer) {
            { "media frame($str1), width: $int1 height: $int2, location:$long1" },
        )
    }

    fun logMediaCarouselDimensions(reason: String, rect: Rect, location: Int) {
        buffer.log(
            TAG,
            LogLevel.DEBUG,
            {
                str1 = reason
                int1 = rect.width()
                int2 = rect.height()
                long1 = location.toLong()
            },
            { "media carousel($str1), width: $int1 height: $int2, location:$long1" },
        )
    }
}

private const val TAG = "MediaCarouselCtlrLog"
+19 −16
Original line number Diff line number Diff line
@@ -1446,13 +1446,15 @@ private fun ContentScope.MediaObject(
                },
                update = { view ->
                    view.update()
                    if (!Flags.mediaFrameDimensionsFix()) {
                        // Update layout params if host view bounds are higher than its child.
                        val height = mediaHost.hostView.height
                        val width = mediaHost.hostView.width
                        var measure = false
                        mediaHost.hostView.children.forEach { child ->
                            if (
                            child is FrameLayout && (height > child.height || width > child.width)
                                child is FrameLayout &&
                                    (height > child.height || width > child.width)
                            ) {
                                measure = true
                                child.layoutParams = FrameLayout.LayoutParams(width, height)
@@ -1464,6 +1466,7 @@ private fun ContentScope.MediaObject(
                            )
                            mediaLogger.logMediaSize("update size in compose", width, height)
                        }
                    }
                },
                onReset = {},
            )
+7 −4
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.Context
import android.view.View
import android.view.ViewGroup
import android.widget.FrameLayout
import com.android.systemui.Flags
import com.android.systemui.res.R

/**
@@ -52,11 +53,13 @@ class UniqueObjectHostView(context: Context) : FrameLayout(context) {
        if (isCurrentHost()) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec)
            getChildAt(0)?.let { mediaFrame ->
                if (!Flags.mediaFrameDimensionsFix()) {
                    // Media host dimensions are correct. Its child cannot show larger dimensions.
                    // We also need to ensure that dimensions are not less than expected.
                    if (cachedWidth > mediaFrame.width || cachedHeight > mediaFrame.height) {
                        mediaFrame.layoutParams = LayoutParams(cachedWidth, cachedHeight)
                    }
                }
                mediaFrame.requiresRemeasuring = false
            }
        }