use of android.graphics.drawable.Animatable in project Ushahidi_Android by ushahidi.
the class IcsProgressBar method onDraw.
@Override
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
Drawable d = mCurrentDrawable;
if (d != null) {
// Translate canvas so a indeterminate circular progress bar with padding
// rotates properly in its animation
canvas.save();
canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop);
long time = getDrawingTime();
if (mAnimation != null) {
mAnimation.getTransformation(time, mTransformation);
float scale = mTransformation.getAlpha();
try {
mInDrawing = true;
d.setLevel((int) (scale * MAX_LEVEL));
} finally {
mInDrawing = false;
}
if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) {
mLastDrawTime = SystemClock.uptimeMillis();
postInvalidateDelayed(mAnimationResolution);
}
}
d.draw(canvas);
canvas.restore();
if (mShouldStartAnimationDrawable && d instanceof Animatable) {
((Animatable) d).start();
mShouldStartAnimationDrawable = false;
}
}
}
use of android.graphics.drawable.Animatable in project android_frameworks_base by ParanoidAndroid.
the class ProgressBar method startAnimation.
/**
* <p>Start the indeterminate progress animation.</p>
*/
void startAnimation() {
if (getVisibility() != VISIBLE) {
return;
}
if (mIndeterminateDrawable instanceof Animatable) {
mShouldStartAnimationDrawable = true;
mHasAnimation = false;
} else {
mHasAnimation = true;
if (mInterpolator == null) {
mInterpolator = new LinearInterpolator();
}
if (mTransformation == null) {
mTransformation = new Transformation();
} else {
mTransformation.clear();
}
if (mAnimation == null) {
mAnimation = new AlphaAnimation(0.0f, 1.0f);
} else {
mAnimation.reset();
}
mAnimation.setRepeatMode(mBehavior);
mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setDuration(mDuration);
mAnimation.setInterpolator(mInterpolator);
mAnimation.setStartTime(Animation.START_ON_FIRST_FRAME);
}
postInvalidate();
}
use of android.graphics.drawable.Animatable in project platform_frameworks_base by android.
the class QSIconView method setIcon.
protected void setIcon(ImageView iv, QSTile.State state) {
if (!Objects.equals(state.icon, iv.getTag(R.id.qs_icon_tag))) {
Drawable d = state.icon != null ? iv.isShown() && mAnimationEnabled ? state.icon.getDrawable(mContext) : state.icon.getInvisibleDrawable(mContext) : null;
int padding = state.icon != null ? state.icon.getPadding() : 0;
if (d != null && state.autoMirrorDrawable) {
d.setAutoMirrored(true);
}
iv.setImageDrawable(d);
iv.setTag(R.id.qs_icon_tag, state.icon);
iv.setPadding(0, padding, 0, padding);
if (d instanceof Animatable && iv.isShown()) {
Animatable a = (Animatable) d;
a.start();
if (!iv.isShown()) {
// skip directly to end state
a.stop();
}
}
}
if (state.disabledByPolicy) {
iv.setColorFilter(getContext().getColor(R.color.qs_tile_disabled_color));
} else {
iv.clearColorFilter();
}
}
use of android.graphics.drawable.Animatable in project AndroidTraining by mixi-inc.
the class IcsProgressBar method onDraw.
@Override
protected synchronized void onDraw(Canvas canvas) {
super.onDraw(canvas);
Drawable d = mCurrentDrawable;
if (d != null) {
// Translate canvas so a indeterminate circular progress bar with padding
// rotates properly in its animation
canvas.save();
canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop);
long time = getDrawingTime();
if (mAnimation != null) {
mAnimation.getTransformation(time, mTransformation);
float scale = mTransformation.getAlpha();
try {
mInDrawing = true;
d.setLevel((int) (scale * MAX_LEVEL));
} finally {
mInDrawing = false;
}
if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) {
mLastDrawTime = SystemClock.uptimeMillis();
postInvalidateDelayed(mAnimationResolution);
}
}
d.draw(canvas);
canvas.restore();
if (mShouldStartAnimationDrawable && d instanceof Animatable) {
((Animatable) d).start();
mShouldStartAnimationDrawable = false;
}
}
}
use of android.graphics.drawable.Animatable in project AndroidTraining by mixi-inc.
the class IcsProgressBar method startAnimation.
/**
* <p>Start the indeterminate progress animation.</p>
*/
void startAnimation() {
if (getVisibility() != VISIBLE) {
return;
}
if (mIndeterminateDrawable instanceof Animatable) {
mShouldStartAnimationDrawable = true;
mAnimation = null;
} else {
if (mInterpolator == null) {
mInterpolator = new LinearInterpolator();
}
mTransformation = new Transformation();
mAnimation = new AlphaAnimation(0.0f, 1.0f);
mAnimation.setRepeatMode(mBehavior);
mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setDuration(mDuration);
mAnimation.setInterpolator(mInterpolator);
mAnimation.setStartTime(Animation.START_ON_FIRST_FRAME);
}
postInvalidate();
}
Aggregations