From e358b47be5a1c1a775a376925ea063b51ec3a3f9 Mon Sep 17 00:00:00 2001 From: Chet Haase Date: Thu, 14 Oct 2010 06:59:27 -0700 Subject: [PATCH] Updating code to use new non-generified animator APIs Change-Id: I3023db9d1f9cb8bf98b788fce4ae2b58b182987d --- .../apis/animation/AnimationCloning.java | 12 ++--- .../apis/animation/AnimationSeeking.java | 4 +- .../apis/animation/AnimatorEvents.java | 12 ++--- .../android/apis/animation/BouncingBalls.java | 27 ++++++---- .../apis/animation/CustomEvaluator.java | 6 +-- .../apis/animation/LayoutAnimations.java | 50 +++++++++---------- .../animation/LayoutAnimationsHideShow.java | 50 +++++++++---------- .../android/apis/animation/ListFlipper.java | 7 ++- .../animation/MultiPropertyAnimation.java | 34 +++++++------ .../apis/animation/ReversingAnimation.java | 4 +- 10 files changed, 108 insertions(+), 98 deletions(-) diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/AnimationCloning.java b/samples/ApiDemos/src/com/example/android/apis/animation/AnimationCloning.java index 71d246016..f8f2da5b5 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/AnimationCloning.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/AnimationCloning.java @@ -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); diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/AnimationSeeking.java b/samples/ApiDemos/src/com/example/android/apis/animation/AnimationSeeking.java index 8307d60c0..b62174a91 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/AnimationSeeking.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/AnimationSeeking.java @@ -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); } diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/AnimatorEvents.java b/samples/ApiDemos/src/com/example/android/apis/animation/AnimatorEvents.java index 650f3509c..81ece1846 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/AnimatorEvents.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/AnimatorEvents.java @@ -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); } } diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/BouncingBalls.java b/samples/ApiDemos/src/com/example/android/apis/animation/BouncingBalls.java index 3ffe24abf..7c42ede8b 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/BouncingBalls.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/BouncingBalls.java @@ -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 diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/CustomEvaluator.java b/samples/ApiDemos/src/com/example/android/apis/animation/CustomEvaluator.java index d1018c95c..7361fc1e8 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/CustomEvaluator.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/CustomEvaluator.java @@ -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); } } diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimations.java b/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimations.java index 203f2c708..e98a6875d 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimations.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimations.java @@ -146,21 +146,21 @@ public class LayoutAnimations extends Activity { private void createCustomAnimations(LayoutTransition transition) { // Changing while Adding - PropertyValuesHolder pvhLeft = - new PropertyValuesHolder("left", 0, 1); - PropertyValuesHolder pvhTop = - new PropertyValuesHolder("top", 0, 1); - PropertyValuesHolder pvhRight = - new PropertyValuesHolder("right", 0, 1); - PropertyValuesHolder pvhBottom = - new PropertyValuesHolder("bottom", 0, 1); - PropertyValuesHolder pvhScaleX = - new PropertyValuesHolder("scaleX", 1f, 0f, 1f); - PropertyValuesHolder pvhScaleY = - new PropertyValuesHolder("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 pvhRotation = - new PropertyValuesHolder("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(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(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(); diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimationsHideShow.java b/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimationsHideShow.java index 9f311b164..44d3f6db4 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimationsHideShow.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/LayoutAnimationsHideShow.java @@ -111,21 +111,21 @@ public class LayoutAnimationsHideShow extends Activity { private void setupAnimations(LayoutTransition transition) { // Changing while Adding - PropertyValuesHolder pvhLeft = - new PropertyValuesHolder("left", 0, 1); - PropertyValuesHolder pvhTop = - new PropertyValuesHolder("top", 0, 1); - PropertyValuesHolder pvhRight = - new PropertyValuesHolder("right", 0, 1); - PropertyValuesHolder pvhBottom = - new PropertyValuesHolder("bottom", 0, 1); - PropertyValuesHolder pvhScaleX = - new PropertyValuesHolder("scaleX", 1f, 0f, 1f); - PropertyValuesHolder pvhScaleY = - new PropertyValuesHolder("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 pvhRotation = - new PropertyValuesHolder("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 animIn = - new ObjectAnimator(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 animOut = - new ObjectAnimator(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) { diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/ListFlipper.java b/samples/ApiDemos/src/com/example/android/apis/animation/ListFlipper.java index 5212781c0..519befd57 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/ListFlipper.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/ListFlipper.java @@ -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 diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/MultiPropertyAnimation.java b/samples/ApiDemos/src/com/example/android/apis/animation/MultiPropertyAnimation.java index 0ba012f99..f6e878cac 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/MultiPropertyAnimation.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/MultiPropertyAnimation.java @@ -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); diff --git a/samples/ApiDemos/src/com/example/android/apis/animation/ReversingAnimation.java b/samples/ApiDemos/src/com/example/android/apis/animation/ReversingAnimation.java index 13f3b89cb..b748f89a3 100644 --- a/samples/ApiDemos/src/com/example/android/apis/animation/ReversingAnimation.java +++ b/samples/ApiDemos/src/com/example/android/apis/animation/ReversingAnimation.java @@ -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); }