FileDocCategorySizeDatePackage
ScrimController.javaAPI DocAndroid 5.1 API11180Thu Mar 12 22:22:42 GMT 2015com.android.systemui.statusbar.phone

ScrimController

public class ScrimController extends Object implements ViewTreeObserver.OnPreDrawListener
Controls both the scrim behind the notifications and in front of the notifications (when a security method gets shown).

Fields Summary
public static final long
ANIMATION_DURATION
private static final float
SCRIM_BEHIND_ALPHA
private static final float
SCRIM_BEHIND_ALPHA_KEYGUARD
private static final float
SCRIM_BEHIND_ALPHA_UNLOCKING
private static final float
SCRIM_IN_FRONT_ALPHA
private static final int
TAG_KEY_ANIM
private final com.android.systemui.statusbar.ScrimView
mScrimBehind
private final com.android.systemui.statusbar.ScrimView
mScrimInFront
private final UnlockMethodCache
mUnlockMethodCache
private boolean
mKeyguardShowing
private float
mFraction
private boolean
mDarkenWhileDragging
private boolean
mBouncerShowing
private boolean
mAnimateChange
private boolean
mUpdatePending
private boolean
mExpanding
private boolean
mAnimateKeyguardFadingOut
private long
mDurationOverride
private long
mAnimationDelay
private Runnable
mOnAnimationFinished
private boolean
mAnimationStarted
private final android.view.animation.Interpolator
mInterpolator
private final android.view.animation.Interpolator
mLinearOutSlowInInterpolator
private com.android.systemui.statusbar.BackDropView
mBackDropView
private boolean
mScrimSrcEnabled
private boolean
mDozing
private float
mDozeInFrontAlpha
private float
mDozeBehindAlpha
private float
mCurrentInFrontAlpha
private float
mCurrentBehindAlpha
Constructors Summary
public ScrimController(com.android.systemui.statusbar.ScrimView scrimBehind, com.android.systemui.statusbar.ScrimView scrimInFront, boolean scrimSrcEnabled)


           
        mScrimBehind = scrimBehind;
        mScrimInFront = scrimInFront;
        final Context context = scrimBehind.getContext();
        mUnlockMethodCache = UnlockMethodCache.getInstance(context);
        mLinearOutSlowInInterpolator = AnimationUtils.loadInterpolator(context,
                android.R.interpolator.linear_out_slow_in);
        mScrimSrcEnabled = scrimSrcEnabled;
    
Methods Summary
public voidanimateGoingToFullShade(long delay, long duration)

        mDurationOverride = duration;
        mAnimationDelay = delay;
        mAnimateChange = true;
        scheduleUpdate();
    
public voidanimateKeyguardFadingOut(long delay, long duration, java.lang.Runnable onAnimationFinished)

        mAnimateKeyguardFadingOut = true;
        mDurationOverride = duration;
        mAnimationDelay = delay;
        mAnimateChange = true;
        mOnAnimationFinished = onAnimationFinished;
        scheduleUpdate();
    
private floatgetCurrentScrimAlpha(android.view.View scrim)

        return scrim == mScrimBehind ? mCurrentBehindAlpha : mCurrentInFrontAlpha;
    
private floatgetDozeAlpha(android.view.View scrim)

        return scrim == mScrimBehind ? mDozeBehindAlpha : mDozeInFrontAlpha;
    
public floatgetDozeBehindAlpha()

        return mDozeBehindAlpha;
    
public floatgetDozeInFrontAlpha()

        return mDozeInFrontAlpha;
    
private android.view.animation.InterpolatorgetInterpolator()

        return mAnimateKeyguardFadingOut ? mLinearOutSlowInInterpolator : mInterpolator;
    
public voidonExpandingFinished()

        mExpanding = false;
    
public booleanonPreDraw()

        mScrimBehind.getViewTreeObserver().removeOnPreDrawListener(this);
        mUpdatePending = false;
        updateScrims();
        mAnimateKeyguardFadingOut = false;
        mDurationOverride = -1;
        mAnimationDelay = 0;

        // Make sure that we always call the listener even if we didn't start an animation.
        if (!mAnimationStarted && mOnAnimationFinished != null) {
            mOnAnimationFinished.run();
            mOnAnimationFinished = null;
        }
        mAnimationStarted = false;
        return true;
    
public voidonTrackingStarted()

        mExpanding = true;
        mDarkenWhileDragging = !mUnlockMethodCache.isCurrentlyInsecure();
    
private voidscheduleUpdate()

        if (mUpdatePending) return;

        // Make sure that a frame gets scheduled.
        mScrimBehind.invalidate();
        mScrimBehind.getViewTreeObserver().addOnPreDrawListener(this);
        mUpdatePending = true;
    
public voidsetBackDropView(com.android.systemui.statusbar.BackDropView backDropView)

        mBackDropView = backDropView;
        mBackDropView.setOnVisibilityChangedRunnable(new Runnable() {
            @Override
            public void run() {
                updateScrimBehindDrawingMode();
            }
        });
        updateScrimBehindDrawingMode();
    
public voidsetBouncerShowing(boolean showing)

        mBouncerShowing = showing;
        mAnimateChange = !mExpanding;
        scheduleUpdate();
    
