FileDocCategorySizeDatePackage
AnimatedRotateDrawable.javaAPI DocAndroid 5.1 API14338Thu Mar 12 22:22:30 GMT 2015android.graphics.drawable

AnimatedRotateDrawable

public class AnimatedRotateDrawable extends Drawable implements Runnable, Animatable, Drawable.Callback
hide

Fields Summary
private static final String
TAG
private AnimatedRotateState
mState
private boolean
mMutated
private float
mCurrentDegrees
private float
mIncrement
private boolean
mRunning
Constructors Summary
public AnimatedRotateDrawable()


      
        this(null, null);
    
private AnimatedRotateDrawable(AnimatedRotateState rotateState, android.content.res.Resources res)

        mState = new AnimatedRotateState(rotateState, this, res);
        init();
    
Methods Summary
public voidapplyTheme(android.content.res.Resources.Theme t)

        super.applyTheme(t);

        final AnimatedRotateState state = mState;
        if (state == null) {
            return;
        }

        if (state.mThemeAttrs != null) {
            final TypedArray a = t.resolveAttributes(
                    state.mThemeAttrs, R.styleable.AnimatedRotateDrawable);
            try {
                updateStateFromTypedArray(a);
                verifyRequiredAttributes(a);
            } catch (XmlPullParserException e) {
                throw new RuntimeException(e);
            } finally {
                a.recycle();
            }
        }

        if (state.mDrawable != null && state.mDrawable.canApplyTheme()) {
            state.mDrawable.applyTheme(t);
        }

        init();
    
public booleancanApplyTheme()

        return (mState != null && mState.canApplyTheme()) || super.canApplyTheme();
    
public voidclearMutated()

hide

        super.clearMutated();
        mState.mDrawable.clearMutated();
        mMutated = false;
    
public voiddraw(android.graphics.Canvas canvas)

        int saveCount = canvas.save();

        final AnimatedRotateState st = mState;
        final Drawable drawable = st.mDrawable;
        final Rect bounds = drawable.getBounds();

        int w = bounds.right - bounds.left;
        int h = bounds.bottom - bounds.top;

        float px = st.mPivotXRel ? (w * st.mPivotX) : st.mPivotX;
        float py = st.mPivotYRel ? (h * st.mPivotY) : st.mPivotY;

        canvas.rotate(mCurrentDegrees, px + bounds.left, py + bounds.top);

        drawable.draw(canvas);

        canvas.restoreToCount(saveCount);
    
public intgetAlpha()

        return mState.mDrawable.getAlpha();
    
public intgetChangingConfigurations()

        return super.getChangingConfigurations()
                | mState.mChangingConfigurations
                | mState.mDrawable.getChangingConfigurations();
    
public ConstantStategetConstantState()

        if (mState.canConstantState()) {
            mState.mChangingConfigurations = getChangingConfigurations();
            return mState;
        }
        return null;
    
public DrawablegetDrawable()
Returns the drawable rotated by this RotateDrawable.

        return mState.mDrawable;
    
public intgetIntrinsicHeight()

        return mState.mDrawable.getIntrinsicHeight();
    
public intgetIntrinsicWidth()

        return mState.mDrawable.getIntrinsicWidth();
    
public intgetOpacity()

        return mState.mDrawable.getOpacity();
    
public booleangetPadding(android.graphics.Rect padding)

        return mState.mDrawable.getPadding(padding);
    
public voidinflate(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)

        final TypedArray a = obtainAttributes(r, theme, attrs, R.styleable.AnimatedRotateDrawable);
        super.inflateWithAttributes(r, parser, a, R.styleable.AnimatedRotateDrawable_visible);
        updateStateFromTypedArray(a);
        a.recycle();

        inflateChildElements(r, parser, attrs, theme);

        init();
    
private voidinflateChildElements(android.content.res.Resources r, org.xmlpull.v1.XmlPullParser parser, android.util.AttributeSet attrs, android.content.res.Resources.Theme theme)

        final AnimatedRotateState state = mState;

        Drawable dr = null;
        int outerDepth = parser.getDepth();
        int type;
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
            if (type != XmlPullParser.START_TAG) {
                continue;
            }

            if ((dr = Drawable.createFromXmlInner(r, parser, attrs, theme)) == null) {
                Log.w(TAG, "Bad element under <animated-rotate>: " + parser.getName());
            }
        }

        if (dr != null) {
            state.mDrawable = dr;
            dr.setCallback(this);
        }
    
private voidinit()

        final AnimatedRotateState state = mState;
        mIncrement = 360.0f / state.mFramesCount;
        final Drawable drawable = state.mDrawable;
        if (drawable != null) {
            drawable.setFilterBitmap(true);
            if (drawable instanceof BitmapDrawable) {
                ((BitmapDrawable) drawable).setAntiAlias(true);
            }
        }
    
