Skip to content

Commit f778bfd

Browse files
cwrenAndroid (Google) Code Review
authored andcommitted
Merge "Update bouncer behavior on tablets." into jb-mr1-lockscreen-dev
2 parents 5b03984 + c345146 commit f778bfd

File tree

5 files changed

+144
-7
lines changed

5 files changed

+144
-7
lines changed

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

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616

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

19+
import android.animation.Animator;
20+
import android.animation.AnimatorListenerAdapter;
21+
import android.animation.ObjectAnimator;
1922
import android.content.ContentResolver;
2023
import android.content.Context;
2124
import android.os.Handler;
@@ -39,11 +42,15 @@ class KeyguardMessageArea extends TextView {
3942
static final int BATTERY_LOW_ICON = 0; //R.drawable.ic_lock_idle_low_battery;
4043

4144
static final int SECURITY_MESSAGE_DURATION = 5000;
42-
static final String SEPARATOR = " ";
45+
protected static final int FADE_DURATION = 750;
46+
static final String SEPARATOR = " ";
4347

4448
// are we showing battery information?
4549
boolean mShowingBatteryInfo = false;
4650

51+
// is the bouncer up?
52+
boolean mShowingBouncer = false;
53+
4754
// last known plugged in state
4855
boolean mPluggedIn = false;
4956

@@ -68,7 +75,11 @@ class KeyguardMessageArea extends TextView {
6875
public void run() {
6976
mMessage = null;
7077
mShowingMessage = false;
71-
update();
78+
if (mShowingBouncer) {
79+
hideMessage(FADE_DURATION, true);
80+
} else {
81+
update();
82+
}
7283
}
7384
};
7485

@@ -102,6 +113,18 @@ public void setMessage(int resId, boolean important, Object... formatArgs) {
102113
}
103114
}
104115

