Merge "Reduce user icon RAM usage" into lmp-mr1-dev

This commit is contained in:
Adrian Roos
2014-11-17 16:43:49 +00:00
committed by Android (Google) Code Review
7 changed files with 38 additions and 19 deletions

View File

@@ -38,8 +38,8 @@
android:layout_alignParentEnd="true" android:layout_alignParentEnd="true"
android:background="@drawable/ripple_drawable" > android:background="@drawable/ripple_drawable" >
<ImageView android:id="@+id/multi_user_avatar" <ImageView android:id="@+id/multi_user_avatar"
android:layout_width="24dp" android:layout_width="@dimen/multi_user_avatar_expanded_size"
android:layout_height="24dp" android:layout_height="@dimen/multi_user_avatar_expanded_size"
android:layout_gravity="center" android:layout_gravity="center"
android:scaleType="centerInside"/> android:scaleType="centerInside"/>
</com.android.systemui.statusbar.phone.MultiUserSwitch> </com.android.systemui.statusbar.phone.MultiUserSwitch>

View File

@@ -405,6 +405,9 @@
<!-- The width of user avatar when on Keyguard --> <!-- The width of user avatar when on Keyguard -->
<dimen name="multi_user_avatar_keyguard_size">22dp</dimen> <dimen name="multi_user_avatar_keyguard_size">22dp</dimen>
<!-- The width of user avatar when expanded -->
<dimen name="multi_user_avatar_expanded_size">24dp</dimen>
<!-- The font size of the time when collapsed in QS --> <!-- The font size of the time when collapsed in QS -->
<dimen name="qs_time_collapsed_size">14sp</dimen> <dimen name="qs_time_collapsed_size">14sp</dimen>

View File

