summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java39
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/car/FullscreenUserSwitcher.java115
2 files changed, 65 insertions, 89 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
index ed067525ed61..304a00fbba4a 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/CarStatusBar.java
@@ -495,32 +495,37 @@ public class CarStatusBar extends StatusBar implements
}
@Override
- public void onUserSwitched(int newUserId) {
- super.onUserSwitched(newUserId);
- if (mFullscreenUserSwitcher != null) {
- mFullscreenUserSwitcher.onUserSwitched(newUserId);
- }
- }
-
- @Override
public void onStateChanged(int newState) {
super.onStateChanged(newState);
- CarUserManagerHelper helper = new CarUserManagerHelper(mContext);
- if (!helper.isHeadlessSystemUser()) {
- showUserSwitcher();
+ if (newState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
+ if (!mFullscreenUserSwitcher.isVisible()) {
+ // Current execution path continues to set state after this, thus we deffer the
+ // dismissal to the next execution cycle.
+ postDismissKeyguard(); // Dismiss the keyguard if switcher is not visible.
+ }
+ } else {
+ mFullscreenUserSwitcher.hide();
}
}
public void showUserSwitcher() {
- if (mFullscreenUserSwitcher != null) {
- if (mState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
- mFullscreenUserSwitcher.show();
- } else {
- mFullscreenUserSwitcher.hide();
- }
+ if (mFullscreenUserSwitcher != null && mState == StatusBarState.FULLSCREEN_USER_SWITCHER) {
+ mFullscreenUserSwitcher.show(); // Makes the switcher visible.
}
}
+ public void postDismissKeyguard() {
+ mHandler.post(this::dismissKeyguard);
+ }
+
+ /**
+ * Dismisses the keyguard and shows bouncer if authentication is necessary.
+ */
+ public void dismissKeyguard() {
+ executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */,
+ true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */);
+ }
+
@Override
public void updateMediaMetaData(boolean metaDataChanged, boolean allowEnterAnimation) {
// Do nothing, we don't want to display media art in the lock screen for a car.
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/car/FullscreenUserSwitcher.java b/packages/SystemUI/src/com/android/systemui/statusbar/car/FullscreenUserSwitcher.java
index 67a76fd86ba7..2ebf5eb39bf6 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/car/FullscreenUserSwitcher.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/car/FullscreenUserSwitcher.java
@@ -18,7 +18,6 @@ package com.android.systemui.statusbar.car;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
-import android.car.user.CarUserManagerHelper;
import android.content.Context;
import android.view.View;
import android.view.ViewStub;
@@ -26,115 +25,87 @@ import android.view.ViewStub;
import androidx.recyclerview.widget.GridLayoutManager;
import com.android.systemui.R;
-import com.android.systemui.statusbar.phone.StatusBar;
/**
* Manages the fullscreen user switcher.
*/
public class FullscreenUserSwitcher {
- private final View mContainer;
- private final View mParent;
private final UserGridRecyclerView mUserGridView;
+ private final View mParent;
private final int mShortAnimDuration;
- private final StatusBar mStatusBar;
- private final CarUserManagerHelper mCarUserManagerHelper;
- private boolean mShowing;
+ private final CarStatusBar mStatusBar;
- public FullscreenUserSwitcher(StatusBar statusBar, ViewStub containerStub, Context context) {
+ public FullscreenUserSwitcher(CarStatusBar statusBar, ViewStub containerStub, Context context) {
mStatusBar = statusBar;
mParent = containerStub.inflate();
- mContainer = mParent.findViewById(R.id.container);
- mUserGridView = mContainer.findViewById(R.id.user_grid);
+ mParent.setVisibility(View.VISIBLE);
+ View container = mParent.findViewById(R.id.container);
+
+ // Initialize user grid.
+ mUserGridView = container.findViewById(R.id.user_grid);
GridLayoutManager layoutManager = new GridLayoutManager(context,
- context.getResources().getInteger(R.integer.user_fullscreen_switcher_num_col));
+ context.getResources().getInteger(R.integer.user_fullscreen_switcher_num_col));
mUserGridView.getRecyclerView().setLayoutManager(layoutManager);
mUserGridView.buildAdapter();
mUserGridView.setUserSelectionListener(this::onUserSelected);
- mCarUserManagerHelper = new CarUserManagerHelper(context);
+ // Hide the user grid by default. It will only be made visible by clicking on a cancel
+ // button in a bouncer.
+ hide();
- mShortAnimDuration = mContainer.getResources()
+ mShortAnimDuration = container.getResources()
.getInteger(android.R.integer.config_shortAnimTime);
}
+ /**
+ * Makes user grid visible.
+ */
public void show() {
- if (mCarUserManagerHelper.isHeadlessSystemUser()) {
- showUserGrid();
- }
- if (mShowing) {
- return;
- }
- mShowing = true;
- mParent.setVisibility(View.VISIBLE);
+ mUserGridView.setVisibility(View.VISIBLE);
}
+ /**
+ * Hides the user grid.
+ */
public void hide() {
- mShowing = false;
- mParent.setVisibility(View.GONE);
+ mUserGridView.setVisibility(View.INVISIBLE);
}
- public void onUserSwitched(int newUserId) {
- toggleSwitchInProgress(false);
- mParent.post(this::dismissKeyguard);
+ /**
+ * @return {@code true} if user grid is visible, {@code false} otherwise.
+ */
+ public boolean isVisible() {
+ return mUserGridView.getVisibility() == View.VISIBLE;
}
+ /**
+ * Every time user clicks on an item in the switcher, we hide the switcher, either
+ * gradually or immediately.
+ *
+ * We dismiss the entire keyguard if user clicked on the foreground user (user we're already
+ * logged in as).
+ */
private void onUserSelected(UserGridRecyclerView.UserRecord record) {
- if (mCarUserManagerHelper.isHeadlessSystemUser()) {
- hideUserGrid();
- }
-
- if (record.mIsForeground || (record.mIsStartGuestSession
- && mCarUserManagerHelper.isForegroundUserGuest())) {
- dismissKeyguard();
+ if (record.mIsForeground) {
+ hide();
+ mStatusBar.dismissKeyguard();
return;
}
- toggleSwitchInProgress(true);
- }
-
- private void showUserGrid() {
- mUserGridView.setVisibility(View.VISIBLE);
+ // Switching is about to happen, since it takes time, fade out the switcher gradually.
+ fadeOut();
}
- private void hideUserGrid() {
- mUserGridView.setVisibility(View.INVISIBLE);
- }
-
- // Dismisses the keyguard and shows bouncer if authentication is necessary.
- private void dismissKeyguard() {
- mStatusBar.executeRunnableDismissingKeyguard(null/* runnable */, null /* cancelAction */,
- true /* dismissShade */, true /* afterKeyguardGone */, true /* deferred */);
- }
-
- private void toggleSwitchInProgress(boolean inProgress) {
- if (inProgress) {
- fadeOut(mContainer);
- } else {
- fadeIn(mContainer);
- }
- }
-
- private void fadeOut(View view) {
- view.animate()
+ private void fadeOut() {
+ mUserGridView.animate()
.alpha(0.0f)
.setDuration(mShortAnimDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
- view.setVisibility(View.GONE);
+ hide();
+ mUserGridView.setAlpha(1.0f);
}
});
- }
- private void fadeIn(View view) {
- view.animate()
- .alpha(1.0f)
- .setDuration(mShortAnimDuration)
- .setListener(new AnimatorListenerAdapter() {
- @Override
- public void onAnimationStart(Animator animator) {
- view.setAlpha(0.0f);
- view.setVisibility(View.VISIBLE);
- }
- });
}
-}
+} \ No newline at end of file