FileDocCategorySizeDatePackage
TileDrawable.javaAPI DocAndroid 5.1 API5445Thu Mar 12 22:22:50 GMT 2015com.android.bitmap.drawable

TileDrawable

public class TileDrawable extends android.graphics.drawable.Drawable implements Drawable.Callback
A drawable that wraps another drawable and places it in the center of this space. This drawable allows a background color for the "tile", and has a fade-out transition when {@link #setVisible(boolean, boolean)} indicates that it is no longer visible.

Fields Summary
private final com.android.bitmap.drawable.ExtendedBitmapDrawable.ExtendedOptions
mOpts
private final android.graphics.Paint
mPaint
private final android.graphics.drawable.Drawable
mInner
private final int
mInnerWidth
private final int
mInnerHeight
protected final android.animation.ValueAnimator
mFadeOutAnimator
Constructors Summary
public TileDrawable(android.graphics.drawable.Drawable inner, int innerWidth, int innerHeight, int fadeOutDurationMs, com.android.bitmap.drawable.ExtendedBitmapDrawable.ExtendedOptions opts)


            
              
        mOpts = opts;
        mInner = inner != null ? inner.mutate() : null;
        mInnerWidth = innerWidth;
        mInnerHeight = innerHeight;
        if (inner != null) {
            mInner.setCallback(this);
        }

        mFadeOutAnimator = ValueAnimator.ofInt(255, 0)
                .setDuration(fadeOutDurationMs);
        mFadeOutAnimator.addUpdateListener(new AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                setAlpha((Integer) animation.getAnimatedValue());
            }
        });

        reset();
    
Methods Summary
public voiddraw(android.graphics.Canvas canvas)

        if (!isVisible() && mPaint.getAlpha() == 0) {
            return;
        }
        final int alpha = mPaint.getAlpha();
        mPaint.setColor(mOpts.backgroundColor);
        mPaint.setAlpha(alpha);
        canvas.drawRect(getBounds(), mPaint);
        if (mInner != null) mInner.draw(canvas);
    
protected intgetCurrentAlpha()

        return mPaint.getAlpha();
    
public android.graphics.drawable.DrawablegetInnerDrawable()

        return mInner;
    
public intgetOpacity()

        return 0;
    
public voidinvalidateDrawable(android.graphics.drawable.Drawable who)

        invalidateSelf();
    
protected voidonBoundsChange(android.graphics.Rect bounds)

        super.onBoundsChange(bounds);

        if (mInner == null) {
            return;
        }

        if (bounds.isEmpty()) {
            mInner.setBounds(0, 0, 0, 0);
        } else {
            final int l = bounds.left + (bounds.width() / 2) - (mInnerWidth / 2);
            final int t = bounds.top + (bounds.height() / 2) - (mInnerHeight / 2);
            mInner.setBounds(l, t, l + mInnerWidth, t + mInnerHeight);
        }
    
protected booleanonLevelChange(int level)

        if (mInner != null)
            return mInner.setLevel(level);
        else {
            return super.onLevelChange(level);
        }
    
public voidreset()

        setAlpha(0);
        setVisible(false);
    
public voidscheduleDrawable(android.graphics.drawable.Drawable who, java.lang.Runnable what, long when)

        scheduleSelf(what, when);
    
public voidsetAlpha(int alpha)

        final int old = mPaint.getAlpha();
        mPaint.setAlpha(alpha);
        setInnerAlpha(alpha);
        if (alpha != old) {
            invalidateSelf();
        }
    
public voidsetColorFilter(android.graphics.ColorFilter cf)

        mPaint.setColorFilter(cf);
        if (mInner != null) mInner.setColorFilter(cf);
    
public voidsetInnerAlpha(int alpha)
Changes the alpha on just the inner wrapped drawable.

        if (mInner != null) mInner.setAlpha(alpha);
    
public booleansetVisible(boolean visible)

        return setVisible(visible, true /* dontcare */);
    
public booleansetVisible(boolean visible, boolean restart)

        if (mInner != null) mInner.setVisible(visible, restart);
        final boolean changed = super.setVisible(visible, restart);
        if (changed) {
            if (isVisible()) {
                // pop in (no-op)
                // the transition will still be smooth if the previous state's layer fades out
                mFadeOutAnimator.cancel();
                setAlpha(255);
            } else {
                // fade out
                if (mPaint.getAlpha() == 255) {
                    mFadeOutAnimator.start();
                }
            }
        }
        return changed;
    
public voidunscheduleDrawable(android.graphics.drawable.Drawable who, java.lang.Runnable what)

        unscheduleSelf(what);