summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAmith Yamasani <yamasani@google.com>2013-03-27 12:36:52 -0700
committerAndroid Git Automerger <android-git-automerger@android.com>2013-03-27 12:36:52 -0700
commit07aa7b8e1876298d4460afc775c1dda66e121380 (patch)
tree08bfb60b9837f722bff13eade751a37489baf815
parent03be9690cf2abc4a3035008ff5f9d877eceae9f8 (diff)
parent0fb0d016dd51b0d8b882d92de58f5c2ea28a9208 (diff)
downloadpackages_apps_Settings-07aa7b8e1876298d4460afc775c1dda66e121380.zip
packages_apps_Settings-07aa7b8e1876298d4460afc775c1dda66e121380.tar.gz
packages_apps_Settings-07aa7b8e1876298d4460afc775c1dda66e121380.tar.bz2
am 0fb0d016: Merge "Split User settings into limited and trusted." into jb-mr2-dev
* commit '0fb0d016dd51b0d8b882d92de58f5c2ea28a9208': Split User settings into limited and trusted.
-rw-r--r--res/values/colors.xml3
-rwxr-xr-xres/values/dimens.xml4
-rw-r--r--res/values/strings.xml6
-rw-r--r--res/xml/user_settings.xml9
-rw-r--r--src/com/android/settings/users/AppRestrictionsFragment.java9
-rw-r--r--src/com/android/settings/users/CircleFramedDrawable.java181
-rw-r--r--src/com/android/settings/users/UserPreference.java2
-rw-r--r--src/com/android/settings/users/UserSettings.java64
8 files changed, 249 insertions, 29 deletions
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 @@
<color name="title_color">@android:color/holo_blue_light</color>
<color name="setup_divider_color">#333333</color>
+ <color name="circle_avatar_frame_color">#ffffffff</color>
+ <color name="circle_avatar_frame_shadow_color">#80000000</color>
+ <color name="circle_avatar_frame_pressed_color">#ffffffff</color>
</resources>
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 @@
<dimen name="keyguard_appwidget_picker_margin_left">6dip</dimen>
<dimen name="keyguard_appwidget_picker_margin_right">6dip</dimen>
<integer name="keyguard_appwidget_picker_cols">1</integer>
+
+ <dimen name="circle_avatar_size">48dp</dimen>
+ <dimen name="circle_avatar_frame_stroke_width">1dp</dimen>
+ <dimen name="circle_avatar_frame_shadow_radius">3dp</dimen>
</resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a928ab1..0e29392 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4281,8 +4281,10 @@
<string name="user_settings_title">Users</string>
<!-- User settings section title for details about you [CHAR LIMIT=25] -->
<string name="user_you_section">You</string>
- <!-- User settings user list section header [CHAR LIMIT=30] -->
- <string name="user_list_title">Other users</string>
+ <!-- User settings trusted user list section header [CHAR LIMIT=30] -->
+ <string name="user_trusted_list_title">Trusted users</string>
+ <!-- User settings limited user list section header [CHAR LIMIT=30] -->
+ <string name="user_limited_list_title">Limited users</string>
<!-- User settings add user menu [CHAR LIMIT=20] -->
<string name="user_add_user_menu">Add user</string>
<!-- User settings add restricted user label [CHAR LIMIT=20] -->
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" />
<PreferenceCategory
- android:key="user_list"
- android:title="@string/user_list_title">
+ android:key="limited_user_list"
+ android:title="@string/user_limited_list_title">
</PreferenceCategory>
<Preference
@@ -45,6 +45,11 @@
android:summary="@string/user_add_restricted_summary"
android:icon="@drawable/ic_menu_add" />
+ <PreferenceCategory
+ android:key="trusted_user_list"
+ android:title="@string/user_trusted_list_title">
+ </PreferenceCategory>
+
<Preference
android:key="user_add_trusted"
android:title="@string/user_add_trusted"
diff --git a/src/com/android/settings/users/AppRestrictionsFragment.java b/src/com/android/settings/users/AppRestrictionsFragment.java
index 9757f30..b610025 100644
--- a/src/com/android/settings/users/AppRestrictionsFragment.java
+++ b/src/com/android/settings/users/AppRestrictionsFragment.java
@@ -25,7 +25,10 @@ import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.pm.UserInfo;
+import android.graphics.Bitmap;
+import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
+import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.UserHandle;
@@ -197,8 +200,10 @@ public class AppRestrictionsFragment extends SettingsPreferenceFragment implemen
}
UserInfo info = mUserManager.getUserInfo(mUser.getIdentifier());
mUserPreference.setTitle(info.name);
- mUserPreference.setIcon(
- new BitmapDrawable(mUserManager.getUserIcon(mUser.getIdentifier())));
+ Bitmap userIcon = mUserManager.getUserIcon(mUser.getIdentifier());
+ CircleFramedDrawable circularIcon =
+ CircleFramedDrawable.getInstance(this.getActivity(), userIcon);
+ mUserPreference.setIcon(circularIcon);
mUserPreference.setText(info.name);
}
diff --git a/src/com/android/settings/users/CircleFramedDrawable.java b/src/com/android/settings/users/CircleFramedDrawable.java
new file mode 100644
index 0000000..7770b47
--- /dev/null
+++ b/src/com/android/settings/users/CircleFramedDrawable.java
@@ -0,0 +1,181 @@
+/*
+ * Copyright (C) 2013 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.settings.users;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.ColorFilter;
+import android.graphics.Paint;
+import android.graphics.Path;
+import android.graphics.PixelFormat;
+import android.graphics.PorterDuff;
+import android.graphics.PorterDuffXfermode;
+import android.graphics.Rect;
+import android.graphics.RectF;
+import android.graphics.drawable.Drawable;
+
+import com.android.settings.R;
+
+/**
+ * Converts the user avatar icon to a circularly clipped one.
+ * TODO: Move this to an internal framework class and share with the one in Keyguard.
+ */
+class CircleFramedDrawable extends Drawable {
+
+ private final Bitmap mBitmap;
+ private final int mSize;
+ private final Paint mPaint;
+ private final float mShadowRadius;
+ private final float mStrokeWidth;
+ private final int mFrameColor;
+ private final int mHighlightColor;
+ private final int mFrameShadowColor;
+
+ private float mScale;
+ private Path mFramePath;
+ private Rect mSrcRect;
+ private RectF mDstRect;
+ private RectF mFrameRect;
+ private boolean mPressed;
+
+ public static CircleFramedDrawable getInstance(Context context, Bitmap icon) {
+ Resources res = context.getResources();
+ float iconSize = res.getDimension(R.dimen.circle_avatar_size);
+ float strokeWidth = res.getDimension(R.dimen.circle_avatar_frame_stroke_width);
+ float shadowRadius = res.getDimension(R.dimen.circle_avatar_frame_shadow_radius);
+ int frameColor = res.getColor(R.color.circle_avatar_frame_color);
+ int frameShadowColor = res.getColor(R.color.circle_avatar_frame_shadow_color);
+ int highlightColor = res.getColor(R.color.circle_avatar_frame_pressed_color);
+
+ CircleFramedDrawable instance = new CircleFramedDrawable(icon,
+ (int) iconSize, frameColor, strokeWidth, frameShadowColor, shadowRadius,
+ highlightColor);
+ return instance;
+ }
+
+ public CircleFramedDrawable(Bitmap icon, int size,
+ int frameColor, float strokeWidth,
+ int frameShadowColor, float shadowRadius,
+ int highlightColor) {
+ super();
+ mSize = size;
+ mShadowRadius = shadowRadius;
+ mFrameColor = frameColor;
+ mFrameShadowColor = frameShadowColor;
+ mStrokeWidth = strokeWidth;
+ mHighlightColor = highlightColor;
+
+ mBitmap = Bitmap.createBitmap(mSize, mSize, Bitmap.Config.ARGB_8888);
+ final Canvas canvas = new Canvas(mBitmap);
+
+ final int width = icon.getWidth();
+ final int height = icon.getHeight();
+ final int square = Math.min(width, height);
+
+ final Rect cropRect = new Rect((width - square) / 2, (height - square) / 2, square, square);
+ final RectF circleRect = new RectF(0f, 0f, mSize, mSize);
+ circleRect.inset(mStrokeWidth / 2f, mStrokeWidth / 2f);
+ circleRect.inset(mShadowRadius, mShadowRadius);
+
+ final Path fillPath = new Path();
+ fillPath.addArc(circleRect, 0f, 360f);
+
+ canvas.drawColor(0, PorterDuff.Mode.CLEAR);
+
+ // opaque circle matte
+ mPaint = new Paint();
+ mPaint.setAntiAlias(true);
+ mPaint.setColor(Color.BLACK);
+ mPaint.setStyle(Paint.Style.FILL);
+ canvas.drawPath(fillPath, mPaint);
+
+ // mask in the icon where the bitmap is opaque
+ mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
+ canvas.drawBitmap(icon, cropRect, circleRect, mPaint);
+
+ // prepare paint for frame drawing
+ mPaint.setXfermode(null);
+
+ mScale = 1f;
+
+ mSrcRect = new Rect(0, 0, mSize, mSize);
+ mDstRect = new RectF(0, 0, mSize, mSize);
+ mFrameRect = new RectF(mDstRect);
+ mFramePath = new Path();
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ // clear background
+ final float outside = Math.min(canvas.getWidth(), canvas.getHeight());
+ final float inside = mScale * outside;
+ final float pad = (outside - inside) / 2f;
+
+ mDstRect.set(pad, pad, outside - pad, outside - pad);
+ canvas.drawBitmap(mBitmap, mSrcRect, mDstRect, null);
+
+ mFrameRect.set(mDstRect);
+ mFrameRect.inset(mStrokeWidth / 2f, mStrokeWidth / 2f);
+ mFrameRect.inset(mShadowRadius, mShadowRadius);
+
+ mFramePath.reset();
+ mFramePath.addArc(mFrameRect, 0f, 360f);
+
+ // white frame
+ if (mPressed) {
+ mPaint.setStyle(Paint.Style.FILL);
+ mPaint.setColor(Color.argb((int) (0.33f * 255),
+ Color.red(mHighlightColor),
+ Color.green(mHighlightColor),
+ Color.blue(mHighlightColor)));
+ canvas.drawPath(mFramePath, mPaint);
+ }
+ mPaint.setStrokeWidth(mStrokeWidth);
+ mPaint.setStyle(Paint.Style.STROKE);
+ mPaint.setColor(mPressed ? mHighlightColor : mFrameColor);
+ mPaint.setShadowLayer(mShadowRadius, 0f, 0f, mFrameShadowColor);
+ canvas.drawPath(mFramePath, mPaint);
+ }
+
+ public void setScale(float scale) {
+ mScale = scale;
+ }
+
+ public float getScale() {
+ return mScale;
+ }
+
+ public void setPressed(boolean pressed) {
+ mPressed = pressed;
+ }
+
+ @Override
+ public int getOpacity() {
+ return PixelFormat.TRANSLUCENT;
+ }
+
+ @Override
+ public void setAlpha(int alpha) {
+ }
+
+ @Override
+ public void setColorFilter(ColorFilter cf) {
+ }
+} \ No newline at end of file
diff --git a/src/com/android/settings/users/UserPreference.java b/src/com/android/settings/users/UserPreference.java
index 6889747..2894bf9 100644
--- a/src/com/android/settings/users/UserPreference.java
+++ b/src/com/android/settings/users/UserPreference.java
@@ -57,7 +57,7 @@ public class UserPreference extends Preference {
mRestricted = ((UserManager) getContext().getSystemService(Context.USER_SERVICE))
.getUserInfo(mUserId).isRestricted();
}
- setSummary(mRestricted ? R.string.user_limited : R.string.user_trusted);
+ //setSummary(mRestricted ? R.string.user_limited : R.string.user_trusted);
}
@Override
diff --git a/src/com/android/settings/users/UserSettings.java b/src/com/android/settings/users/UserSettings.java
index b6385c8..872d144 100644
--- a/src/com/android/settings/users/UserSettings.java
+++ b/src/com/android/settings/users/UserSettings.java
@@ -31,6 +31,7 @@ import android.content.pm.UserInfo;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
+import android.graphics.Color;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
@@ -76,7 +77,8 @@ public class UserSettings extends SettingsPreferenceFragment
private static final String SAVE_ADDING_USER = "adding_user";
private static final String KEY_USER_NICKNAME = "user_nickname";
- private static final String KEY_USER_LIST = "user_list";
+ private static final String KEY_TRUSTED_USER_LIST = "trusted_user_list";
+ private static final String KEY_LIMITED_USER_LIST = "limited_user_list";
private static final String KEY_USER_ME = "user_me";
private static final String KEY_ADD_RESTRICTED_USER = "user_add_restricted";
private static final String KEY_ADD_TRUSTED_USER = "user_add_trusted";
@@ -106,7 +108,8 @@ public class UserSettings extends SettingsPreferenceFragment
R.drawable.avatar_default_8
};
- private PreferenceGroup mUserListCategory;
+ private PreferenceGroup mTrustedUserListCategory;
+ private PreferenceGroup mLimitedUserListCategory;
private Preference mMePreference;
private SelectableEditTextPreference mNicknamePreference;
private Preference mAddRestrictedUser;
@@ -118,7 +121,7 @@ public class UserSettings extends SettingsPreferenceFragment
private final Object mUserLock = new Object();
private UserManager mUserManager;
- private SparseArray<Drawable> mUserIcons = new SparseArray<Drawable>();
+ private SparseArray<Bitmap> mUserIcons = new SparseArray<Bitmap>();
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<UserInfo> users = mUserManager.getUsers(true);
- mUserListCategory.removeAll();
- mUserListCategory.setOrderingAsAdded(false);
+ mTrustedUserListCategory.removeAll();
+ mTrustedUserListCategory.setOrderingAsAdded(false);
+ mLimitedUserListCategory.removeAll();
+ mLimitedUserListCategory.setOrderingAsAdded(false);
final ArrayList<Integer> missingIcons = new ArrayList<Integer>();
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<Integer> missingIcons) {
@@ -504,8 +515,7 @@ public class UserSettings extends SettingsPreferenceFragment
protected Void doInBackground(List<Integer>... 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) {