private voidsetCurrentScrimAlpha(android.view.View scrim, float alpha)

        if (scrim == mScrimBehind) {
            mCurrentBehindAlpha = alpha;
        } else {
            mCurrentInFrontAlpha = alpha;
        }
    
public voidsetDozeBehindAlpha(float alpha)

        mDozeBehindAlpha = alpha;
        updateScrimColor(mScrimBehind);
    
public voidsetDozeInFrontAlpha(float alpha)

        mDozeInFrontAlpha = alpha;
        updateScrimColor(mScrimInFront);
    
public voidsetDozing(boolean dozing)

        mDozing = dozing;
        scheduleUpdate();
    
public voidsetKeyguardShowing(boolean showing)

        mKeyguardShowing = showing;
        scheduleUpdate();
    
public voidsetPanelExpansion(float fraction)

        if (mFraction != fraction) {
            mFraction = fraction;
            scheduleUpdate();
        }
    
private voidsetScrimBehindColor(float alpha)

        setScrimColor(mScrimBehind, alpha);
    
private voidsetScrimColor(com.android.systemui.statusbar.ScrimView scrim, float alpha)

        Object runningAnim = scrim.getTag(TAG_KEY_ANIM);
        if (runningAnim instanceof ValueAnimator) {
            ((ValueAnimator) runningAnim).cancel();
            scrim.setTag(TAG_KEY_ANIM, null);
        }
        if (mAnimateChange) {
            startScrimAnimation(scrim, alpha);
        } else {
            setCurrentScrimAlpha(scrim, alpha);
            updateScrimColor(scrim);
        }
    
private voidsetScrimInFrontColor(float alpha)

        setScrimColor(mScrimInFront, alpha);
        if (alpha == 0f) {
            mScrimInFront.setClickable(false);
        } else {

            // Eat touch events (unless dozing).
            mScrimInFront.setClickable(!mDozing);
        }
    
private voidstartScrimAnimation(com.android.systemui.statusbar.ScrimView scrim, float target)

        float current = getCurrentScrimAlpha(scrim);
        ValueAnimator anim = ValueAnimator.ofFloat(current, target);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float alpha = (float) animation.getAnimatedValue();
                setCurrentScrimAlpha(scrim, alpha);
                updateScrimColor(scrim);
            }
        });
        anim.setInterpolator(getInterpolator());
        anim.setStartDelay(mAnimationDelay);
        anim.setDuration(mDurationOverride != -1 ? mDurationOverride : ANIMATION_DURATION);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                if (mOnAnimationFinished != null) {
                    mOnAnimationFinished.run();
                    mOnAnimationFinished = null;
                }
                scrim.setTag(TAG_KEY_ANIM, null);
            }
        });
        anim.start();
        scrim.setTag(TAG_KEY_ANIM, anim);
        mAnimationStarted = true;
    
private voidupdateScrimBehindDrawingMode()

        boolean asSrc = mBackDropView.getVisibility() != View.VISIBLE && mScrimSrcEnabled;
        mScrimBehind.setDrawAsSrc(asSrc);
    
private voidupdateScrimColor(com.android.systemui.statusbar.ScrimView scrim)

        float alpha1 = getCurrentScrimAlpha(scrim);
        float alpha2 = getDozeAlpha(scrim);
        float alpha = 1 - (1 - alpha1) * (1 - alpha2);
        scrim.setScrimColor(Color.argb((int) (alpha * 255), 0, 0, 0));
    
private voidupdateScrimKeyguard()

        if (mExpanding && mDarkenWhileDragging) {
            float behindFraction = Math.max(0, Math.min(mFraction, 1));
            float fraction = 1 - behindFraction;
            fraction = (float) Math.pow(fraction, 0.8f);
            behindFraction = (float) Math.pow(behindFraction, 0.8f);
            setScrimInFrontColor(fraction * SCRIM_IN_FRONT_ALPHA);
            setScrimBehindColor(behindFraction * SCRIM_BEHIND_ALPHA_KEYGUARD);
        } else if (mBouncerShowing) {
            setScrimInFrontColor(SCRIM_IN_FRONT_ALPHA);
            setScrimBehindColor(0f);
        } else {
            float fraction = Math.max(0, Math.min(mFraction, 1));
            setScrimInFrontColor(0f);
            setScrimBehindColor(fraction
                    * (SCRIM_BEHIND_ALPHA_KEYGUARD - SCRIM_BEHIND_ALPHA_UNLOCKING)
                    + SCRIM_BEHIND_ALPHA_UNLOCKING);
        }
    
private voidupdateScrimNormal()

        float frac = mFraction;
        // let's start this 20% of the way down the screen
        frac = frac * 1.2f - 0.2f;
        if (frac <= 0) {
            setScrimBehindColor(0);
        } else {
            // woo, special effects
            final float k = (float)(1f-0.5f*(1f-Math.cos(3.14159f * Math.pow(1f-frac, 2f))));
            setScrimBehindColor(k * SCRIM_BEHIND_ALPHA);
        }
    
private voidupdateScrims()

        if (mAnimateKeyguardFadingOut) {
            setScrimInFrontColor(0f);
            setScrimBehindColor(0f);
        } else if (!mKeyguardShowing && !mBouncerShowing) {
            updateScrimNormal();
            setScrimInFrontColor(0);
        } else {
            updateScrimKeyguard();
        }
        mAnimateChange = false;