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

Commit 4b60dc5a authored by Peter Kalauskas's avatar Peter Kalauskas
Browse files

Fade background when keyguard user switcher open

 - Bring back KeyguardUserSwitcherScrim for when the keyguard user
   switcher is opened

 - Remove callback for keyguard user switcher state changes

 - Do not try to change visibility of clock and notifications when user
   switcher is open

Test: Switch between primary user and guest repeatedly
Bug: 179930842
Change-Id: I3f3f10e8fa88c10b023bb74ca5b9d6f623b86516
parent 60cccdad
Loading
Loading
Loading
Loading
+6 −6
Original line number Diff line number Diff line
@@ -37,12 +37,6 @@
        android:layout_height="match_parent"
        android:layout_width="match_parent" />

    <ViewStub
        android:id="@+id/keyguard_user_switcher_stub"
        android:layout="@layout/keyguard_user_switcher"
        android:layout_height="match_parent"
        android:layout_width="match_parent" />

    <include
        layout="@layout/keyguard_status_view"
        android:visibility="gone" />
@@ -109,5 +103,11 @@
        layout="@layout/keyguard_bottom_area"
        android:visibility="gone" />

    <ViewStub
        android:id="@+id/keyguard_user_switcher_stub"
        android:layout="@layout/keyguard_user_switcher"
        android:layout_height="match_parent"
        android:layout_width="match_parent" />

    <include layout="@layout/status_bar_expanded_plugin_frame"/>
</com.android.systemui.statusbar.phone.NotificationPanelView>
+0 −46
Original line number Diff line number Diff line
@@ -287,21 +287,6 @@ public class NotificationPanelViewController extends PanelViewController {
                }
    };

    final KeyguardUserSwitcherController.KeyguardUserSwitcherListener
            mKeyguardUserSwitcherListener =
            new KeyguardUserSwitcherController.KeyguardUserSwitcherListener() {
                @Override
                public void onKeyguardUserSwitcherChanged(boolean open) {
                    if (mKeyguardUserSwitcherController == null) {
                        updateUserSwitcherVisibility(false);
                    } else if (!mKeyguardUserSwitcherController.isSimpleUserSwitcher()) {
                        updateUserSwitcherVisibility(open
                                && mKeyguardStateController.isShowing()
                                && !mKeyguardStateController.isKeyguardFadingAway());
                    }
                }
            };

    private final LayoutInflater mLayoutInflater;
    private final PowerManager mPowerManager;
    private final AccessibilityManager mAccessibilityManager;
