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

DozeScrimController

public class DozeScrimController extends Object
Controller which handles all the doze animations of the scrims.

Fields Summary
private static final String
TAG
private static final boolean
DEBUG
private final DozeParameters
mDozeParameters
private final android.view.animation.Interpolator
mPulseInInterpolator
private final android.view.animation.Interpolator
mPulseInInterpolatorPickup
private final android.view.animation.Interpolator
mPulseOutInterpolator
private final android.view.animation.Interpolator
mDozeAnimationInterpolator
private final android.os.Handler
mHandler
private final ScrimController
mScrimController
private boolean
mDozing
private DozeHost.PulseCallback
mPulseCallback
private int
mPulseReason
private android.animation.Animator
mInFrontAnimator
private android.animation.Animator
mBehindAnimator
private float
mInFrontTarget
private float
mBehindTarget
private final Runnable
mPulseIn
private final Runnable
mPulseInFinished
private final Runnable
mPulseOut
private final Runnable
mPulseOutFinished
Constructors Summary
public DozeScrimController(ScrimController scrimController, android.content.Context context)


         
        mScrimController = scrimController;
        mDozeParameters = new DozeParameters(context);
        mDozeAnimationInterpolator = mPulseInInterpolatorPickup =
                AnimationUtils.loadInterpolator(context, android.R.interpolator.linear_out_slow_in);
    
Methods Summary
private voidabortAnimations()

        if (mInFrontAnimator != null) {
            mInFrontAnimator.cancel();
        }
        if (mBehindAnimator != null) {
            mBehindAnimator.cancel();
        }
    
private voidcancelPulsing()

        if (DEBUG) Log.d(TAG, "Cancel pulsing");

        if (mPulseCallback != null) {
            mHandler.removeCallbacks(mPulseIn);
            mHandler.removeCallbacks(mPulseOut);
            pulseFinished();
        }
    
private android.animation.AnimatorgetCurrentAnimator(boolean inFront)

        return inFront ? mInFrontAnimator : mBehindAnimator;
    
private floatgetCurrentTarget(boolean inFront)

        return inFront ? mInFrontTarget : mBehindTarget;
    
private floatgetDozeAlpha(boolean inFront)

        return inFront
                ? mScrimController.getDozeInFrontAlpha()
                : mScrimController.getDozeBehindAlpha();
    
public booleanisPulsing()

        return mPulseCallback != null;
    
public voidpulse(DozeHost.PulseCallback callback, int reason)
When dozing, fade screen contents in and out using the front scrim.

        if (callback == null) {
            throw new IllegalArgumentException("callback must not be null");
        }

        if (!mDozing || mPulseCallback != null) {
            // Pulse suppressed.
            callback.onPulseFinished();
            return;
        }

        // Begin pulse.  Note that it's very important that the pulse finished callback
        // be invoked when we're done so that the caller can drop the pulse wakelock.
        mPulseCallback = callback;
        mPulseReason = reason;
        mHandler.post(mPulseIn);
    
private voidpulseFinished()

        if (mPulseCallback != null) {
            mPulseCallback.onPulseFinished();
            mPulseCallback = null;
        }
    
private voidpulseStarted()

        if (mPulseCallback != null) {
            mPulseCallback.onPulseStarted();
        }
    
private voidsetCurrentAnimator(boolean inFront, android.animation.Animator animator)

        if (inFront) {
            mInFrontAnimator = animator;
        } else {
            mBehindAnimator = animator;
        }
    
private voidsetCurrentTarget(boolean inFront, float target)

        if (inFront) {
            mInFrontTarget = target;
        } else {
            mBehindTarget = target;
        }
    
private voidsetDozeAlpha(boolean inFront, float alpha)

        if (inFront) {
            mScrimController.setDozeInFrontAlpha(alpha);
        } else {
            mScrimController.setDozeBehindAlpha(alpha);
        }
    
public voidsetDozing(boolean dozing, boolean animate)

        if (mDozing == dozing) return;
        mDozing = dozing;
        if (mDozing) {
            abortAnimations();
            mScrimController.setDozeBehindAlpha(1f);
            mScrimController.setDozeInFrontAlpha(1f);
        } else {
            cancelPulsing();
            if (animate) {
                startScrimAnimation(false /* inFront */, 0f /* target */,
                        NotificationPanelView.DOZE_ANIMATION_DURATION, mDozeAnimationInterpolator);
                startScrimAnimation(true /* inFront */, 0f /* target */,
                        NotificationPanelView.DOZE_ANIMATION_DURATION, mDozeAnimationInterpolator);
            } else {
                abortAnimations();
                mScrimController.setDozeBehindAlpha(0f);
                mScrimController.setDozeInFrontAlpha(0f);
            }
        }
    
private voidstartScrimAnimation(boolean inFront, float target, long duration, android.view.animation.Interpolator interpolator, long delay, java.lang.Runnable endRunnable)

        Animator current = getCurrentAnimator(inFront);
        if (current != null) {
            float currentTarget = getCurrentTarget(inFront);
            if (currentTarget == target) {
                return;
            }
            current.cancel();
        }
        ValueAnimator anim = ValueAnimator.ofFloat(getDozeAlpha(inFront), target);
        anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                float value = (float) animation.getAnimatedValue();
                setDozeAlpha(inFront, value);
            }
        });
        anim.setInterpolator(interpolator);
        anim.setDuration(duration);
        anim.setStartDelay(delay);
        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                setCurrentAnimator(inFront, null);
                if (endRunnable != null) {
                    endRunnable.run();
                }
            }
        });
        anim.start();
        setCurrentAnimator(inFront, anim);
        setCurrentTarget(inFront, target);
    
private voidstartScrimAnimation(boolean inFront, float target, long duration, android.view.animation.Interpolator interpolator)

        startScrimAnimation(inFront, target, duration, interpolator, 0 /* delay */,
                null /* endRunnable */);