From 8ba446c9bad94e91cf83c579261298552d51d249 Mon Sep 17 00:00:00 2001 From: Daniel Nishi Date: Mon, 20 Jun 2016 18:56:35 -0700 Subject: [PATCH] On phones, don't show the avatar icon when it is the only user. The keyguard user switcher isn't enabled for layouts under 600dp width. For these thinner devices, we don't show the multi-user switch view when there is only one user. In order to update this visibility when user changes occur, we re-calculate the visibilities when the keyguard status bar view is made visible again. Bug: 28795981 Change-Id: I980a4c400adc1d9a6c0ce3465854284997e86596 --- .../statusbar/phone/KeyguardStatusBarView.java | 13 +++++++++++++ .../statusbar/policy/UserSwitcherController.java | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java index 7db2870620a02..d5ff0b356d6db 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardStatusBarView.java @@ -56,6 +56,7 @@ public class KeyguardStatusBarView extends RelativeLayout private BatteryController mBatteryController; private KeyguardUserSwitcher mKeyguardUserSwitcher; + private UserSwitcherController mUserSwitcherController; private int mSystemIconsSwitcherHiddenExpandedMargin; private View mSystemIconsContainer; @@ -149,6 +150,15 @@ public class KeyguardStatusBarView extends RelativeLayout } else if (mMultiUserSwitch.getParent() == this && mKeyguardUserSwitcherShowing) { removeView(mMultiUserSwitch); } + if (mKeyguardUserSwitcher == null) { + // If we have no keyguard switcher, the screen width is under 600dp. In this case, + // we don't show the multi-user avatar unless there is more than 1 user on the device. + if (mUserSwitcherController.getSwitchableUserCount() > 1) { + mMultiUserSwitch.setVisibility(View.VISIBLE); + } else { + mMultiUserSwitch.setVisibility(View.GONE); + } + } mBatteryLevel.setVisibility(mBatteryCharging ? View.VISIBLE : View.GONE); } @@ -187,6 +197,7 @@ public class KeyguardStatusBarView extends RelativeLayout } public void setUserSwitcherController(UserSwitcherController controller) { + mUserSwitcherController = controller; mMultiUserSwitch.setUserSwitcherController(controller); } @@ -287,6 +298,8 @@ public class KeyguardStatusBarView extends RelativeLayout mSystemIconsSuperContainer.animate().cancel(); mMultiUserSwitch.animate().cancel(); mMultiUserSwitch.setAlpha(1f); + } else { + updateVisibilities(); } } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java index 89d2712db0d05..379ad53c6dba5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java @@ -381,6 +381,18 @@ public class UserSwitcherController { Log.e(TAG, "Couldn't switch to user, id=" + userId); } + public int getSwitchableUserCount() { + int count = 0; + final int N = mUsers.size(); + for (int i = 0; i < N; ++i) { + UserRecord record = mUsers.get(i); + if (record.info != null && record.info.supportsSwitchTo()) { + count++; + } + } + return count; + } + private void switchToUserId(int id) { try { pauseRefreshUsers();