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

Commit bc45c182 authored by Darrell Shi's avatar Darrell Shi Committed by Android (Google) Code Review
Browse files

Merge "Add MediaHost setting to allow UMO to match parent height" into main

parents db832e69 5b1916f1
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -74,6 +74,7 @@ constructor(
        // before the MediaHierarchyManager attempts to move the UMO to the hub.
        with(mediaHost) {
            expansion = MediaHostState.EXPANDED
            expandedMatchesParentHeight = true
            showsOnlyActiveMedia = false
            falsingProtectionNeeded = false
            init(MediaHierarchyManager.LOCATION_COMMUNAL_HUB)
+15 −0
Original line number Diff line number Diff line
@@ -228,6 +228,14 @@ constructor(
                }
            }

        override var expandedMatchesParentHeight: Boolean = false
            set(value) {
                if (value != field) {
                    field = value
                    changedListener?.invoke()
                }
            }

        override var squishFraction: Float = 1.0f
            set(value) {
                if (!value.equals(field)) {
@@ -282,6 +290,7 @@ constructor(
        override fun copy(): MediaHostState {
            val mediaHostState = MediaHostStateHolder()
            mediaHostState.expansion = expansion
            mediaHostState.expandedMatchesParentHeight = expandedMatchesParentHeight
            mediaHostState.squishFraction = squishFraction
            mediaHostState.showsOnlyActiveMedia = showsOnlyActiveMedia
            mediaHostState.measurementInput = measurementInput?.copy()
@@ -360,6 +369,12 @@ interface MediaHostState {
     */
    var expansion: Float

    /**
     * If true, the [EXPANDED] layout should stretch to match the height of its parent container,
     * rather than having a fixed height.
     */
    var expandedMatchesParentHeight: Boolean

    /** Fraction of the height animation. */
    var squishFraction: Float

+29 −12
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ import android.content.Context
import android.content.res.Configuration
import androidx.annotation.VisibleForTesting
import androidx.constraintlayout.widget.ConstraintSet
import androidx.constraintlayout.widget.ConstraintSet.MATCH_CONSTRAINT
import com.android.app.tracing.traceSection
import com.android.systemui.media.controls.models.GutsViewHolder
import com.android.systemui.media.controls.models.player.MediaViewHolder
@@ -152,18 +153,11 @@ constructor(
                        lastOrientation = newOrientation
                        // Update the height of media controls for the expanded layout. it is needed
                        // for large screen devices.
                        val backgroundIds =
                            if (type == TYPE.PLAYER) {
                                MediaViewHolder.backgroundIds
                            } else {
                                setOf(RecommendationViewHolder.backgroundId)
                            }
                        backgroundIds.forEach { id ->
                            expandedLayout.getConstraint(id).layout.mHeight =
                        setBackgroundHeights(
                            context.resources.getDimensionPixelSize(
                                R.dimen.qs_media_session_height_expanded
                            )
                        }
                        )
                    }
                    if (this@MediaViewController::configurationChangeListener.isInitialized) {
                        configurationChangeListener.invoke()
@@ -276,6 +270,17 @@ constructor(
    private fun constraintSetForExpansion(expansion: Float): ConstraintSet =
        if (expansion > 0) expandedLayout else collapsedLayout

    /** Set the height of UMO background constraints. */
    private fun setBackgroundHeights(height: Int) {
        val backgroundIds =
            if (type == TYPE.PLAYER) {
                MediaViewHolder.backgroundIds
            } else {
                setOf(RecommendationViewHolder.backgroundId)
            }
        backgroundIds.forEach { id -> expandedLayout.getConstraint(id).layout.mHeight = height }
    }

    /**
     * Set the views to be showing/hidden based on the [isGutsVisible] for a given
     * [TransitionViewState].
@@ -454,6 +459,18 @@ constructor(
        }
        // Let's create a new measurement
        if (state.expansion == 0.0f || state.expansion == 1.0f) {
            if (state.expansion == 1.0f) {
                val height =
                    if (state.expandedMatchesParentHeight) {
                        MATCH_CONSTRAINT
                    } else {
                        context.resources.getDimensionPixelSize(
                            R.dimen.qs_media_session_height_expanded
                        )
                    }
                setBackgroundHeights(height)
            }

            result =
                transitionLayout!!.calculateViewState(
                    state.measurementInput!!,
+33 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ import android.content.res.Configuration.ORIENTATION_LANDSCAPE
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.view.View
import androidx.constraintlayout.widget.ConstraintSet
import androidx.test.filters.SmallTest
import com.android.systemui.SysuiTestCase
import com.android.systemui.media.controls.models.player.MediaViewHolder
@@ -170,6 +171,38 @@ class MediaViewControllerTest : SysuiTestCase() {
        assertTrue(mediaViewController.obtainViewState(mediaHostStateHolder)!!.measureHeight == 100)
    }

    @Test
    fun testObtainViewState_expandedMatchesParentHeight() {
        mediaViewController.attach(player, MediaViewController.TYPE.PLAYER)
        player.measureState =
            TransitionViewState().apply {
                this.height = 100
                this.measureHeight = 100
            }
        mediaHostStateHolder.expandedMatchesParentHeight = true
        mediaHostStateHolder.expansion = 1f
        mediaHostStateHolder.measurementInput =
            MeasurementInput(
                View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY),
                View.MeasureSpec.makeMeasureSpec(100, View.MeasureSpec.EXACTLY),
            )

        // Assign the height of each expanded layout
        MediaViewHolder.backgroundIds.forEach { id ->
            mediaViewController.expandedLayout.getConstraint(id).layout.mHeight = 100
        }

        mediaViewController.obtainViewState(mediaHostStateHolder)

        // Verify height of each expanded layout is updated to match constraint
        MediaViewHolder.backgroundIds.forEach { id ->
            assertTrue(
                mediaViewController.expandedLayout.getConstraint(id).layout.mHeight ==
                    ConstraintSet.MATCH_CONSTRAINT
            )
        }
    }

    @Test
    fun testSquishViewState_applySquishFraction_toTransitionViewState_alpha_forMediaPlayer() {
        whenever(mockViewState.copy()).thenReturn(mockCopiedState)