@@ -67,15 +67,18 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
@Override @Override
public void onClick(View v) { public void onClick(View v) {
if (opensUserSwitcherWhenClicked()) { if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)) {
if (mKeyguardMode) { if (mKeyguardMode) {
if (mKeyguardUserSwitcher != null) { if (mKeyguardUserSwitcher != null) {
mKeyguardUserSwitcher.show(true /* animate */); mKeyguardUserSwitcher.show(true /* animate */);
} }
} else { } else {
if (mQsPanel != null) { if (mQsPanel != null) {
mQsPanel.showDetailAdapter(true, UserSwitcherController userSwitcherController =
mQsPanel.getHost().getUserSwitcherController().userDetailAdapter); mQsPanel.getHost().getUserSwitcherController();
if (userSwitcherController != null) {
mQsPanel.showDetailAdapter(true, userSwitcherController.userDetailAdapter);
}
} }
} }
} else { } else {
@@ -92,12 +95,14 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
if (isClickable()) { if (isClickable()) {
String text; String text;
if (opensUserSwitcherWhenClicked()) { if (UserSwitcherController.isUserSwitcherAvailable(mUserManager)) {
String currentUser = null; String currentUser = null;
if (mQsPanel != null) { if (mQsPanel != null) {
UserSwitcherController controller = mQsPanel.getHost() UserSwitcherController controller = mQsPanel.getHost()
.getUserSwitcherController(); .getUserSwitcherController();
currentUser = controller.getCurrentUserName(mContext); if (controller != null) {
currentUser = controller.getCurrentUserName(mContext);
}
} }
if (TextUtils.isEmpty(currentUser)) { if (TextUtils.isEmpty(currentUser)) {
text = mContext.getString(R.string.accessibility_multi_user_switch_switcher); text = mContext.getString(R.string.accessibility_multi_user_switch_switcher);
@@ -121,8 +126,4 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
return false; return false;
} }
private boolean opensUserSwitcherWhenClicked() {
UserManager um = UserManager.get(getContext());
return UserManager.supportsMultipleUsers() && um.isUserSwitcherEnabled();
}
} }

View File

@@ -74,6 +74,7 @@ import android.os.PowerManager;
import android.os.RemoteException; import android.os.RemoteException;
import android.os.SystemClock; import android.os.SystemClock;
import android.os.UserHandle; import android.os.UserHandle;
import android.os.UserManager;
import android.provider.Settings; import android.provider.Settings;
import android.service.notification.NotificationListenerService; import android.service.notification.NotificationListenerService;
import android.service.notification.NotificationListenerService.RankingMap; import android.service.notification.NotificationListenerService.RankingMap;
@@ -853,8 +854,9 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
mKeyguardBottomArea.setAccessibilityController(mAccessibilityController); mKeyguardBottomArea.setAccessibilityController(mAccessibilityController);
mNextAlarmController = new NextAlarmController(mContext); mNextAlarmController = new NextAlarmController(mContext);
mKeyguardMonitor = new KeyguardMonitor(); mKeyguardMonitor = new KeyguardMonitor();
mUserSwitcherController = new UserSwitcherController(mContext, mKeyguardMonitor); if (UserSwitcherController.isUserSwitcherAvailable(UserManager.get(mContext))) {
mUserSwitcherController = new UserSwitcherController(mContext, mKeyguardMonitor);
}
mKeyguardUserSwitcher = new KeyguardUserSwitcher(mContext, mKeyguardUserSwitcher = new KeyguardUserSwitcher(mContext,
(ViewStub) mStatusBarWindow.findViewById(R.id.keyguard_user_switcher), (ViewStub) mStatusBarWindow.findViewById(R.id.keyguard_user_switcher),
mKeyguardStatusBar, mNotificationPanel, mUserSwitcherController); mKeyguardStatusBar, mNotificationPanel, mUserSwitcherController);
@@ -1510,7 +1512,8 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode,
// If the user switcher is simple then disable QS during setup because // If the user switcher is simple then disable QS during setup because
// the user intends to use the lock screen user switcher, QS in not needed. // the user intends to use the lock screen user switcher, QS in not needed.
mNotificationPanel.setQsExpansionEnabled(isDeviceProvisioned() mNotificationPanel.setQsExpansionEnabled(isDeviceProvisioned()
&& (!mUserSwitcherController.isSimpleUserSwitcher() || mUserSetup)); && (mUserSetup || mUserSwitcherController == null
|| !mUserSwitcherController.isSimpleUserSwitcher()));
mShadeUpdates.check(); mShadeUpdates.check();
} }

View File

@@ -58,7 +58,9 @@ public class KeyguardUserSwitcher {
public KeyguardUserSwitcher(Context context, ViewStub userSwitcher, public KeyguardUserSwitcher(Context context, ViewStub userSwitcher,
KeyguardStatusBarView statusBarView, NotificationPanelView panelView, KeyguardStatusBarView statusBarView, NotificationPanelView panelView,
UserSwitcherController userSwitcherController) { UserSwitcherController userSwitcherController) {
if (context.getResources().getBoolean(R.bool.config_keyguardUserSwitcher) || ALWAYS_ON) { boolean keyguardUserSwitcherEnabled =
context.getResources().getBoolean(R.bool.config_keyguardUserSwitcher) || ALWAYS_ON;
if (userSwitcherController != null && keyguardUserSwitcherEnabled) {
mUserSwitcherContainer = (Container) userSwitcher.inflate(); mUserSwitcherContainer = (Container) userSwitcher.inflate();
mUserSwitcher = (ViewGroup) mUserSwitcher = (ViewGroup)
mUserSwitcherContainer.findViewById(R.id.keyguard_user_switcher_inner); mUserSwitcherContainer.findViewById(R.id.keyguard_user_switcher_inner);

View File

@@ -23,6 +23,7 @@ import android.content.Intent;
import android.content.IntentFilter; import android.content.IntentFilter;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
import android.content.pm.UserInfo; import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.database.Cursor; import android.database.Cursor;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable; import android.graphics.drawable.BitmapDrawable;
@@ -131,8 +132,11 @@ public final class UserInfoController {
final int userId = userInfo.id; final int userId = userInfo.id;
final boolean isGuest = userInfo.isGuest(); final boolean isGuest = userInfo.isGuest();
final String userName = userInfo.name; final String userName = userInfo.name;
final int avatarSize
= mContext.getResources().getDimensionPixelSize(R.dimen.max_avatar_size); final Resources res = mContext.getResources();
final int avatarSize = Math.max(
res.getDimensionPixelSize(R.dimen.multi_user_avatar_expanded_size),
res.getDimensionPixelSize(R.dimen.multi_user_avatar_keyguard_size));
final Context context = currentUserContext; final Context context = currentUserContext;
mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() { mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
@@ -160,8 +164,9 @@ public final class UserInfoController {
// Try and read the display name from the local profile // Try and read the display name from the local profile
final Cursor cursor = context.getContentResolver().query( final Cursor cursor = context.getContentResolver().query(
ContactsContract.Profile.CONTENT_URI, new String[] { ContactsContract.Profile.CONTENT_URI, new String[] {
ContactsContract.CommonDataKinds.Phone._ID, ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME}, ContactsContract.CommonDataKinds.Phone._ID,
null, null, null); ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME
}, null, null, null);
if (cursor != null) { if (cursor != null) {
try { try {
if (cursor.moveToFirst()) { if (cursor.moveToFirst()) {

View File

@@ -589,4 +589,9 @@ public class UserSwitcherController {
} }
} }
} }
public static boolean isUserSwitcherAvailable(UserManager um) {
return UserManager.supportsMultipleUsers() && um.isUserSwitcherEnabled();
}
} }