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

Commit d98f375a authored by Michael Mikhail's avatar Michael Mikhail
Browse files

Add unknown location to media locations

Flag: com.android.systemui.scene_container
Bug: 296122467
Test: build
Change-Id: If440c9b738bc6d06ab57e7d6ddf83561605f1bd7
parent 90c38a11
Loading
Loading
Loading
Loading
+7 −7
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ object MediaCarouselStateLoader {
            Scenes.Shade -> MediaHierarchyManager.LOCATION_QQS
            Scenes.Lockscreen -> MediaHierarchyManager.LOCATION_LOCKSCREEN
            Scenes.Communal -> MediaHierarchyManager.LOCATION_COMMUNAL_HUB
            else -> -1
            else -> MediaHierarchyManager.LOCATION_UNKNOWN
        }
    }

@@ -59,7 +59,7 @@ object MediaCarouselStateLoader {
        return when (content) {
            Overlays.QuickSettingsShade -> MediaHierarchyManager.LOCATION_QS
            Overlays.NotificationsShade -> MediaHierarchyManager.LOCATION_QQS
            else -> -1
            else -> MediaHierarchyManager.LOCATION_UNKNOWN
        }
    }

@@ -75,8 +75,8 @@ object MediaCarouselStateLoader {
        data object Gone : State {
            override val transitionProgress: Float = 1.0F
            override val squishFraction: () -> Float = { 1.0F }
            override val endLocation: Int = -1
            override val startLocation: Int = -1
            override val endLocation: Int = MediaHierarchyManager.LOCATION_UNKNOWN
            override val startLocation: Int = MediaHierarchyManager.LOCATION_UNKNOWN
        }

        /** State when media carousel is moving from one media location to another */
@@ -91,7 +91,7 @@ object MediaCarouselStateLoader {
        /** State when media carousel reached the end location. */
        data class Idle(override val endLocation: Int) : State {
            override val transitionProgress = 1.0F
            override val startLocation = -1
            override val startLocation = MediaHierarchyManager.LOCATION_UNKNOWN
            override val squishFraction = { 1.0F }
        }
    }
@@ -120,7 +120,7 @@ object MediaCarouselStateLoader {
                    } else if (MediaContentPicker.contents.contains(toScene)) {
                        State.InProgress(
                            transitionProgress = 1.0F,
                            startLocation = -1,
                            startLocation = MediaHierarchyManager.LOCATION_UNKNOWN,
                            getMediaLocation(toScene),
                        )
                    } else {
@@ -141,7 +141,7 @@ object MediaCarouselStateLoader {
                    } else if (MediaContentPicker.contents.contains(toContent)) {
                        State.InProgress(
                            transitionProgress = 1.0F,
                            startLocation = -1,
                            startLocation = MediaHierarchyManager.LOCATION_UNKNOWN,
                            getMediaLocation(toContent),
                        )
                    } else {
+5 −3
Original line number Diff line number Diff line
@@ -175,19 +175,21 @@ constructor(
     * The desired location where we'll be at the end of the transformation. Usually this matches
     * the end location, except when we're still waiting on a state update call.
     */
    @MediaLocation private var desiredLocation: Int = -1
    @MediaLocation private var desiredLocation: Int = MediaHierarchyManager.LOCATION_UNKNOWN

    /**
     * The ending location of the view where it ends when all animations and transitions have
     * finished
     */
    @MediaLocation @VisibleForTesting var currentEndLocation: Int = -1
    @MediaLocation
    @VisibleForTesting
    var currentEndLocation: Int = MediaHierarchyManager.LOCATION_UNKNOWN

    /**
     * The ending location of the view where it ends when all animations and transitions have
     * finished
     */
    @MediaLocation private var currentStartLocation: Int = -1
    @MediaLocation private var currentStartLocation: Int = MediaHierarchyManager.LOCATION_UNKNOWN

    /** The progress of the transition or 1.0 if there is no transition happening */
    private var currentTransitionProgress: Float = 1.0f
+30 −27
Original line number Diff line number Diff line
@@ -64,7 +64,6 @@ import com.android.systemui.util.settings.SecureSettings
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.combine
import kotlinx.coroutines.flow.distinctUntilChanged
@@ -161,10 +160,10 @@ constructor(
    private var animationStartAlpha = 0.0f

    /** The starting location of the cross fade if an animation is running right now. */
    @MediaLocation private var crossFadeAnimationStartLocation = -1
    @MediaLocation private var crossFadeAnimationStartLocation = LOCATION_UNKNOWN

    /** The end location of the cross fade if an animation is running right now. */
    @MediaLocation private var crossFadeAnimationEndLocation = -1
    @MediaLocation private var crossFadeAnimationEndLocation = LOCATION_UNKNOWN
    private var targetBounds: Rect = Rect()
    private val mediaFrame
        get() = mediaCarouselController.mediaFrame
@@ -191,7 +190,7 @@ constructor(
                    animationStartBounds,
                    targetBounds,
                    boundsProgress,
                    result = currentBounds
                    result = currentBounds,
                )
                resolveClipping(currentClipping)
                applyState(currentBounds, currentAlpha, clipBounds = currentClipping)
@@ -233,16 +232,16 @@ constructor(
     * The last location where this view was at before going to the desired location. This is useful
     * for guided transitions.
     */
    @MediaLocation private var previousLocation = -1
    @MediaLocation private var previousLocation = LOCATION_UNKNOWN
    /** The desired location where the view will be at the end of the transition. */
    @MediaLocation private var desiredLocation = -1
    @MediaLocation private var desiredLocation = LOCATION_UNKNOWN

    /**
     * The current attachment location where the view is currently attached. Usually this matches
     * the desired location except for animations whenever a view moves to the new desired location,
     * during which it is in [IN_OVERLAY].
     */
    @MediaLocation private var currentAttachmentLocation = -1
    @MediaLocation private var currentAttachmentLocation = LOCATION_UNKNOWN

    private var inSplitShade = false

@@ -627,7 +626,7 @@ constructor(
                            secureSettings.getBoolForUser(
                                Settings.Secure.MEDIA_CONTROLS_LOCK_SCREEN,
                                true,
                                UserHandle.USER_CURRENT
                                UserHandle.USER_CURRENT,
                            )
                    }
                }
@@ -635,7 +634,7 @@ constructor(
        secureSettings.registerContentObserverForUserSync(
            Settings.Secure.MEDIA_CONTROLS_LOCK_SCREEN,
            settingsObserver,
            UserHandle.USER_ALL
            UserHandle.USER_ALL,
        )

        // Listen to the communal UI state. Make sure that communal UI is showing and hub itself is
@@ -651,7 +650,7 @@ constructor(
                    shadeInteractor.shadeExpansion
                        .mapLatest { it < EXPANSION_THRESHOLD }
                        .distinctUntilChanged(),
                    ::Triple
                    ::Triple,
                )
                .collectLatest { (communalShowing, isDreaming, isShadeExpanding) ->
                    isCommunalShowing = communalShowing
@@ -689,10 +688,10 @@ constructor(
        if (mediaObject.location == desiredLocation) {
            // In case we are overriding a view that is already visible, make sure we attach it
            // to this new host view in the below call
            desiredLocation = -1
            desiredLocation = LOCATION_UNKNOWN
        }
        if (mediaObject.location == currentAttachmentLocation) {
            currentAttachmentLocation = -1
            currentAttachmentLocation = LOCATION_UNKNOWN
        }
        updateDesiredLocation()
        return viewHost
@@ -734,7 +733,7 @@ constructor(
     */
    private fun updateDesiredLocation(
        forceNoAnimation: Boolean = false,
        forceStateUpdate: Boolean = false
        forceStateUpdate: Boolean = false,
    ) =
        traceSection("MediaHierarchyManager#updateDesiredLocation") {
            val desiredLocation = calculateLocation()
@@ -758,7 +757,7 @@ constructor(
                        previousLocation = LOCATION_QQS
                    }
                }
                val isNewView = this.desiredLocation == -1
                val isNewView = this.desiredLocation == LOCATION_UNKNOWN
                this.desiredLocation = desiredLocation
                // Let's perform a transition
                val animate =
@@ -774,7 +773,7 @@ constructor(
                        host,
                        animate,
                        animDuration,
                        delay
                        delay,
                    )
                }
                performTransitionToNewLocation(isNewView, animate)
@@ -868,7 +867,7 @@ constructor(

    private fun shouldAnimateTransition(
        @MediaLocation currentLocation: Int,
        @MediaLocation previousLocation: Int
        @MediaLocation previousLocation: Int,
    ): Boolean {
        if (isCurrentlyInGuidedTransformation()) {
            return false
@@ -990,7 +989,7 @@ constructor(
        startBounds: Rect,
        endBounds: Rect,
        progress: Float,
        result: Rect? = null
        result: Rect? = null,
    ): Rect {
        val left =
            MathUtils.lerp(startBounds.left.toFloat(), endBounds.left.toFloat(), progress).toInt()
@@ -1014,7 +1013,7 @@ constructor(
    }

    private fun hasValidStartAndEndLocations(): Boolean {
        return previousLocation != -1 && desiredLocation != -1
        return previousLocation != LOCATION_UNKNOWN && desiredLocation != LOCATION_UNKNOWN
    }

    /** Calculate the transformation type for the current animation */
@@ -1099,21 +1098,21 @@ constructor(
        bounds: Rect,
        alpha: Float,
        immediately: Boolean = false,
        clipBounds: Rect = EMPTY_RECT
        clipBounds: Rect = EMPTY_RECT,
    ) =
        traceSection("MediaHierarchyManager#applyState") {
            currentBounds.set(bounds)
            currentClipping = clipBounds
            carouselAlpha = if (isCurrentlyFading()) alpha else 1.0f
            val onlyUseEndState = !isCurrentlyInGuidedTransformation() || isCurrentlyFading()
            val startLocation = if (onlyUseEndState) -1 else previousLocation
            val startLocation = if (onlyUseEndState) LOCATION_UNKNOWN else previousLocation
            val progress = if (onlyUseEndState) 1.0f else getTransformationProgress()
            val endLocation = resolveLocationForFading()
            mediaCarouselController.setCurrentState(
                startLocation,
                endLocation,
                progress,
                immediately
                immediately,
            )
            updateHostAttachment()
            if (currentAttachmentLocation == IN_OVERLAY) {
@@ -1125,7 +1124,7 @@ constructor(
                    currentBounds.left,
                    currentBounds.top,
                    currentBounds.right,
                    currentBounds.bottom
                    currentBounds.bottom,
                )
            }
        }
@@ -1186,7 +1185,7 @@ constructor(
                    mediaCarouselController.onDesiredLocationChanged(
                        newLocation,
                        getHost(newLocation),
                        animate = false
                        animate = false,
                    )
                }
            }
@@ -1201,7 +1200,7 @@ constructor(
        if (isCrossFadeAnimatorRunning) {
            // When animating between two hosts with a fade, let's keep ourselves in the old
            // location for the first half, and then switch over to the end location
            if (animationCrossFadeProgress > 0.5 || previousLocation == -1) {
            if (animationCrossFadeProgress > 0.5 || previousLocation == LOCATION_UNKNOWN) {
                return crossFadeAnimationEndLocation
            } else {
                return crossFadeAnimationStartLocation
@@ -1364,6 +1363,9 @@ constructor(
        /** Attached at the root of the hierarchy in an overlay */
        const val IN_OVERLAY = -1000

        /** Not attached to any view */
        const val LOCATION_UNKNOWN = -1

        /**
         * The default transformation type where the hosts transform into each other using a direct
         * transition
@@ -1388,8 +1390,8 @@ private val EMPTY_RECT = Rect()
    value =
        [
            MediaHierarchyManager.TRANSFORMATION_TYPE_TRANSITION,
            MediaHierarchyManager.TRANSFORMATION_TYPE_FADE
        ]
            MediaHierarchyManager.TRANSFORMATION_TYPE_FADE,
        ],
)
@Retention(AnnotationRetention.SOURCE)
private annotation class TransformationType
@@ -1403,7 +1405,8 @@ private annotation class TransformationType
            MediaHierarchyManager.LOCATION_LOCKSCREEN,
            MediaHierarchyManager.LOCATION_DREAM_OVERLAY,
            MediaHierarchyManager.LOCATION_COMMUNAL_HUB,
        ]
            MediaHierarchyManager.LOCATION_UNKNOWN,
        ],
)
@Retention(AnnotationRetention.SOURCE)
annotation class MediaLocation
+3 −3
Original line number Diff line number Diff line
@@ -120,7 +120,7 @@ constructor(
     * finished
     */
    @MediaLocation
    var currentEndLocation: Int = -1
    var currentEndLocation: Int = MediaHierarchyManager.LOCATION_UNKNOWN
        set(value) {
            if (field != value) {
                field = value
@@ -130,7 +130,7 @@ constructor(
        }

    /** The starting location of the view where it starts for all animations and transitions */
    @MediaLocation private var currentStartLocation: Int = -1
    @MediaLocation private var currentStartLocation: Int = MediaHierarchyManager.LOCATION_UNKNOWN

    /** The progress of the transition or 1.0 if there is no transition happening */
    private var currentTransitionProgress: Float = 1.0f
@@ -653,7 +653,7 @@ constructor(
            logger.logMediaLocation("attach $type", currentStartLocation, currentEndLocation)
            this.transitionLayout = transitionLayout
            layoutController.attach(transitionLayout)
            if (currentEndLocation == -1) {
            if (currentEndLocation == MediaHierarchyManager.LOCATION_UNKNOWN) {
                return
            }
            // Set the previously set state immediately to the view, now that it's finally attached
+3 −1
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ import com.android.systemui.media.controls.domain.pipeline.interactor.MediaContr
import com.android.systemui.media.controls.shared.model.MediaAction
import com.android.systemui.media.controls.shared.model.MediaButton
import com.android.systemui.media.controls.shared.model.MediaControlModel
import com.android.systemui.media.controls.ui.controller.MediaHierarchyManager
import com.android.systemui.media.controls.ui.controller.MediaLocation
import com.android.systemui.media.controls.util.MediaSmartspaceLogger.Companion.SMARTSPACE_CARD_CLICK_EVENT
import com.android.systemui.media.controls.util.MediaSmartspaceLogger.Companion.SMARTSPACE_CARD_DISMISS_EVENT
import com.android.systemui.media.controls.util.MediaUiEventLogger
@@ -70,7 +72,7 @@ class MediaControlViewModel(

    private var isPlaying = false
    private var isAnyButtonClicked = false
    private var location = -1
    @MediaLocation private var location = MediaHierarchyManager.LOCATION_UNKNOWN
    private var playerViewModel: MediaPlayerViewModel? = null

    fun isNewPlayer(viewModel: MediaPlayerViewModel): Boolean {
Loading