From 864e3b7c5176199f7f0fae53c2639f9dacd737e2 Mon Sep 17 00:00:00 2001 From: Amith Yamasani Date: Wed, 27 Mar 2013 12:27:01 -0700 Subject: Split User settings into limited and trusted. Also show avatars with the circular frame like on lockscreen. Change-Id: I032d842555b2f50a07166460f9cfb1963366dbb1 --- res/values/colors.xml | 3 + res/values/dimens.xml | 4 + res/values/strings.xml | 6 +- res/xml/user_settings.xml | 9 +- .../settings/users/AppRestrictionsFragment.java | 9 +- .../settings/users/CircleFramedDrawable.java | 181 +++++++++++++++++++++ src/com/android/settings/users/UserPreference.java | 2 +- src/com/android/settings/users/UserSettings.java | 64 +++++--- 8 files changed, 249 insertions(+), 29 deletions(-) create mode 100644 src/com/android/settings/users/CircleFramedDrawable.java diff --git a/res/values/colors.xml b/res/values/colors.xml index e7a00c3..bd385f6 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -37,4 +37,7 @@ @android:color/holo_blue_light #333333 + #ffffffff + #80000000 + #ffffffff diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 91f293c..759b407 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -61,4 +61,8 @@ 6dip 6dip 1 + + 48dp + 1dp + 3dp diff --git a/res/values/strings.xml b/res/values/strings.xml index 4a8f796..7b028db 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4276,8 +4276,10 @@ Users You - - Other users + + Trusted users + + Limited users Add user diff --git a/res/xml/user_settings.xml b/res/xml/user_settings.xml index 3e61bd7..2e73e9e 100644 --- a/res/xml/user_settings.xml +++ b/res/xml/user_settings.xml @@ -35,8 +35,8 @@ android:fragment="com.android.settings.OwnerInfoSettings" /> + android:key="limited_user_list" + android:title="@string/user_limited_list_title"> + + + mUserIcons = new SparseArray(); + private SparseArray mUserIcons = new SparseArray(); private boolean mIsOwner = UserHandle.myUserId() == UserHandle.USER_OWNER; @@ -166,7 +169,8 @@ public class UserSettings extends SettingsPreferenceFragment mUserManager = (UserManager) getActivity().getSystemService(Context.USER_SERVICE); addPreferencesFromResource(R.xml.user_settings); - mUserListCategory = (PreferenceGroup) findPreference(KEY_USER_LIST); + mTrustedUserListCategory = (PreferenceGroup) findPreference(KEY_TRUSTED_USER_LIST); + mLimitedUserListCategory = (PreferenceGroup) findPreference(KEY_LIMITED_USER_LIST); mMePreference = (Preference) findPreference(KEY_USER_ME); mMePreference.setOnPreferenceClickListener(this); if (!mIsOwner) { @@ -269,9 +273,8 @@ public class UserSettings extends SettingsPreferenceFragment int myUserId = UserHandle.myUserId(); Bitmap b = mUserManager.getUserIcon(myUserId); if (b != null) { - Drawable d = new BitmapDrawable(b); - mMePreference.setIcon(d); - mUserIcons.put(myUserId, d); + mMePreference.setIcon(encircle(b)); + mUserIcons.put(myUserId, b); } } @@ -441,8 +444,10 @@ public class UserSettings extends SettingsPreferenceFragment if (getActivity() == null) return; List users = mUserManager.getUsers(true); - mUserListCategory.removeAll(); - mUserListCategory.setOrderingAsAdded(false); + mTrustedUserListCategory.removeAll(); + mTrustedUserListCategory.setOrderingAsAdded(false); + mLimitedUserListCategory.removeAll(); + mLimitedUserListCategory.setOrderingAsAdded(false); final ArrayList missingIcons = new ArrayList(); for (UserInfo user : users) { @@ -456,19 +461,23 @@ public class UserSettings extends SettingsPreferenceFragment UserHandle.myUserId() == UserHandle.USER_OWNER, this, this); pref.setOnPreferenceClickListener(this); pref.setKey("id=" + user.id); - mUserListCategory.addPreference(pref); + if (user.isRestricted()) { + mLimitedUserListCategory.addPreference(pref); + } else { + mTrustedUserListCategory.addPreference(pref); + } if (user.id == UserHandle.USER_OWNER) { pref.setSummary(R.string.user_owner); } pref.setTitle(user.name); -// if (!isInitialized(user)) { -// pref.setSummary(R.string.user_summary_not_set_up); -// } + if (!isInitialized(user)) { + pref.setSummary(R.string.user_summary_not_set_up); + } } if (user.iconPath != null) { if (mUserIcons.get(user.id) == null) { missingIcons.add(user.id); - pref.setIcon(R.drawable.avatar_default_1); + pref.setIcon(encircle(R.drawable.avatar_default_1)); } else { setPhotoId(pref, user); } @@ -480,9 +489,8 @@ public class UserSettings extends SettingsPreferenceFragment false, null, null); pref.setEnabled(false); pref.setTitle(R.string.user_new_user_name); - //pref.setSummary(R.string.user_adding_new_user); - pref.setIcon(R.drawable.avatar_default_1); - mUserListCategory.addPreference(pref); + pref.setIcon(encircle(R.drawable.avatar_default_1)); + mTrustedUserListCategory.addPreference(pref); } getActivity().invalidateOptionsMenu(); @@ -490,6 +498,9 @@ public class UserSettings extends SettingsPreferenceFragment if (missingIcons.size() > 0) { loadIconsAsync(missingIcons); } + boolean moreUsers = mUserManager.getMaxSupportedUsers() > users.size(); + mAddRestrictedUser.setEnabled(moreUsers); + mAddTrustedUser.setEnabled(moreUsers); } private void loadIconsAsync(List missingIcons) { @@ -504,8 +515,7 @@ public class UserSettings extends SettingsPreferenceFragment protected Void doInBackground(List... values) { for (int userId : values[0]) { Bitmap bitmap = mUserManager.getUserIcon(userId); - Drawable d = new BitmapDrawable(resources, bitmap); - mUserIcons.append(userId, d); + mUserIcons.append(userId, bitmap); } return null; } @@ -533,9 +543,9 @@ public class UserSettings extends SettingsPreferenceFragment } private void setPhotoId(Preference pref, UserInfo user) { - Drawable d = mUserIcons.get(user.id); // UserUtils.getUserIcon(mUserManager, user); - if (d != null) { - pref.setIcon(d); + Bitmap bitmap = mUserIcons.get(user.id); // UserUtils.getUserIcon(mUserManager, user); + if (bitmap != null) { + pref.setIcon(encircle(bitmap)); } } @@ -591,6 +601,16 @@ public class UserSettings extends SettingsPreferenceFragment return (user.flags & UserInfo.FLAG_INITIALIZED) != 0; } + private Drawable encircle(int iconResId) { + Bitmap icon = BitmapFactory.decodeResource(getResources(), iconResId); + return encircle(icon); + } + + private Drawable encircle(Bitmap icon) { + Drawable circled = CircleFramedDrawable.getInstance(getActivity(), icon); + return circled; + } + @Override public void onClick(View v) { if (v.getTag() instanceof UserPreference) { -- cgit v1.1