Fix progressbar when orientation changes

The progressbar shrinks whenver we switch orientation. This occurs
because we reload the constraint set of media player. A fix is only to
update the height of the media player instead of loading the
expanded/collapsed layouts.

Bug: 273679622
Test: atest MediaViewControllerTest
Change-Id: Ia8f35865b07c3431f1a557e8e3d855d3b0ab622a
This commit is contained in:
Michael Mikhail
2023-03-15 20:15:54 +00:00
parent 743a409ac9
commit cbabd24279
2 changed files with 55 additions and 10 deletions

View File

@@ -89,6 +89,9 @@ constructor(
R.id.turbulence_noise_view,
R.id.touch_ripple_view,
)
// Sizing view id for recommendation card view.
val recSizingViewId = R.id.sizing_view
}
/** A listener when the current dimensions of the player change */
@@ -176,7 +179,21 @@ constructor(
// Layout dimensions are possibly changing, so we need to update them. (at
// least on large screen devices)
lastOrientation = newOrientation
loadLayoutForType(type)
// Update the height of media controls for the expanded layout. it is needed
// for large screen devices.
if (type == TYPE.PLAYER) {
backgroundIds.forEach { id ->
expandedLayout.getConstraint(id).layout.mHeight =
context.resources.getDimensionPixelSize(
R.dimen.qs_media_session_height_expanded
)
}
} else {
expandedLayout.getConstraint(recSizingViewId).layout.mHeight =
context.resources.getDimensionPixelSize(
R.dimen.qs_media_session_height_expanded
)
}
}
}
}

View File

@@ -21,7 +21,6 @@ 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.R
import com.android.systemui.SysuiTestCase
@@ -61,8 +60,6 @@ class MediaViewControllerTest : SysuiTestCase() {
@Mock private lateinit var mediaSubTitleWidgetState: WidgetState
@Mock private lateinit var mediaContainerWidgetState: WidgetState
@Mock private lateinit var mediaFlags: MediaFlags
@Mock private lateinit var expandedLayout: ConstraintSet
@Mock private lateinit var collapsedLayout: ConstraintSet
val delta = 0.1F
@@ -82,16 +79,47 @@ class MediaViewControllerTest : SysuiTestCase() {
}
@Test
fun testOrientationChanged_layoutsAreLoaded() {
mediaViewController.expandedLayout = expandedLayout
mediaViewController.collapsedLayout = collapsedLayout
fun testOrientationChanged_heightOfPlayerIsUpdated() {
val newConfig = Configuration()
mediaViewController.attach(player, MediaViewController.TYPE.PLAYER)
// Change the height to see the effect of orientation change.
MediaViewController.backgroundIds.forEach { id ->
mediaViewController.expandedLayout.getConstraint(id).layout.mHeight = 10
}
newConfig.orientation = ORIENTATION_LANDSCAPE
configurationController.onConfigurationChanged(newConfig)
verify(expandedLayout).load(context, R.xml.media_session_expanded)
verify(collapsedLayout).load(context, R.xml.media_session_collapsed)
MediaViewController.backgroundIds.forEach { id ->
assertTrue(
mediaViewController.expandedLayout.getConstraint(id).layout.mHeight ==
context.resources.getDimensionPixelSize(
R.dimen.qs_media_session_height_expanded
)
)
}
}
@Test
fun testOrientationChanged_heightOfRecCardIsUpdated() {
val newConfig = Configuration()
mediaViewController.attach(recommendation, MediaViewController.TYPE.RECOMMENDATION)
// Change the height to see the effect of orientation change.
mediaViewController.expandedLayout
.getConstraint(MediaViewController.recSizingViewId)
.layout
.mHeight = 10
newConfig.orientation = ORIENTATION_LANDSCAPE
configurationController.onConfigurationChanged(newConfig)
assertTrue(
mediaViewController.expandedLayout
.getConstraint(MediaViewController.recSizingViewId)
.layout
.mHeight ==
context.resources.getDimensionPixelSize(R.dimen.qs_media_session_height_expanded)
)
}
@Test