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

Commit 791332f4 authored by Riddle Hsu's avatar Riddle Hsu
Browse files

Add debounce for hide animation of fixed rotation recents

If navigation bar is pressed, it may trigger recents animation with
fixed rotation, and if the touch is released immediately, the show/hide
animation will apply in a short time that looks blinking.

Bug: 160238664
Test: With 2 button navigation, launch a landscape activity and press
      home key. The status bar should fade out and fade in smoothly.

Change-Id: I2e92e614c95b30a1e5de53e28b4140a430015414
parent 83d5c830
Loading
Loading
Loading
Loading
+32 −4
Original line number Original line Diff line number Diff line
@@ -490,6 +490,8 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
     */
     */
    private ActivityRecord mFixedRotationLaunchingApp;
    private ActivityRecord mFixedRotationLaunchingApp;


    /** The delay to avoid toggling the animation quickly. */
    private static final long FIXED_ROTATION_HIDE_ANIMATION_DEBOUNCE_DELAY_MS = 250;
    private FixedRotationAnimationController mFixedRotationAnimationController;
    private FixedRotationAnimationController mFixedRotationAnimationController;


    final FixedRotationTransitionListener mFixedRotationTransitionListener =
    final FixedRotationTransitionListener mFixedRotationTransitionListener =
@@ -1524,10 +1526,10 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
    void setFixedRotationLaunchingAppUnchecked(@Nullable ActivityRecord r, int rotation) {
    void setFixedRotationLaunchingAppUnchecked(@Nullable ActivityRecord r, int rotation) {
        if (mFixedRotationLaunchingApp == null && r != null) {
        if (mFixedRotationLaunchingApp == null && r != null) {
            mWmService.mDisplayNotificationController.dispatchFixedRotationStarted(this, rotation);
            mWmService.mDisplayNotificationController.dispatchFixedRotationStarted(this, rotation);
            if (mFixedRotationAnimationController == null) {
            startFixedRotationAnimation(
                mFixedRotationAnimationController = new FixedRotationAnimationController(this);
                    // Delay the hide animation to avoid blinking by clicking navigation bar that
                mFixedRotationAnimationController.hide();
                    // may toggle fixed rotation in a short time.
            }
                    r == mFixedRotationTransitionListener.mAnimatingRecents /* shouldDebounce */);
        } else if (mFixedRotationLaunchingApp != null && r == null) {
        } else if (mFixedRotationLaunchingApp != null && r == null) {
            mWmService.mDisplayNotificationController.dispatchFixedRotationFinished(this);
            mWmService.mDisplayNotificationController.dispatchFixedRotationFinished(this);
            finishFixedRotationAnimationIfPossible();
            finishFixedRotationAnimationIfPossible();
@@ -1625,6 +1627,32 @@ class DisplayContent extends RootDisplayArea implements WindowManagerPolicy.Disp
        }
        }
    }
    }


    /**
     * Starts the hide animation for the windows which will be rotated seamlessly.
     *
     * @return {@code true} if the animation is executed right now.
     */
    private boolean startFixedRotationAnimation(boolean shouldDebounce) {
        if (shouldDebounce) {
            mWmService.mH.postDelayed(() -> {
                synchronized (mWmService.mGlobalLock) {
                    if (mFixedRotationLaunchingApp != null
                            && startFixedRotationAnimation(false /* shouldDebounce */)) {
                        // Apply the transaction so the animation leash can take effect immediately.
                        getPendingTransaction().apply();
                    }
                }
            }, FIXED_ROTATION_HIDE_ANIMATION_DEBOUNCE_DELAY_MS);
            return false;
        }
        if (mFixedRotationAnimationController == null) {
            mFixedRotationAnimationController = new FixedRotationAnimationController(this);
            mFixedRotationAnimationController.hide();
            return true;
        }
        return false;
    }

    /** Re-show the previously hidden windows if all seamless rotated windows are done. */
    /** Re-show the previously hidden windows if all seamless rotated windows are done. */
    void finishFixedRotationAnimationIfPossible() {
    void finishFixedRotationAnimationIfPossible() {
        final FixedRotationAnimationController controller = mFixedRotationAnimationController;
        final FixedRotationAnimationController controller = mFixedRotationAnimationController;