|
16 | 16 |
|
17 | 17 | package com.android.internal.policy.impl.keyguard; |
18 | 18 |
|
19 | | -import android.app.ActivityManagerNative; |
| 19 | +import android.animation.Animator; |
| 20 | +import android.animation.AnimatorListenerAdapter; |
| 21 | +import android.animation.ValueAnimator; |
| 22 | +import android.animation.ValueAnimator.AnimatorUpdateListener; |
20 | 23 | import android.content.Context; |
21 | 24 | import android.content.pm.UserInfo; |
| 25 | +import android.graphics.Color; |
22 | 26 | import android.graphics.drawable.Drawable; |
23 | | -import android.os.RemoteException; |
24 | 27 | import android.util.AttributeSet; |
25 | | -import android.util.Log; |
26 | 28 | import android.view.LayoutInflater; |
27 | | -import android.view.View; |
28 | | -import android.view.WindowManagerGlobal; |
| 29 | +import android.view.ViewGroup; |
29 | 30 | import android.widget.FrameLayout; |
30 | 31 | import android.widget.ImageView; |
31 | 32 | import android.widget.TextView; |
32 | 33 |
|
33 | 34 | import com.android.internal.R; |
34 | 35 |
|
35 | 36 | class KeyguardMultiUserAvatar extends FrameLayout { |
36 | | - private static final String TAG = "KeyguardViewHost"; |
37 | 37 |
|
38 | 38 | private ImageView mUserImage; |
39 | 39 | private TextView mUserName; |
40 | 40 | private UserInfo mUserInfo; |
| 41 | + private static final int INACTIVE_COLOR = 85; |
| 42 | + private static final int INACTIVE_ALPHA = 195; |
| 43 | + private static final float ACTIVE_SCALE = 1.1f; |
| 44 | + private boolean mActive; |
| 45 | + private boolean mInit = true; |
41 | 46 | private KeyguardMultiUserSelectorView mUserSelector; |
42 | 47 |
|
43 | 48 | public static KeyguardMultiUserAvatar fromXml(int resId, Context context, |
@@ -73,17 +78,86 @@ private void init() { |
73 | 78 |
|
74 | 79 | mUserImage.setImageDrawable(Drawable.createFromPath(mUserInfo.iconPath)); |
75 | 80 | mUserName.setText(mUserInfo.name); |
76 | | - setOnClickListener(new OnClickListener() { |
77 | | - @Override |
78 | | - public void onClick(View v) { |
79 | | - try { |
80 | | - ActivityManagerNative.getDefault().switchUser(mUserInfo.id); |
81 | | - WindowManagerGlobal.getWindowManagerService().lockNow(); |
82 | | - mUserSelector.init(); |
83 | | - } catch (RemoteException re) { |
84 | | - Log.e(TAG, "Couldn't switch user " + re); |
| 81 | + setOnClickListener(mUserSelector); |
| 82 | + setActive(false, false, 0, null); |
| 83 | + mInit = false; |
| 84 | + } |
| 85 | + |
| 86 | + public void setActive(boolean active, boolean animate, int duration, final Runnable onComplete) { |
| 87 | + if (mActive != active || mInit) { |
| 88 | + mActive = active; |
| 89 | + final int finalFilterAlpha = mActive ? 0 : INACTIVE_ALPHA; |
| 90 | + final int initFilterAlpha = mActive ? INACTIVE_ALPHA : 0; |
| 91 | + |
| 92 | + final float finalScale = mActive ? ACTIVE_SCALE : 1.0f; |
| 93 | + final float initScale = mActive ? 1.0f : ACTIVE_SCALE; |
| 94 | + |
| 95 | + if (active) { |
| 96 | + KeyguardSubdivisionLayout parent = (KeyguardSubdivisionLayout) getParent(); |
| 97 | + parent.setTopChild(parent.indexOfChild(this)); |
| 98 | + } |
| 99 | + |
| 100 | + if (animate) { |
| 101 | + ValueAnimator va = ValueAnimator.ofFloat(0f, 1f); |
| 102 | + va.addUpdateListener(new AnimatorUpdateListener() { |
| 103 | + @Override |
| 104 | + public void onAnimationUpdate(ValueAnimator animation) { |
| 105 | + float r = animation.getAnimatedFraction(); |
| 106 | + float scale = (1 - r) * initScale + r * finalScale; |
| 107 | + int filterAlpha = (int) ((1 - r) * initFilterAlpha + r * finalFilterAlpha); |
| 108 | + setScaleX(scale); |
| 109 | + setScaleY(scale); |
| 110 | + mUserImage.setColorFilter(Color.argb(filterAlpha, INACTIVE_COLOR, |
| 111 | + INACTIVE_COLOR, INACTIVE_COLOR)); |
| 112 | + mUserSelector.invalidate(); |
| 113 | + |
| 114 | + } |
| 115 | + }); |
| 116 | + va.addListener(new AnimatorListenerAdapter() { |
| 117 | + @Override |
| 118 | + public void onAnimationEnd(Animator animation) { |
| 119 | + if (onComplete != null) { |
| 120 | + onComplete.run(); |
| 121 | + } |
| 122 | + } |
| 123 | + }); |
| 124 | + va.setDuration(duration); |
| 125 | + va.start(); |
| 126 | + } else { |
| 127 | + setScaleX(finalScale); |
| 128 | + setScaleY(finalScale); |
| 129 | + mUserImage.setColorFilter(Color.argb(finalFilterAlpha, INACTIVE_COLOR, |
| 130 | + INACTIVE_COLOR, INACTIVE_COLOR)); |
| 131 | + if (onComplete != null) { |
| 132 | + post(onComplete); |
85 | 133 | } |
86 | 134 | } |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + boolean mLockDrawableState = false; |
| 139 | + |
| 140 | + public void lockDrawableState() { |
| 141 | + mLockDrawableState = true; |
| 142 | + } |
| 143 | + |
| 144 | + public void resetDrawableState() { |
| 145 | + mLockDrawableState = false; |
| 146 | + post(new Runnable() { |
| 147 | + @Override |
| 148 | + public void run() { |
| 149 | + refreshDrawableState(); |
| 150 | + } |
87 | 151 | }); |
88 | 152 | } |
| 153 | + |
| 154 | + protected void drawableStateChanged() { |
| 155 | + if (!mLockDrawableState) { |
| 156 | + super.drawableStateChanged(); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + public UserInfo getUserInfo() { |
| 161 | + return mUserInfo; |
| 162 | + } |
89 | 163 | } |
0 commit comments