Merge "Fix media transitions when inactive" into sc-dev

This commit is contained in:
Beth Thibodeau
2021-06-16 19:08:21 +00:00
committed by Android (Google) Code Review
2 changed files with 23 additions and 6 deletions

View File

@@ -186,6 +186,12 @@ class MediaHierarchyManager @Inject constructor(
@MediaLocation @MediaLocation
private var currentAttachmentLocation = -1 private var currentAttachmentLocation = -1
/**
* Is there any active media in the carousel?
*/
private var hasActiveMedia: Boolean = false
get() = mediaHosts.get(LOCATION_QQS)?.visible == true
/** /**
* Are we currently waiting on an animation to start? * Are we currently waiting on an animation to start?
*/ */
@@ -476,8 +482,12 @@ class MediaHierarchyManager @Inject constructor(
val viewHost = createUniqueObjectHost() val viewHost = createUniqueObjectHost()
mediaObject.hostView = viewHost mediaObject.hostView = viewHost
mediaObject.addVisibilityChangeListener { mediaObject.addVisibilityChangeListener {
// If QQS changes visibility, we need to force an update to ensure the transition
// goes into the correct state
val stateUpdate = mediaObject.location == LOCATION_QQS
// Never animate because of a visibility change, only state changes should do that // Never animate because of a visibility change, only state changes should do that
updateDesiredLocation(forceNoAnimation = true) updateDesiredLocation(forceNoAnimation = true, forceStateUpdate = stateUpdate)
} }
mediaHosts[mediaObject.location] = mediaObject mediaHosts[mediaObject.location] = mediaObject
if (mediaObject.location == desiredLocation) { if (mediaObject.location == desiredLocation) {
@@ -521,10 +531,15 @@ class MediaHierarchyManager @Inject constructor(
* going from the old desired location to the new one. * going from the old desired location to the new one.
* *
* @param forceNoAnimation optional parameter telling the system not to animate * @param forceNoAnimation optional parameter telling the system not to animate
* @param forceStateUpdate optional parameter telling the system to update transition state
* even if location did not change
*/ */
private fun updateDesiredLocation(forceNoAnimation: Boolean = false) { private fun updateDesiredLocation(
forceNoAnimation: Boolean = false,
forceStateUpdate: Boolean = false
) {
val desiredLocation = calculateLocation() val desiredLocation = calculateLocation()
if (desiredLocation != this.desiredLocation) { if (desiredLocation != this.desiredLocation || forceStateUpdate) {
if (this.desiredLocation >= 0) { if (this.desiredLocation >= 0) {
previousLocation = this.desiredLocation previousLocation = this.desiredLocation
} }
@@ -784,7 +799,7 @@ class MediaHierarchyManager @Inject constructor(
private fun getQSTransformationProgress(): Float { private fun getQSTransformationProgress(): Float {
val currentHost = getHost(desiredLocation) val currentHost = getHost(desiredLocation)
val previousHost = getHost(previousLocation) val previousHost = getHost(previousLocation)
if (currentHost?.location == LOCATION_QS) { if (hasActiveMedia && currentHost?.location == LOCATION_QS) {
if (previousHost?.location == LOCATION_QQS) { if (previousHost?.location == LOCATION_QQS) {
if (previousHost.visible || statusbarState != StatusBarState.KEYGUARD) { if (previousHost.visible || statusbarState != StatusBarState.KEYGUARD) {
return qsExpansion return qsExpansion
@@ -917,6 +932,7 @@ class MediaHierarchyManager @Inject constructor(
val location = when { val location = when {
qsExpansion > 0.0f && !onLockscreen -> LOCATION_QS qsExpansion > 0.0f && !onLockscreen -> LOCATION_QS
qsExpansion > 0.4f && onLockscreen -> LOCATION_QS qsExpansion > 0.4f && onLockscreen -> LOCATION_QS
!hasActiveMedia -> LOCATION_QS
onLockscreen && isTransformingToFullShadeAndInQQS() -> LOCATION_QQS onLockscreen && isTransformingToFullShadeAndInQQS() -> LOCATION_QQS
onLockscreen && allowedOnLockscreen -> LOCATION_LOCKSCREEN onLockscreen && allowedOnLockscreen -> LOCATION_LOCKSCREEN
else -> LOCATION_QQS else -> LOCATION_QQS

View File

@@ -539,8 +539,9 @@ public class QSFragment extends LifecycleFragment implements QS, CommandQueue.Ca
private void pinToBottom(float absoluteBottomPosition, MediaHost mediaHost, boolean expanded) { private void pinToBottom(float absoluteBottomPosition, MediaHost mediaHost, boolean expanded) {
View hostView = mediaHost.getHostView(); View hostView = mediaHost.getHostView();
// on keyguard we cross-fade to expanded, so no need to pin it. // On keyguard we cross-fade to expanded, so no need to pin it.
if (mLastQSExpansion > 0 && !isKeyguardState()) { // If the collapsed qs isn't visible, we also just keep it at the laid out position.
if (mLastQSExpansion > 0 && !isKeyguardState() && mQqsMediaHost.getVisible()) {
float targetPosition = absoluteBottomPosition - getTotalBottomMargin(hostView) float targetPosition = absoluteBottomPosition - getTotalBottomMargin(hostView)
- hostView.getHeight(); - hostView.getHeight();
float currentPosition = mediaHost.getCurrentBounds().top float currentPosition = mediaHost.getCurrentBounds().top