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

Commit bb87a428 authored by Nick Chameyev's avatar Nick Chameyev
Browse files

Fix fold/unfold animation on split shade and keyguard

Most of the animations were broken because of the recent
changes in the view structure and refactorings.

Bug: 334100546
Test: manual fold/unfold on lockscreen and split shade
  with and without 'migrate clocks to blueprint' flag
Test: atest UnfoldConstantTranslateAnimatorTest
Test: atest KeyguardUnfoldTransitionTest
Test: functional tests are planned in b/342375409
Flag: EXEMPT bugfix
Change-Id: I9472bf95ad3bf9e661b092f5d0b15b74299400f8
parent 4f9ed146
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -62,7 +62,9 @@
    <com.android.systemui.keyguard.ui.view.KeyguardRootView
        android:id="@id/keyguard_root_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
        android:layout_height="match_parent"
        android:clipChildren="false"
        />

    <!-- Shared container for the notification stack. Can be positioned by either
         the keyguard_root_view or notification_panel -->
+8 −1
Original line number Diff line number Diff line
@@ -37,10 +37,17 @@ class UnfoldConstantTranslateAnimator(
    private lateinit var rootView: ViewGroup
    private var translationMax = 0f

    /**
     * Initializes the animator, it is allowed to call this method multiple times, for example
     * to update the rootView or maximum translation
     */
    fun init(rootView: ViewGroup, translationMax: Float) {
        if (!::rootView.isInitialized) {
            progressProvider.addCallback(this)
        }

        this.rootView = rootView
        this.translationMax = translationMax
        progressProvider.addCallback(this)
    }

    override fun onTransitionStarted() {
+92 −18
Original line number Diff line number Diff line
@@ -17,16 +17,21 @@
package com.android.keyguard

import android.content.Context
import android.view.ViewGroup
import com.android.systemui.res.R
import android.view.View
import com.android.systemui.keyguard.MigrateClocksToBlueprint
import com.android.systemui.keyguard.ui.view.KeyguardRootView
import com.android.systemui.plugins.statusbar.StatusBarStateController
import com.android.systemui.statusbar.StatusBarState.KEYGUARD
import com.android.systemui.res.R
import com.android.systemui.shared.R as sharedR
import com.android.systemui.shade.NotificationShadeWindowView
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.END
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.Direction.START
import com.android.systemui.shared.animation.UnfoldConstantTranslateAnimator.ViewIdToTranslate
import com.android.systemui.statusbar.StatusBarState.KEYGUARD
import com.android.systemui.unfold.SysUIUnfoldScope
import com.android.systemui.unfold.util.NaturalRotationUnfoldProgressProvider
import com.android.systemui.unfold.UnfoldTransitionProgressProvider
import com.android.systemui.unfold.dagger.NaturalRotation
import javax.inject.Inject

/**
@@ -38,8 +43,10 @@ class KeyguardUnfoldTransition
@Inject
constructor(
    private val context: Context,
    private val keyguardRootView: KeyguardRootView,
    private val shadeWindowView: NotificationShadeWindowView,
    statusBarStateController: StatusBarStateController,
    unfoldProgressProvider: NaturalRotationUnfoldProgressProvider,
    @NaturalRotation unfoldProgressProvider: UnfoldTransitionProgressProvider,
) {

    /** Certain views only need to move if they are not currently centered */
@@ -50,27 +57,94 @@ constructor(
    private val filterKeyguard: () -> Boolean = { statusBarStateController.getState() == KEYGUARD }

    private val translateAnimator by lazy {
        val smartSpaceViews = if (MigrateClocksToBlueprint.isEnabled) {
            // Use scrollX instead of translationX as translation is already set by [AodBurnInLayer]
            val scrollXTranslation = { view: View, translation: Float ->
                view.scrollX = -translation.toInt()
            }

            setOf(
                ViewIdToTranslate(
                    viewId = sharedR.id.date_smartspace_view,
                    direction = START,
                    shouldBeAnimated = filterKeyguard,
                    translateFunc = scrollXTranslation,
                ),
                ViewIdToTranslate(
                    viewId = sharedR.id.bc_smartspace_view,
                    direction = START,
                    shouldBeAnimated = filterKeyguard,
                    translateFunc = scrollXTranslation,
                ),
                ViewIdToTranslate(
                    viewId = sharedR.id.weather_smartspace_view,
                    direction = START,
                    shouldBeAnimated = filterKeyguard,
                    translateFunc = scrollXTranslation,
                )
            )
        } else {
            setOf(ViewIdToTranslate(
                viewId = R.id.keyguard_status_area,
                direction = START,
                shouldBeAnimated = filterKeyguard,
                translateFunc = { view, value ->
                    (view as? KeyguardStatusAreaView)?.translateXFromUnfold = value
                }
            ))
        }

        UnfoldConstantTranslateAnimator(
            viewsIdToTranslate =
                setOf(
                    ViewIdToTranslate(
                        viewId = R.id.lockscreen_clock_view_large,
                        direction = START,
                        shouldBeAnimated = filterKeyguardAndSplitShadeOnly
                    ),
                    ViewIdToTranslate(
                        viewId = R.id.lockscreen_clock_view,
                        direction = START,
                        shouldBeAnimated = filterKeyguard
                    ),
                    ViewIdToTranslate(
                        viewId = R.id.notification_stack_scroller,
                        direction = END,
                        shouldBeAnimated = filterKeyguardAndSplitShadeOnly
                    )
                ) + smartSpaceViews,
            progressProvider = unfoldProgressProvider
        )
    }

    private val shortcutButtonsAnimator by lazy {
        UnfoldConstantTranslateAnimator(
            viewsIdToTranslate =
            setOf(
                    ViewIdToTranslate(R.id.keyguard_status_area, START, filterKeyguard,
                        { view, value ->
                            (view as? KeyguardStatusAreaView)?.translateXFromUnfold = value
                        }),
                ViewIdToTranslate(
                        R.id.lockscreen_clock_view_large, START, filterKeyguardAndSplitShadeOnly),
                    ViewIdToTranslate(R.id.lockscreen_clock_view, START, filterKeyguard),
                    viewId = R.id.start_button,
                    direction = START,
                    shouldBeAnimated = filterKeyguard
                ),
                ViewIdToTranslate(
                        R.id.notification_stack_scroller, END, filterKeyguardAndSplitShadeOnly),
                    ViewIdToTranslate(R.id.start_button, START, filterKeyguard),
                    ViewIdToTranslate(R.id.end_button, END, filterKeyguard)),
            progressProvider = unfoldProgressProvider)
                    viewId = R.id.end_button,
                    direction = END,
                    shouldBeAnimated = filterKeyguard
                )
            ),
            progressProvider = unfoldProgressProvider
        )
    }

    /** Relies on the [parent] to locate views to translate. */
    fun setup(parent: ViewGroup) {
    /** Initializes the keyguard fold/unfold transition */
    fun setup() {
        val translationMax =
            context.resources.getDimensionPixelSize(R.dimen.keyguard_unfold_translation_x).toFloat()
        translateAnimator.init(parent, translationMax)

        translateAnimator.init(shadeWindowView, translationMax)

        // Use keyguard root view as there is another instance of start/end buttons with the same ID
        // outside of the keyguard root view
        shortcutButtonsAnimator.init(keyguardRootView, translationMax)
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ constructor(
            viewsIdToTranslate =
                setOf(
                    ViewIdToTranslate(R.id.quick_settings_panel, START, filterShade),
                    ViewIdToTranslate(R.id.qs_footer_actions, START, filterShade),
                    ViewIdToTranslate(R.id.notification_stack_scroller, END, filterShade)),
            progressProvider = progressProvider)
    }
@@ -55,9 +56,8 @@ constructor(
        UnfoldConstantTranslateAnimator(
            viewsIdToTranslate =
            setOf(
                ViewIdToTranslate(R.id.statusIcons, END, filterShade),
                ViewIdToTranslate(R.id.shade_header_system_icons, END, filterShade),
                ViewIdToTranslate(R.id.privacy_container, END, filterShade),
                ViewIdToTranslate(R.id.batteryRemainingIcon, END, filterShade),
                ViewIdToTranslate(R.id.carrier_group, END, filterShade),
                ViewIdToTranslate(R.id.clock, START, filterShade),
                ViewIdToTranslate(R.id.date, START, filterShade)
+1 −11
Original line number Diff line number Diff line
@@ -537,8 +537,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
    private final KeyguardMediaController mKeyguardMediaController;

    private final Optional<KeyguardUnfoldTransition> mKeyguardUnfoldTransition;
    private final Optional<NotificationPanelUnfoldAnimationController>
            mNotificationPanelUnfoldAnimationController;

    /** The drag distance required to fully expand the split shade. */
    private int mSplitShadeFullTransitionDistance;
@@ -964,8 +962,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump

        mKeyguardUnfoldTransition = unfoldComponent.map(
                SysUIUnfoldComponent::getKeyguardUnfoldTransition);
        mNotificationPanelUnfoldAnimationController = unfoldComponent.map(
                SysUIUnfoldComponent::getNotificationPanelUnfoldAnimationController);

        updateUserSwitcherFlags();
        mKeyguardBottomAreaViewModel = keyguardBottomAreaViewModel;
@@ -1131,9 +1127,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
        mShadeHeaderController.init();
        mShadeHeaderController.setShadeCollapseAction(
                () -> collapse(/* delayed= */ false , /* speedUpFactor= */ 1.0f));
        mKeyguardUnfoldTransition.ifPresent(u -> u.setup(mView));
        mNotificationPanelUnfoldAnimationController.ifPresent(controller ->
                controller.setup(mNotificationContainerParent));

        // Dreaming->Lockscreen
        collectFlow(
@@ -1511,9 +1504,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
        if (!KeyguardBottomAreaRefactor.isEnabled()) {
            setKeyguardBottomAreaVisibility(mBarState, false);
        }

        mKeyguardUnfoldTransition.ifPresent(u -> u.setup(mView));
        mNotificationPanelUnfoldAnimationController.ifPresent(u -> u.setup(mView));
    }

    private void attachSplitShadeMediaPlayerContainer(FrameLayout container) {
@@ -1797,6 +1787,7 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump

    private void updateKeyguardStatusViewAlignment(boolean animate) {
        boolean shouldBeCentered = shouldKeyguardStatusViewBeCentered();
        mKeyguardUnfoldTransition.ifPresent(t -> t.setStatusViewCentered(shouldBeCentered));
        if (MigrateClocksToBlueprint.isEnabled()) {
            mKeyguardInteractor.setClockShouldBeCentered(shouldBeCentered);
            return;
@@ -1804,7 +1795,6 @@ public final class NotificationPanelViewController implements ShadeSurface, Dump
        ConstraintLayout layout = mNotificationContainerParent;
        mKeyguardStatusViewController.updateAlignment(
                layout, mSplitShadeEnabled, shouldBeCentered, animate);
        mKeyguardUnfoldTransition.ifPresent(t -> t.setStatusViewCentered(shouldBeCentered));
    }

    private boolean shouldKeyguardStatusViewBeCentered() {
Loading