Switch to using system-wide default user icons

User icons were either User Settings specific, or missing. This makes it
consistent with the ones in the new helper class.

Bug: 17311038
Change-Id: I20cc1deba989cf7a397c5a8dba41bd91bd62472b
This commit is contained in:
Alexandra Gherghina
2014-09-03 10:22:09 +01:00
parent f8310c1850
commit bc6e78f9da
20 changed files with 39 additions and 323 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 884 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 695 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/pink_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/indigo_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/blue_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/teal_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/green_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/light_green_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/orange_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/deep_orange_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

View File

@@ -1,28 +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.
-->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size android:width="40dp" android:height="40dp" />
<solid android:color="@color/grey_500" />
</shape>
</item>
<item android:top="8dp" android:bottom="8dp" android:left="8dp" android:right="8dp"
android:drawable="@drawable/ic_person_white" />
</layer-list>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

View File

@@ -80,18 +80,6 @@
<color name="setup_wizard_preference_background_color_dark">@*android:color/background_material_dark</color>
<color name="setup_wizard_preference_background_color_light">@*android:color/background_material_light</color>
<!-- Default avatar colors -->
<color name="pink_500">#ffe91e63</color>
<color name="indigo_500">#ff3f51b5</color>
<color name="blue_500">#ff4285f4</color>
<color name="teal_500">#ff00bcd4</color>
<color name="green_500">#ff0f9d58</color>
<color name="light_green_500">#ff8bc34a</color>
<color name="orange_500">#ffff9800</color>
<color name="deep_orange_500">#ffff5722</color>
<!-- Avatar color used for guest -->
<color name="grey_500">#ff9e9e9e</color>
<color name="wifi_divider">#ffe0e0e0</color>
</resources>

View File

@@ -31,6 +31,7 @@ import android.widget.ImageView;
import android.widget.SpinnerAdapter;
import android.widget.TextView;
import com.android.internal.util.UserIcons;
import com.android.settings.drawable.CircleFramedDrawable;
import com.android.settings.R;
@@ -57,7 +58,11 @@ public class UserSpinnerAdapter implements SpinnerAdapter {
} else {
name = userInfo.name;
Bitmap bitmap = um.getUserIcon(userHandle.getIdentifier());
icon = (bitmap == null) ? null : CircleFramedDrawable.getInstance(context, bitmap);
if (bitmap != null) {
icon = CircleFramedDrawable.getInstance(context, bitmap);
} else {
icon = UserIcons.getDefaultUserIcon(userInfo.id, /* light= */ false);
}
}
}
}

View File