public voidinvalidateDrawable(Drawable who)

        final Callback callback = getCallback();
        if (callback != null) {
            callback.invalidateDrawable(this);
        }
    
public booleanisRunning()

        return mRunning;
    
public booleanisStateful()

        return mState.mDrawable.isStateful();
    
public Drawablemutate()

        if (!mMutated && super.mutate() == this) {
            mState.mDrawable.mutate();
            mMutated = true;
        }
        return this;
    
private voidnextFrame()

        unscheduleSelf(this);
        scheduleSelf(this, SystemClock.uptimeMillis() + mState.mFrameDuration);
    
protected voidonBoundsChange(android.graphics.Rect bounds)

        mState.mDrawable.setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
    
protected booleanonLevelChange(int level)

        return mState.mDrawable.setLevel(level);
    
protected booleanonStateChange(int[] state)

        return mState.mDrawable.setState(state);
    
public voidrun()

        // TODO: This should be computed in draw(Canvas), based on the amount
        // of time since the last frame drawn
        mCurrentDegrees += mIncrement;
        if (mCurrentDegrees > (360.0f - mIncrement)) {
            mCurrentDegrees = 0.0f;
        }
        invalidateSelf();
        nextFrame();
    
public voidscheduleDrawable(Drawable who, java.lang.Runnable what, long when)

        final Callback callback = getCallback();
        if (callback != null) {
            callback.scheduleDrawable(this, what, when);
        }
    
public voidsetAlpha(int alpha)

        mState.mDrawable.setAlpha(alpha);
    
public voidsetColorFilter(android.graphics.ColorFilter cf)

        mState.mDrawable.setColorFilter(cf);
    
public voidsetFramesCount(int framesCount)

        mState.mFramesCount = framesCount;
        mIncrement = 360.0f / mState.mFramesCount;
    
public voidsetFramesDuration(int framesDuration)

        mState.mFrameDuration = framesDuration;
    
public voidsetTintList(android.content.res.ColorStateList tint)

        mState.mDrawable.setTintList(tint);
    
public voidsetTintMode(android.graphics.PorterDuff.Mode tintMode)

        mState.mDrawable.setTintMode(tintMode);
    
public booleansetVisible(boolean visible, boolean restart)

        mState.mDrawable.setVisible(visible, restart);
        boolean changed = super.setVisible(visible, restart);
        if (visible) {
            if (changed || restart) {
                mCurrentDegrees = 0.0f;
                nextFrame();
            }
        } else {
            unscheduleSelf(this);
        }
        return changed;
    
public voidstart()

        if (!mRunning) {
            mRunning = true;
            nextFrame();
        }
    
public voidstop()

        mRunning = false;
        unscheduleSelf(this);
    
public voidunscheduleDrawable(Drawable who, java.lang.Runnable what)

        final Callback callback = getCallback();
        if (callback != null) {
            callback.unscheduleDrawable(this, what);
        }
    
private voidupdateStateFromTypedArray(android.content.res.TypedArray a)

        final AnimatedRotateState state = mState;

        // Account for any configuration changes.
        state.mChangingConfigurations |= a.getChangingConfigurations();

        // Extract the theme attributes, if any.
        state.mThemeAttrs = a.extractThemeAttrs();

        if (a.hasValue(R.styleable.AnimatedRotateDrawable_pivotX)) {
            final TypedValue tv = a.peekValue(R.styleable.AnimatedRotateDrawable_pivotX);
            state.mPivotXRel = tv.type == TypedValue.TYPE_FRACTION;
            state.mPivotX = state.mPivotXRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
        }

        if (a.hasValue(R.styleable.AnimatedRotateDrawable_pivotY)) {
            final TypedValue tv = a.peekValue(R.styleable.AnimatedRotateDrawable_pivotY);
            state.mPivotYRel = tv.type == TypedValue.TYPE_FRACTION;
            state.mPivotY = state.mPivotYRel ? tv.getFraction(1.0f, 1.0f) : tv.getFloat();
        }

        setFramesCount(a.getInt(
                R.styleable.AnimatedRotateDrawable_framesCount, state.mFramesCount));
        setFramesDuration(a.getInt(
                R.styleable.AnimatedRotateDrawable_frameDuration, state.mFrameDuration));

        final Drawable dr = a.getDrawable(R.styleable.AnimatedRotateDrawable_drawable);
        if (dr != null) {
            state.mDrawable = dr;
            dr.setCallback(this);
        }
    
private voidverifyRequiredAttributes(android.content.res.TypedArray a)

        // If we're not waiting on a theme, verify required attributes.
        if (mState.mDrawable == null && (mState.mThemeAttrs == null
                || mState.mThemeAttrs[R.styleable.AnimatedRotateDrawable_drawable] == 0)) {
            throw new XmlPullParserException(a.getPositionDescription()
                    + ": <animated-rotate> tag requires a 'drawable' attribute or "
                    + "child tag defining a drawable");
        }