FileDocCategorySizeDatePackage
DrawableHolder.javaAPI DocAndroid 5.1 API6603Thu Mar 12 22:22:10 GMT 2015com.android.internal.widget

DrawableHolder

public class DrawableHolder extends Object implements android.animation.Animator.AnimatorListener
This class is a container for a Drawable with multiple animated properties.

Fields Summary
public static final android.view.animation.DecelerateInterpolator
EASE_OUT_INTERPOLATOR
private static final String
TAG
private static final boolean
DBG
private float
mX
private float
mY
private float
mScaleX
private float
mScaleY
private android.graphics.drawable.BitmapDrawable
mDrawable
private float
mAlpha
private ArrayList
mAnimators
private ArrayList
mNeedToStart
Constructors Summary
public DrawableHolder(android.graphics.drawable.BitmapDrawable drawable)


       
        this(drawable, 0.0f, 0.0f);
    
public DrawableHolder(android.graphics.drawable.BitmapDrawable drawable, float x, float y)

        mDrawable = drawable;
        mX = x;
        mY = y;
        mDrawable.getPaint().setAntiAlias(true); // Force AA
        mDrawable.setBounds(0, 0, mDrawable.getIntrinsicWidth(), mDrawable.getIntrinsicHeight());
    
Methods Summary
public android.animation.ObjectAnimatoraddAnimTo(long duration, long delay, java.lang.String property, float toValue, boolean replace)
Adds an animation that interpolates given property from its current value to the given value.

param
duration the duration, in ms.
param
delay the delay to start the animation, in ms.
param
property the property to animate
param
toValue the target value
param
replace if true, replace the current animation with this one.


        if (replace) removeAnimationFor(property);

        ObjectAnimator anim = ObjectAnimator.ofFloat(this, property, toValue);
        anim.setDuration(duration);
        anim.setStartDelay(delay);
        anim.setInterpolator(EASE_OUT_INTERPOLATOR);
        this.addAnimation(anim, replace);
        if (DBG) Log.v(TAG, "animationCount = " + mAnimators.size());
        return anim;
    
private com.android.internal.widget.DrawableHolderaddAnimation(android.animation.ObjectAnimator anim, boolean overwrite)
Adds the given animation to the list of animations for this object.

param
anim
param
overwrite
return

        if (anim != null)
            mAnimators.add(anim);
        mNeedToStart.add(anim);
        return this;
    
public voidclearAnimations()
Stops all animations and removes them from the list.

        for (ObjectAnimator currentAnim : mAnimators) {
            currentAnim.cancel();
        }
        mAnimators.clear();
    
public voiddraw(android.graphics.Canvas canvas)
Draw this object to the canvas using the properties defined in this class.

param
canvas canvas to draw into

        final float threshold = 1.0f / 256.0f; // contribution less than 1 LSB of RGB byte
        if (mAlpha <= threshold) // don't bother if it won't show up
            return;
        canvas.save(Canvas.MATRIX_SAVE_FLAG);
        canvas.translate(mX, mY);
        canvas.scale(mScaleX, mScaleY);
        canvas.translate(-0.5f*getWidth(), -0.5f*getHeight());
        mDrawable.setAlpha((int) Math.round(mAlpha * 255f));
        mDrawable.draw(canvas);
        canvas.restore();
    
public floatgetAlpha()

        return mAlpha;
    
public android.graphics.drawable.BitmapDrawablegetDrawable()

        return mDrawable;
    
public intgetHeight()

        return mDrawable.getIntrinsicHeight();
    
public floatgetScaleX()

        return mScaleX;
    
public floatgetScaleY()

        return mScaleY;
    
public intgetWidth()

        return mDrawable.getIntrinsicWidth();
    
public floatgetX()

        return mX;
    
public floatgetY()

        return mY;
    
public voidonAnimationCancel(android.animation.Animator animation)


    
public voidonAnimationEnd(android.animation.Animator animation)

        mAnimators.remove(animation);
    
public voidonAnimationRepeat(android.animation.Animator animation)


    
public voidonAnimationStart(android.animation.Animator animation)


    
public voidremoveAnimationFor(java.lang.String property)
Stops all animations for the given property and removes it from the list.

param
property

        ArrayList<ObjectAnimator> removalList = (ArrayList<ObjectAnimator>)mAnimators.clone();
        for (ObjectAnimator currentAnim : removalList) {
            if (property.equals(currentAnim.getPropertyName())) {
                currentAnim.cancel();
            }
        }
    
public voidsetAlpha(float alpha)

        mAlpha = alpha;
    
public voidsetScaleX(float value)

        mScaleX = value;
    
public voidsetScaleY(float value)

        mScaleY = value;
    
public voidsetX(float value)

        mX = value;
    
public voidsetY(float value)

        mY = value;
    
public voidstartAnimations(ValueAnimator.AnimatorUpdateListener listener)
Starts all animations added since the last call to this function. Used to synchronize animations.

param
listener an optional listener to add to the animations. Typically used to know when to invalidate the surface these are being drawn to.

        for (int i = 0; i < mNeedToStart.size(); i++) {
            ObjectAnimator anim = mNeedToStart.get(i);
            anim.addUpdateListener(listener);
            anim.addListener(this);
            anim.start();
        }
        mNeedToStart.clear();