FileDocCategorySizeDatePackage
KeyguardGlowStripView.javaAPI DocAndroid 5.1 API5188Thu Mar 12 22:22:42 GMT 2015com.android.keyguard

KeyguardGlowStripView

public class KeyguardGlowStripView extends android.widget.LinearLayout
A layout which animates a strip of horizontal, pulsing dots on request. This is used to indicate the presence of pages to the left / right.

Fields Summary
private static final int
DURATION
private static final float
SLIDING_WINDOW_SIZE
private int
mDotStripTop
private int
mHorizontalDotGap
private int
mDotSize
private int
mNumDots
private android.graphics.drawable.Drawable
mDotDrawable
private boolean
mLeftToRight
private float
mAnimationProgress
private boolean
mDrawDots
private android.animation.ValueAnimator
mAnimator
private android.view.animation.Interpolator
mDotAlphaInterpolator
Constructors Summary
public KeyguardGlowStripView(android.content.Context context)


       
        this(context, null, 0);
    
public KeyguardGlowStripView(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, 0);
    
public KeyguardGlowStripView(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);

        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.KeyguardGlowStripView);
        mDotSize = a.getDimensionPixelSize(R.styleable.KeyguardGlowStripView_dotSize, mDotSize);
        mNumDots = a.getInt(R.styleable.KeyguardGlowStripView_numDots, mNumDots);
        mDotDrawable = a.getDrawable(R.styleable.KeyguardGlowStripView_glowDot);
        mLeftToRight = a.getBoolean(R.styleable.KeyguardGlowStripView_leftToRight, mLeftToRight);
    
Methods Summary
protected voiddispatchDraw(android.graphics.Canvas canvas)

        super.dispatchDraw(canvas);

        if (!mDrawDots) return;

        int xOffset = getPaddingLeft();
        mDotDrawable.setBounds(0, 0, mDotSize, mDotSize);

        for (int i = 0; i < mNumDots; i++) {
            // We fudge the relative position to provide a fade in of the first dot and a fade
            // out of the final dot.
            float relativeDotPosition = SLIDING_WINDOW_SIZE / 2 + ((1.0f * i) / (mNumDots - 1)) *
                    (1 - SLIDING_WINDOW_SIZE);
            float distance = Math.abs(relativeDotPosition - mAnimationProgress);
            float alpha = Math.max(0, 1 - distance / (SLIDING_WINDOW_SIZE / 2));

            alpha = mDotAlphaInterpolator.getInterpolation(alpha);

            canvas.save();
            canvas.translate(xOffset, mDotStripTop);
            mDotDrawable.setAlpha((int) (alpha * 255));
            mDotDrawable.draw(canvas);
            canvas.restore();
            xOffset += mDotSize + mHorizontalDotGap;
        }
    
public voidmakeEmGo()

        if (mAnimator != null) {
            mAnimator.cancel();
        }
        float from = mLeftToRight ? 0f : 1f;
        float to = mLeftToRight ? 1f : 0f;
        mAnimator = ValueAnimator.ofFloat(from, to);
        mAnimator.setDuration(DURATION);
        mAnimator.setInterpolator(new LinearInterpolator());
        mAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                mDrawDots = false;
                // make sure we draw one frame at the end with everything gone.
                invalidate();
            }

            @Override
            public void onAnimationStart(Animator animation) {
                mDrawDots = true;
            }
        });
        mAnimator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mAnimationProgress = (Float) animation.getAnimatedValue();
                invalidate();
            }
        });
        mAnimator.start();
    
protected voidonSizeChanged(int w, int h, int oldw, int oldh)

        int availableWidth = w - getPaddingLeft() - getPaddingRight();
        mHorizontalDotGap = (availableWidth - mDotSize * mNumDots) /  (mNumDots - 1);
        mDotStripTop = getPaddingTop();
        invalidate();