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

Commit 213955e5 authored by Tony Mak's avatar Tony Mak
Browse files

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
parent 4769d2fe
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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);
        }
+5 −3
Original line number Diff line number Diff line
@@ -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;
    }
+2 −1
Original line number Diff line number Diff line
@@ -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 **/
+2 −1
Original line number Diff line number Diff line
@@ -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);
+3 −1
Original line number Diff line number Diff line
@@ -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);
                }

Loading