Animation classname changes

Change-Id: I0b3b5f1563ab0ac301684880957ed55ebfc54da5
This commit is contained in:
Chet Haase
2010-09-07 13:43:53 -07:00
parent e0a989bcfa
commit d9855a8dbe
13 changed files with 169 additions and 209 deletions

View File

@@ -14,15 +14,15 @@
limitations under the License. limitations under the License.
--> -->
<sequencer> <set>
<property xmlns:android="http://schemas.android.com/apk/res/android" <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000" android:duration="1000"
android:valueTo="200" android:valueTo="200"
android:valueType="floatType" android:valueType="floatType"
android:propertyName="x" android:propertyName="x"
android:repeatCount="1" android:repeatCount="1"
android:repeatMode="reverse"/> android:repeatMode="reverse"/>
<property xmlns:android="http://schemas.android.com/apk/res/android" <objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000" android:duration="1000"
android:valueFrom="0" android:valueFrom="0"
android:valueTo="400" android:valueTo="400"
@@ -30,4 +30,4 @@
android:propertyName="y" android:propertyName="y"
android:repeatCount="1" android:repeatCount="1"
android:repeatMode="reverse"/> android:repeatMode="reverse"/>
</sequencer> </set>

View File

@@ -30,9 +30,7 @@ import android.graphics.RadialGradient;
import android.graphics.Shader; import android.graphics.Shader;
import android.graphics.drawable.ShapeDrawable; import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape; import android.graphics.drawable.shapes.OvalShape;
import android.graphics.drawable.shapes.RectShape;
import android.os.Bundle; import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.animation.AccelerateInterpolator; import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
@@ -60,10 +58,10 @@ public class AnimationCloning extends Activity {
}); });
} }
public class MyAnimationView extends View implements Animator.AnimatorUpdateListener { public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener {
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Sequencer animation = null; AnimatorSet animation = null;
private float mDensity; private float mDensity;
public MyAnimationView(Context context) { public MyAnimationView(Context context) {
@@ -81,27 +79,27 @@ public class AnimationCloning extends Activity {
private void createAnimation() { private void createAnimation() {
if (animation == null) { if (animation == null) {
PropertyAnimator anim1 = new PropertyAnimator(500, balls.get(0), "y", ObjectAnimator anim1 = new ObjectAnimator(500, balls.get(0), "y",
0f, getHeight() - balls.get(0).getHeight()); 0f, getHeight() - balls.get(0).getHeight());
PropertyAnimator anim2 = anim1.clone(); ObjectAnimator anim2 = anim1.clone();
anim2.setTarget(balls.get(1)); anim2.setTarget(balls.get(1));
anim1.addUpdateListener(this); anim1.addUpdateListener(this);
ShapeHolder ball2 = balls.get(2); ShapeHolder ball2 = balls.get(2);
PropertyAnimator animDown = new PropertyAnimator(500, ball2, "y", ObjectAnimator animDown = new ObjectAnimator(500, ball2, "y",
0f, getHeight() - ball2.getHeight()); 0f, getHeight() - ball2.getHeight());
animDown.setInterpolator(new AccelerateInterpolator()); animDown.setInterpolator(new AccelerateInterpolator());
PropertyAnimator animUp = new PropertyAnimator(500, ball2, "y", ObjectAnimator animUp = new ObjectAnimator(500, ball2, "y",
getHeight() - ball2.getHeight(), 0f); getHeight() - ball2.getHeight(), 0f);
animDown.setInterpolator(new DecelerateInterpolator()); animDown.setInterpolator(new DecelerateInterpolator());
Sequencer s1 = new Sequencer(); AnimatorSet s1 = new AnimatorSet();
s1.playSequentially(animDown, animUp); s1.playSequentially(animDown, animUp);
animDown.addUpdateListener(this); animDown.addUpdateListener(this);
animUp.addUpdateListener(this); animUp.addUpdateListener(this);
Sequencer s2 = (Sequencer) s1.clone(); AnimatorSet s2 = (AnimatorSet) s1.clone();
s2.setTarget(balls.get(3)); s2.setTarget(balls.get(3));
animation = new Sequencer(); animation = new AnimatorSet();
animation.playTogether(anim1, anim2, s1); animation.playTogether(anim1, anim2, s1);
animation.playSequentially(s1, s2); animation.playSequentially(s1, s2);
} }
@@ -144,7 +142,7 @@ public class AnimationCloning extends Activity {
animation.start(); animation.start();
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
} }

View File

@@ -18,15 +18,15 @@ package com.example.android.apis.animation;
// Need the following import to get access to the app resources, since this // Need the following import to get access to the app resources, since this
// class is in a sub-package. // class is in a sub-package.
import android.animation.AnimatableInflater; import android.animation.AnimatorInflater;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import com.example.android.apis.R; import com.example.android.apis.R;
import java.util.ArrayList; import java.util.ArrayList;
import android.animation.Animatable;
import android.animation.Animator; import android.animation.Animator;
import android.animation.PropertyAnimator; import android.animation.ValueAnimator;
import android.animation.Sequencer;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -41,7 +41,7 @@ import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
/** /**
* This application demonstrates loading Animatable objects from XML resources. * This application demonstrates loading Animator objects from XML resources.
*/ */
public class AnimationLoading extends Activity { public class AnimationLoading extends Activity {
@@ -67,12 +67,12 @@ public class AnimationLoading extends Activity {
} }
public class MyAnimationView extends View implements Animator.AnimatorUpdateListener { public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener {
private static final float BALL_SIZE = 100f; private static final float BALL_SIZE = 100f;
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Animatable animation = null; Animator animation = null;
public MyAnimationView(Context context) { public MyAnimationView(Context context) {
super(context); super(context);
@@ -83,28 +83,28 @@ public class AnimationLoading extends Activity {
private void createAnimation() { private void createAnimation() {
if (animation == null) { if (animation == null) {
PropertyAnimator anim = ObjectAnimator anim =
(PropertyAnimator) AnimatableInflater. (ObjectAnimator) AnimatorInflater.
loadAnimatable(getApplicationContext(), R.anim.property_animator); loadAnimator(getApplicationContext(), R.anim.property_animator);
anim.addUpdateListener(this); anim.addUpdateListener(this);
anim.setTarget(balls.get(0)); anim.setTarget(balls.get(0));
Animator fader = ValueAnimator fader =
(Animator) AnimatableInflater.loadAnimatable(getApplicationContext(), (ValueAnimator) AnimatorInflater.loadAnimator(getApplicationContext(),
R.anim.animator); R.anim.animator);
fader.addUpdateListener(new Animator.AnimatorUpdateListener() { fader.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
balls.get(1).setAlpha((Float) animation.getAnimatedValue()); balls.get(1).setAlpha((Float) animation.getAnimatedValue());
} }
}); });
Sequencer seq = AnimatorSet seq =
(Sequencer) AnimatableInflater.loadAnimatable(getApplicationContext(), (AnimatorSet) AnimatorInflater.loadAnimator(getApplicationContext(),
R.anim.sequencer); R.anim.animator_set);
seq.setTarget(balls.get(2)); seq.setTarget(balls.get(2));
animation = new Sequencer(); animation = new AnimatorSet();
((Sequencer) animation).playTogether(anim, fader, seq); ((AnimatorSet) animation).playTogether(anim, fader, seq);
} }
} }
@@ -143,7 +143,7 @@ public class AnimationLoading extends Activity {
} }
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
ShapeHolder ball = balls.get(0); ShapeHolder ball = balls.get(0);

View File

@@ -18,15 +18,14 @@ package com.example.android.apis.animation;
// Need the following import to get access to the app resources, since this // Need the following import to get access to the app resources, since this
// class is in a sub-package. // class is in a sub-package.
import android.animation.Animator;
import com.example.android.apis.R; import com.example.android.apis.R;
import java.util.ArrayList; import java.util.ArrayList;
import android.animation.Animatable; import android.animation.ValueAnimator;
import android.animation.Animator; import android.animation.ObjectAnimator;
import android.animation.PropertyAnimator; import android.animation.AnimatorSet;
import android.animation.Sequencer;
import android.animation.Animatable.AnimatableListener;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -43,7 +42,7 @@ import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
/** /**
* This application demonstrates the seeking capability of Animator. The SeekBar in the * This application demonstrates the seeking capability of ValueAnimator. The SeekBar in the
* UI allows you to set the position of the animation. Pressing the Run button will play from * UI allows you to set the position of the animation. Pressing the Run button will play from
* the current position of the animation. * the current position of the animation.
*/ */
@@ -93,7 +92,7 @@ public class AnimationSeeking extends Activity {
}); });
} }
public class MyAnimationView extends View implements Animator.AnimatorUpdateListener, AnimatableListener { public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
private static final int RED = 0xffFF8080; private static final int RED = 0xffFF8080;
private static final int BLUE = 0xff8080FF; private static final int BLUE = 0xff8080FF;
@@ -102,8 +101,8 @@ public class AnimationSeeking extends Activity {
private static final float BALL_SIZE = 100f; private static final float BALL_SIZE = 100f;
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Sequencer animation = null; AnimatorSet animation = null;
Animator bounceAnim = null; ValueAnimator bounceAnim = null;
ShapeHolder ball = null; ShapeHolder ball = null;
public MyAnimationView(Context context) { public MyAnimationView(Context context) {
@@ -113,7 +112,7 @@ public class AnimationSeeking extends Activity {
private void createAnimation() { private void createAnimation() {
if (bounceAnim == null) { if (bounceAnim == null) {
bounceAnim = new PropertyAnimator(1500, ball, "y", bounceAnim = new ObjectAnimator(1500, ball, "y",
ball.getY(), getHeight() - BALL_SIZE); ball.getY(), getHeight() - BALL_SIZE);
bounceAnim.setInterpolator(new BounceInterpolator()); bounceAnim.setInterpolator(new BounceInterpolator());
bounceAnim.addUpdateListener(this); bounceAnim.addUpdateListener(this);
@@ -157,28 +156,28 @@ public class AnimationSeeking extends Activity {
ball.getShape().draw(canvas); ball.getShape().draw(canvas);
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
long playtime = bounceAnim.getCurrentPlayTime(); long playtime = bounceAnim.getCurrentPlayTime();
//mSeekBar.setProgress((int)playtime); //mSeekBar.setProgress((int)playtime);
} }
@Override @Override
public void onAnimationCancel(Animatable animation) { public void onAnimationCancel(Animator animation) {
} }
@Override @Override
public void onAnimationEnd(Animatable animation) { public void onAnimationEnd(Animator animation) {
balls.remove(((PropertyAnimator)animation).getTarget()); balls.remove(((ObjectAnimator)animation).getTarget());
} }
@Override @Override
public void onAnimationRepeat(Animatable animation) { public void onAnimationRepeat(Animator animation) {
} }
@Override @Override
public void onAnimationStart(Animatable animation) { public void onAnimationStart(Animator animation) {
} }
} }
} }

View File

@@ -18,16 +18,16 @@ package com.example.android.apis.animation;
// Need the following import to get access to the app resources, since this // Need the following import to get access to the app resources, since this
// class is in a sub-package. // class is in a sub-package.
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.widget.CheckBox; import android.widget.CheckBox;
import android.widget.TextView; import android.widget.TextView;
import com.example.android.apis.R; import com.example.android.apis.R;
import java.util.ArrayList; import java.util.ArrayList;
import android.animation.Animatable; import android.animation.ValueAnimator;
import android.animation.Animator; import android.animation.AnimatorSet;
import android.animation.PropertyAnimator;
import android.animation.Sequencer;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -43,7 +43,7 @@ import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
/** /**
* This demo shows how the AnimatableListener events work. * This demo shows how the AnimatorListener events work.
*/ */
public class AnimatorEvents extends Activity { public class AnimatorEvents extends Activity {
@@ -79,7 +79,6 @@ public class AnimatorEvents extends Activity {
Button starter = (Button) findViewById(R.id.startButton); Button starter = (Button) findViewById(R.id.startButton);
starter.setOnClickListener(new View.OnClickListener() { starter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { public void onClick(View v) {
animView.startAnimation(endCB.isChecked()); animView.startAnimation(endCB.isChecked());
} }
@@ -88,7 +87,6 @@ public class AnimatorEvents extends Activity {
Button canceler = (Button) findViewById(R.id.cancelButton); Button canceler = (Button) findViewById(R.id.cancelButton);
canceler.setOnClickListener(new View.OnClickListener() { canceler.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { public void onClick(View v) {
animView.cancelAnimation(); animView.cancelAnimation();
} }
@@ -97,7 +95,6 @@ public class AnimatorEvents extends Activity {
Button ender = (Button) findViewById(R.id.endButton); Button ender = (Button) findViewById(R.id.endButton);
ender.setOnClickListener(new View.OnClickListener() { ender.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { public void onClick(View v) {
animView.endAnimation(); animView.endAnimation();
} }
@@ -105,11 +102,11 @@ public class AnimatorEvents extends Activity {
} }
public class MyAnimationView extends View implements Animatable.AnimatableListener, public class MyAnimationView extends View implements Animator.AnimatorListener,
Animator.AnimatorUpdateListener { ValueAnimator.AnimatorUpdateListener {
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Animatable animation; Animator animation;
ShapeHolder ball = null; ShapeHolder ball = null;
boolean endImmediately = false; boolean endImmediately = false;
@@ -120,28 +117,28 @@ public class AnimatorEvents extends Activity {
private void createAnimation() { private void createAnimation() {
if (animation == null) { if (animation == null) {
PropertyAnimator yAnim = new PropertyAnimator(1500, ball, "y", ObjectAnimator yAnim = new ObjectAnimator(1500, ball, "y",
ball.getY(), getHeight() - 50f); ball.getY(), getHeight() - 50f);
yAnim.setRepeatCount(0); yAnim.setRepeatCount(0);
yAnim.setRepeatMode(Animator.REVERSE); yAnim.setRepeatMode(ValueAnimator.REVERSE);
yAnim.setInterpolator(new AccelerateInterpolator(2f)); yAnim.setInterpolator(new AccelerateInterpolator(2f));
yAnim.addUpdateListener(this); yAnim.addUpdateListener(this);
yAnim.addListener(this); yAnim.addListener(this);
PropertyAnimator xAnim = new PropertyAnimator(1000, ball, "x", ObjectAnimator xAnim = new ObjectAnimator(1000, ball, "x",
ball.getX(), ball.getX() + 300); ball.getX(), ball.getX() + 300);
xAnim.setStartDelay(0); xAnim.setStartDelay(0);
xAnim.setRepeatCount(0); xAnim.setRepeatCount(0);
xAnim.setRepeatMode(Animator.REVERSE); xAnim.setRepeatMode(ValueAnimator.REVERSE);
xAnim.setInterpolator(new AccelerateInterpolator(2f)); xAnim.setInterpolator(new AccelerateInterpolator(2f));
PropertyAnimator alphaAnim = new PropertyAnimator(1000, ball, "alpha", 1f, .5f); ObjectAnimator alphaAnim = new ObjectAnimator(1000, ball, "alpha", 1f, .5f);
Sequencer alphaSeq = new Sequencer(); AnimatorSet alphaSeq = new AnimatorSet();
alphaSeq.play(alphaAnim); alphaSeq.play(alphaAnim);
animation = new Sequencer(); animation = new AnimatorSet();
((Sequencer) animation).playTogether(yAnim, xAnim); ((AnimatorSet) animation).playTogether(yAnim, xAnim);
//((Sequencer) animation).play(alphaSeq).after(500); //((AnimatorSet) animation).play(alphaSeq).after(500);
animation.addListener(this); animation.addListener(this);
} }
} }
@@ -198,12 +195,12 @@ public class AnimatorEvents extends Activity {
canvas.restore(); canvas.restore();
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
} }
public void onAnimationStart(Animatable animation) { public void onAnimationStart(Animator animation) {
if (animation instanceof Sequencer) { if (animation instanceof AnimatorSet) {
startText.setAlpha(1f); startText.setAlpha(1f);
} else { } else {
startTextAnimator.setAlpha(1f); startTextAnimator.setAlpha(1f);
@@ -213,24 +210,24 @@ public class AnimatorEvents extends Activity {
} }
} }
public void onAnimationEnd(Animatable animation) { public void onAnimationEnd(Animator animation) {
if (animation instanceof Sequencer) { if (animation instanceof AnimatorSet) {
endText.setAlpha(1f); endText.setAlpha(1f);
} else { } else {
endTextAnimator.setAlpha(1f); endTextAnimator.setAlpha(1f);
} }
} }
public void onAnimationCancel(Animatable animation) { public void onAnimationCancel(Animator animation) {
if (animation instanceof Sequencer) { if (animation instanceof AnimatorSet) {
cancelText.setAlpha(1f); cancelText.setAlpha(1f);
} else { } else {
cancelTextAnimator.setAlpha(1f); cancelTextAnimator.setAlpha(1f);
} }
} }
public void onAnimationRepeat(Animatable animation) { public void onAnimationRepeat(Animator animation) {
if (animation instanceof Sequencer) { if (animation instanceof AnimatorSet) {
repeatText.setAlpha(1f); repeatText.setAlpha(1f);
} else { } else {
repeatTextAnimator.setAlpha(1f); repeatTextAnimator.setAlpha(1f);

View File

@@ -50,7 +50,7 @@ public class BouncingBalls extends Activity {
container.addView(new MyAnimationView(this)); container.addView(new MyAnimationView(this));
} }
public class MyAnimationView extends View implements Animator.AnimatorUpdateListener, Animatable.AnimatableListener { public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener, Animator.AnimatorListener {
private static final int RED = 0xffFF8080; private static final int RED = 0xffFF8080;
private static final int BLUE = 0xff8080FF; private static final int BLUE = 0xff8080FF;
@@ -58,7 +58,7 @@ public class BouncingBalls extends Activity {
private static final int GREEN = 0xff80ff80; private static final int GREEN = 0xff80ff80;
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Sequencer animation = null; AnimatorSet animation = null;
public MyAnimationView(Context context) { public MyAnimationView(Context context) {
super(context); super(context);
@@ -70,10 +70,10 @@ public class BouncingBalls extends Activity {
paint.setColor(RED); paint.setColor(RED);
// Animate background color // Animate background color
Animator colorAnim = new PropertyAnimator(3000, paint, "color", BLUE); ValueAnimator colorAnim = new ObjectAnimator(3000, paint, "color", BLUE);
colorAnim.setEvaluator(new RGBEvaluator()); colorAnim.setEvaluator(new RGBEvaluator());
colorAnim.setRepeatCount(Animator.INFINITE); colorAnim.setRepeatCount(ValueAnimator.INFINITE);
colorAnim.setRepeatMode(Animator.REVERSE); colorAnim.setRepeatMode(ValueAnimator.REVERSE);
colorAnim.addUpdateListener(this); // forces invalidation to get the redraw colorAnim.addUpdateListener(this); // forces invalidation to get the redraw
colorAnim.start(); colorAnim.start();
} }
@@ -92,33 +92,33 @@ public class BouncingBalls extends Activity {
float h = (float)getHeight(); float h = (float)getHeight();
float eventY = event.getY(); float eventY = event.getY();
int duration = (int)(500 * ((h - eventY)/h)); int duration = (int)(500 * ((h - eventY)/h));
Animator bounceAnim = new PropertyAnimator(duration, newBall, "y", startY, endY); ValueAnimator bounceAnim = new ObjectAnimator(duration, newBall, "y", startY, endY);
bounceAnim.setInterpolator(new AccelerateInterpolator()); bounceAnim.setInterpolator(new AccelerateInterpolator());
Animator squashAnim1 = new PropertyAnimator(duration/4, newBall, "x", newBall.getX(), ValueAnimator squashAnim1 = new ObjectAnimator(duration/4, newBall, "x", newBall.getX(),
newBall.getX() - 25f); newBall.getX() - 25f);
squashAnim1.setRepeatCount(1); squashAnim1.setRepeatCount(1);
squashAnim1.setRepeatMode(Animator.REVERSE); squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
squashAnim1.setInterpolator(new DecelerateInterpolator()); squashAnim1.setInterpolator(new DecelerateInterpolator());
Animator squashAnim2 = new PropertyAnimator(duration/4, newBall, "width", newBall.getWidth(), ValueAnimator squashAnim2 = new ObjectAnimator(duration/4, newBall, "width", newBall.getWidth(),
newBall.getWidth() + 50); newBall.getWidth() + 50);
squashAnim2.setRepeatCount(1); squashAnim2.setRepeatCount(1);
squashAnim2.setRepeatMode(Animator.REVERSE); squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
squashAnim2.setInterpolator(new DecelerateInterpolator()); squashAnim2.setInterpolator(new DecelerateInterpolator());
Animator stretchAnim1 = new PropertyAnimator(duration/4, newBall, "y", endY, ValueAnimator stretchAnim1 = new ObjectAnimator(duration/4, newBall, "y", endY,
endY + 25f); endY + 25f);
stretchAnim1.setRepeatCount(1); stretchAnim1.setRepeatCount(1);
stretchAnim1.setInterpolator(new DecelerateInterpolator()); stretchAnim1.setInterpolator(new DecelerateInterpolator());
stretchAnim1.setRepeatMode(Animator.REVERSE); stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);
Animator stretchAnim2 = new PropertyAnimator(duration/4, newBall, "height", ValueAnimator stretchAnim2 = new ObjectAnimator(duration/4, newBall, "height",
newBall.getHeight(), newBall.getHeight() - 25); newBall.getHeight(), newBall.getHeight() - 25);
stretchAnim2.setRepeatCount(1); stretchAnim2.setRepeatCount(1);
stretchAnim2.setInterpolator(new DecelerateInterpolator()); stretchAnim2.setInterpolator(new DecelerateInterpolator());
stretchAnim2.setRepeatMode(Animator.REVERSE); stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);
Animator bounceBackAnim = new PropertyAnimator(duration, newBall, "y", endY, ValueAnimator bounceBackAnim = new ObjectAnimator(duration, newBall, "y", endY,
startY); startY);
bounceBackAnim.setInterpolator(new DecelerateInterpolator()); bounceBackAnim.setInterpolator(new DecelerateInterpolator());
// Sequence the down/squash&stretch/up animations // Sequence the down/squash&stretch/up animations
Sequencer bouncer = new Sequencer(); AnimatorSet bouncer = new AnimatorSet();
bouncer.play(bounceAnim).before(squashAnim1); bouncer.play(bounceAnim).before(squashAnim1);
bouncer.play(squashAnim1).with(squashAnim2); bouncer.play(squashAnim1).with(squashAnim2);
bouncer.play(squashAnim1).with(stretchAnim1); bouncer.play(squashAnim1).with(stretchAnim1);
@@ -126,15 +126,15 @@ public class BouncingBalls extends Activity {
bouncer.play(bounceBackAnim).after(stretchAnim2); bouncer.play(bounceBackAnim).after(stretchAnim2);
// Fading animation - remove the ball when the animation is done // Fading animation - remove the ball when the animation is done
Animator fadeAnim = new PropertyAnimator(250, newBall, "alpha", 1f, 0f); ValueAnimator fadeAnim = new ObjectAnimator(250, newBall, "alpha", 1f, 0f);
fadeAnim.addListener(this); fadeAnim.addListener(this);
// Sequence the two animations to play one after the other // Sequence the two animations to play one after the other
Sequencer sequencer = new Sequencer(); AnimatorSet animatorSet = new AnimatorSet();
sequencer.play(bouncer).before(fadeAnim); animatorSet.play(bouncer).before(fadeAnim);
// Start the animation // Start the animation
sequencer.start(); animatorSet.start();
return true; return true;
} }
@@ -171,26 +171,26 @@ public class BouncingBalls extends Activity {
} }
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
} }
@Override @Override
public void onAnimationCancel(Animatable animation) { public void onAnimationCancel(Animator animation) {
} }
@Override @Override
public void onAnimationEnd(Animatable animation) { public void onAnimationEnd(Animator animation) {
balls.remove(((PropertyAnimator)animation).getTarget()); balls.remove(((ObjectAnimator)animation).getTarget());
} }
@Override @Override
public void onAnimationRepeat(Animatable animation) { public void onAnimationRepeat(Animator animation) {
} }
@Override @Override
public void onAnimationStart(Animatable animation) { public void onAnimationStart(Animator animation) {
} }
} }
} }

View File

@@ -18,16 +18,13 @@ package com.example.android.apis.animation;
// Need the following import to get access to the app resources, since this // Need the following import to get access to the app resources, since this
// class is in a sub-package. // class is in a sub-package.
import android.animation.ObjectAnimator;
import android.animation.TypeEvaluator; import android.animation.TypeEvaluator;
import android.animation.ValueAnimator;
import com.example.android.apis.R; import com.example.android.apis.R;
import java.util.ArrayList; import java.util.ArrayList;
import android.animation.Animatable;
import android.animation.Animator;
import android.animation.PropertyAnimator;
import android.animation.Sequencer;
import android.animation.Animatable.AnimatableListener;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -38,7 +35,6 @@ import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape; import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.animation.AccelerateInterpolator;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
@@ -117,10 +113,10 @@ public class CustomEvaluator extends Activity {
} }
} }
public class MyAnimationView extends View implements Animator.AnimatorUpdateListener { public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener {
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Animator bounceAnim = null; ValueAnimator bounceAnim = null;
ShapeHolder ball = null; ShapeHolder ball = null;
BallXYHolder ballHolder = null; BallXYHolder ballHolder = null;
@@ -134,7 +130,7 @@ public class CustomEvaluator extends Activity {
if (bounceAnim == null) { if (bounceAnim == null) {
XYHolder startXY = new XYHolder(0f, 0f); XYHolder startXY = new XYHolder(0f, 0f);
XYHolder endXY = new XYHolder(300f, 500f); XYHolder endXY = new XYHolder(300f, 500f);
bounceAnim = new PropertyAnimator(1500, ballHolder, "xY", bounceAnim = new ObjectAnimator(1500, ballHolder, "xY",
endXY); endXY);
bounceAnim.setEvaluator(new XYEvaluator()); bounceAnim.setEvaluator(new XYEvaluator());
bounceAnim.addUpdateListener(this); bounceAnim.addUpdateListener(this);
@@ -174,7 +170,7 @@ public class CustomEvaluator extends Activity {
canvas.restore(); canvas.restore();
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
} }

View File

@@ -18,13 +18,13 @@ package com.example.android.apis.animation;
// Need the following import to get access to the app resources, since this // Need the following import to get access to the app resources, since this
// class is in a sub-package. // class is in a sub-package.
import android.animation.Animator;
import android.animation.ObjectAnimator;
import com.example.android.apis.R; import com.example.android.apis.R;
import android.animation.Animatable; import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatableListenerAdapter;
import android.animation.Keyframe; import android.animation.Keyframe;
import android.animation.LayoutTransition; import android.animation.LayoutTransition;
import android.animation.PropertyAnimator;
import android.animation.PropertyValuesHolder; import android.animation.PropertyValuesHolder;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
@@ -36,7 +36,7 @@ import android.os.Bundle;
import android.widget.Button; import android.widget.Button;
/** /**
* This application demonstrates the seeking capability of Animator. The SeekBar in the * This application demonstrates the seeking capability of ValueAnimator. The SeekBar in the
* UI allows you to set the position of the animation. Pressing the Run button will play from * UI allows you to set the position of the animation. Pressing the Run button will play from
* the current position of the animation. * the current position of the animation.
*/ */
@@ -85,10 +85,10 @@ public class LayoutAnimations extends Activity {
} else { } else {
transitioner.setStagger(LayoutTransition.CHANGE_APPEARING, 0); transitioner.setStagger(LayoutTransition.CHANGE_APPEARING, 0);
transitioner.setStagger(LayoutTransition.CHANGE_DISAPPEARING, 0); transitioner.setStagger(LayoutTransition.CHANGE_DISAPPEARING, 0);
transitioner.setAnimatable(LayoutTransition.APPEARING, null); transitioner.setAnimator(LayoutTransition.APPEARING, null);
transitioner.setAnimatable(LayoutTransition.DISAPPEARING, null); transitioner.setAnimator(LayoutTransition.DISAPPEARING, null);
transitioner.setAnimatable(LayoutTransition.CHANGE_APPEARING, null); transitioner.setAnimator(LayoutTransition.CHANGE_APPEARING, null);
transitioner.setAnimatable(LayoutTransition.CHANGE_DISAPPEARING, null); transitioner.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, null);
duration = 300; duration = 300;
} }
transitioner.setDuration(duration); transitioner.setDuration(duration);
@@ -110,13 +110,13 @@ public class LayoutAnimations extends Activity {
new PropertyValuesHolder<Float>("scaleX", 1f, 0f, 1f); new PropertyValuesHolder<Float>("scaleX", 1f, 0f, 1f);
PropertyValuesHolder<Float> pvhScaleY = PropertyValuesHolder<Float> pvhScaleY =
new PropertyValuesHolder<Float>("scaleY", 1f, 0f, 1f); new PropertyValuesHolder<Float>("scaleY", 1f, 0f, 1f);
final PropertyAnimator changeIn = final ObjectAnimator changeIn =
new PropertyAnimator(transition.getDuration(LayoutTransition.CHANGE_APPEARING), new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_APPEARING),
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY); this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY);
transition.setAnimatable(LayoutTransition.CHANGE_APPEARING, changeIn); transition.setAnimator(LayoutTransition.CHANGE_APPEARING, changeIn);
changeIn.addListener(new AnimatableListenerAdapter() { changeIn.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animatable anim) { public void onAnimationEnd(Animator anim) {
View view = (View) ((PropertyAnimator) anim).getTarget(); View view = (View) ((ObjectAnimator) anim).getTarget();
view.setScaleX(1f); view.setScaleX(1f);
view.setScaleY(1f); view.setScaleY(1f);
} }
@@ -128,37 +128,37 @@ public class LayoutAnimations extends Activity {
Keyframe kf2 = new Keyframe(1f, 0f); Keyframe kf2 = new Keyframe(1f, 0f);
PropertyValuesHolder<Keyframe> pvhRotation = PropertyValuesHolder<Keyframe> pvhRotation =
new PropertyValuesHolder<Keyframe>("rotation", kf0, kf1, kf2); new PropertyValuesHolder<Keyframe>("rotation", kf0, kf1, kf2);
final PropertyAnimator changeOut = final ObjectAnimator changeOut =
new PropertyAnimator(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING), new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING),
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation); this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation);
transition.setAnimatable(LayoutTransition.CHANGE_DISAPPEARING, changeOut); transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, changeOut);
changeOut.addListener(new AnimatableListenerAdapter() { changeOut.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animatable anim) { public void onAnimationEnd(Animator anim) {
View view = (View) ((PropertyAnimator) anim).getTarget(); View view = (View) ((ObjectAnimator) anim).getTarget();
view.setRotation(0f); view.setRotation(0f);
} }
}); });
// Adding // Adding
PropertyAnimator<Float> animIn = ObjectAnimator<Float> animIn =
new PropertyAnimator<Float>(transition.getDuration(LayoutTransition.APPEARING), new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.APPEARING),
null, "rotationY", 90f, 0f); null, "rotationY", 90f, 0f);
transition.setAnimatable(LayoutTransition.APPEARING, animIn); transition.setAnimator(LayoutTransition.APPEARING, animIn);
animIn.addListener(new AnimatableListenerAdapter() { animIn.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animatable anim) { public void onAnimationEnd(Animator anim) {
View view = (View) ((PropertyAnimator) anim).getTarget(); View view = (View) ((ObjectAnimator) anim).getTarget();
view.setRotationY(0f); view.setRotationY(0f);
} }
}); });
// Removing // Removing
PropertyAnimator<Float> animOut = ObjectAnimator<Float> animOut =
new PropertyAnimator<Float>(transition.getDuration(LayoutTransition.DISAPPEARING), new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.DISAPPEARING),
null, "rotationX", 0f, 90f); null, "rotationX", 0f, 90f);
transition.setAnimatable(LayoutTransition.DISAPPEARING, animOut); transition.setAnimator(LayoutTransition.DISAPPEARING, animOut);
animIn.addListener(new AnimatableListenerAdapter() { animIn.addListener(new AnimatorListenerAdapter() {
public void onAnimationEnd(Animatable anim) { public void onAnimationEnd(Animator anim) {
View view = (View) ((PropertyAnimator) anim).getTarget(); View view = (View) ((ObjectAnimator) anim).getTarget();
view.setRotationX(0f); view.setRotationX(0f);
} }
}); });

View File

@@ -20,23 +20,15 @@ package com.example.android.apis.animation;
// class is in a sub-package. // class is in a sub-package.
import com.example.android.apis.R; import com.example.android.apis.R;
import android.animation.Animatable;
import android.animation.AnimatableListenerAdapter;
import android.animation.Keyframe;
import android.animation.LayoutTransition;
import android.animation.PropertyAnimator;
import android.animation.PropertyValuesHolder;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Button; import android.widget.Button;
/** /**
* This application demonstrates the seeking capability of Animator. The SeekBar in the * This application demonstrates the seeking capability of ValueAnimator. The SeekBar in the
* UI allows you to set the position of the animation. Pressing the Run button will play from * UI allows you to set the position of the animation. Pressing the Run button will play from
* the current position of the animation. * the current position of the animation.
*/ */

View File

@@ -18,39 +18,24 @@ package com.example.android.apis.animation;
// Need the following import to get access to the app resources, since this // Need the following import to get access to the app resources, since this
// class is in a sub-package. // class is in a sub-package.
import android.animation.AnimatableListenerAdapter; import android.animation.AnimatorListenerAdapter;
import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.view.animation.AccelerateInterpolator; import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator; import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator; import android.view.animation.Interpolator;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.FrameLayout;
import android.widget.ListView; import android.widget.ListView;
import com.example.android.apis.R; import com.example.android.apis.R;
import java.util.ArrayList;
import android.animation.Animatable;
import android.animation.Animator;
import android.animation.PropertyAnimator;
import android.animation.Sequencer;
import android.animation.Animatable.AnimatableListener;
import android.app.Activity; import android.app.Activity;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.RadialGradient;
import android.graphics.Shader;
import android.graphics.drawable.ShapeDrawable;
import android.graphics.drawable.shapes.OvalShape;
import android.os.Bundle; import android.os.Bundle;
import android.view.View; import android.view.View;
import android.view.animation.BounceInterpolator;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
/** /**
* This application demonstrates the seeking capability of Animator. The SeekBar in the * This application demonstrates the seeking capability of ValueAnimator. The SeekBar in the
* UI allows you to set the position of the animation. Pressing the Run button will play from * UI allows you to set the position of the animation. Pressing the Run button will play from
* the current position of the animation. * the current position of the animation.
*/ */
@@ -121,13 +106,13 @@ public class ListFlipper extends Activity {
invisibleList = mFrenchList; invisibleList = mFrenchList;
visibleList = mEnglishList; visibleList = mEnglishList;
} }
PropertyAnimator visToInvis = new PropertyAnimator(500, visibleList, "rotationY", 0f, 90f); ObjectAnimator visToInvis = new ObjectAnimator(500, visibleList, "rotationY", 0f, 90f);
visToInvis.setInterpolator(accelerator); visToInvis.setInterpolator(accelerator);
final PropertyAnimator invisToVis = new PropertyAnimator(500, invisibleList, "rotationY", -90f, 0f); final ObjectAnimator invisToVis = new ObjectAnimator(500, invisibleList, "rotationY", -90f, 0f);
invisToVis.setInterpolator(decelerator); invisToVis.setInterpolator(decelerator);
visToInvis.addListener(new AnimatableListenerAdapter() { visToInvis.addListener(new AnimatorListenerAdapter() {
@Override @Override
public void onAnimationEnd(Animatable anim) { public void onAnimationEnd(Animator anim) {
visibleList.setVisibility(View.GONE); visibleList.setVisibility(View.GONE);
invisToVis.start(); invisToVis.start();
invisibleList.setVisibility(View.VISIBLE); invisibleList.setVisibility(View.VISIBLE);

View File

@@ -24,7 +24,6 @@ import com.example.android.apis.R;
import java.util.ArrayList; import java.util.ArrayList;
import android.animation.Animatable.AnimatableListener;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -38,10 +37,9 @@ import android.view.View;
import android.view.animation.BounceInterpolator; import android.view.animation.BounceInterpolator;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.SeekBar;
/** /**
* This application demonstrates the seeking capability of Animator. The SeekBar in the * This application demonstrates the seeking capability of ValueAnimator. The SeekBar in the
* UI allows you to set the position of the animation. Pressing the Run button will play from * UI allows you to set the position of the animation. Pressing the Run button will play from
* the current position of the animation. * the current position of the animation.
*/ */
@@ -60,7 +58,6 @@ public class MultiPropertyAnimation extends Activity {
Button starter = (Button) findViewById(R.id.startButton); Button starter = (Button) findViewById(R.id.startButton);
starter.setOnClickListener(new View.OnClickListener() { starter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) { public void onClick(View v) {
animView.startAnimation(); animView.startAnimation();
} }
@@ -68,13 +65,13 @@ public class MultiPropertyAnimation extends Activity {
} }
public class MyAnimationView extends View implements Animator.AnimatorUpdateListener { public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener {
private static final float BALL_SIZE = 100f; private static final float BALL_SIZE = 100f;
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Sequencer animation = null; AnimatorSet animation = null;
Animatable bounceAnim = null; Animator bounceAnim = null;
ShapeHolder ball = null; ShapeHolder ball = null;
public MyAnimationView(Context context) { public MyAnimationView(Context context) {
@@ -89,7 +86,7 @@ public class MultiPropertyAnimation extends Activity {
if (bounceAnim == null) { if (bounceAnim == null) {
ShapeHolder ball; ShapeHolder ball;
ball = balls.get(0); ball = balls.get(0);
PropertyAnimator yBouncer = new PropertyAnimator(DURATION, ball, "y", ObjectAnimator yBouncer = new ObjectAnimator(DURATION, ball, "y",
ball.getY(), getHeight() - BALL_SIZE); ball.getY(), getHeight() - BALL_SIZE);
yBouncer.setInterpolator(new BounceInterpolator()); yBouncer.setInterpolator(new BounceInterpolator());
yBouncer.addUpdateListener(this); yBouncer.addUpdateListener(this);
@@ -99,10 +96,10 @@ public class MultiPropertyAnimation extends Activity {
getHeight() - BALL_SIZE); getHeight() - BALL_SIZE);
PropertyValuesHolder pvhAlpha = new PropertyValuesHolder("alpha", 1.0f, PropertyValuesHolder pvhAlpha = new PropertyValuesHolder("alpha", 1.0f,
0f); 0f);
PropertyAnimator yAlphaBouncer = new PropertyAnimator(DURATION/2, ball, pvhY, pvhAlpha); ObjectAnimator yAlphaBouncer = new ObjectAnimator(DURATION/2, ball, pvhY, pvhAlpha);
yAlphaBouncer.setInterpolator(new AccelerateInterpolator()); yAlphaBouncer.setInterpolator(new AccelerateInterpolator());
yAlphaBouncer.setRepeatCount(1); yAlphaBouncer.setRepeatCount(1);
yAlphaBouncer.setRepeatMode(Animator.REVERSE); yAlphaBouncer.setRepeatMode(ValueAnimator.REVERSE);
ball = balls.get(2); ball = balls.get(2);
@@ -112,10 +109,10 @@ public class MultiPropertyAnimation extends Activity {
ball.getHeight() * 2); ball.getHeight() * 2);
PropertyValuesHolder pvTX = new PropertyValuesHolder("x", ball.getX(), ball.getX() - BALL_SIZE/2f); 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); PropertyValuesHolder pvTY = new PropertyValuesHolder("y", 0f, ball.getY(), ball.getY() - BALL_SIZE/2f);
PropertyAnimator whxyBouncer = new PropertyAnimator(DURATION/2, ball, pvhW, pvhH, ObjectAnimator whxyBouncer = new ObjectAnimator(DURATION/2, ball, pvhW, pvhH,
pvTX, pvTY); pvTX, pvTY);
whxyBouncer.setRepeatCount(1); whxyBouncer.setRepeatCount(1);
whxyBouncer.setRepeatMode(Animator.REVERSE); whxyBouncer.setRepeatMode(ValueAnimator.REVERSE);
ball = balls.get(3); ball = balls.get(3);
pvhY = new PropertyValuesHolder("y", ball.getY(), pvhY = new PropertyValuesHolder("y", ball.getY(),
@@ -125,13 +122,13 @@ public class MultiPropertyAnimation extends Activity {
Keyframe kf1 = new Keyframe(.5f, ballX + 100f); Keyframe kf1 = new Keyframe(.5f, ballX + 100f);
Keyframe kf2 = new Keyframe(1f, ballX + 50f); Keyframe kf2 = new Keyframe(1f, ballX + 50f);
PropertyValuesHolder pvhX = new PropertyValuesHolder("x", kf0, kf1, kf2); PropertyValuesHolder pvhX = new PropertyValuesHolder("x", kf0, kf1, kf2);
PropertyAnimator yxBouncer = new PropertyAnimator(DURATION/2, ball, pvhY, pvhX); ObjectAnimator yxBouncer = new ObjectAnimator(DURATION/2, ball, pvhY, pvhX);
yxBouncer.setRepeatCount(1); yxBouncer.setRepeatCount(1);
yxBouncer.setRepeatMode(Animator.REVERSE); yxBouncer.setRepeatMode(ValueAnimator.REVERSE);
bounceAnim = new Sequencer(); bounceAnim = new AnimatorSet();
((Sequencer)bounceAnim).playTogether(yBouncer, yAlphaBouncer, whxyBouncer, yxBouncer); ((AnimatorSet)bounceAnim).playTogether(yBouncer, yAlphaBouncer, whxyBouncer, yxBouncer);
} }
} }
@@ -170,7 +167,7 @@ public class MultiPropertyAnimation extends Activity {
} }
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
} }

View File

@@ -18,15 +18,12 @@ package com.example.android.apis.animation;
// Need the following import to get access to the app resources, since this // Need the following import to get access to the app resources, since this
// class is in a sub-package. // class is in a sub-package.
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import com.example.android.apis.R; import com.example.android.apis.R;
import java.util.ArrayList; import java.util.ArrayList;
import android.animation.Animatable;
import android.animation.Animator;
import android.animation.PropertyAnimator;
import android.animation.Sequencer;
import android.animation.Animatable.AnimatableListener;
import android.app.Activity; import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.graphics.Canvas; import android.graphics.Canvas;
@@ -71,10 +68,10 @@ public class ReversingAnimation extends Activity {
} }
public class MyAnimationView extends View implements Animator.AnimatorUpdateListener { public class MyAnimationView extends View implements ValueAnimator.AnimatorUpdateListener {
public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>(); public final ArrayList<ShapeHolder> balls = new ArrayList<ShapeHolder>();
Animator bounceAnim = null; ValueAnimator bounceAnim = null;
ShapeHolder ball = null; ShapeHolder ball = null;
public MyAnimationView(Context context) { public MyAnimationView(Context context) {
@@ -84,7 +81,7 @@ public class ReversingAnimation extends Activity {
private void createAnimation() { private void createAnimation() {
if (bounceAnim == null) { if (bounceAnim == null) {
bounceAnim = new PropertyAnimator(1500, ball, "y", bounceAnim = new ObjectAnimator(1500, ball, "y",
ball.getY(), getHeight() - 50f); ball.getY(), getHeight() - 50f);
bounceAnim.setInterpolator(new AccelerateInterpolator(2f)); bounceAnim.setInterpolator(new AccelerateInterpolator(2f));
bounceAnim.addUpdateListener(this); bounceAnim.addUpdateListener(this);
@@ -134,7 +131,7 @@ public class ReversingAnimation extends Activity {
canvas.restore(); canvas.restore();
} }
public void onAnimationUpdate(Animator animation) { public void onAnimationUpdate(ValueAnimator animation) {
invalidate(); invalidate();
} }

View File

@@ -23,11 +23,10 @@ import com.example.android.apis.R;
import android.app.Activity; import android.app.Activity;
import android.os.Bundle; import android.os.Bundle;
import android.widget.Button; import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.SeekBar; import android.widget.SeekBar;
/** /**
* This application demonstrates the seeking capability of Animator. The SeekBar in the * This application demonstrates the seeking capability of ValueAnimator. The SeekBar in the
* UI allows you to set the position of the animation. Pressing the Run button will play from * UI allows you to set the position of the animation. Pressing the Run button will play from
* the current position of the animation. * the current position of the animation.
*/ */