am 443a5766: Merge "Assign default icon to users at creation time and in SystemUI." into lmp-dev
* commit '443a5766fa9b079c9612105cfe962d057fc98fe8': Assign default icon to users at creation time and in SystemUI.
This commit is contained in:
committed by
Android Git Automerger
commit
08324acd94
@@ -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;
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
75
core/java/com/android/internal/util/UserIcons.java
Normal file
75
core/java/com/android/internal/util/UserIcons.java
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -1170,6 +1170,18 @@
|
||||
<java-symbol type="drawable" name="sim_dark_orange" />
|
||||
<java-symbol type="drawable" name="sim_dark_purple" />
|
||||
|
||||
<java-symbol type="drawable" name="ic_account_circle" />
|
||||
<java-symbol type="color" name="user_icon_1" />
|
||||
<java-symbol type="color" name="user_icon_2" />
|
||||
<java-symbol type="color" name="user_icon_3" />
|
||||
<java-symbol type="color" name="user_icon_4" />
|
||||
<java-symbol type="color" name="user_icon_5" />
|
||||
<java-symbol type="color" name="user_icon_6" />
|
||||
<java-symbol type="color" name="user_icon_7" />
|
||||
<java-symbol type="color" name="user_icon_8" />
|
||||
<java-symbol type="color" name="user_icon_default_gray" />
|
||||
<java-symbol type="color" name="user_icon_default_white" />
|
||||
|
||||
<java-symbol type="layout" name="action_bar_home" />
|
||||
<java-symbol type="layout" name="action_bar_title_item" />
|
||||
<java-symbol type="layout" name="action_menu_item_layout" />
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
|
||||
<!--
|
||||
~ 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
|
||||
-->
|
||||
|
||||
<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">
|
||||
<path
|
||||
android:fillColor="@color/qs_user_detail_icon_muted"
|
||||
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>
|
||||
</vector>
|
||||
@@ -376,7 +376,8 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL
|
||||
return;
|
||||
}
|
||||
// TODO: Real icon for facelock.
|
||||
int iconRes = mUnlockMethodCache.isFaceUnlockRunning() ? R.drawable.ic_account_circle
|
||||
int iconRes = mUnlockMethodCache.isFaceUnlockRunning()
|
||||
? com.android.internal.R.drawable.ic_account_circle
|
||||
: mUnlockMethodCache.isMethodInsecure() ? R.drawable.ic_lock_open_24dp
|
||||
: R.drawable.ic_lock_24dp;
|
||||
mLockIcon.setImageResource(iconRes);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package com.android.systemui.statusbar.policy;
|
||||
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.bluetooth.BluetoothAdapter;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -26,33 +25,21 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.UserInfo;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.Shader;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.hardware.display.DisplayManager;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.RemoteException;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.provider.ContactsContract;
|
||||
import android.security.KeyChain;
|
||||
import android.util.Log;
|
||||
import android.util.Pair;
|
||||
|
||||
import com.android.internal.view.RotationPolicy;
|
||||
import com.android.systemui.BitmapHelper;
|
||||
import com.android.systemui.R;
|
||||
import com.android.internal.util.UserIcons;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
public final class UserInfoController {
|
||||
|
||||
@@ -142,6 +129,7 @@ public final class UserInfoController {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
final int userId = userInfo.id;
|
||||
final boolean isGuest = userInfo.isGuest();
|
||||
final String userName = userInfo.name;
|
||||
final int avatarSize
|
||||
= mContext.getResources().getDimensionPixelSize(R.dimen.max_avatar_size);
|
||||
@@ -161,7 +149,8 @@ public final class UserInfoController {
|
||||
avatar = new BitmapDrawable(mContext.getResources(),
|
||||
BitmapHelper.createCircularClip(rawAvatar, avatarSize, avatarSize));
|
||||
} else {
|
||||
avatar = mContext.getResources().getDrawable(R.drawable.ic_account_circle);
|
||||
avatar = UserIcons.getDefaultUserIcon(isGuest? UserHandle.USER_NULL : userId,
|
||||
/* light= */ true);
|
||||
mUseDefaultAvatar = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -16,13 +16,6 @@
|
||||
|
||||
package com.android.systemui.statusbar.policy;
|
||||
|
||||
import com.android.systemui.BitmapHelper;
|
||||
import com.android.systemui.GuestResumeSessionReceiver;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.qs.QSTile;
|
||||
import com.android.systemui.qs.tiles.UserDetailView;
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialog;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.ActivityManagerNative;
|
||||
import android.app.Dialog;
|
||||
@@ -45,9 +38,16 @@ import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowManagerGlobal;
|
||||
import android.widget.BaseAdapter;
|
||||
|
||||
import com.android.internal.util.UserIcons;
|
||||
import com.android.systemui.BitmapHelper;
|
||||
import com.android.systemui.GuestResumeSessionReceiver;
|
||||
import com.android.systemui.R;
|
||||
import com.android.systemui.qs.QSTile;
|
||||
import com.android.systemui.qs.tiles.UserDetailView;
|
||||
import com.android.systemui.statusbar.phone.SystemUIDialog;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.ref.WeakReference;
|
||||
@@ -425,7 +425,8 @@ public class UserSwitcherController {
|
||||
if (item.isAddUser) {
|
||||
return context.getDrawable(R.drawable.ic_add_circle_qs);
|
||||
}
|
||||
return context.getDrawable(R.drawable.ic_account_circle_qs);
|
||||
return UserIcons.getDefaultUserIcon(item.isGuest ? UserHandle.USER_NULL : item.info.id,
|
||||
/* light= */ true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -565,6 +566,9 @@ public class UserSwitcherController {
|
||||
dismiss();
|
||||
int id = mUserManager.createUser(
|
||||
mContext.getString(R.string.user_new_user_name), 0 /* flags */).id;
|
||||
Bitmap icon = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(
|
||||
id, /* light= */ false));
|
||||
mUserManager.setUserIcon(id, icon);
|
||||
switchToUserId(id);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user