OSDN Git Service

Update bouncer behavior on tablets.
authorChris Wren <cwren@android.com>
Tue, 30 Oct 2012 15:22:58 +0000 (11:22 -0400)
committerChris Wren <cwren@android.com>
Wed, 31 Oct 2012 19:31:20 +0000 (15:31 -0400)
Bug: 7411293
Change-Id: I1000987b9b5d481d04e095c4f8eb9eda44a81021
Proto:Id: I81fcf3541a81812b212963a5c4b379424506bc5a

policy/src/com/android/internal/policy/impl/keyguard/KeyguardMessageArea.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardSecurityContainer.java
policy/src/com/android/internal/policy/impl/keyguard/KeyguardStatusViewManager.java
policy/src/com/android/internal/policy/impl/keyguard/MultiPaneChallengeLayout.java
policy/src/com/android/internal/policy/impl/keyguard/SecurityMessageDisplay.java

index ca78cf9..5e331e1 100644 (file)
@@ -16,6 +16,9 @@
 
 package com.android.internal.policy.impl.keyguard;
 
+import android.animation.Animator;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
 import android.content.ContentResolver;
 import android.content.Context;
 import android.os.Handler;
@@ -39,11 +42,15 @@ class KeyguardMessageArea extends TextView {
     static final int BATTERY_LOW_ICON = 0; //R.drawable.ic_lock_idle_low_battery;
 
     static final int SECURITY_MESSAGE_DURATION = 5000;
-    static final String SEPARATOR = " ";
+    protected static final int FADE_DURATION = 750;
+    static final String SEPARATOR = "  ";
 
     // are we showing battery information?
     boolean mShowingBatteryInfo = false;
 
+    // is the bouncer up?
+    boolean mShowingBouncer = false;
+
     // last known plugged in state
     boolean mPluggedIn = false;
 
@@ -68,7 +75,11 @@ class KeyguardMessageArea extends TextView {
         public void run() {
             mMessage = null;
             mShowingMessage = false;
-            update();
+            if (mShowingBouncer) {
+                hideMessage(FADE_DURATION, true);
+            } else {
+                update();
+            }
         }
     };
 
@@ -103,6 +114,18 @@ class KeyguardMessageArea extends TextView {
         }
 
         @Override
+        public void showBouncer(int duration) {
+            mMessageArea.hideMessage(duration, false);
+            mMessageArea.mShowingBouncer = true;
+        }
+
+        @Override
+        public void hideBouncer(int duration) {
+            mMessageArea.showMessage(duration);
+            mMessageArea.mShowingBouncer = false;
+        }
+
+        @Override
         public void setTimeout(int timeoutMs) {
             mMessageArea.mTimeout = timeoutMs;
         }
@@ -139,6 +162,7 @@ class KeyguardMessageArea extends TextView {
     }
 
     public void securityMessageChanged() {
+        setAlpha(1f);
         mShowingMessage = true;
         update();
         mHandler.removeCallbacks(mClearMessageRunnable);
@@ -212,4 +236,23 @@ class KeyguardMessageArea extends TextView {
         return string;
     }
 
+    private void hideMessage(int duration, boolean thenUpdate) {
+        Animator anim = ObjectAnimator.ofFloat(this, "alpha", 0f);
+        anim.setDuration(duration);
+        if (thenUpdate) {
+            anim.addListener(new AnimatorListenerAdapter() {
+                    @Override
+                        public void onAnimationEnd(Animator animation) {
+                        update();
+                    }
+                });
+        }
+        anim.start();
+    }
+
+    private void showMessage(int duration) {
+        Animator anim = ObjectAnimator.ofFloat(this, "alpha", 1f);
+        anim.setDuration(duration);
+        anim.start();
+    }
 }
index f6a90c5..04ab0a2 100644 (file)
@@ -1,11 +1,20 @@
 package com.android.internal.policy.impl.keyguard;
 
+import android.animation.Animator;
+import android.animation.ObjectAnimator;
 import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.drawable.Drawable;
 import android.util.AttributeSet;
 import android.widget.FrameLayout;
 
+import com.android.internal.R;
+
 public class KeyguardSecurityContainer extends FrameLayout {
 
+    private float mBackgroundAlpha;
+    private Drawable mBackgroundDrawable;
+
     public KeyguardSecurityContainer(Context context, AttributeSet attrs) {
         this(context, attrs, 0);
     }
@@ -16,5 +25,44 @@ public class KeyguardSecurityContainer extends FrameLayout {
 
     public KeyguardSecurityContainer(Context context, AttributeSet attrs, int defStyle) {
         super(context, attrs, defStyle);
+        mBackgroundDrawable = context.getResources().getDrawable(R.drawable.kg_bouncer_bg_white);
+    }
+
+    public void setBackgroundAlpha(float alpha) {
+        if (Float.compare(mBackgroundAlpha, alpha) != 0) {
+            mBackgroundAlpha = alpha;
+            invalidate();
+        }
+    }
+
+    public float getBackgroundAlpha() {
+        return mBackgroundAlpha;
+    }
+
+    @Override
+    protected void dispatchDraw(Canvas canvas) {
+        if (mBackgroundAlpha > 0.0f && mBackgroundDrawable != null) {
+            Drawable bg = mBackgroundDrawable;
+            bg.setAlpha((int) (mBackgroundAlpha * 255));
+            bg.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
+            bg.draw(canvas);
+        }
+        super.dispatchDraw(canvas);
+    }
+
+    public void showBouncer(int duration) {
+        SecurityMessageDisplay message = new KeyguardMessageArea.Helper(this);
+        message.showBouncer(duration);
+        Animator anim = ObjectAnimator.ofFloat(this, "BackgroundAlpha", 1f);
+        anim.setDuration(duration);
+        anim.start();
+    }
+
+    public void hideBouncer(int duration) {
+        SecurityMessageDisplay message = new KeyguardMessageArea.Helper(this);
+        message.hideBouncer(duration);
+        Animator anim = ObjectAnimator.ofFloat(this, "BackgroundAlpha", 0f);
+        anim.setDuration(duration);
+        anim.start();
     }
 }
index b4bd6e9..7100f1c 100644 (file)
@@ -327,6 +327,14 @@ class KeyguardStatusViewManager implements SecurityMessageDisplay {
     }
 
     @Override
+    public void showBouncer(int duration) {
+    }
+
+    @Override
+    public void hideBouncer(int duration) {
+    }
+
+    @Override
     public void setTimeout(int timeout_ms) {
     }
 
index a207f5d..b38eb28 100644 (file)
 
 package com.android.internal.policy.impl.keyguard;
 
+import android.animation.Animator;
+import android.animation.AnimatorSet;
+import android.animation.AnimatorListenerAdapter;
+import android.animation.ObjectAnimator;
 import android.content.Context;
 import android.content.res.TypedArray;
 import android.graphics.Rect;
@@ -35,8 +39,9 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
 
     public static final int HORIZONTAL = LinearLayout.HORIZONTAL;
     public static final int VERTICAL = LinearLayout.VERTICAL;
+    protected static final int ANIMATE_BOUNCE_DURATION = 750;
 
-    private View mChallengeView;
+    private KeyguardSecurityContainer mChallengeView;
     private View mUserSwitcherView;
     private View mScrimView;
     private OnBouncerStateChangedListener mBouncerListener;
@@ -87,7 +92,19 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
         if (mIsBouncing) return;
         mIsBouncing = true;
         if (mScrimView != null) {
-            mScrimView.setVisibility(GONE);
+            if (mChallengeView != null) {
+                mChallengeView.showBouncer(ANIMATE_BOUNCE_DURATION);
+            }
+
+            Animator anim = ObjectAnimator.ofFloat(mScrimView, "alpha", 1f);
+            anim.setDuration(ANIMATE_BOUNCE_DURATION);
+            anim.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationStart(Animator animation) {
+                    mScrimView.setVisibility(VISIBLE);
+                }
+            });
+            anim.start();
         }
         if (mBouncerListener != null) {
             mBouncerListener.onBouncerStateChanged(true);
@@ -99,7 +116,19 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
         if (!mIsBouncing) return;
         mIsBouncing = false;
         if (mScrimView != null) {
-            mScrimView.setVisibility(GONE);
+            if (mChallengeView != null) {
+                mChallengeView.hideBouncer(ANIMATE_BOUNCE_DURATION);
+            }
+
+            Animator anim = ObjectAnimator.ofFloat(mScrimView, "alpha", 0f);
+            anim.setDuration(ANIMATE_BOUNCE_DURATION);
+            anim.addListener(new AnimatorListenerAdapter() {
+                @Override
+                public void onAnimationEnd(Animator animation) {
+                    mScrimView.setVisibility(INVISIBLE);
+                }
+            });
+            anim.start();
         }
         if (mBouncerListener != null) {
             mBouncerListener.onBouncerStateChanged(false);
@@ -131,7 +160,8 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
             mScrimView.setOnClickListener(null);
         }
         mScrimView = scrim;
-        mScrimView.setVisibility(mIsBouncing ? VISIBLE : GONE);
+        mScrimView.setAlpha(mIsBouncing ? 1.0f : 0.0f);
+        mScrimView.setVisibility(mIsBouncing ? VISIBLE : INVISIBLE);
         mScrimView.setFocusable(true);
         mScrimView.setOnClickListener(mScrimClickListener);
     }
@@ -165,7 +195,11 @@ public class MultiPaneChallengeLayout extends ViewGroup implements ChallengeLayo
                     throw new IllegalStateException(
                             "There may only be one child of type challenge");
                 }
-                mChallengeView = child;
+                if (!(child instanceof KeyguardSecurityContainer)) {
+                    throw new IllegalArgumentException(
+                            "Challenge must be a KeyguardSecurityContainer");
+                }
+                mChallengeView = (KeyguardSecurityContainer) child;
             } else if (lp.childType == LayoutParams.CHILD_TYPE_USER_SWITCHER) {
                 if (mUserSwitcherView != null) {
                     throw new IllegalStateException(
index ec6472f..7760279 100644 (file)
@@ -24,4 +24,8 @@ public interface SecurityMessageDisplay {
     public void setMessage(int resId, boolean important, Object... formatArgs);
 
     public void setTimeout(int timeout_ms);
+
+    public void showBouncer(int animationDuration);
+
+    public void hideBouncer(int animationDuration);
 }