Skip to content

Commit 6253985

Browse files
Adam CohenAndroid (Google) Code Review
authored andcommitted
Merge "Second pass on Keyguard multi-user switcher" into jb-mr1-dev
2 parents 4505a43 + 24b351a commit 6253985

File tree

10 files changed

+428
-63
lines changed

10 files changed

+428
-63
lines changed

core/res/res/anim/screen_user_enter.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
-->
1818

1919
<set xmlns:android="http://schemas.android.com/apk/res/android">
20-
<translate android:fromXDelta="100%p" android:toXDelta="0"
21-
android:duration="500"
22-
android:interpolator="@interpolator/decelerate_quad" />
2320
<alpha android:fromAlpha="0.0" android:toAlpha="1.0"
2421
android:duration="500"
2522
android:interpolator="@interpolator/decelerate_quad" />

core/res/res/anim/screen_user_exit.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,6 @@
1717
-->
1818

1919
<set xmlns:android="http://schemas.android.com/apk/res/android">
20-
<translate android:fromXDelta="0" android:toXDelta="-100%p"
21-
android:duration="500"
22-
android:interpolator="@interpolator/decelerate_quad" />
2320
<alpha android:fromAlpha="1.0" android:toAlpha="0.0"
2421
android:duration="500"
2522
android:interpolator="@interpolator/decelerate_quad" />
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!-- Copyright (C) 2012 The Android Open Source Project
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
-->
16+
17+
<selector xmlns:android="http://schemas.android.com/apk/res/android">
18+
<item android:state_pressed="true"
19+
android:drawable="@drawable/activity_picker_bg_activated" />
20+
</selector>

core/res/res/layout/keyguard_multi_user_avatar.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,11 @@
2323
android:layout_width="125dp"
2424
android:layout_height="125dp"
2525
android:background="#550000ff"
26-
android:gravity="center_horizontal">
26+
android:gravity="center_horizontal"
27+
android:foreground="@drawable/kg_avatar_overlay">
2728
<ImageView
2829
android:id="@+id/keyguard_user_avatar"
30+
android:scaleType="centerCrop"
2931
android:layout_width="match_parent"
3032
android:layout_height="match_parent"
3133
android:layout_gravity="center"/>

core/res/res/layout/keyguard_multi_user_selector.xml

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,23 +19,15 @@
1919
<com.android.internal.policy.impl.keyguard.KeyguardMultiUserSelectorView
2020
xmlns:android="http://schemas.android.com/apk/res/android"
2121
android:orientation="horizontal"
22-
android:layout_width="375dp"
23-
android:layout_height="wrap_content"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
2424
android:layout_gravity="center">
2525

26-
<include
27-
android:id="@+id/keyguard_active_user"
28-
android:layout_width="250dp"
29-
android:layout_height="250dp"
30-
layout="@layout/keyguard_multi_user_avatar"/>
26+
<com.android.internal.policy.impl.keyguard.KeyguardSubdivisionLayout
27+
android:id="@+id/keyguard_users_grid"
28+
android:orientation="horizontal"
29+
android:layout_width="300dp"
30+
android:layout_height="300dp"
31+
android:layout_gravity="center" />
3132

32-
<ScrollView
33-
android:layout_width="125dp"
34-
android:layout_height="250dp">
35-
<LinearLayout
36-
android:id="@+id/keyguard_inactive_users"
37-
android:orientation="vertical"
38-
layout_width="match_parent"
39-
layout_height="wrap_content"/>
40-
</ScrollView>
4133
</com.android.internal.policy.impl.keyguard.KeyguardMultiUserSelectorView>

core/res/res/values/symbols.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,10 +1260,9 @@
12601260
<java-symbol type="id" name="pin_delete_button" />
12611261
<java-symbol type="id" name="keyguard_user_avatar" />
12621262
<java-symbol type="id" name="keyguard_user_name" />
1263-
<java-symbol type="id" name="keyguard_active_user" />
1264-
<java-symbol type="id" name="keyguard_inactive_users" />
12651263
<java-symbol type="id" name="keyguard_transport_control" />
12661264
<java-symbol type="id" name="keyguard_status_view" />
1265+
<java-symbol type="id" name="keyguard_users_grid" />
12671266
<java-symbol type="integer" name="config_carDockRotation" />
12681267
<java-symbol type="integer" name="config_defaultUiModeType" />
12691268
<java-symbol type="integer" name="config_deskDockRotation" />

