Merge "Avoid media players inflations while changing orientation" into tm-qpr-dev

This commit is contained in:
Michael Mikhail
2023-03-06 14:48:11 +00:00
committed by Android (Google) Code Review
4 changed files with 34 additions and 55 deletions

View File

@@ -197,7 +197,6 @@ constructor(
private val configListener =
object : ConfigurationController.ConfigurationListener {
var lastOrientation = -1
override fun onDensityOrFontScaleChanged() {
// System font changes should only happen when UMO is offscreen or a flicker may
@@ -214,13 +213,6 @@ constructor(
override fun onConfigChanged(newConfig: Configuration?) {
if (newConfig == null) return
isRtl = newConfig.layoutDirection == View.LAYOUT_DIRECTION_RTL
val newOrientation = newConfig.orientation
if (lastOrientation != newOrientation) {
// The players actually depend on the orientation possibly, so we have to
// recreate them (at least on large screen devices)
lastOrientation = newOrientation
updatePlayers(recreateMedia = true)
}
}
override fun onUiModeChanged() {

View File

@@ -154,9 +154,11 @@ constructor(
return transitionLayout?.translationY ?: 0.0f
}
/** A callback for RTL config changes */
/** A callback for config changes */
private val configurationListener =
object : ConfigurationController.ConfigurationListener {
var lastOrientation = -1
override fun onConfigChanged(newConfig: Configuration?) {
// Because the TransitionLayout is not always attached (and calculates/caches layout
// results regardless of attach state), we have to force the layoutDirection of the
@@ -169,6 +171,13 @@ constructor(
transitionLayout?.layoutDirection = layoutDirection
refreshState()
}
val newOrientation = newConfig.orientation
if (lastOrientation != newOrientation) {
// Layout dimensions are possibly changing, so we need to update them. (at
// least on large screen devices)
lastOrientation = newOrientation
loadLayoutForType(type)
}
}
}
}
@@ -195,13 +204,14 @@ constructor(
* The expanded constraint set used to render a expanded player. If it is modified, make sure to
* call [refreshState]
*/
val collapsedLayout = ConstraintSet()
var collapsedLayout = ConstraintSet()
@VisibleForTesting set
/**
* The expanded constraint set used to render a collapsed player. If it is modified, make sure
* to call [refreshState]
*/
val expandedLayout = ConstraintSet()
var expandedLayout = ConstraintSet()
@VisibleForTesting set
/** Whether the guts are visible for the associated player. */
var isGutsVisible = false
@@ -483,7 +493,7 @@ constructor(
*/
fun attach(transitionLayout: TransitionLayout, type: TYPE) =
traceSection("MediaViewController#attach") {
updateMediaViewControllerType(type)
loadLayoutForType(type)
logger.logMediaLocation("attach $type", currentStartLocation, currentEndLocation)
this.transitionLayout = transitionLayout
layoutController.attach(transitionLayout)
@@ -641,7 +651,7 @@ constructor(
return result
}
private fun updateMediaViewControllerType(type: TYPE) {
private fun loadLayoutForType(type: TYPE) {
this.type = type
// These XML resources contain ConstraintSets that will apply to this player type's layout

View File

@@ -18,7 +18,6 @@ package com.android.systemui.media.controls.ui
import android.app.PendingIntent
import android.content.res.ColorStateList
import android.content.res.Configuration
import android.testing.AndroidTestingRunner
import android.testing.TestableLooper
import android.util.MathUtils.abs
@@ -684,46 +683,6 @@ class MediaCarouselControllerTest : SysuiTestCase() {
verify(pageIndicator).alpha = floatThat { abs(it - 1.0F) < delta }
}
@Test
fun testOnConfigChanged_playersAreAddedBack() {
mediaCarouselController.pageIndicator = pageIndicator
listener.value.onMediaDataLoaded(
"playing local",
null,
DATA.copy(
active = true,
isPlaying = true,
playbackLocation = MediaData.PLAYBACK_LOCAL,
resumption = false
)
)
listener.value.onMediaDataLoaded(
"paused local",
null,
DATA.copy(
active = true,
isPlaying = false,
playbackLocation = MediaData.PLAYBACK_LOCAL,
resumption = false
)
)
runAllReady()
val playersSize = MediaPlayerData.players().size
configListener.value.onConfigChanged(Configuration())
runAllReady()
verify(pageIndicator).tintList =
ColorStateList.valueOf(context.getColor(R.color.media_paging_indicator))
assertEquals(playersSize, MediaPlayerData.players().size)
assertEquals(
MediaPlayerData.getMediaPlayerIndex("playing local"),
mediaCarouselController.mediaCarouselScrollHandler.visibleMediaIndex
)
}
@Test
fun testOnUiModeChanged_playersAreAddedBack() {
mediaCarouselController.pageIndicator = pageIndicator

View File

@@ -16,9 +16,12 @@
package com.android.systemui.media.controls.ui
import android.content.res.Configuration
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
@@ -58,6 +61,8 @@ 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
@@ -76,6 +81,19 @@ class MediaViewControllerTest : SysuiTestCase() {
)
}
@Test
fun testOrientationChanged_layoutsAreLoaded() {
mediaViewController.expandedLayout = expandedLayout
mediaViewController.collapsedLayout = collapsedLayout
val newConfig = Configuration()
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)
}
@Test
fun testObtainViewState_applySquishFraction_toPlayerTransitionViewState_height() {
mediaViewController.attach(player, MediaViewController.TYPE.PLAYER)