merge new multiuser avatars in from proto app

Change-Id: I6a7f63738279be1c036061b4cea461e94fb51658
diff --git a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardMultiUserAvatar.java b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardMultiUserAvatar.java
index 3f4a73e..b025079 100644
--- a/policy/src/com/android/internal/policy/impl/keyguard/KeyguardMultiUserAvatar.java
+++ b/policy/src/com/android/internal/policy/impl/keyguard/KeyguardMultiUserAvatar.java
@@ -25,24 +25,16 @@
 import android.content.res.Resources;
 import android.graphics.Bitmap;
 import android.graphics.BitmapFactory;
-import android.graphics.Canvas;
 import android.graphics.Color;
-import android.graphics.Paint;
-import android.graphics.Path;
-import android.graphics.PorterDuff;
-import android.graphics.PorterDuffXfermode;
-import android.graphics.Rect;
-import android.graphics.RectF;
-import android.graphics.drawable.BitmapDrawable;
 import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.util.Log;
 import android.view.LayoutInflater;
+import android.view.View;
 import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.TextView;
 
-import android.util.Log;
 import com.android.internal.R;
 
 class KeyguardMultiUserAvatar extends FrameLayout {
@@ -53,34 +45,29 @@
     private static final float ACTIVE_ALPHA = 1.0f;
     private static final float INACTIVE_ALPHA = 1.0f;
     private static final float ACTIVE_SCALE = 1.5f;
-    private static final float ACTIVE_TEXT_BACGROUND_ALPHA = 0f;
-    private static final float INACTIVE_TEXT_BACGROUND_ALPHA = 0f;
+    private static final float ACTIVE_TEXT_ALPHA = 0f;
+    private static final float INACTIVE_TEXT_ALPHA = 0.5f;
     private static final int SWITCH_ANIMATION_DURATION = 150;
 
     private final float mActiveAlpha;
     private final float mActiveScale;
-    private final float mActiveTextBacgroundAlpha;
+    private final float mActiveTextAlpha;
     private final float mInactiveAlpha;
-    private final float mInactiveTextBacgroundAlpha;
-    private final float mShadowDx;
-    private final float mShadowDy;
+    private final float mInactiveTextAlpha;
     private final float mShadowRadius;
     private final float mStroke;
     private final float mIconSize;
-    private final int mActiveTextColor;
     private final int mFrameColor;
     private final int mFrameShadowColor;
-    private final int mInactiveTextColor;
-    private final int mMatteColor;
+    private final int mTextColor;
+    private final int mHighlightColor;
 
     private boolean mTouched;
 
     private boolean mActive;
     private boolean mInit = true;
     private KeyguardMultiUserSelectorView mUserSelector;
-
-    boolean mPressedStateLocked = false;
-    boolean mTempPressedStateHolder = false;
+    private KeyguardCircleFramedDrawable mFramed;
 
     public static KeyguardMultiUserAvatar fromXml(int resId, Context context,
             KeyguardMultiUserSelectorView userSelector, UserInfo info) {
@@ -103,24 +90,22 @@
         super(context, attrs, defStyle);
 
         Resources res = mContext.getResources();
-        mActiveTextColor = 0x00000000;
-        mInactiveTextColor = 0x00000000;
-        mIconSize = res.getDimension(R.dimen.keyguard_avatar_height);
+        mTextColor = res.getColor(R.color.keyguard_avatar_nick_color);
+        mIconSize = res.getDimension(R.dimen.keyguard_avatar_size);
         mStroke = res.getDimension(R.dimen.keyguard_avatar_frame_stroke_width);
         mShadowRadius = res.getDimension(R.dimen.keyguard_avatar_frame_shadow_radius);
-        mShadowDx = res.getDimension(R.dimen.keyguard_avatar_frame_shadow_dx);
-        mShadowDy = res.getDimension(R.dimen.keyguard_avatar_frame_shadow_dy);
         mFrameColor = res.getColor(R.color.keyguard_avatar_frame_color);
         mFrameShadowColor = res.getColor(R.color.keyguard_avatar_frame_shadow_color);
-        mMatteColor = res.getColor(R.color.keyguard_avatar_matte_color);
-
-        mActiveTextBacgroundAlpha = ACTIVE_TEXT_BACGROUND_ALPHA;
-        mInactiveTextBacgroundAlpha = INACTIVE_TEXT_BACGROUND_ALPHA;
+        mHighlightColor = res.getColor(R.color.keyguard_avatar_frame_pressed_color);
+        mActiveTextAlpha = ACTIVE_TEXT_ALPHA;
+        mInactiveTextAlpha = INACTIVE_TEXT_ALPHA;
         mActiveScale = ACTIVE_SCALE;
         mActiveAlpha = ACTIVE_ALPHA;
         mInactiveAlpha = INACTIVE_ALPHA;
 
         mTouched = false;
+
+        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
     }
 
     protected String rewriteIconPath(String path) {
@@ -130,54 +115,6 @@
         return path;
     }
 
-    // called from within {@link #init} to unpack the profile icon
-    protected Drawable createIcon(UserInfo user) {
-        Bitmap icon = BitmapFactory.decodeFile(rewriteIconPath(user.iconPath));
-
-        final int width = icon.getWidth();
-        final int height = icon.getHeight();
-        final int square = Math.min(width, height);
-        final float size = (float) Math.floor(mIconSize * mActiveScale);
-
-        final Bitmap output = Bitmap.createBitmap((int) size, (int) size, Bitmap.Config.ARGB_8888);
-        final Canvas canvas = new Canvas(output);
-
-        final Rect srcRect = new Rect((width - square) / 2, (height - square) / 2, square, square);
-        final RectF dstRect = new RectF(0f, 0f, size, size);
-        final RectF frameRect = new RectF(0f, 0f, size - mStroke, size - mStroke);
-        frameRect.offset(mStroke / 2f, mStroke / 2f);
-
-        final Path fillPath = new Path();
-        fillPath.addArc(dstRect, 0f, 360f);
-
-        final Path framePath = new Path();
-        framePath.addArc(frameRect, 0f, 360f);
-
-        // clear background
-        canvas.drawARGB(0, 0, 0, 0);
-
-        // opaque circle matte
-        final Paint paint = new Paint();
-        paint.setAntiAlias(true);
-        paint.setStrokeWidth(mStroke);
-        paint.setColor(mMatteColor);
-        paint.setStyle(Paint.Style.FILL);
-        canvas.drawPath(fillPath, paint);
-        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
-
-        // mask in the icon where the bitmap is opaque
-        canvas.drawBitmap(icon, srcRect, dstRect, paint);
-
-        // white frame
-        paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
-        paint.setStyle(Paint.Style.STROKE);
-        paint.setColor(mFrameColor);
-        paint.setShadowLayer(mShadowRadius, mShadowDx, mShadowDy, mFrameShadowColor);
-        canvas.drawPath(framePath, paint);
-
-        return new BitmapDrawable(output);
-    }
-
     public void init(UserInfo user, KeyguardMultiUserSelectorView userSelector) {
         mUserInfo = user;
         mUserSelector = userSelector;
@@ -185,7 +122,10 @@
         mUserImage = (ImageView) findViewById(R.id.keyguard_user_avatar);
         mUserName = (TextView) findViewById(R.id.keyguard_user_name);
 
-        mUserImage.setImageDrawable(createIcon(mUserInfo));
+        mFramed = new KeyguardCircleFramedDrawable(
+                BitmapFactory.decodeFile(rewriteIconPath(user.iconPath)), (int) mIconSize,
+                mFrameColor, mStroke, mFrameShadowColor, mShadowRadius, mHighlightColor);
+        mUserImage.setImageDrawable(mFramed);
         mUserName.setText(mUserInfo.name);
         setOnClickListener(mUserSelector);
         mInit = false;
@@ -207,13 +147,13 @@
             final Runnable onComplete) {
         final float finalAlpha = active ? mActiveAlpha : mInactiveAlpha;
         final float initAlpha = active ? mInactiveAlpha : mActiveAlpha;
-        final float finalScale = active ? mActiveScale : 1.0f;
-        final float initScale = getScaleX();
-        final int finalTextBgAlpha = active ? (int) (mActiveTextBacgroundAlpha * 255) :
-            (int) (mInactiveTextBacgroundAlpha * 255);
-        final int initTextBgAlpha = active ? (int) (mInactiveTextBacgroundAlpha * 255) :
-            (int) (mActiveTextBacgroundAlpha * 255);
-        int textColor = active ? mActiveTextColor : mInactiveTextColor;
+        final float finalScale = active ? 1f : 1f / mActiveScale;
+        final float initScale = mFramed.getScale();
+        final int finalTextAlpha = active ? (int) (mActiveTextAlpha * 255) :
+                (int) (mInactiveTextAlpha * 255);
+        final int initTextAlpha = active ? (int) (mInactiveTextAlpha * 255) :
+                (int) (mActiveTextAlpha * 255);
+        int textColor = mTextColor;
         mUserName.setTextColor(textColor);
 
         if (animate && mTouched) {
@@ -224,12 +164,11 @@
                     float r = animation.getAnimatedFraction();
                     float scale = (1 - r) * initScale + r * finalScale;
                     float alpha = (1 - r) * initAlpha + r * finalAlpha;
-                    int textBgAlpha = (int) ((1 - r) * initTextBgAlpha + r * finalTextBgAlpha);
-                    setScaleX(scale);
-                    setScaleY(scale);
+                    int textAlpha = (int) ((1 - r) * initTextAlpha + r * finalTextAlpha);
+                    mFramed.setScale(scale);
                     mUserImage.setAlpha(alpha);
-                    mUserName.setBackgroundColor(Color.argb(textBgAlpha, 0, 0, 0));
-                    mUserSelector.invalidate();
+                    mUserName.setTextColor(Color.argb(textAlpha, 255, 255, 255));
+                    mUserImage.invalidate();
                 }
             });
             va.addListener(new AnimatorListenerAdapter() {
@@ -243,10 +182,9 @@
             va.setDuration(duration);
             va.start();
         } else {
-            setScaleX(finalScale);
-            setScaleY(finalScale);
+            mFramed.setScale(finalScale);
             mUserImage.setAlpha(finalAlpha);
-            mUserName.setBackgroundColor(Color.argb(finalTextBgAlpha, 0, 0, 0));
+            mUserName.setTextColor(Color.argb(finalTextAlpha, 255, 255, 255));
             if (onComplete != null) {
                 post(onComplete);
             }
@@ -255,22 +193,11 @@
         mTouched = true;
     }
 
-    public void lockPressedState() {
-        mPressedStateLocked = true;
-    }
-
-    public void releasePressedState() {
-        mPressedStateLocked = false;
-    }
-
     @Override
     public void setPressed(boolean pressed) {
-        if (!mPressedStateLocked) {
-            super.setPressed(pressed);
-            updateVisualsForActive(pressed || mActive, false, SWITCH_ANIMATION_DURATION, null);
-        } else {
-            mTempPressedStateHolder = pressed;
-        }
+        super.setPressed(pressed);
+        mFramed.setPressed(pressed);
+        mUserImage.invalidate();
     }
 
     public UserInfo getUserInfo() {