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

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

Merge "Set layoutparams of media frame when measuring media host" into main

parents 253fcdae f5e40b62
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -262,7 +262,7 @@ public class LogModule {
    @SysUISingleton
    @MediaCarouselControllerLog
    public static LogBuffer provideMediaCarouselControllerBuffer(LogBufferFactory factory) {
        return factory.create("MediaCarouselCtlrLog", 100);
        return factory.create("MediaCarouselCtlrLog", 150);
    }

    /**
+13 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ import com.android.systemui.statusbar.policy.ConfigurationController
import com.android.systemui.util.Utils
import com.android.systemui.util.animation.UniqueObjectHostView
import com.android.systemui.util.animation.requiresRemeasuring
import com.android.systemui.util.boundsOnScreen
import com.android.systemui.util.concurrency.DelayableExecutor
import com.android.systemui.util.settings.GlobalSettings
import com.android.systemui.util.settings.SecureSettings
@@ -339,6 +340,9 @@ constructor(
            .isInTransition(Edge.create(to = DOZING))
            .stateIn(applicationScope, SharingStarted.Eagerly, true)

    private var mediaFrameHeight: Int = 0
    private var mediaFrameWidth: Int = 0

    init {
        // TODO(b/397989775): avoid unnecessary setup with media_controls_in_compose enabled
        dumpManager.registerNormalDumpable(TAG, this)
@@ -381,6 +385,15 @@ constructor(
            setUpListeners()
        }
        mediaFrame.addOnLayoutChangeListener { _, _, _, _, _, _, _, _, _ ->
            if (mediaFrameHeight != mediaFrame.height || mediaFrameWidth != mediaFrame.width) {
                mediaFrameHeight = mediaFrame.height
                mediaFrameWidth = mediaFrame.width
                debugLogger.logMediaBounds(
                    reason = "layout change",
                    rect = mediaFrame.boundsOnScreen,
                    location = desiredLocation,
                )
            }
            // The pageIndicator is not laid out yet when we get the current state update,
            // Lets make sure we have the right dimensions
            updatePageIndicatorLocation()
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.media.controls.ui.controller

import android.graphics.Rect
import com.android.systemui.dagger.SysUISingleton
import com.android.systemui.log.LogBuffer
import com.android.systemui.log.core.LogLevel
@@ -80,6 +81,20 @@ constructor(@MediaCarouselControllerLog private val buffer: LogBuffer) {
            { "media host visibility changed location=$int1, visible:$bool1, was:$bool2" },
        )
    }

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

private const val TAG = "MediaCarouselCtlrLog"
+20 −17
Original line number Diff line number Diff line
@@ -26,16 +26,12 @@ import com.android.systemui.res.R
/**
 * A special view that is designed to host a single "unique object". The unique object is
 * dynamically added and removed from this view and may transition to other UniqueObjectHostViews
 * available in the system.
 * This is useful to share a singular instance of a view that can transition between completely
 * independent parts of the view hierarchy.
 * If the view currently hosts the unique object, it's measuring it normally,
 * but if it's not attached, it will obtain the size by requesting a measure, as if it were
 * always attached.
 * available in the system. This is useful to share a singular instance of a view that can
 * transition between completely independent parts of the view hierarchy. If the view currently
 * hosts the unique object, it's measuring it normally, but if it's not attached, it will obtain the
 * size by requesting a measure, as if it were always attached.
 */
class UniqueObjectHostView(
    context: Context
) : FrameLayout(context) {
class UniqueObjectHostView(context: Context) : FrameLayout(context) {
    lateinit var measurementManager: MeasurementManager

    @SuppressLint("DrawAllocation")
@@ -55,7 +51,14 @@ class UniqueObjectHostView(

        if (isCurrentHost()) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec)
            getChildAt(0)?.requiresRemeasuring = false
            getChildAt(0)?.let { mediaFrame ->
                // 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
            }
        }
        // The goal here is that the view will always have a consistent measuring, regardless
        // if it's attached or not.
@@ -87,10 +90,12 @@ class UniqueObjectHostView(
        val top = paddingTop
        val paddingHorizontal = paddingStart + paddingEnd
        val paddingVertical = paddingTop + paddingBottom
        child.layout(left,
        child.layout(
            left,
            top,
            left + measuredWidth - paddingHorizontal,
                top + measuredHeight - paddingVertical)
            top + measuredHeight - paddingVertical,
        )
    }

    private fun isCurrentHost() = childCount != 0
@@ -100,9 +105,7 @@ class UniqueObjectHostView(
    }
}

/**
 * Does this view require remeasuring currently outside of the regular measure flow?
 */
/** Does this view require remeasuring currently outside of the regular measure flow? */
var View.requiresRemeasuring: Boolean
    get() {
        val required = getTag(R.id.requires_remeasuring)