Loading core/java/android/app/ApplicationPackageManager.java +6 −1 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import android.view.Display; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.android.internal.util.UserIcons; import dalvik.system.VMRuntime; Loading Loading @@ -1660,7 +1661,11 @@ final class ApplicationPackageManager extends PackageManager { */ public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { if (itemInfo.showUserIcon != UserHandle.USER_NULL) { return new BitmapDrawable(getUserManager().getUserIcon(itemInfo.showUserIcon)); Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon); if (bitmap == null) { return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false); } return new BitmapDrawable(bitmap); } Drawable dr = null; if (itemInfo.packageName != null) { Loading core/java/android/os/UserManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -998,6 +998,7 @@ public class UserManager { * Returns a file descriptor for the user's photo. PNG data can be read from this file. * @param userHandle the user whose photo we want to read. * @return a {@link Bitmap} of the user's photo, or null if there's no photo. * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. * @hide */ public Bitmap getUserIcon(int userHandle) { Loading core/java/com/android/internal/util/UserIcons.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.util; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.PorterDuff.Mode; import android.graphics.drawable.Drawable; import android.os.UserHandle; import com.android.internal.R; /** * Helper class that generates default user icons. */ public class UserIcons { private static final int[] USER_ICON_COLORS = { R.color.user_icon_1, R.color.user_icon_2, R.color.user_icon_3, R.color.user_icon_4, R.color.user_icon_5, R.color.user_icon_6, R.color.user_icon_7, R.color.user_icon_8 }; /** * Converts a given drawable to a bitmap. */ public static Bitmap convertToBitmap(Drawable icon) { if (icon == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); icon.draw(new Canvas(bitmap)); return bitmap; } /** * 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) */ public static Drawable getDefaultUserIcon(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).mutate(); icon.setColorFilter(Resources.getSystem().getColor(colorResId), Mode.SRC_IN); icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); return icon; } } packages/SystemUI/res/drawable/ic_account_circle.xml→core/res/res/drawable/ic_account_circle.xml +6 −13 Original line number Diff line number Diff line Loading @@ -14,18 +14,11 @@ Copyright (C) 2014 The Android Open Source Project limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <group android:scaleX="1.2" android:scaleY="1.2" android:pivotX="12.0" android:pivotY="12.0"> android:width="48.0dp" android:height="48.0dp" android:viewportWidth="48.0" android:viewportHeight="48.0"> <path android:fillColor="#FFFFFFFF" android:pathData="M12.0,2.0C6.5,2.0 2.0,6.5 2.0,12.0s4.5,10.0 10.0,10.0c5.5,0.0 10.0,-4.5 10.0,-10.0S17.5,2.0 12.0,2.0zM12.0,5.0c1.7,0.0 3.0,1.3 3.0,3.0c0.0,1.7 -1.3,3.0 -3.0,3.0c-1.7,0.0 -3.0,-1.3 -3.0,-3.0C9.0,6.3 10.3,5.0 12.0,5.0zM12.0,19.2c-2.5,0.0 -4.7,-1.3 -6.0,-3.2c0.0,-2.0 4.0,-3.1 6.0,-3.1c2.0,0.0 6.0,1.1 6.0,3.1C16.7,17.9 14.5,19.2 12.0,19.2z"/> </group> android:pathData="M24,0C10.8,0 0,10.8 0,24s10.8,24 24,24s24,-10.8 24,-24S37.200001,0 24,0zM24,7.2c3.96,0 7.2,3.24 7.2,7.2s-3.24,7.2 -7.2,7.2s-7.2,-3.24 -7.2,-7.2S20.040001,7.2 24,7.2zM24,41.279999c-6,0 -11.28,-3.12 -14.4,-7.68c0.12,-4.8 9.6,-7.44 14.4,-7.44s14.28,2.64 14.4,7.44C35.279999,38.16 30,41.279999 24,41.279999z" android:fillColor="#FFFFFFFF"/> </vector> core/res/res/values/colors.xml +11 −0 Original line number Diff line number Diff line Loading @@ -147,5 +147,16 @@ <color name="system_notification_accent_color">#ff607D8B</color> <color name="battery_saver_mode_color">#fff4511e</color><!-- deep orange 600 --> <!-- Default user icon colors --> <color name="user_icon_1">#ffe91e63</color><!-- pink 500 --> <color name="user_icon_2">#ff3f51b5</color><!-- indigo 500 --> <color name="user_icon_3">#ff4285f4</color><!-- blue 500 --> <color name="user_icon_4">#ff00bcd4</color><!-- teal 500 --> <color name="user_icon_5">#ff0f9d58</color><!-- green 500 --> <color name="user_icon_6">#ff8bc34a</color><!-- light green 500 --> <color name="user_icon_7">#ffff9800</color><!-- orange 500 --> <color name="user_icon_8">#ffff5722</color><!-- deep orange 500 --> <color name="user_icon_default_gray">#ff9e9e9e</color><!-- gray 500 --> <color name="user_icon_default_white">#ffffffff</color><!-- white --> </resources> Loading
core/java/android/app/ApplicationPackageManager.java +6 −1 Original line number Diff line number Diff line Loading @@ -66,6 +66,7 @@ import android.view.Display; import com.android.internal.annotations.GuardedBy; import com.android.internal.util.Preconditions; import com.android.internal.util.UserIcons; import dalvik.system.VMRuntime; Loading Loading @@ -1660,7 +1661,11 @@ final class ApplicationPackageManager extends PackageManager { */ public Drawable loadItemIcon(PackageItemInfo itemInfo, ApplicationInfo appInfo) { if (itemInfo.showUserIcon != UserHandle.USER_NULL) { return new BitmapDrawable(getUserManager().getUserIcon(itemInfo.showUserIcon)); Bitmap bitmap = getUserManager().getUserIcon(itemInfo.showUserIcon); if (bitmap == null) { return UserIcons.getDefaultUserIcon(itemInfo.showUserIcon, /* light= */ false); } return new BitmapDrawable(bitmap); } Drawable dr = null; if (itemInfo.packageName != null) { Loading
core/java/android/os/UserManager.java +1 −0 Original line number Diff line number Diff line Loading @@ -998,6 +998,7 @@ public class UserManager { * Returns a file descriptor for the user's photo. PNG data can be read from this file. * @param userHandle the user whose photo we want to read. * @return a {@link Bitmap} of the user's photo, or null if there's no photo. * @see com.android.internal.util.UserIcons#getDefaultUserIcon for a default. * @hide */ public Bitmap getUserIcon(int userHandle) { Loading
core/java/com/android/internal/util/UserIcons.java 0 → 100644 +75 −0 Original line number Diff line number Diff line /* * Copyright (C) 2014 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.internal.util; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; import android.graphics.PorterDuff.Mode; import android.graphics.drawable.Drawable; import android.os.UserHandle; import com.android.internal.R; /** * Helper class that generates default user icons. */ public class UserIcons { private static final int[] USER_ICON_COLORS = { R.color.user_icon_1, R.color.user_icon_2, R.color.user_icon_3, R.color.user_icon_4, R.color.user_icon_5, R.color.user_icon_6, R.color.user_icon_7, R.color.user_icon_8 }; /** * Converts a given drawable to a bitmap. */ public static Bitmap convertToBitmap(Drawable icon) { if (icon == null) { return null; } Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); icon.draw(new Canvas(bitmap)); return bitmap; } /** * 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) */ public static Drawable getDefaultUserIcon(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).mutate(); icon.setColorFilter(Resources.getSystem().getColor(colorResId), Mode.SRC_IN); icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight()); return icon; } }
packages/SystemUI/res/drawable/ic_account_circle.xml→core/res/res/drawable/ic_account_circle.xml +6 −13 Original line number Diff line number Diff line Loading @@ -14,18 +14,11 @@ Copyright (C) 2014 The Android Open Source Project limitations under the License. --> <vector xmlns:android="http://schemas.android.com/apk/res/android" android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <group android:scaleX="1.2" android:scaleY="1.2" android:pivotX="12.0" android:pivotY="12.0"> android:width="48.0dp" android:height="48.0dp" android:viewportWidth="48.0" android:viewportHeight="48.0"> <path android:fillColor="#FFFFFFFF" android:pathData="M12.0,2.0C6.5,2.0 2.0,6.5 2.0,12.0s4.5,10.0 10.0,10.0c5.5,0.0 10.0,-4.5 10.0,-10.0S17.5,2.0 12.0,2.0zM12.0,5.0c1.7,0.0 3.0,1.3 3.0,3.0c0.0,1.7 -1.3,3.0 -3.0,3.0c-1.7,0.0 -3.0,-1.3 -3.0,-3.0C9.0,6.3 10.3,5.0 12.0,5.0zM12.0,19.2c-2.5,0.0 -4.7,-1.3 -6.0,-3.2c0.0,-2.0 4.0,-3.1 6.0,-3.1c2.0,0.0 6.0,1.1 6.0,3.1C16.7,17.9 14.5,19.2 12.0,19.2z"/> </group> android:pathData="M24,0C10.8,0 0,10.8 0,24s10.8,24 24,24s24,-10.8 24,-24S37.200001,0 24,0zM24,7.2c3.96,0 7.2,3.24 7.2,7.2s-3.24,7.2 -7.2,7.2s-7.2,-3.24 -7.2,-7.2S20.040001,7.2 24,7.2zM24,41.279999c-6,0 -11.28,-3.12 -14.4,-7.68c0.12,-4.8 9.6,-7.44 14.4,-7.44s14.28,2.64 14.4,7.44C35.279999,38.16 30,41.279999 24,41.279999z" android:fillColor="#FFFFFFFF"/> </vector>
core/res/res/values/colors.xml +11 −0 Original line number Diff line number Diff line Loading @@ -147,5 +147,16 @@ <color name="system_notification_accent_color">#ff607D8B</color> <color name="battery_saver_mode_color">#fff4511e</color><!-- deep orange 600 --> <!-- Default user icon colors --> <color name="user_icon_1">#ffe91e63</color><!-- pink 500 --> <color name="user_icon_2">#ff3f51b5</color><!-- indigo 500 --> <color name="user_icon_3">#ff4285f4</color><!-- blue 500 --> <color name="user_icon_4">#ff00bcd4</color><!-- teal 500 --> <color name="user_icon_5">#ff0f9d58</color><!-- green 500 --> <color name="user_icon_6">#ff8bc34a</color><!-- light green 500 --> <color name="user_icon_7">#ffff9800</color><!-- orange 500 --> <color name="user_icon_8">#ffff5722</color><!-- deep orange 500 --> <color name="user_icon_default_gray">#ff9e9e9e</color><!-- gray 500 --> <color name="user_icon_default_white">#ffffffff</color><!-- white --> </resources>