policy/src/com/android/internal/policy/impl/keyguard/KeyguardHostView.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ public class KeyguardHostView extends KeyguardViewBase {
8686
void show();
8787
}
8888

89+
/*package*/ interface UserSwitcherCallback {
90+
void hideSecurityView(int duration);
91+
void showSecurityView();
92+
}
93+
8994
public KeyguardHostView(Context context) {
9095
this(context, null);
9196
}
@@ -691,11 +696,27 @@ private void inflateAndAddUserSelectorWidgetIfNecessary() {
691696
List<UserInfo> users = mUm.getUsers();
692697

693698
if (users.size() > 1) {
694-
KeyguardWidgetFrame userswitcher = (KeyguardWidgetFrame)
699+
KeyguardWidgetFrame userSwitcher = (KeyguardWidgetFrame)
695700
LayoutInflater.from(mContext).inflate(R.layout.keyguard_multi_user_selector_widget,
696701
mAppWidgetContainer, false);
697-
// add the switcher to the left of status view
698-
mAppWidgetContainer.addView(userswitcher, getWidgetPosition(R.id.keyguard_status_view));
702+
703+
// add the switcher in the first position
704+
mAppWidgetContainer.addView(userSwitcher, getWidgetPosition(R.id.keyguard_status_view));
705+
KeyguardMultiUserSelectorView multiUser = (KeyguardMultiUserSelectorView)
706+
userSwitcher.getChildAt(0);
707+
708+
UserSwitcherCallback callback = new UserSwitcherCallback() {
709+
@Override
710+
public void hideSecurityView(int duration) {
711+
mSecurityViewContainer.animate().alpha(0).setDuration(duration);
712+
}
713+
714+
@Override
715+
public void showSecurityView() {
716+
mSecurityViewContainer.setAlpha(1.0f);
717+
}
718+
};
719+
multiUser.setCallback(callback);
699720
}
700721
}
701722

policy/src/com/android/internal/policy/impl/keyguard/KeyguardMultiUserAvatar.java

Lines changed: 89 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,28 +16,33 @@
1616

1717
package com.android.internal.policy.impl.keyguard;
1818

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;
2023
import android.content.Context;
2124
import android.content.pm.UserInfo;
25+
import android.graphics.Color;
2226
import android.graphics.drawable.Drawable;
23-
import android.os.RemoteException;
2427
import android.util.AttributeSet;
25-
import android.util.Log;
2628
import android.view.LayoutInflater;
27-
import android.view.View;
28-
import android.view.WindowManagerGlobal;
29+
import android.view.ViewGroup;
2930
import android.widget.FrameLayout;
3031
import android.widget.ImageView;
3132
import android.widget.TextView;
3233

3334
import com.android.internal.R;
3435

3536
class KeyguardMultiUserAvatar extends FrameLayout {
36-
private static final String TAG = "KeyguardViewHost";
3737

3838
private ImageView mUserImage;
3939
private TextView mUserName;
4040
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;
4146
private KeyguardMultiUserSelectorView mUserSelector;
4247

4348
public static KeyguardMultiUserAvatar fromXml(int resId, Context context,
@@ -73,17 +78,86 @@ private void init() {
7378

7479
mUserImage.setImageDrawable(Drawable.createFromPath(mUserInfo.iconPath));
7580
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);
85133
}
86134
}
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+
}
87151
});
88152
}
153+
154+
protected void drawableStateChanged() {
155+
if (!mLockDrawableState) {
156+
super.drawableStateChanged();
157+
}
158+
}
159+
160+
public UserInfo getUserInfo() {
161+
return mUserInfo;
162+
}
89163
}

0 commit comments

Comments
 (0)