diff options
-rw-r--r-- | src/com/android/settings/Utils.java | 21 | ||||
-rw-r--r-- | src/com/android/settings/users/UserSettings.java | 9 |
2 files changed, 24 insertions, 6 deletions
diff --git a/src/com/android/settings/Utils.java b/src/com/android/settings/Utils.java index 5a2618e..16037c5 100644 --- a/src/com/android/settings/Utils.java +++ b/src/com/android/settings/Utils.java @@ -67,6 +67,7 @@ import android.telephony.SubscriptionManager; import android.telephony.TelephonyManager; import android.text.TextUtils; import android.util.Log; +import android.util.SparseArray; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -133,6 +134,8 @@ public final class Utils { private static final int SECONDS_PER_HOUR = 60 * 60; private static final int SECONDS_PER_DAY = 24 * 60 * 60; + private static SparseArray<Bitmap> sDarkDefaultUserBitmapCache = new SparseArray<Bitmap>(); + /** * Finds a matching activity for a preference's intent. If a matching * activity is not found, it will remove the preference. @@ -1083,4 +1086,22 @@ public final class Utils { return (sm.getStorageBytesUntilLow(context.getFilesDir()) < 0); } + + /** + * Returns a default user icon (as a {@link Bitmap}) for the given user. + * + * Note that for guest users, you should pass in {@code UserHandle.USER_NULL}. + * @param userId the user id or {@code UserHandle.USER_NULL} for a non-user specific icon + */ + public static Bitmap getDefaultUserIconAsBitmap(int userId) { + Bitmap bitmap = null; + // Try finding the corresponding bitmap in the dark bitmap cache + bitmap = sDarkDefaultUserBitmapCache.get(userId); + if (bitmap == null) { + bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(userId, false)); + // Save it to cache + sDarkDefaultUserBitmapCache.put(userId, bitmap); + } + return bitmap; + } } diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java index dbd0481..e54ea9f 100644 --- a/src/com/android/settings/users/UserSettings.java +++ b/src/com/android/settings/users/UserSettings.java @@ -872,8 +872,7 @@ public class UserSettings extends SettingsPreferenceFragment for (int userId : values[0]) { Bitmap bitmap = mUserManager.getUserIcon(userId); if (bitmap == null) { - bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(userId, - /* light= */ false)); + bitmap = Utils.getDefaultUserIconAsBitmap(userId); } mUserIcons.append(userId, bitmap); } @@ -889,15 +888,13 @@ public class UserSettings extends SettingsPreferenceFragment } private void assignDefaultPhoto(UserInfo user) { - Bitmap bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(user.id, - /* light= */ false)); + Bitmap bitmap = Utils.getDefaultUserIconAsBitmap(user.id); mUserManager.setUserIcon(user.id, bitmap); } private Drawable getEncircledDefaultIcon() { if (mDefaultIconDrawable == null) { - mDefaultIconDrawable = encircle(UserIcons.convertToBitmap( - UserIcons.getDefaultUserIcon(UserHandle.USER_NULL, /* light= */ false))); + mDefaultIconDrawable = encircle(Utils.getDefaultUserIconAsBitmap(UserHandle.USER_NULL)); } return mDefaultIconDrawable; } |