@@ -70,6 +70,8 @@ import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.TabWidget;
import com.android.internal.util.ImageUtils;
import com.android.internal.util.UserIcons;
import com.android.settings.UserSpinnerAdapter.UserDetails;
import com.android.settings.dashboard.DashboardCategory;
import com.android.settings.dashboard.DashboardTile;
@@ -847,11 +849,14 @@ public final class Utils {
* Returns a circular icon for a user.
*/
public static Drawable getUserIcon(Context context, UserManager um, UserInfo user) {
if (user.iconPath == null) return null;
if (user.iconPath != null) {
Bitmap icon = um.getUserIcon(user.id);
if (icon == null) return null;
if (icon != null) {
return CircleFramedDrawable.getInstance(context, icon);
}
}
return UserIcons.getDefaultUserIcon(user.id, /* light= */ false);
}
/**
* Return whether or not the user should have a SIM Cards option in Settings.

View File

@@ -107,7 +107,7 @@ public class CircleFramedDrawable extends Drawable {
canvas.drawPath(fillPath, mPaint);
// mask in the icon where the bitmap is opaque
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(icon, cropRect, circleRect, mPaint);
// prepare paint for frame drawing

View File

@@ -16,10 +16,6 @@
package com.android.settings.users;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import android.accounts.Account;
import android.accounts.AccountManager;
import android.app.Activity;
@@ -37,7 +33,6 @@ import android.content.SharedPreferences;
import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.os.Bundle;
@@ -60,6 +55,7 @@ import android.view.View;
import android.view.View.OnClickListener;
import android.widget.SimpleAdapter;
import com.android.internal.util.UserIcons;
import com.android.internal.widget.LockPatternUtils;
import com.android.settings.ChooseLockGeneric;
import com.android.settings.OwnerInfoSettings;
@@ -70,6 +66,10 @@ import com.android.settings.SettingsPreferenceFragment;
import com.android.settings.Utils;
import com.android.settings.drawable.CircleFramedDrawable;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
/**
* Screen that manages the list of users on the device.
* Guest user is an always visible entry, even if the guest is not currently
@@ -119,19 +119,6 @@ public class UserSettings extends SettingsPreferenceFragment
private static final String KEY_ADD_USER_LONG_MESSAGE_DISPLAYED =
"key_add_user_long_message_displayed";
static final int[] USER_DRAWABLES = {
R.drawable.ic_avatar_default_1,
R.drawable.ic_avatar_default_2,
R.drawable.ic_avatar_default_3,
R.drawable.ic_avatar_default_4,
R.drawable.ic_avatar_default_5,
R.drawable.ic_avatar_default_6,
R.drawable.ic_avatar_default_7,
R.drawable.ic_avatar_default_8
};
private static final int GUEST_DRAWABLE_ID = R.drawable.ic_avatar_guest;
private static final String KEY_TITLE = "title";
private static final String KEY_SUMMARY = "summary";
@@ -154,10 +141,8 @@ public class UserSettings extends SettingsPreferenceFragment
private EditUserInfoController mEditUserInfoController =
new EditUserInfoController();
// A place to cache the generated guest avatar
private Drawable mGuestDrawable;
// A place to cache the generated default avatar
private Drawable mDefaultAvatarDrawable;
private Drawable mDefaultIconDrawable;
private Handler mHandler = new Handler() {
@Override
@@ -325,7 +310,7 @@ public class UserSettings extends SettingsPreferenceFragment
private void loadProfile() {
if (mIsGuest) {
// No need to load profile information
mMePreference.setIcon(getEncircledGuestDrawable());
mMePreference.setIcon(getEncircledDefaultIcon());
mMePreference.setTitle(R.string.user_exit_guest_title);
return;
}
@@ -423,9 +408,7 @@ public class UserSettings extends SettingsPreferenceFragment
Secure.putIntForUser(getContentResolver(),
Secure.LOCATION_MODE, Secure.LOCATION_MODE_OFF, userId);
mUserManager.setUserRestriction(UserManager.DISALLOW_SHARE_LOCATION, true, user);
Bitmap bitmap = createBitmapFromDrawable(
USER_DRAWABLES[userId % UserSettings.USER_DRAWABLES.length]);
mUserManager.setUserIcon(userId, bitmap);
assignDefaultPhoto(newUserInfo);
// Add shared accounts
AccountManager am = AccountManager.get(getActivity());
Account [] accounts = am.getAccounts();
@@ -437,15 +420,6 @@ public class UserSettings extends SettingsPreferenceFragment
return newUserInfo;
}
private Bitmap createBitmapFromDrawable(int resId) {
Drawable icon = getResources().getDrawable(resId);
icon.setBounds(0, 0, icon.getIntrinsicWidth(), icon.getIntrinsicHeight());
Bitmap bitmap = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
icon.draw(new Canvas(bitmap));
return bitmap;
}
private UserInfo createTrustedUser() {
UserInfo newUserInfo = mUserManager.createUser(
getResources().getString(R.string.user_new_user_name), 0);
@@ -787,13 +761,15 @@ public class UserSettings extends SettingsPreferenceFragment
}
if (user.iconPath != null) {
if (mUserIcons.get(user.id) == null) {
// Icon not loaded yet, print a placeholder
missingIcons.add(user.id);
pref.setIcon(getEncircledDefaultAvatar());
pref.setIcon(getEncircledDefaultIcon());
} else {
setPhotoId(pref, user);
}
} else {
pref.setIcon(getEncircledDefaultAvatar());
// Icon not available yet, print a placeholder
pref.setIcon(getEncircledDefaultIcon());
}
}
@@ -803,7 +779,7 @@ public class UserSettings extends SettingsPreferenceFragment
null, null);
pref.setEnabled(false);
pref.setTitle(R.string.user_new_user_name);
pref.setIcon(getEncircledDefaultAvatar());
pref.setIcon(getEncircledDefaultIcon());
mUserListCategory.addPreference(pref);
}
@@ -826,7 +802,7 @@ public class UserSettings extends SettingsPreferenceFragment
mIsOwner && voiceCapable? this : null /* settings icon handler */,
null /* delete icon handler */);
pref.setTitle(R.string.user_guest);
pref.setIcon(getEncircledGuestDrawable());
pref.setIcon(getEncircledDefaultIcon());
pref.setOnPreferenceClickListener(this);
mUserListCategory.addPreference(pref);
}
@@ -854,7 +830,8 @@ public class UserSettings extends SettingsPreferenceFragment
for (int userId : values[0]) {
Bitmap bitmap = mUserManager.getUserIcon(userId);
if (bitmap == null) {
bitmap = createBitmapFromDrawable(R.drawable.ic_avatar_default_1);
bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(userId,
/* light= */ false));
}
mUserIcons.append(userId, bitmap);
}
@@ -870,24 +847,17 @@ public class UserSettings extends SettingsPreferenceFragment
}
private void assignDefaultPhoto(UserInfo user) {
Bitmap bitmap = createBitmapFromDrawable(
USER_DRAWABLES[user.id % UserSettings.USER_DRAWABLES.length]);
Bitmap bitmap = UserIcons.convertToBitmap(UserIcons.getDefaultUserIcon(user.id,
/* light= */ false));
mUserManager.setUserIcon(user.id, bitmap);
}
private Drawable getEncircledGuestDrawable() {
if (mGuestDrawable == null) {
mGuestDrawable = encircle(createBitmapFromDrawable(GUEST_DRAWABLE_ID));
private Drawable getEncircledDefaultIcon() {
if (mDefaultIconDrawable == null) {
mDefaultIconDrawable = encircle(UserIcons.convertToBitmap(
UserIcons.getDefaultUserIcon(UserHandle.USER_NULL, /* light= */ false)));
}
return mGuestDrawable;
}
private Drawable getEncircledDefaultAvatar() {
if (mDefaultAvatarDrawable == null) {
mDefaultAvatarDrawable =
encircle(createBitmapFromDrawable(R.drawable.ic_avatar_default_1));
}
return mDefaultAvatarDrawable;
return mDefaultIconDrawable;
}
private void setPhotoId(Preference pref, UserInfo user) {