Methods Summary |
---|
public void | applyTheme(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 boolean | canApplyTheme()
return (mState != null && mState.canApplyTheme()) || super.canApplyTheme();
|
public void | clearMutated()
super.clearMutated();
mState.mDrawable.clearMutated();
mMutated = false;
|
public void | draw(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 int | getAlpha()
return mState.mDrawable.getAlpha();
|
public int | getChangingConfigurations()
return super.getChangingConfigurations()
| mState.mChangingConfigurations
| mState.mDrawable.getChangingConfigurations();
|
public ConstantState | getConstantState()
if (mState.canConstantState()) {
mState.mChangingConfigurations = getChangingConfigurations();
return mState;
}
return null;
|
public Drawable | getDrawable()Returns the drawable rotated by this RotateDrawable.
return mState.mDrawable;
|
public int | getIntrinsicHeight()
return mState.mDrawable.getIntrinsicHeight();
|
public int | getIntrinsicWidth()
return mState.mDrawable.getIntrinsicWidth();
|
public int | getOpacity()
return mState.mDrawable.getOpacity();
|
public boolean | getPadding(android.graphics.Rect padding)
return mState.mDrawable.getPadding(padding);
|
public void | inflate(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 void | inflateChildElements(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 void | init()
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 void | invalidateDrawable(Drawable who)
final Callback callback = getCallback();
if (callback != null) {
callback.invalidateDrawable(this);
}
|
public boolean | isRunning()
return mRunning;
|
public boolean | isStateful()
return mState.mDrawable.isStateful();
|
public Drawable | mutate()
if (!mMutated && super.mutate() == this) {
mState.mDrawable.mutate();
mMutated = true;
}
return this;
|
private void | nextFrame()
unscheduleSelf(this);
scheduleSelf(this, SystemClock.uptimeMillis() + mState.mFrameDuration);
|
protected void | onBoundsChange(android.graphics.Rect bounds)
mState.mDrawable.setBounds(bounds.left, bounds.top, bounds.right, bounds.bottom);
|
protected boolean | onLevelChange(int level)
return mState.mDrawable.setLevel(level);
|
protected boolean | onStateChange(int[] state)
return mState.mDrawable.setState(state);
|
public void | run()
// 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 void | scheduleDrawable(Drawable who, java.lang.Runnable what, long when)
final Callback callback = getCallback();
if (callback != null) {
callback.scheduleDrawable(this, what, when);
}
|
public void | setAlpha(int alpha)
mState.mDrawable.setAlpha(alpha);
|
public void | setColorFilter(android.graphics.ColorFilter cf)
mState.mDrawable.setColorFilter(cf);
|
public void | setFramesCount(int framesCount)
mState.mFramesCount = framesCount;
mIncrement = 360.0f / mState.mFramesCount;
|
public void | setFramesDuration(int framesDuration)
mState.mFrameDuration = framesDuration;
|
public void | setTintList(android.content.res.ColorStateList tint)
mState.mDrawable.setTintList(tint);
|
public void | setTintMode(android.graphics.PorterDuff.Mode tintMode)
mState.mDrawable.setTintMode(tintMode);
|
public boolean | setVisible(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 void | start()
if (!mRunning) {
mRunning = true;
nextFrame();
}
|
public void | stop()
mRunning = false;
unscheduleSelf(this);
|
public void | unscheduleDrawable(Drawable who, java.lang.Runnable what)
final Callback callback = getCallback();
if (callback != null) {
callback.unscheduleDrawable(this, what);
}
|
private void | updateStateFromTypedArray(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 void | verifyRequiredAttributes(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");
}
|