Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c345146a authored by Chris Wren's avatar Chris Wren
Browse files

Update bouncer behavior on tablets.

Bug: 7411293
Change-Id: I1000987b9b5d481d04e095c4f8eb9eda44a81021
Proto:Id: I81fcf3541a81812b212963a5c4b379424506bc5a
parent 1b33342b
Loading
Loading
Loading
Loading
+45 −2
Original line number Diff line number Diff line
@@ -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;
    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,8 +75,12 @@ class KeyguardMessageArea extends TextView {
        public void run() {
            mMessage = null;
            mShowingMessage = false;
            if (mShowingBouncer) {
                hideMessage(FADE_DURATION, true);
            } else {
                update();
            }
        }
    };

    public static class Helper implements SecurityMessageDisplay {
@@ -102,6 +113,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();
    }
}
+48 −0
Original line number Diff line number Diff line
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();
    }
}
+8 −0
Original line number Diff line number Diff line
@@ -326,6 +326,14 @@ class KeyguardStatusViewManager implements SecurityMessageDisplay {
        return mContainer.getContext();
    }

    @Override
    public void showBouncer(int duration) {
    }

    @Override
    public void hideBouncer(int duration) {
    }

    @Override
    public void setTimeout(int timeout_ms) {
    }
+39 −5
Original line number Diff line number Diff line
@@ -16,6 +16,10 @@

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(
+4 −0
Original line number Diff line number Diff line
@@ -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);
}