FileDocCategorySizeDatePackage
KeyguardMultiUserAvatar.javaAPI DocAndroid 5.1 API9424Thu Mar 12 22:22:42 GMT 2015com.android.keyguard

KeyguardMultiUserAvatar

public class KeyguardMultiUserAvatar extends android.widget.FrameLayout

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private android.widget.ImageView
mUserImage
private android.widget.TextView
mUserName
private android.content.pm.UserInfo
mUserInfo
private static final float
ACTIVE_ALPHA
private static final float
INACTIVE_ALPHA
private static final float
ACTIVE_SCALE
private static final float
ACTIVE_TEXT_ALPHA
private static final float
INACTIVE_TEXT_ALPHA
private static final int
SWITCH_ANIMATION_DURATION
private final float
mActiveAlpha
private final float
mActiveScale
private final float
mActiveTextAlpha
private final float
mInactiveAlpha
private final float
mInactiveTextAlpha
private final float
mShadowRadius
private final float
mStroke
private final float
mIconSize
private final int
mFrameColor
private final int
mFrameShadowColor
private final int
mTextColor
private final int
mHighlightColor
private boolean
mTouched
private boolean
mActive
private boolean
mInit
private KeyguardMultiUserSelectorView
mUserSelector
private KeyguardCircleFramedDrawable
mFramed
private boolean
mPressLock
private android.os.UserManager
mUserManager
Constructors Summary
public KeyguardMultiUserAvatar(android.content.Context context)

        this(context, null, 0);
    
public KeyguardMultiUserAvatar(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, 0);
    
public KeyguardMultiUserAvatar(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);

        Resources res = mContext.getResources();
        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);
        mFrameColor = res.getColor(R.color.keyguard_avatar_frame_color);
        mFrameShadowColor = res.getColor(R.color.keyguard_avatar_frame_shadow_color);
        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;
        mUserManager = (UserManager) mContext.getSystemService(Context.USER_SERVICE);

        mTouched = false;

        setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    
Methods Summary
public static com.android.keyguard.KeyguardMultiUserAvatarfromXml(int resId, android.content.Context context, KeyguardMultiUserSelectorView userSelector, android.content.pm.UserInfo info)


          
                
        KeyguardMultiUserAvatar icon = (KeyguardMultiUserAvatar)
                LayoutInflater.from(context).inflate(resId, userSelector, false);

        icon.init(info, userSelector);
        return icon;
    
public android.content.pm.UserInfogetUserInfo()

        return mUserInfo;
    
public voidinit(android.content.pm.UserInfo user, KeyguardMultiUserSelectorView userSelector)

        mUserInfo = user;
        mUserSelector = userSelector;

        mUserImage = (ImageView) findViewById(R.id.keyguard_user_avatar);
        mUserName = (TextView) findViewById(R.id.keyguard_user_name);

        mFramed = (KeyguardCircleFramedDrawable)
                MultiUserAvatarCache.getInstance().get(user.id);

        // If we can't find it or the params don't match, create the drawable again
        if (mFramed == null
                || !mFramed.verifyParams(mIconSize, mFrameColor, mStroke, mFrameShadowColor,
                        mShadowRadius, mHighlightColor)) {
            Bitmap icon = null;
            try {
                icon = mUserManager.getUserIcon(user.id);
            } catch (Exception e) {
                if (DEBUG) Log.d(TAG, "failed to get profile icon " + user, e);
            }

            if (icon == null) {
                icon = BitmapFactory.decodeResource(mContext.getResources(),
                        com.android.internal.R.drawable.ic_contact_picture);
            }

            mFramed = new KeyguardCircleFramedDrawable(icon, (int) mIconSize, mFrameColor, mStroke,
                    mFrameShadowColor, mShadowRadius, mHighlightColor);
            MultiUserAvatarCache.getInstance().put(user.id, mFramed);
        }

        mFramed.reset();

        mUserImage.setImageDrawable(mFramed);
        mUserName.setText(mUserInfo.name);
        setOnClickListener(mUserSelector);
        mInit = false;
    
public voidlockPressed(boolean pressed)

        mPressLock = pressed;
        setPressed(pressed);
    
protected java.lang.StringrewriteIconPath(java.lang.String path)

        return path;
    
public voidsetActive(boolean active, boolean animate, java.lang.Runnable onComplete)

        if (mActive != active || mInit) {
            mActive = active;

            if (active) {
                KeyguardLinearLayout parent = (KeyguardLinearLayout) getParent();
                parent.setTopChild(this);
                // TODO: Create an appropriate asset when string changes are possible.
                setContentDescription(mUserName.getText()
                        + ". " + mContext.getString(R.string.user_switched, ""));
            } else {
                setContentDescription(mUserName.getText());
            }
        }
        updateVisualsForActive(mActive, animate, SWITCH_ANIMATION_DURATION, onComplete);
    
public voidsetPressed(boolean pressed)

        if (mPressLock && !pressed) {
            return;
        }

        if (mPressLock || !pressed || isClickable()) {
            super.setPressed(pressed);
            mFramed.setPressed(pressed);
            mUserImage.invalidate();
        }
    
voidupdateVisualsForActive(boolean active, boolean animate, int duration, java.lang.Runnable onComplete)

        final float finalAlpha = active ? mActiveAlpha : mInactiveAlpha;
        final float initAlpha = active ? mInactiveAlpha : mActiveAlpha;
        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) {
            ValueAnimator va = ValueAnimator.ofFloat(0f, 1f);
            va.addUpdateListener(new AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float r = animation.getAnimatedFraction();
                    float scale = (1 - r) * initScale + r * finalScale;
                    float alpha = (1 - r) * initAlpha + r * finalAlpha;
                    int textAlpha = (int) ((1 - r) * initTextAlpha + r * finalTextAlpha);
                    mFramed.setScale(scale);
                    mUserImage.setAlpha(alpha);
                    mUserName.setTextColor(Color.argb(textAlpha, 255, 255, 255));
                    mUserImage.invalidate();
                }
            });
            va.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (onComplete != null) {
                        onComplete.run();
                    }
                }
            });
            va.setDuration(duration);
            va.start();
        } else {
            mFramed.setScale(finalScale);
            mUserImage.setAlpha(finalAlpha);
            mUserName.setTextColor(Color.argb(finalTextAlpha, 255, 255, 255));
            if (onComplete != null) {
                post(onComplete);
            }
        }

        mTouched = true;