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

Commit 9923e62f authored by Xiaowen Lei's avatar Xiaowen Lei
Browse files

Animate split shade media container on Smartspace visibility changes.

In split shade, media is part of the Keyguard status view.

This CL uses the KeyguardClockSwitch view height as a proxy for the
Smartspace visibility. This is a relatively straightforward solution,
since it avoids having to pass states between the SystemUI library and
the Smartspace implementation library.

Other transitions tested include:
  - Same transiton not in split shade
  - AOD <-> Lockscreen <-> Launcher
  - Fold / unfold, and rotate
  - Pick a different wallpaper/clock

(cherry picked from https://googleplex-android-review.googlesource.com/q/commit:e804daf6fcfbd8bcad4ffaf42db7edd5c85d07df)
To fix merge conflicts resulted from recent enabling of use_resource_processor (b/295208392).

Fix: 296907535
Test: On split shade with media, turn on/off flashlight via shortcut.
Test: With CHANGING duration = 10000, test other transitions with media.
Test: KeyguardStatusViewControllerTest
Test: KeyguardStatusViewTest
Test: KeyguardPresentationTest

Change-Id: I7df08fe6f8e15eb3cec2b020634cd20784a37577
parent a8998599
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -184,6 +184,10 @@ public class KeyguardClockSwitch extends RelativeLayout {
        }
    }

    public boolean getSplitShadeCentered() {
        return mSplitShadeCentered;
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
+4 −0
Original line number Diff line number Diff line
@@ -234,6 +234,10 @@ public class KeyguardClockSwitchController extends ViewController<KeyguardClockS
        }
    }

    public KeyguardClockSwitch getView() {
        return mView;
    }

    private void hideSliceViewAndNotificationIconContainer() {
        View ksv = mView.findViewById(R.id.keyguard_slice_view);
        ksv.setVisibility(View.GONE);
+9 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.keyguard;

import static java.util.Collections.emptySet;

import android.animation.LayoutTransition;
import android.content.Context;
import android.graphics.Canvas;
import android.os.Build;
@@ -78,6 +79,14 @@ public class KeyguardStatusView extends GridLayout {
        mKeyguardSlice = findViewById(R.id.keyguard_slice_view);

        mMediaHostContainer = findViewById(R.id.status_view_media_container);
        if (mMediaHostContainer != null) {
            LayoutTransition mediaLayoutTransition = new LayoutTransition();
            ((ViewGroup) mMediaHostContainer).setLayoutTransition(mediaLayoutTransition);
            mediaLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_APPEARING);
            mediaLayoutTransition.disableTransitionType(LayoutTransition.CHANGE_DISAPPEARING);
            mediaLayoutTransition.disableTransitionType(LayoutTransition.APPEARING);
            mediaLayoutTransition.disableTransitionType(LayoutTransition.DISAPPEARING);
        }

        updateDark();
    }
+45 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import static com.android.internal.jank.InteractionJankMonitor.CUJ_LOCKSCREEN_CL
import static com.android.systemui.util.kotlin.JavaAdapterKt.collectFlow;

import android.animation.Animator;
import android.animation.LayoutTransition;
import android.animation.ValueAnimator;
import android.annotation.Nullable;
import android.content.res.Configuration;
@@ -101,6 +102,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
    private final Rect mClipBounds = new Rect();
    private final KeyguardInteractor mKeyguardInteractor;

    private Boolean mSplitShadeEnabled = false;
    private Boolean mStatusViewCentered = true;

    private DumpManager mDumpManager;
@@ -150,6 +152,48 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
    @Override
    public void onInit() {
        mKeyguardClockSwitchController.init();
        final View mediaHostContainer = mView.findViewById(R.id.status_view_media_container);
        if (mediaHostContainer != null) {
            mKeyguardClockSwitchController.getView().addOnLayoutChangeListener(
                    (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
                        if (!mSplitShadeEnabled
                                || mKeyguardClockSwitchController.getView().getSplitShadeCentered()
                                // Note: isKeyguardVisible() returns false after Launcher -> AOD.
                                || !mKeyguardUpdateMonitor.isKeyguardVisible()) {
                            return;
                        }

                        int oldHeight = oldBottom - oldTop;
                        if (v.getHeight() == oldHeight) return;

                        if (mediaHostContainer.getVisibility() != View.VISIBLE
                                // If the media is appearing, also don't do the transition.
                                || mediaHostContainer.getHeight() == 0) {
                            return;
                        }

                        final LayoutTransition mediaLayoutTransition =
                                ((ViewGroup) mediaHostContainer).getLayoutTransition();
                        if (mediaLayoutTransition == null) return;

                        mediaLayoutTransition.enableTransitionType(LayoutTransition.CHANGING);
                    });

            mediaHostContainer.addOnLayoutChangeListener(
                    (v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
                        final LayoutTransition mediaLayoutTransition =
                                ((ViewGroup) mediaHostContainer).getLayoutTransition();
                        if (mediaLayoutTransition == null) return;
                        if (!mediaLayoutTransition.isTransitionTypeEnabled(
                                LayoutTransition.CHANGING)) {
                            return;
                        }
                        // Note: when this is called, the LayoutTransition is already been set up.
                        // Disables the LayoutTransition until it's explicitly enabled again.
                        mediaLayoutTransition.disableTransitionType(LayoutTransition.CHANGING);
                    }
            );
        }

        mDumpManager.registerDumpable(getInstanceName(), this);
        if (mFeatureFlags.isEnabled(Flags.MIGRATE_KEYGUARD_STATUS_VIEW)) {
@@ -385,6 +429,7 @@ public class KeyguardStatusViewController extends ViewController<KeyguardStatusV
     */
    public void setSplitShadeEnabled(boolean enabled) {
        mKeyguardClockSwitchController.setSplitShadeEnabled(enabled);
        mSplitShadeEnabled = enabled;
    }

    /**
+9 −0
Original line number Diff line number Diff line
@@ -20,8 +20,10 @@ import static org.mockito.Mockito.atLeast;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import android.animation.LayoutTransition;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.FrameLayout;

import com.android.internal.jank.InteractionJankMonitor;
import com.android.keyguard.logging.KeyguardLogger;
@@ -44,6 +46,7 @@ import org.mockito.MockitoAnnotations;
public class KeyguardStatusViewControllerBaseTest extends SysuiTestCase {

    @Mock protected KeyguardStatusView mKeyguardStatusView;

    @Mock protected KeyguardSliceViewController mKeyguardSliceViewController;
    @Mock protected KeyguardClockSwitchController mKeyguardClockSwitchController;
    @Mock protected KeyguardStateController mKeyguardStateController;
@@ -61,6 +64,10 @@ public class KeyguardStatusViewControllerBaseTest extends SysuiTestCase {

    protected KeyguardStatusViewController mController;

    @Mock protected KeyguardClockSwitch mKeyguardClockSwitch;
    @Mock protected FrameLayout mMediaHostContainer;
    @Mock protected LayoutTransition mMediaLayoutTransition;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
@@ -93,6 +100,8 @@ public class KeyguardStatusViewControllerBaseTest extends SysuiTestCase {
                };

        when(mKeyguardStatusView.getViewTreeObserver()).thenReturn(mViewTreeObserver);

        when(mKeyguardClockSwitchController.getView()).thenReturn(mKeyguardClockSwitch);
    }

    protected void givenViewAttached() {
Loading