Fix user color overlay is not applied
Resource overlay is now done in runtime with non-system resources object. Amend getDefaultUserIcon to take resources object as parameter. BUG: 69355037 Test: Factory reset, verify that overlayed color is used in multiple places, including keyguard, the bar under quick settings and Settings app. Change-Id: I20b0527bdcb2eb38e8bea6a05f53eea1edcba932
This commit is contained in:
@@ -2476,7 +2476,8 @@ public class ApplicationPackageManager extends PackageManager {
|
||||
if (itemInfo.showUserIcon != UserHandle.USER_NULL) {
|
||||
Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon);
|
||||
if (bitmap == null) {
|
||||
return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false);
|
||||
return UserIcons.getDefaultUserIcon(
|
||||
mContext.getResources(), itemInfo.showUserIcon, /* light= */ false);
|
||||
}
|
||||
return new BitmapDrawable(bitmap);
|
||||
}
|
||||
|
||||
@@ -61,17 +61,19 @@ public class UserIcons {
|
||||
* Returns a default user icon for the given user.
|
||||
*
|
||||
* Note that for guest users, you should pass in {@code UserHandle.USER_NULL}.
|
||||
*
|
||||
* @param resources resources object to fetch user icon / color.
|
||||
* @param userId the user id or {@code UserHandle.USER_NULL} for a non-user specific icon
|
||||
* @param light whether we want a light icon (suitable for a dark background)
|
||||
*/
|
||||
public static Drawable getDefaultUserIcon(int userId, boolean light) {
|
||||
public static Drawable getDefaultUserIcon(Resources resources, int userId, boolean light) {
|
||||
int colorResId = light ? R.color.user_icon_default_white : R.color.user_icon_default_gray;
|
||||
if (userId != UserHandle.USER_NULL) {
|
||||
// Return colored icon instead
|
||||
colorResId = USER_ICON_COLORS[userId % USER_ICON_COLORS.length];
|
||||
}
|
||||
Drawable icon = Resources.getSystem().getDrawable(R.drawable.ic_account_circle, null).mutate();
|
||||
icon.setColorFilter(Resources.getSystem().getColor(colorResId, null), Mode.SRC_IN);
|
||||
Drawable icon = resources.getDrawable(R.drawable.ic_account_circle, null).mutate();
|
||||
icon.setColorFilter(resources.getColor(colorResId, null), Mode.SRC_IN);
|
||||
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
|
||||
return icon;
|
||||
}
|
||||
|
||||
@@ -105,7 +105,8 @@ public class Utils {
|
||||
}
|
||||
}
|
||||
return new UserIconDrawable(iconSize).setIconDrawable(
|
||||
UserIcons.getDefaultUserIcon(user.id, /* light= */ false)).bake();
|
||||
UserIcons.getDefaultUserIcon(context.getResources(), user.id, /* light= */ false))
|
||||
.bake();
|
||||
}
|
||||
|
||||
/** Formats a double from 0.0..100.0 with an option to round **/
|
||||
|
||||
@@ -64,7 +64,8 @@ public class UserAdapter implements SpinnerAdapter, ListAdapter {
|
||||
if (um.getUserIcon(userId) != null) {
|
||||
icon = new BitmapDrawable(context.getResources(), um.getUserIcon(userId));
|
||||
} else {
|
||||
icon = UserIcons.getDefaultUserIcon(userId, /* light= */ false);
|
||||
icon = UserIcons.getDefaultUserIcon(
|
||||
context.getResources(), userId, /* light= */ false);
|
||||
}
|
||||
}
|
||||
this.mIcon = encircle(context, icon);
|
||||
|
||||
@@ -154,7 +154,9 @@ public class UserInfoControllerImpl implements UserInfoController {
|
||||
avatar = new UserIconDrawable(avatarSize)
|
||||
.setIcon(rawAvatar).setBadgeIfManagedUser(mContext, userId).bake();
|
||||
} else {
|
||||
avatar = UserIcons.getDefaultUserIcon(isGuest? UserHandle.USER_NULL : userId,
|
||||
avatar = UserIcons.getDefaultUserIcon(
|
||||
context.getResources(),
|
||||
isGuest? UserHandle.USER_NULL : userId,
|
||||
lightIcon);
|
||||
}
|
||||
|
||||
|
||||
@@ -747,7 +747,8 @@ public class UserSwitcherController {
|
||||
if (item.isAddUser) {
|
||||
return context.getDrawable(R.drawable.ic_add_circle_qs);
|
||||
}
|
||||
Drawable icon = UserIcons.getDefaultUserIcon(item.resolveId(), /* light= */ false);
|
||||
Drawable icon = UserIcons.getDefaultUserIcon(
|
||||
context.getResources(), item.resolveId(), /* light= */ false);
|
||||
if (item.isGuest) {
|
||||
icon.setColorFilter(Utils.getColorAttr(context, android.R.attr.colorForeground),
|
||||
Mode.SRC_IN);
|
||||
@@ -957,7 +958,7 @@ public class UserSwitcherController {
|
||||
}
|
||||
int id = user.id;
|
||||
Bitmap icon = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(
|
||||
id, /* light= */ false));
|
||||
mContext.getResources(), id, /* light= */ false));
|
||||
mUserManager.setUserIcon(id, icon);
|
||||
switchToUserId(id);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user