116+
@Override
117+
public void showBouncer(int duration) {
118+
mMessageArea.hideMessage(duration, false);
119+
mMessageArea.mShowingBouncer = true;
120+
}
121+
122+
@Override
123+
public void hideBouncer(int duration) {
124+
mMessageArea.showMessage(duration);
125+
mMessageArea.mShowingBouncer = false;
126+
}
127+
105128
@Override
106129
public void setTimeout(int timeoutMs) {
107130
mMessageArea.mTimeout = timeoutMs;
@@ -139,6 +162,7 @@ public KeyguardMessageArea(Context context, AttributeSet attrs) {
139162
}
140163

141164
public void securityMessageChanged() {
165+
setAlpha(1f);
142166
mShowingMessage = true;
143167
update();
144168
mHandler.removeCallbacks(mClearMessageRunnable);
@@ -212,4 +236,23 @@ private CharSequence getChargeInfo(MutableInt icon) {
212236
return string;
213237
}
214238

239+
private void hideMessage(int duration, boolean thenUpdate) {
240+
Animator anim = ObjectAnimator.ofFloat(this, "alpha", 0f);
241+
anim.setDuration(duration);
242+
if (thenUpdate) {
243+
anim.addListener(new AnimatorListenerAdapter() {
244+
@Override
245+
public void onAnimationEnd(Animator animation) {
246+
update();
247+
}
248+
});
249+
}
250+
anim.start();
251+
}
252+
253+
private void showMessage(int duration) {
254+
Animator anim = ObjectAnimator.ofFloat(this, "alpha", 1f);
255+
anim.setDuration(duration);
256+
anim.start();
257+
}
215258
}

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

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
package com.android.internal.policy.impl.keyguard;
22

3+
import android.animation.Animator;
4+
import android.animation.ObjectAnimator;
35
import android.content.Context;
6+
import android.graphics.Canvas;
7+
import android.graphics.drawable.Drawable;
48
import android.util.AttributeSet;
59
import android.widget.FrameLayout;
610

11+
import com.android.internal.R;
12+
713
public class KeyguardSecurityContainer extends FrameLayout {
814

15+
private float mBackgroundAlpha;
16+
private Drawable mBackgroundDrawable;
17+
918
public KeyguardSecurityContainer(Context context, AttributeSet attrs) {
1019
this(context, attrs, 0);
1120
}
@@ -16,5 +25,44 @@ public KeyguardSecurityContainer(Context context) {
1625

1726
public KeyguardSecurityContainer(Context context, AttributeSet attrs, int defStyle) {
1827
super(context, attrs, defStyle);
28+
mBackgroundDrawable = context.getResources().getDrawable(R.drawable.kg_bouncer_bg_white);
29+
}
30+
31+
public void setBackgroundAlpha(float alpha) {
32+
if (Float.compare(mBackgroundAlpha, alpha) != 0) {
33+
mBackgroundAlpha = alpha;
34+
invalidate();
35+
}
36+
}
37+
38+
public float getBackgroundAlpha() {
39+
return mBackgroundAlpha;
40+
}
41+
42+
@Override
43+
protected void dispatchDraw(Canvas canvas) {
44+
if (mBackgroundAlpha > 0.0f && mBackgroundDrawable != null) {
45+
Drawable bg = mBackgroundDrawable;
46+
bg.setAlpha((int) (mBackgroundAlpha * 255));
47+
bg.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
48+
bg.draw(canvas);
49+
}
50+
super.dispatchDraw(canvas);
51+
}
52+
53+
public void showBouncer(int duration) {
54+
SecurityMessageDisplay message = new KeyguardMessageArea.Helper(this);
55+
message.showBouncer(duration);
56+
Animator anim = ObjectAnimator.ofFloat(this, "BackgroundAlpha", 1f);
57+
anim.setDuration(duration);
58+
anim.start();
59+
}
60+
61+
public void hideBouncer(int duration) {
62+
SecurityMessageDisplay message = new KeyguardMessageArea.Helper(this);
63+
message.hideBouncer(duration);
64+
Animator anim = ObjectAnimator.ofFloat(this, "BackgroundAlpha", 0f);
65+
anim.setDuration(duration);
66+
anim.start();
1967
}
2068
}

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,14 @@ private Context getContext() {
326326
return mContainer.getContext();
327327
}
328328

329+
@Override
330+
public void showBouncer(int duration) {
331+
}
332+
333+
@Override
334+
public void hideBouncer(int duration) {
335+
}
336+
329337
@Override
330338
public void setTimeout(int timeout_ms) {
331339
}

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

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616

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

19+
import android.animation.Animator;
20+
import android.animation.AnimatorSet;
21+
import android.animation.AnimatorListenerAdapter;
22+
import android.animation.ObjectAnimator;
1923
import android.content.Context;
2024
import android.content.res.TypedArray;
2125
import android.graphics.Rect;
@@ -35,8 +39,9 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
3539

3640
public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
3741
public static final int VERTICAL = LinearLayout.VERTICAL;
42+
protected static final int ANIMATE_BOUNCE_DURATION = 750;
3843

39-
private View mChallengeView;
44+
private KeyguardSecurityContainer mChallengeView;
4045
private View mUserSwitcherView;
4146
private View mScrimView;
4247
private OnBouncerStateChangedListener mBouncerListener;
@@ -87,7 +92,19 @@ public void showBouncer() {
8792
if (mIsBouncing) return;
8893
mIsBouncing = true;
8994
if (mScrimView != null) {
90-
mScrimView.setVisibility(GONE);
95+
if (mChallengeView != null) {
96+
mChallengeView.showBouncer(ANIMATE_BOUNCE_DURATION);
97+
}
98+
99+
Animator anim = ObjectAnimator.ofFloat(mScrimView, "alpha", 1f);
100+
anim.setDuration(ANIMATE_BOUNCE_DURATION);
101+
anim.addListener(new AnimatorListenerAdapter() {
102+
@Override
103+
public void onAnimationStart(Animator animation) {
104+
mScrimView.setVisibility(VISIBLE);
105+
}
106+
});
107+
anim.start();
91108
}
92109
if (mBouncerListener != null) {
93110
mBouncerListener.onBouncerStateChanged(true);
@@ -99,7 +116,19 @@ public void hideBouncer() {
99116
if (!mIsBouncing) return;
100117
mIsBouncing = false;
101118
if (mScrimView != null) {
102-
mScrimView.setVisibility(GONE);
119+
if (mChallengeView != null) {
120+
mChallengeView.hideBouncer(ANIMATE_BOUNCE_DURATION);
121+
}
122+
123+
Animator anim = ObjectAnimator.ofFloat(mScrimView, "alpha", 0f);
124+
anim.setDuration(ANIMATE_BOUNCE_DURATION);
125+
anim.addListener(new AnimatorListenerAdapter() {
126+
@Override
127+
public void onAnimationEnd(Animator animation) {
128+
mScrimView.setVisibility(INVISIBLE);
129+
}
130+
});
131+
anim.start();
103132
}
104133
if (mBouncerListener != null) {
105134
mBouncerListener.onBouncerStateChanged(false);
@@ -131,7 +160,8 @@ void setScrimView(View scrim) {
131160
mScrimView.setOnClickListener(null);
132161
}
133162
mScrimView = scrim;
134-
mScrimView.setVisibility(mIsBouncing ? VISIBLE : GONE);
163+
mScrimView.setAlpha(mIsBouncing ? 1.0f : 0.0f);
164+
mScrimView.setVisibility(mIsBouncing ? VISIBLE : INVISIBLE);
135165
mScrimView.setFocusable(true);
136166
mScrimView.setOnClickListener(mScrimClickListener);
137167
}
@@ -165,7 +195,11 @@ protected void onMeasure(int widthSpec, int heightSpec) {
165195
throw new IllegalStateException(
166196
"There may only be one child of type challenge");
167197
}
168-
mChallengeView = child;
198+
if (!(child instanceof KeyguardSecurityContainer)) {
199+
throw new IllegalArgumentException(
200+
"Challenge must be a KeyguardSecurityContainer");
201+
}
202+
mChallengeView = (KeyguardSecurityContainer) child;
169203
} else if (lp.childType == LayoutParams.CHILD_TYPE_USER_SWITCHER) {
170204
if (mUserSwitcherView != null) {
171205
throw new IllegalStateException(

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,8 @@ public interface SecurityMessageDisplay {
2424
public void setMessage(int resId, boolean important, Object... formatArgs);
2525

2626
public void setTimeout(int timeout_ms);
27+
28+
public void showBouncer(int animationDuration);
29+
30+
public void hideBouncer(int animationDuration);
2731
}

0 commit comments

Comments
 (0)