@@ -329,7 +314,6 @@ public class NotificationPanelViewController extends PanelViewController {

    private KeyguardAffordanceHelper mAffordanceHelper;
    private KeyguardQsUserSwitchController mKeyguardQsUserSwitchController;
    private boolean mKeyguardUserSwitcherIsShowing;
    private KeyguardUserSwitcherController mKeyguardUserSwitcherController;
    private KeyguardStatusBarView mKeyguardStatusBar;
    private ViewGroup mBigClockContainer;
@@ -811,7 +795,6 @@ public class NotificationPanelViewController extends PanelViewController {
            // Try to close the switcher so that callbacks are triggered if necessary.
            // Otherwise, NPV can get into a state where some of the views are still hidden
            mKeyguardUserSwitcherController.closeSwitcherIfOpenAndNotSimple(false);
            mKeyguardUserSwitcherController.removeCallback();
        }

        mKeyguardQsUserSwitchController = null;
@@ -831,7 +814,6 @@ public class NotificationPanelViewController extends PanelViewController {
                    mKeyguardUserSwitcherComponentFactory.build(keyguardUserSwitcherView);
            mKeyguardUserSwitcherController =
                    userSwitcherComponent.getKeyguardUserSwitcherController();
            mKeyguardUserSwitcherController.setCallback(mKeyguardUserSwitcherListener);
            mKeyguardUserSwitcherController.init();
            mKeyguardStatusBar.setKeyguardUserSwitcherEnabled(true);
        } else {
@@ -3527,34 +3509,6 @@ public class NotificationPanelViewController extends PanelViewController {
        return false;
    }

    private void updateUserSwitcherVisibility(boolean open) {
        // Do not update if previously called with the same state.
        if (mKeyguardUserSwitcherIsShowing == open) {
            return;
        }
        mKeyguardUserSwitcherIsShowing = open;

        if (open) {
            animateKeyguardStatusBarOut();
            mKeyguardStatusViewController.setKeyguardStatusViewVisibility(
                    mBarState,
                    true /* keyguardFadingAway */,
                    true /* goingToFullShade */,
                    mBarState);
            setKeyguardBottomAreaVisibility(mBarState, true);
            mNotificationContainerParent.setVisibility(View.GONE);
        } else {
            animateKeyguardStatusBarIn(StackStateAnimator.ANIMATION_DURATION_STANDARD);
            mKeyguardStatusViewController.setKeyguardStatusViewVisibility(
                    StatusBarState.KEYGUARD,
                    false,
                    false,
                    StatusBarState.SHADE_LOCKED);
            setKeyguardBottomAreaVisibility(mBarState, false);
            mNotificationContainerParent.setVisibility(View.VISIBLE);
        }
    }

    private void updateDisabledUdfpsController() {
        final boolean udfpsEnrolled = mAuthController.getUdfpsRegion() != null
                && mAuthController.isUdfpsEnrolled(
+52 −59
Original line number Diff line number Diff line
@@ -19,9 +19,13 @@ package com.android.systemui.statusbar.policy;
import static com.android.systemui.statusbar.policy.UserSwitcherController.USER_SWITCH_DISABLED_ALPHA;
import static com.android.systemui.statusbar.policy.UserSwitcherController.USER_SWITCH_ENABLED_ALPHA;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.UserHandle;
@@ -50,7 +54,6 @@ import com.android.systemui.statusbar.notification.stack.StackStateAnimator;
import com.android.systemui.statusbar.phone.DozeParameters;
import com.android.systemui.util.ViewController;

import java.lang.ref.WeakReference;
import java.util.ArrayList;

import javax.inject.Inject;
@@ -73,9 +76,10 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
    private final KeyguardUserAdapter mAdapter;
    private final KeyguardStateController mKeyguardStateController;
    private final KeyguardUpdateMonitor mKeyguardUpdateMonitor;
    private WeakReference<KeyguardUserSwitcherListener> mKeyguardUserSwitcherCallback;
    protected final SysuiStatusBarStateController mStatusBarStateController;
    private final KeyguardVisibilityHelper mKeyguardVisibilityHelper;
    private ObjectAnimator mBgAnimator;
    private final KeyguardUserSwitcherScrim mBackground;

    // Child views of KeyguardUserSwitcherView
    private KeyguardUserSwitcherListView mListView;
@@ -171,6 +175,7 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
                mUserSwitcherController, this);
        mKeyguardVisibilityHelper = new KeyguardVisibilityHelper(mView,
                keyguardStateController, dozeParameters);
        mBackground = new KeyguardUserSwitcherScrim(context);
    }

    @Override
@@ -204,6 +209,9 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        mKeyguardUpdateMonitor.registerCallback(mInfoCallback);
        mStatusBarStateController.addCallback(mStatusBarStateListener);
        mScreenLifecycle.addObserver(mScreenObserver);
        mView.addOnLayoutChangeListener(mBackground);
        mView.setBackground(mBackground);
        mBackground.setAlpha(0);
    }

    @Override
@@ -217,6 +225,9 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        mKeyguardUpdateMonitor.removeCallback(mInfoCallback);
        mStatusBarStateController.removeCallback(mStatusBarStateListener);
        mScreenLifecycle.removeObserver(mScreenObserver);
        mView.removeOnLayoutChangeListener(mBackground);
        mView.setBackground(null);
        mBackground.setAlpha(0);
    }

    /**
@@ -338,6 +349,13 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
                animate);
        PropertyAnimator.setProperty(mListView, AnimatableProperty.TRANSLATION_X, -Math.abs(x),
                ANIMATION_PROPERTIES, animate);

        Rect r = new Rect();
        mListView.getDrawingRect(r);
        mView.offsetDescendantRectToMyCoords(mListView, r);
        mBackground.setGradientCenter(
                (int) (mListView.getTranslationX() + r.left + r.width() / 2),
                (int) (mListView.getTranslationY() + r.top + r.height() / 2));
    }

    /**
@@ -372,49 +390,52 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
    }

    /**
     * Remove the callback if it exists.
     */
    public void removeCallback() {
        if (DEBUG) Log.d(TAG, "removeCallback");
        mKeyguardUserSwitcherCallback = null;
    }

    /**
     * Register to receive notifications about keyguard user switcher state
     * (see {@link KeyguardUserSwitcherListener}.
     *
     * Only one callback can be used at a time.
     *
     * @param callback The callback to register
     */
    public void setCallback(KeyguardUserSwitcherListener callback) {
        if (DEBUG) Log.d(TAG, "setCallback");
        mKeyguardUserSwitcherCallback = new WeakReference<>(callback);
    }

    /**
     * If user switcher state changes, notifies all {@link KeyguardUserSwitcherListener}.
     * Switcher state is updatd before animations finish.
     * NOTE: switcher state is updated before animations finish.
     *
     * @param animate true to animate transition. The user switcher state (i.e.
     *                {@link #isUserSwitcherOpen()}) is updated before animation is finished.
     */
    private void setUserSwitcherOpened(boolean open, boolean animate) {
        boolean wasOpen = mUserSwitcherOpen;
        if (DEBUG) {
            Log.d(TAG, String.format("setUserSwitcherOpened: %b -> %b (animate=%b)", wasOpen,
                    open, animate));
            Log.d(TAG,
                    String.format("setUserSwitcherOpened: %b -> %b (animate=%b)",
                            mUserSwitcherOpen, open, animate));
        }
        mUserSwitcherOpen = open;
        if (mUserSwitcherOpen != wasOpen) {
            notifyUserSwitcherStateChanged();
        }
        updateVisibilities(animate);
    }

    private void updateVisibilities(boolean animate) {
        if (DEBUG) Log.d(TAG, String.format("updateVisibilities: animate=%b", animate));
        mEndGuestButton.animate().cancel();
        if (mBgAnimator != null) {
            mBgAnimator.cancel();
        }

        if (mUserSwitcherOpen) {
            mBgAnimator = ObjectAnimator.ofInt(mBackground, "alpha", 0, 255);
            mBgAnimator.setDuration(400);
            mBgAnimator.setInterpolator(Interpolators.ALPHA_IN);
            mBgAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mBgAnimator = null;
                }
            });
            mBgAnimator.start();
        } else {
            mBgAnimator = ObjectAnimator.ofInt(mBackground, "alpha", 255, 0);
            mBgAnimator.setDuration(400);
            mBgAnimator.setInterpolator(Interpolators.ALPHA_OUT);
            mBgAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mBgAnimator = null;
                }
            });
            mBgAnimator.start();
        }

        if (mUserSwitcherOpen && mCurrentUserIsGuest) {
            // Show the "End guest session" button
            mEndGuestButton.setVisibility(View.VISIBLE);
@@ -459,34 +480,6 @@ public class KeyguardUserSwitcherController extends ViewController<KeyguardUserS
        return mUserSwitcherOpen;
    }

    private void notifyUserSwitcherStateChanged() {
        if (DEBUG) {
            Log.d(TAG, String.format("notifyUserSwitcherStateChanged: mUserSwitcherOpen=%b",
                    mUserSwitcherOpen));
        }
        if (mKeyguardUserSwitcherCallback != null) {
            KeyguardUserSwitcherListener cb = mKeyguardUserSwitcherCallback.get();
            if (cb != null) {
                cb.onKeyguardUserSwitcherChanged(mUserSwitcherOpen);
            }
        }
    }

    /**
     * Callback for keyguard user switcher state information
     */
    public interface KeyguardUserSwitcherListener {

        /**
         * Called when the keyguard enters or leaves user switcher mode. This will be called
         * before the animations are finished.
         *
         * @param open if true, keyguard is showing the user switcher or transitioning from/to user
         *             switcher mode.
         */
        void onKeyguardUserSwitcherChanged(boolean open);
    }

    static class KeyguardUserAdapter extends
            UserSwitcherController.BaseUserAdapter implements View.OnClickListener {

+27 −18
Original line number Diff line number Diff line
@@ -26,7 +26,6 @@ import android.graphics.RadialGradient;
import android.graphics.Rect;
import android.graphics.Shader;
import android.graphics.drawable.Drawable;
import android.util.LayoutDirection;
import android.view.View;

import com.android.systemui.R;
@@ -38,13 +37,14 @@ public class KeyguardUserSwitcherScrim extends Drawable
        implements View.OnLayoutChangeListener {

    private static final float OUTER_EXTENT = 2.5f;
    private static final float INNER_EXTENT = 0.75f;
    private static final float INNER_EXTENT = 0.25f;

    private int mDarkColor;
    private int mTop;
    private int mAlpha = 255;
    private Paint mRadialGradientPaint = new Paint();
    private int mLayoutWidth;
    private int mCircleX;
    private int mCircleY;
    private int mSize;

    public KeyguardUserSwitcherScrim(Context context) {
        mDarkColor = context.getColor(
@@ -53,14 +53,11 @@ public class KeyguardUserSwitcherScrim extends Drawable

    @Override
    public void draw(Canvas canvas) {
        boolean isLtr = getLayoutDirection() == LayoutDirection.LTR;
        if (mAlpha == 0) {
            return;
        }
        Rect bounds = getBounds();
        float width = bounds.width() * OUTER_EXTENT;
        float height = (mTop + bounds.height()) * OUTER_EXTENT;
        canvas.translate(0, -mTop);
        canvas.scale(1, height / width);
        canvas.drawRect(isLtr ? bounds.right - width : 0, 0,
                isLtr ? bounds.right : bounds.left + width, width, mRadialGradientPaint);
        canvas.drawRect(bounds.left, bounds.top, bounds.right, bounds.bottom, mRadialGradientPaint);
    }

    @Override
@@ -88,24 +85,36 @@ public class KeyguardUserSwitcherScrim extends Drawable
    public void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft,
            int oldTop, int oldRight, int oldBottom) {
        if (left != oldLeft || top != oldTop || right != oldRight || bottom != oldBottom) {
            mLayoutWidth = right - left;
            mTop = top;
            int width = right - left;
            int height = bottom - top;
            mSize = Math.max(width, height);
            updatePaint();
        }
    }

    private void updatePaint() {
        if (mLayoutWidth == 0) {
        if (mSize == 0) {
            return;
        }
        float radius = mLayoutWidth * OUTER_EXTENT;
        boolean isLtr = getLayoutDirection() == LayoutDirection.LTR;
        float outerRadius = mSize * OUTER_EXTENT;
        mRadialGradientPaint.setShader(
                new RadialGradient(isLtr ? mLayoutWidth : 0, 0, radius,
                new RadialGradient(mCircleX, mCircleY, outerRadius,
                        new int[] { Color.argb(
                                        (int) (Color.alpha(mDarkColor) * mAlpha / 255f), 0, 0, 0),
                                Color.TRANSPARENT },
                        new float[] { Math.max(0f, mLayoutWidth * INNER_EXTENT / radius), 1f },
                        new float[] { Math.max(0f, INNER_EXTENT / OUTER_EXTENT), 1f },
                        Shader.TileMode.CLAMP));
    }

    /**
     * Sets the center of the radial gradient used as a background
     *
     * @param x
     * @param y
     */
    public void setGradientCenter(int x, int y) {
        mCircleX = x;
        mCircleY = y;
        updatePaint();
    }
}