Updating code to use new non-generified animator APIs

Change-Id: I3023db9d1f9cb8bf98b788fce4ae2b58b182987d
This commit is contained in:
Chet Haase
2010-10-14 06:59:27 -07:00
parent ec8a83055a
commit e358b47be5
10 changed files with 108 additions and 98 deletions

View File

@@ -79,18 +79,18 @@ public class AnimationCloning extends Activity {
private void createAnimation() {
if (animation == null) {
ObjectAnimator anim1 = new ObjectAnimator(500, balls.get(0), "y",
0f, getHeight() - balls.get(0).getHeight());
ObjectAnimator anim1 = ObjectAnimator.ofFloat(balls.get(0), "y",
0f, getHeight() - balls.get(0).getHeight()).setDuration(500);
ObjectAnimator anim2 = anim1.clone();
anim2.setTarget(balls.get(1));
anim1.addUpdateListener(this);
ShapeHolder ball2 = balls.get(2);
ObjectAnimator animDown = new ObjectAnimator(500, ball2, "y",
0f, getHeight() - ball2.getHeight());
ObjectAnimator animDown = ObjectAnimator.ofFloat(ball2, "y",
0f, getHeight() - ball2.getHeight()).setDuration(500);
animDown.setInterpolator(new AccelerateInterpolator());
ObjectAnimator animUp = new ObjectAnimator(500, ball2, "y",
getHeight() - ball2.getHeight(), 0f);
ObjectAnimator animUp = ObjectAnimator.ofFloat(ball2, "y",
getHeight() - ball2.getHeight(), 0f).setDuration(500);
animDown.setInterpolator(new DecelerateInterpolator());
AnimatorSet s1 = new AnimatorSet();
s1.playSequentially(animDown, animUp);

View File

@@ -112,8 +112,8 @@ public class AnimationSeeking extends Activity {
private void createAnimation() {
if (bounceAnim == null) {
bounceAnim = new ObjectAnimator(1500, ball, "y",
ball.getY(), getHeight() - BALL_SIZE);
bounceAnim = ObjectAnimator.ofFloat(ball, "y",
ball.getY(), getHeight() - BALL_SIZE).setDuration(1500);
bounceAnim.setInterpolator(new BounceInterpolator());
bounceAnim.addUpdateListener(this);
}

View File

@@ -117,28 +117,28 @@ public class AnimatorEvents extends Activity {
private void createAnimation() {
if (animation == null) {
ObjectAnimator yAnim = new ObjectAnimator(1500, ball, "y",
ball.getY(), getHeight() - 50f);
ObjectAnimator yAnim = ObjectAnimator.ofFloat(ball, "y",
ball.getY(), getHeight() - 50f).setDuration(1500);
yAnim.setRepeatCount(0);
yAnim.setRepeatMode(ValueAnimator.REVERSE);
yAnim.setInterpolator(new AccelerateInterpolator(2f));
yAnim.addUpdateListener(this);
yAnim.addListener(this);
ObjectAnimator xAnim = new ObjectAnimator(1000, ball, "x",
ball.getX(), ball.getX() + 300);
ObjectAnimator xAnim = ObjectAnimator.ofFloat(ball, "x",
ball.getX(), ball.getX() + 300).setDuration(1000);
xAnim.setStartDelay(0);
xAnim.setRepeatCount(0);
xAnim.setRepeatMode(ValueAnimator.REVERSE);
xAnim.setInterpolator(new AccelerateInterpolator(2f));
ObjectAnimator alphaAnim = new ObjectAnimator(1000, ball, "alpha", 1f, .5f);
ObjectAnimator alphaAnim = ObjectAnimator.ofFloat(ball, "alpha", 1f, .5f).
setDuration(1000);
AnimatorSet alphaSeq = new AnimatorSet();
alphaSeq.play(alphaAnim);
animation = new AnimatorSet();
((AnimatorSet) animation).playTogether(yAnim, xAnim);
//((AnimatorSet) animation).play(alphaSeq).after(500);
animation.addListener(this);
}
}

View File

@@ -50,7 +50,8 @@ public class BouncingBalls extends Activity {
container.addView(new MyAnimationView(this));
}
public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener,
Animator.AnimatorListener {
private static final int RED = 0xffFF8080;
private static final int BLUE = 0xff8080FF;
@@ -70,7 +71,8 @@ public class BouncingBalls extends Activity {
paint.setColor(RED);
// Animate background color
ValueAnimator colorAnim = new ObjectAnimator(3000, paint, "color", BLUE);
ValueAnimator colorAnim = ObjectAnimator.ofInt(paint, "color", BLUE);
colorAnim.setDuration(3000);
colorAnim.setEvaluator(new RGBEvaluator());
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
@@ -92,30 +94,36 @@ public class BouncingBalls extends Activity {
float h = (float)getHeight();
float eventY = event.getY();
int duration = (int)(500 * ((h - eventY)/h));
ValueAnimator bounceAnim = new ObjectAnimator(duration, newBall, "y", startY, endY);
ValueAnimator bounceAnim = ObjectAnimator.ofFloat(newBall, "y", startY, endY);
bounceAnim.setDuration(duration);
bounceAnim.setInterpolator(new AccelerateInterpolator());
ValueAnimator squashAnim1 = new ObjectAnimator(duration/4, newBall, "x", newBall.getX(),
ValueAnimator squashAnim1 = ObjectAnimator.ofFloat(newBall, "x", newBall.getX(),
newBall.getX() - 25f);
squashAnim1.setDuration(duration/4);
squashAnim1.setRepeatCount(1);
squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
squashAnim1.setInterpolator(new DecelerateInterpolator());
ValueAnimator squashAnim2 = new ObjectAnimator(duration/4, newBall, "width", newBall.getWidth(),
ValueAnimator squashAnim2 = ObjectAnimator.ofFloat(newBall, "width", newBall.getWidth(),
newBall.getWidth() + 50);
squashAnim2.setDuration(duration/4);
squashAnim2.setRepeatCount(1);
squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
squashAnim2.setInterpolator(new DecelerateInterpolator());
ValueAnimator stretchAnim1 = new ObjectAnimator(duration/4, newBall, "y", endY,
ValueAnimator stretchAnim1 = ObjectAnimator.ofFloat(newBall, "y", endY,
endY + 25f);
stretchAnim1.setDuration(duration/4);
stretchAnim1.setRepeatCount(1);
stretchAnim1.setInterpolator(new DecelerateInterpolator());
stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);
ValueAnimator stretchAnim2 = new ObjectAnimator(duration/4, newBall, "height",
ValueAnimator stretchAnim2 = ObjectAnimator.ofFloat(newBall, "height",
newBall.getHeight(), newBall.getHeight() - 25);
stretchAnim2.setDuration(duration/4);
stretchAnim2.setRepeatCount(1);
stretchAnim2.setInterpolator(new DecelerateInterpolator());
stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);
ValueAnimator bounceBackAnim = new ObjectAnimator(duration, newBall, "y", endY,
ValueAnimator bounceBackAnim = ObjectAnimator.ofFloat(newBall, "y", endY,
startY);
bounceBackAnim.setDuration(duration);
bounceBackAnim.setInterpolator(new DecelerateInterpolator());
// Sequence the down/squash&stretch/up animations
AnimatorSet bouncer = new AnimatorSet();
@@ -126,7 +134,8 @@ public class BouncingBalls extends Activity {
bouncer.play(bounceBackAnim).after(stretchAnim2);
// Fading animation - remove the ball when the animation is done
ValueAnimator fadeAnim = new ObjectAnimator(250, newBall, "alpha", 1f, 0f);
ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
fadeAnim.setDuration(250);
fadeAnim.addListener(this);
// Sequence the two animations to play one after the other

View File

@@ -130,9 +130,9 @@ public class CustomEvaluator extends Activity {
if (bounceAnim == null) {
XYHolder startXY = new XYHolder(0f, 0f);
XYHolder endXY = new XYHolder(300f, 500f);
bounceAnim = new ObjectAnimator(1500, ballHolder, "xY",
endXY);
bounceAnim.setEvaluator(new XYEvaluator());
bounceAnim = ObjectAnimator.ofObject(ballHolder, "xY",
new XYEvaluator(), endXY);
bounceAnim.setDuration(1500);
bounceAnim.addUpdateListener(this);
}
}

View File

@@ -146,21 +146,21 @@ public class LayoutAnimations extends Activity {
private void createCustomAnimations(LayoutTransition transition) {
// Changing while Adding
PropertyValuesHolder<Integer> pvhLeft =
new PropertyValuesHolder<Integer>("left", 0, 1);
PropertyValuesHolder<Integer> pvhTop =
new PropertyValuesHolder<Integer>("top", 0, 1);
PropertyValuesHolder<Integer> pvhRight =
new PropertyValuesHolder<Integer>("right", 0, 1);
PropertyValuesHolder<Integer> pvhBottom =
new PropertyValuesHolder<Integer>("bottom", 0, 1);
PropertyValuesHolder<Float> pvhScaleX =
new PropertyValuesHolder<Float>("scaleX", 1f, 0f, 1f);
PropertyValuesHolder<Float> pvhScaleY =
new PropertyValuesHolder<Float>("scaleY", 1f, 0f, 1f);
customChangingAppearingAnim =
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_APPEARING),
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY);
PropertyValuesHolder pvhLeft =
PropertyValuesHolder.ofInt("left", 0, 1);
PropertyValuesHolder pvhTop =
PropertyValuesHolder.ofInt("top", 0, 1);
PropertyValuesHolder pvhRight =
PropertyValuesHolder.ofInt("right", 0, 1);
PropertyValuesHolder pvhBottom =
PropertyValuesHolder.ofInt("bottom", 0, 1);
PropertyValuesHolder pvhScaleX =
PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
PropertyValuesHolder pvhScaleY =
PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
customChangingAppearingAnim = ObjectAnimator.ofPropertyValuesHolder(
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY).
setDuration(transition.getDuration(LayoutTransition.CHANGE_APPEARING));
customChangingAppearingAnim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
View view = (View) ((ObjectAnimator) anim).getTarget();
@@ -173,11 +173,11 @@ public class LayoutAnimations extends Activity {
Keyframe kf0 = new Keyframe(0f, 0f);
Keyframe kf1 = new Keyframe(.9999f, 360f);
Keyframe kf2 = new Keyframe(1f, 0f);
PropertyValuesHolder<Keyframe> pvhRotation =
new PropertyValuesHolder<Keyframe>("rotation", kf0, kf1, kf2);
customChangingDisappearingAnim =
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING),
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation);
PropertyValuesHolder pvhRotation =
PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
customChangingDisappearingAnim = ObjectAnimator.ofPropertyValuesHolder(
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation).
setDuration(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING));
customChangingDisappearingAnim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
View view = (View) ((ObjectAnimator) anim).getTarget();
@@ -186,9 +186,8 @@ public class LayoutAnimations extends Activity {
});
// Adding
customAppearingAnim =
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.APPEARING),
null, "rotationY", 90f, 0f);
customAppearingAnim = ObjectAnimator.ofFloat(null, "rotationY", 90f, 0f).
setDuration(transition.getDuration(LayoutTransition.APPEARING));
customAppearingAnim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
View view = (View) ((ObjectAnimator) anim).getTarget();
@@ -197,9 +196,8 @@ public class LayoutAnimations extends Activity {
});
// Removing
customDisappearingAnim =
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.DISAPPEARING),
null, "rotationX", 0f, 90f);
customDisappearingAnim = ObjectAnimator.ofFloat(null, "rotationX", 0f, 90f).
setDuration(transition.getDuration(LayoutTransition.DISAPPEARING));
customDisappearingAnim.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
View view = (View) ((ObjectAnimator) anim).getTarget();

View File

@@ -111,21 +111,21 @@ public class LayoutAnimationsHideShow extends Activity {
private void setupAnimations(LayoutTransition transition) {
// Changing while Adding
PropertyValuesHolder<Integer> pvhLeft =
new PropertyValuesHolder<Integer>("left", 0, 1);
PropertyValuesHolder<Integer> pvhTop =
new PropertyValuesHolder<Integer>("top", 0, 1);
PropertyValuesHolder<Integer> pvhRight =
new PropertyValuesHolder<Integer>("right", 0, 1);
PropertyValuesHolder<Integer> pvhBottom =
new PropertyValuesHolder<Integer>("bottom", 0, 1);
PropertyValuesHolder<Float> pvhScaleX =
new PropertyValuesHolder<Float>("scaleX", 1f, 0f, 1f);
PropertyValuesHolder<Float> pvhScaleY =
new PropertyValuesHolder<Float>("scaleY", 1f, 0f, 1f);
final ObjectAnimator changeIn =
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_APPEARING),
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY);
PropertyValuesHolder pvhLeft =
PropertyValuesHolder.ofInt("left", 0, 1);
PropertyValuesHolder pvhTop =
PropertyValuesHolder.ofInt("top", 0, 1);
PropertyValuesHolder pvhRight =
PropertyValuesHolder.ofInt("right", 0, 1);
PropertyValuesHolder pvhBottom =
PropertyValuesHolder.ofInt("bottom", 0, 1);
PropertyValuesHolder pvhScaleX =
PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
PropertyValuesHolder pvhScaleY =
PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
final ObjectAnimator changeIn = ObjectAnimator.ofPropertyValuesHolder(
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY).
setDuration(transition.getDuration(LayoutTransition.CHANGE_APPEARING));
transition.setAnimator(LayoutTransition.CHANGE_APPEARING, changeIn);
changeIn.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
@@ -139,11 +139,11 @@ public class LayoutAnimationsHideShow extends Activity {
Keyframe kf0 = new Keyframe(0f, 0f);
Keyframe kf1 = new Keyframe(.9999f, 360f);
Keyframe kf2 = new Keyframe(1f, 0f);
PropertyValuesHolder<Keyframe> pvhRotation =
new PropertyValuesHolder<Keyframe>("rotation", kf0, kf1, kf2);
final ObjectAnimator changeOut =
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING),
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation);
PropertyValuesHolder pvhRotation =
PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
final ObjectAnimator changeOut = ObjectAnimator.ofPropertyValuesHolder(
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation).
setDuration(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING));
transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, changeOut);
changeOut.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
@@ -153,9 +153,8 @@ public class LayoutAnimationsHideShow extends Activity {
});
// Adding
ObjectAnimator<Float> animIn =
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.APPEARING),
null, "rotationY", 90f, 0f);
ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "rotationY", 90f, 0f).
setDuration(transition.getDuration(LayoutTransition.APPEARING));
transition.setAnimator(LayoutTransition.APPEARING, animIn);
animIn.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {
@@ -165,9 +164,8 @@ public class LayoutAnimationsHideShow extends Activity {
});
// Removing
ObjectAnimator<Float> animOut =
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.DISAPPEARING),
null, "rotationX", 0f, 90f);
ObjectAnimator animOut = ObjectAnimator.ofFloat(null, "rotationX", 0f, 90f).
setDuration(transition.getDuration(LayoutTransition.DISAPPEARING));
transition.setAnimator(LayoutTransition.DISAPPEARING, animOut);
animIn.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animator anim) {

View File

@@ -106,9 +106,12 @@ public class ListFlipper extends Activity {
invisibleList = mFrenchList;
visibleList = mEnglishList;
}
ObjectAnimator visToInvis = new ObjectAnimator(500, visibleList, "rotationY", 0f, 90f);
ObjectAnimator visToInvis = ObjectAnimator.ofFloat(visibleList, "rotationY", 0f, 90f);
visToInvis.setDuration(500);
visToInvis.setInterpolator(accelerator);
final ObjectAnimator invisToVis = new ObjectAnimator(500, invisibleList, "rotationY", -90f, 0f);
final ObjectAnimator invisToVis = ObjectAnimator.ofFloat(invisibleList, "rotationY",
-90f, 0f);
invisToVis.setDuration(500);
invisToVis.setInterpolator(decelerator);
visToInvis.addListener(new AnimatorListenerAdapter() {
@Override

View File

@@ -86,43 +86,45 @@ public class MultiPropertyAnimation extends Activity {
if (bounceAnim == null) {
ShapeHolder ball;
ball = balls.get(0);
ObjectAnimator yBouncer = new ObjectAnimator(DURATION, ball, "y",
ball.getY(), getHeight() - BALL_SIZE);
ObjectAnimator yBouncer = ObjectAnimator.ofFloat(ball, "y",
ball.getY(), getHeight() - BALL_SIZE).setDuration(DURATION);
yBouncer.setInterpolator(new BounceInterpolator());
yBouncer.addUpdateListener(this);
ball = balls.get(1);
PropertyValuesHolder pvhY = new PropertyValuesHolder("y", ball.getY(),
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", ball.getY(),
getHeight() - BALL_SIZE);
PropertyValuesHolder pvhAlpha = new PropertyValuesHolder("alpha", 1.0f,
0f);
ObjectAnimator yAlphaBouncer = new ObjectAnimator(DURATION/2, ball, pvhY, pvhAlpha);
PropertyValuesHolder pvhAlpha = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f);
ObjectAnimator yAlphaBouncer = ObjectAnimator.ofPropertyValuesHolder(ball,
pvhY, pvhAlpha).setDuration(DURATION/2);
yAlphaBouncer.setInterpolator(new AccelerateInterpolator());
yAlphaBouncer.setRepeatCount(1);
yAlphaBouncer.setRepeatMode(ValueAnimator.REVERSE);
ball = balls.get(2);
PropertyValuesHolder pvhW = new PropertyValuesHolder("width", ball.getWidth(),
PropertyValuesHolder pvhW = PropertyValuesHolder.ofFloat("width", ball.getWidth(),
ball.getWidth() * 2);
PropertyValuesHolder pvhH = new PropertyValuesHolder("height", ball.getHeight(),
PropertyValuesHolder pvhH = PropertyValuesHolder.ofFloat("height", ball.getHeight(),
ball.getHeight() * 2);
PropertyValuesHolder pvTX = new PropertyValuesHolder("x", ball.getX(), ball.getX() - BALL_SIZE/2f);
PropertyValuesHolder pvTY = new PropertyValuesHolder("y", 0f, ball.getY(), ball.getY() - BALL_SIZE/2f);
ObjectAnimator whxyBouncer = new ObjectAnimator(DURATION/2, ball, pvhW, pvhH,
pvTX, pvTY);
PropertyValuesHolder pvTX = PropertyValuesHolder.ofFloat("x", ball.getX(),
ball.getX() - BALL_SIZE/2f);
PropertyValuesHolder pvTY = PropertyValuesHolder.ofFloat("y", 0f, ball.getY(),
ball.getY() - BALL_SIZE/2f);
ObjectAnimator whxyBouncer = ObjectAnimator.ofPropertyValuesHolder(ball, pvhW, pvhH,
pvTX, pvTY).setDuration(DURATION/2);
whxyBouncer.setRepeatCount(1);
whxyBouncer.setRepeatMode(ValueAnimator.REVERSE);
ball = balls.get(3);
pvhY = new PropertyValuesHolder("y", ball.getY(),
getHeight() - BALL_SIZE);
pvhY = PropertyValuesHolder.ofFloat("y", ball.getY(), getHeight() - BALL_SIZE);
float ballX = ball.getX();
Keyframe kf0 = new Keyframe(0f, ballX);
Keyframe kf1 = new Keyframe(.5f, ballX + 100f);
Keyframe kf2 = new Keyframe(1f, ballX + 50f);
PropertyValuesHolder pvhX = new PropertyValuesHolder("x", kf0, kf1, kf2);
ObjectAnimator yxBouncer = new ObjectAnimator(DURATION/2, ball, pvhY, pvhX);
PropertyValuesHolder pvhX = PropertyValuesHolder.ofKeyframe("x", kf0, kf1, kf2);
ObjectAnimator yxBouncer = ObjectAnimator.ofPropertyValuesHolder(ball, pvhY,
pvhX).setDuration(DURATION/2);
yxBouncer.setRepeatCount(1);
yxBouncer.setRepeatMode(ValueAnimator.REVERSE);

View File

@@ -81,8 +81,8 @@ public class ReversingAnimation extends Activity {
private void createAnimation() {
if (bounceAnim == null) {
bounceAnim = new ObjectAnimator(1500, ball, "y",
ball.getY(), getHeight() - 50f);
bounceAnim = ObjectAnimator.ofFloat(ball, "y", ball.getY(), getHeight() - 50f).
setDuration(1500);
bounceAnim.setInterpolator(new AccelerateInterpolator(2f));
bounceAnim.addUpdateListener(this);
}