FileDocCategorySizeDatePackage
UserIcons.javaAPI DocAndroid 5.1 API2656Thu Mar 12 22:22:10 GMT 2015com.android.internal.util

UserIcons

public class UserIcons extends Object
Helper class that generates default user icons.

Fields Summary
private static final int[]
USER_ICON_COLORS
Constructors Summary
Methods Summary
public static android.graphics.BitmapconvertToBitmap(android.graphics.drawable.Drawable icon)
Converts a given drawable to a bitmap.


                
         
        if (icon == null) {
            return null;
        }
        Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
                Bitmap.Config.ARGB_8888);
        icon.draw(new Canvas(bitmap));
        return bitmap;
    
public static android.graphics.drawable.DrawablegetDefaultUserIcon(int userId, boolean light)
Returns a default user icon 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
param
light whether we want a light icon (suitable for a dark background)

        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).mutate();
        icon.setColorFilter(Resources.getSystem().getColor(colorResId), Mode.SRC_IN);
        icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
        return icon;