summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/layout/keyguard_user_switcher_item.xml4
-rw-r--r--packages/SystemUI/res/layout/qs_user_detail_item.xml4
-rw-r--r--packages/SystemUI/res/values/dimens.xml4
-rw-r--r--packages/SystemUI/src/com/android/systemui/BitmapHelper.java52
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcher.java8
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/UserInfoController.java19
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java7
7 files changed, 81 insertions, 17 deletions
diff --git a/packages/SystemUI/res/layout/keyguard_user_switcher_item.xml b/packages/SystemUI/res/layout/keyguard_user_switcher_item.xml
index 691a80e..d17390e 100644
--- a/packages/SystemUI/res/layout/keyguard_user_switcher_item.xml
+++ b/packages/SystemUI/res/layout/keyguard_user_switcher_item.xml
@@ -32,8 +32,8 @@
android:textAppearance="@style/TextAppearance.StatusBar.Expanded.UserSwitcher.UserName"
/>
<com.android.systemui.statusbar.phone.UserAvatarView android:id="@+id/picture"
- android:layout_width="48dp"
- android:layout_height="48dp"
+ android:layout_width="@dimen/max_avatar_size"
+ android:layout_height="@dimen/max_avatar_size"
android:contentDescription="@null"
sysui:frameWidth="@dimen/keyguard_user_switcher_border_thickness"
sysui:activeFrameColor="@color/current_user_border_color" />
diff --git a/packages/SystemUI/res/layout/qs_user_detail_item.xml b/packages/SystemUI/res/layout/qs_user_detail_item.xml
index 29d92e5..526aa5e 100644
--- a/packages/SystemUI/res/layout/qs_user_detail_item.xml
+++ b/packages/SystemUI/res/layout/qs_user_detail_item.xml
@@ -29,8 +29,8 @@
<com.android.systemui.statusbar.phone.UserAvatarView
android:id="@+id/user_picture"
- android:layout_width="48dp"
- android:layout_height="48dp"
+ android:layout_width="@dimen/max_avatar_size"
+ android:layout_height="@dimen/max_avatar_size"
android:layout_marginBottom="12dp"
systemui:frameWidth="2dp"
systemui:activeFrameColor="@color/current_user_border_color"/>
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index e86aa0a..bb18120 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -361,4 +361,8 @@
<!-- Battery level padding end when in expanded QS (but not on Keyguard) -->
<dimen name="battery_level_padding_end">4dp</dimen>
+
+ <!-- Largest size an avatar might need to be drawn in the user picker, status bar, or
+ quick settings header -->
+ <dimen name="max_avatar_size">48dp</dimen>
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/BitmapHelper.java b/packages/SystemUI/src/com/android/systemui/BitmapHelper.java
new file mode 100644
index 0000000..008b422
--- /dev/null
+++ b/packages/SystemUI/src/com/android/systemui/BitmapHelper.java
@@ -0,0 +1,52 @@
+/*
+ * 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.systemui;
+
+import android.graphics.Bitmap;
+import android.graphics.BitmapShader;
+import android.graphics.Canvas;
+import android.graphics.Matrix;
+import android.graphics.Paint;
+import android.graphics.RectF;
+import android.graphics.Shader;
+
+public class BitmapHelper {
+ /**
+ * Generate a new bitmap (width x height pixels, ARGB_8888) with the input bitmap scaled
+ * to fit and clipped to an inscribed circle.
+ * @param input Bitmap to resize and clip
+ * @param width Width of output bitmap (and diameter of circle)
+ * @param height Height of output bitmap
+ * @return A shiny new bitmap for you to use
+ */
+ public static Bitmap createCircularClip(Bitmap input, int width, int height) {
+ final int inWidth = input.getWidth();
+ final int inHeight = input.getHeight();
+ final Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
+ final Canvas canvas = new Canvas(output);
+ final Paint paint = new Paint();
+ paint.setShader(new BitmapShader(input, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
+ paint.setAntiAlias(true);
+ final RectF srcRect = new RectF(0, 0, inWidth, inHeight);
+ final RectF dstRect = new RectF(0, 0, width, height);
+ final Matrix m = new Matrix();
+ m.setRectToRect(srcRect, dstRect, Matrix.ScaleToFit.CENTER);
+ canvas.setMatrix(m);
+ canvas.drawCircle(inWidth / 2, inHeight / 2, inWidth / 2, paint);
+ return output;
+ }
+}
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcher.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcher.java
index c90750c..a3f3819 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcher.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/KeyguardUserSwitcher.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.policy;
+import com.android.systemui.BitmapHelper;
import com.android.systemui.R;
import com.android.systemui.statusbar.phone.StatusBarHeaderView;
import com.android.systemui.statusbar.phone.UserAvatarView;
@@ -176,11 +177,16 @@ public class KeyguardUserSwitcher implements View.OnClickListener {
} catch (RemoteException e) {
Log.e(TAG, "Couln't get current user.", e);
}
+ final int avatarSize
+ = mContext.getResources().getDimensionPixelSize(R.dimen.max_avatar_size);
for (int i = 0; i < N; i++) {
UserInfo user = users.get(i);
if (user.supportsSwitchTo()) {
boolean isCurrent = user.id == currentUser;
- result.add(new UserData(user, mUserManager.getUserIcon(user.id), isCurrent));
+ final Bitmap picture = BitmapHelper.createCircularClip(
+ mUserManager.getUserIcon(user.id),
+ avatarSize, avatarSize);
+ result.add(new UserData(user, picture, isCurrent));
}
}
return result;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserInfoController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserInfoController.java
index 3ce6905..8cbe272 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserInfoController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserInfoController.java
@@ -28,10 +28,12 @@ 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;
@@ -46,6 +48,7 @@ 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 java.util.ArrayList;
@@ -124,17 +127,6 @@ public final class UserInfoController {
queryForUserInformation();
}
- private Bitmap circularClip(Bitmap input) {
- Bitmap output = Bitmap.createBitmap(input.getWidth(),
- input.getHeight(), Bitmap.Config.ARGB_8888);
- Canvas canvas = new Canvas(output);
- final Paint paint = new Paint();
- paint.setShader(new BitmapShader(input, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
- paint.setAntiAlias(true);
- canvas.drawCircle(input.getWidth() / 2, input.getHeight() / 2, input.getWidth() / 2, paint);
- return output;
- }
-
private void queryForUserInformation() {
Context currentUserContext;
UserInfo userInfo;
@@ -151,6 +143,8 @@ public final class UserInfoController {
}
final int userId = userInfo.id;
final String userName = userInfo.name;
+ final int avatarSize
+ = mContext.getResources().getDimensionPixelSize(R.dimen.max_avatar_size);
final Context context = currentUserContext;
mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
@@ -164,7 +158,8 @@ public final class UserInfoController {
Drawable avatar = null;
Bitmap rawAvatar = um.getUserIcon(userId);
if (rawAvatar != null) {
- avatar = new BitmapDrawable(mContext.getResources(), circularClip(rawAvatar));
+ avatar = new BitmapDrawable(mContext.getResources(),
+ BitmapHelper.createCircularClip(rawAvatar, avatarSize, avatarSize));
} else {
avatar = mContext.getResources().getDrawable(R.drawable.ic_account_circle);
mUseDefaultAvatar = true;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
index 7cc8ed5..2134042 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/policy/UserSwitcherController.java
@@ -16,6 +16,7 @@
package com.android.systemui.statusbar.policy;
+import com.android.systemui.BitmapHelper;
import com.android.systemui.R;
import com.android.systemui.qs.QSTile;
import com.android.systemui.qs.tiles.UserDetailView;
@@ -104,6 +105,8 @@ public class UserSwitcherController {
ArrayList<UserRecord> records = new ArrayList<>(infos.size());
int currentId = ActivityManager.getCurrentUser();
UserRecord guestRecord = null;
+ int avatarSize = mContext.getResources()
+ .getDimensionPixelSize(R.dimen.max_avatar_size);
for (UserInfo info : infos) {
boolean isCurrent = currentId == info.id;
@@ -115,6 +118,10 @@ public class UserSwitcherController {
if (picture == null) {
picture = mUserManager.getUserIcon(info.id);
}
+ if (picture != null) {
+ picture = BitmapHelper.createCircularClip(
+ picture, avatarSize, avatarSize);
+ }
records.add(new UserRecord(info, picture, false /* isGuest */, isCurrent));
}
}