Talk from droidcon London
Creating eye candy animations takes time and effort, but the end result is worth it. To make your life a bit easier, in this talk Ivan will share with you 10 tips he learned while working on all sorts of animations. Those tips will help you break your fear of animations and after this talk, you will have no more excuses.
45. HOW IT WORKS
Determine elapsed time
Calculate positions, sizes, colors….
Draw objects
Repeat → Invalidate view with delay
46. public class AnimatedDrawable extends Drawable
public AnimatedDrawable() {
// Init all Paint and other resources used in draw method
}
@Override
public void draw(Canvas canvas) {
}
}
47. public class AnimatedDrawable extends Drawable
implements Animatable {
public AnimatedDrawable() {
// Init all Paint and other resources used in draw method
}
@Override
public void draw(Canvas canvas) {
draw(canvas, (SystemClock.uptimeMillis() - startTime) / DURATION);
}
@Override
public void start() {
startTime = SystemClock.uptimeMillis();
}
}
48. public class AnimatedDrawable extends Drawable
implements Animatable, Runnable, Drawable.Callback {
public AnimatedDrawable() {
// Init all Paint and other resources used in draw method
}
@Override
public void draw(Canvas canvas) {
draw(canvas, (SystemClock.uptimeMillis() - startTime) / DURATION);
}
@Override
public void start() {
startTime = SystemClock.uptimeMillis();
}
@Override
public void run() {
invalidateSelf();
scheduleSelf(this, SystemClock.uptimeMillis() + FRAME_DELAY);
}
@Override
public void invalidateDrawable(Drawable who) {
who.invalidateSelf();
}
}