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

Commit 37e2f8d5 authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Fix animation bugs in keyguard user switcher

 - Fix bug where user detail items disappeared too quickly when closing
   the user switcher.

 - Change input to clock position algorithm so that it no longer pushes
   the clock down when the keyguard user switcher is used.

 - Cleanup updateVisibilities() for readability

Bug: 181265906
Bug: 169783558
Test: Open and close keyguard user switcher

Change-Id: Ib83a5666ca548d78e39ac2a6d0ded6925bcadcb2
parent 13c23428
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -1051,9 +1051,7 @@ public class NotificationPanelViewController extends PanelViewController {
                    .getVisibleNotificationCount() != 0 || mMediaDataManager.hasActiveMedia();
            mKeyguardStatusViewController.setHasVisibleNotifications(hasVisibleNotifications);
            int userIconHeight = mKeyguardQsUserSwitchController != null
                    ? mKeyguardQsUserSwitchController.getUserIconHeight()
                    : (mKeyguardUserSwitcherController != null
                            ? mKeyguardUserSwitcherController.getUserIconHeight() : 0);
                    ? mKeyguardQsUserSwitchController.getUserIconHeight() : 0;
            mClockPositionAlgorithm.setup(mStatusBarHeaderHeightKeyguard,
                    totalHeight - bottomPadding,
                    mNotificationStackScrollLayoutController.getIntrinsicContentHeight(),
+0 −8
Original line number Diff line number Diff line
@@ -321,14 +321,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        }
    }

    /**
     * Get the height of the keyguard user switcher view when closed.
     */
    public int getUserIconHeight() {
        View firstChild = mListView.getChildAt(0);
        return firstChild == null ? 0 : firstChild.getHeight();
    }

    /**
     * Set the visibility of the keyguard user switcher view based on some new state.
     */
+37 −64
Original line number Diff line number Diff line
@@ -35,20 +35,22 @@ public class KeyguardUserSwitcherListView extends AlphaOptimizedLinearLayout {
    private static final String TAG = "KeyguardUserSwitcherListView";
    private static final boolean DEBUG = KeyguardConstants.DEBUG;

    private static final int ANIMATION_DURATION_OPENING = 360;
    private static final int ANIMATION_DURATION_CLOSING = 240;

    private boolean mAnimating;
    private final AppearAnimationUtils mAppearAnimationUtils;
    private final DisappearAnimationUtils mDisappearAnimationUtils;

    public KeyguardUserSwitcherListView(Context context, AttributeSet attrs) {
        super(context, attrs);
        setClipChildren(false);
        mAppearAnimationUtils = new AppearAnimationUtils(context, ANIMATION_DURATION_OPENING,
                -0.5f, 0.5f, Interpolators.FAST_OUT_SLOW_IN);
        mDisappearAnimationUtils = new DisappearAnimationUtils(context, ANIMATION_DURATION_CLOSING,
                0.5f, 0.5f, Interpolators.FAST_OUT_LINEAR_IN);
        mAppearAnimationUtils = new AppearAnimationUtils(context,
                AppearAnimationUtils.DEFAULT_APPEAR_DURATION,
                -0.5f /* translationScaleFactor */,
                0.5f /* delayScaleFactor */,
                Interpolators.FAST_OUT_SLOW_IN);
        mDisappearAnimationUtils = new DisappearAnimationUtils(context,
                AppearAnimationUtils.DEFAULT_APPEAR_DURATION,
                0.2f /* translationScaleFactor */,
                0.2f /* delayScaleFactor */,
                Interpolators.FAST_OUT_SLOW_IN_REVERSE);
    }

    /**
@@ -82,70 +84,41 @@ public class KeyguardUserSwitcherListView extends AlphaOptimizedLinearLayout {

        mAnimating = false;

        int userListCount = getChildCount();
        if (userListCount > 0) {
        int childCount = getChildCount();
        KeyguardUserDetailItemView[] userItemViews = new KeyguardUserDetailItemView[childCount];
        for (int i = 0; i < childCount; i++) {
            userItemViews[i] = (KeyguardUserDetailItemView) getChildAt(i);
            userItemViews[i].clearAnimation();
            if (i == 0) {
                // The first child is always the current user.
            KeyguardUserDetailItemView currentUserView = ((KeyguardUserDetailItemView) getChildAt(
                    0));
            currentUserView.updateVisibilities(true /* showItem */, open /* showTextName */,
                userItemViews[i].updateVisibilities(true /* showItem */, open /* showTextName */,
                        animate);
            currentUserView.setClickable(true);
            currentUserView.clearAnimation();
                userItemViews[i].setClickable(true);
            } else {
                // Update clickable state immediately so that the menu feels more responsive
                userItemViews[i].setClickable(open);
                // Before running the animation, ensure visibility is set correctly
                userItemViews[i].updateVisibilities(animate || open /* showItem */,
                        true /* showTextName */, false /* animate */);
            }

        if (userListCount <= 1) {
            return;
        }

        if (animate) {
            // Create an array of all the remaining users (that aren't the current user).
            KeyguardUserDetailItemView[] otherUserViews =
                    new KeyguardUserDetailItemView[userListCount - 1];
            for (int i = 1, n = 0; i < userListCount; i++, n++) {
                otherUserViews[n] = (KeyguardUserDetailItemView) getChildAt(i);

                // Update clickable state immediately so that the menu feels more responsive
                otherUserViews[n].setClickable(open);

                // Before running the animation, ensure visibility is set correctly
                otherUserViews[n].updateVisibilities(
                        true /* showItem */, true /* showTextName */, false /* animate */);
                otherUserViews[n].clearAnimation();
            }
            // AnimationUtils will immediately hide/show the first item in the array. Since the
            // first view is the current user, we want to manage its visibility separately.
            // Set first item to null so AnimationUtils ignores it.
            userItemViews[0] = null;

            setClipChildren(false);
            setClipToPadding(false);

            mAnimating = true;

            final int nonCurrentUserCount = otherUserViews.length;
            if (open) {
                mAppearAnimationUtils.startAnimation(otherUserViews, () -> {
                    setClipChildren(true);
                    setClipToPadding(true);
                    mAnimating = false;
                });
            } else {
                mDisappearAnimationUtils.startAnimation(otherUserViews, () -> {
            (open ? mAppearAnimationUtils : mDisappearAnimationUtils)
                    .startAnimation(userItemViews, () -> {
                        setClipChildren(true);
                        setClipToPadding(true);
                    for (int i = 0; i < nonCurrentUserCount; i++) {
                        otherUserViews[i].updateVisibilities(
                                false /* showItem */, true /* showTextName */, false /* animate */);
                    }
                        mAnimating = false;
                    });
        }
        } else {
            for (int i = 1; i < userListCount; i++) {
                KeyguardUserDetailItemView nonCurrentUserView =
                        ((KeyguardUserDetailItemView) getChildAt(i));
                nonCurrentUserView.clearAnimation();
                nonCurrentUserView.updateVisibilities(
                        open /* showItem */, true /* showTextName */, false /* animate */);
                nonCurrentUserView.setClickable(open);
            }
        }
    }

    /**