summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt1
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt15
-rw-r--r--packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt41
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaViewControllerTest.kt33
4 files changed, 78 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt
index d619362b0311..ecc3fffbad19 100644
--- a/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt
+++ b/packages/SystemUI/src/com/android/systemui/communal/ui/viewmodel/CommunalViewModel.kt
@@ -77,6 +77,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)
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt
index 631a0b8471b8..437218f9f440 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaHost.kt
@@ -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
diff --git a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt
index be9393655c5d..962764c028fc 100644
--- a/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt
+++ b/packages/SystemUI/src/com/android/systemui/media/controls/ui/MediaViewController.kt
@@ -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 =
- context.resources.getDimensionPixelSize(
- R.dimen.qs_media_session_height_expanded
- )
- }
+ 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!!,
diff --git a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaViewControllerTest.kt b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaViewControllerTest.kt
index 0a464e6047d3..b701d7f315bc 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaViewControllerTest.kt
+++ b/packages/SystemUI/tests/src/com/android/systemui/media/controls/ui/MediaViewControllerTest.kt
@@ -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
@@ -171,6 +172,38 @@ class MediaViewControllerTest : SysuiTestCase() {
}
@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)
whenever(mockCopiedState.widgetStates)