Updating code to use new non-generified animator APIs
Change-Id: I3023db9d1f9cb8bf98b788fce4ae2b58b182987d
This commit is contained in:
@@ -79,18 +79,18 @@ public class AnimationCloning extends Activity {
|
|||||||
|
|
||||||
private void createAnimation() {
|
private void createAnimation() {
|
||||||
if (animation == null) {
|
if (animation == null) {
|
||||||
ObjectAnimator anim1 = new ObjectAnimator(500, balls.get(0), "y",
|
ObjectAnimator anim1 = ObjectAnimator.ofFloat(balls.get(0), "y",
|
||||||
0f, getHeight() - balls.get(0).getHeight());
|
0f, getHeight() - balls.get(0).getHeight()).setDuration(500);
|
||||||
ObjectAnimator 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);
|
||||||
ObjectAnimator animDown = new ObjectAnimator(500, ball2, "y",
|
ObjectAnimator animDown = ObjectAnimator.ofFloat(ball2, "y",
|
||||||
0f, getHeight() - ball2.getHeight());
|
0f, getHeight() - ball2.getHeight()).setDuration(500);
|
||||||
animDown.setInterpolator(new AccelerateInterpolator());
|
animDown.setInterpolator(new AccelerateInterpolator());
|
||||||
ObjectAnimator animUp = new ObjectAnimator(500, ball2, "y",
|
ObjectAnimator animUp = ObjectAnimator.ofFloat(ball2, "y",
|
||||||
getHeight() - ball2.getHeight(), 0f);
|
getHeight() - ball2.getHeight(), 0f).setDuration(500);
|
||||||
animDown.setInterpolator(new DecelerateInterpolator());
|
animDown.setInterpolator(new DecelerateInterpolator());
|
||||||
AnimatorSet s1 = new AnimatorSet();
|
AnimatorSet s1 = new AnimatorSet();
|
||||||
s1.playSequentially(animDown, animUp);
|
s1.playSequentially(animDown, animUp);
|
||||||
|
|||||||
@@ -112,8 +112,8 @@ public class AnimationSeeking extends Activity {
|
|||||||
|
|
||||||
private void createAnimation() {
|
private void createAnimation() {
|
||||||
if (bounceAnim == null) {
|
if (bounceAnim == null) {
|
||||||
bounceAnim = new ObjectAnimator(1500, ball, "y",
|
bounceAnim = ObjectAnimator.ofFloat(ball, "y",
|
||||||
ball.getY(), getHeight() - BALL_SIZE);
|
ball.getY(), getHeight() - BALL_SIZE).setDuration(1500);
|
||||||
bounceAnim.setInterpolator(new BounceInterpolator());
|
bounceAnim.setInterpolator(new BounceInterpolator());
|
||||||
bounceAnim.addUpdateListener(this);
|
bounceAnim.addUpdateListener(this);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -117,28 +117,28 @@ public class AnimatorEvents extends Activity {
|
|||||||
|
|
||||||
private void createAnimation() {
|
private void createAnimation() {
|
||||||
if (animation == null) {
|
if (animation == null) {
|
||||||
ObjectAnimator yAnim = new ObjectAnimator(1500, ball, "y",
|
ObjectAnimator yAnim = ObjectAnimator.ofFloat(ball, "y",
|
||||||
ball.getY(), getHeight() - 50f);
|
ball.getY(), getHeight() - 50f).setDuration(1500);
|
||||||
yAnim.setRepeatCount(0);
|
yAnim.setRepeatCount(0);
|
||||||
yAnim.setRepeatMode(ValueAnimator.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);
|
||||||
|
|
||||||
ObjectAnimator xAnim = new ObjectAnimator(1000, ball, "x",
|
ObjectAnimator xAnim = ObjectAnimator.ofFloat(ball, "x",
|
||||||
ball.getX(), ball.getX() + 300);
|
ball.getX(), ball.getX() + 300).setDuration(1000);
|
||||||
xAnim.setStartDelay(0);
|
xAnim.setStartDelay(0);
|
||||||
xAnim.setRepeatCount(0);
|
xAnim.setRepeatCount(0);
|
||||||
xAnim.setRepeatMode(ValueAnimator.REVERSE);
|
xAnim.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
xAnim.setInterpolator(new AccelerateInterpolator(2f));
|
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();
|
AnimatorSet alphaSeq = new AnimatorSet();
|
||||||
alphaSeq.play(alphaAnim);
|
alphaSeq.play(alphaAnim);
|
||||||
|
|
||||||
animation = new AnimatorSet();
|
animation = new AnimatorSet();
|
||||||
((AnimatorSet) animation).playTogether(yAnim, xAnim);
|
((AnimatorSet) animation).playTogether(yAnim, xAnim);
|
||||||
//((AnimatorSet) animation).play(alphaSeq).after(500);
|
|
||||||
animation.addListener(this);
|
animation.addListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,8 @@ public class BouncingBalls extends Activity {
|
|||||||
container.addView(new MyAnimationView(this));
|
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 RED = 0xffFF8080;
|
||||||
private static final int BLUE = 0xff8080FF;
|
private static final int BLUE = 0xff8080FF;
|
||||||
@@ -70,7 +71,8 @@ public class BouncingBalls extends Activity {
|
|||||||
paint.setColor(RED);
|
paint.setColor(RED);
|
||||||
|
|
||||||
// Animate background color
|
// 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.setEvaluator(new RGBEvaluator());
|
||||||
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
|
colorAnim.setRepeatCount(ValueAnimator.INFINITE);
|
||||||
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
|
colorAnim.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
@@ -92,30 +94,36 @@ 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));
|
||||||
ValueAnimator bounceAnim = new ObjectAnimator(duration, newBall, "y", startY, endY);
|
ValueAnimator bounceAnim = ObjectAnimator.ofFloat(newBall, "y", startY, endY);
|
||||||
|
bounceAnim.setDuration(duration);
|
||||||
bounceAnim.setInterpolator(new AccelerateInterpolator());
|
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);
|
newBall.getX() - 25f);
|
||||||
|
squashAnim1.setDuration(duration/4);
|
||||||
squashAnim1.setRepeatCount(1);
|
squashAnim1.setRepeatCount(1);
|
||||||
squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
|
squashAnim1.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
squashAnim1.setInterpolator(new DecelerateInterpolator());
|
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);
|
newBall.getWidth() + 50);
|
||||||
|
squashAnim2.setDuration(duration/4);
|
||||||
squashAnim2.setRepeatCount(1);
|
squashAnim2.setRepeatCount(1);
|
||||||
squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
|
squashAnim2.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
squashAnim2.setInterpolator(new DecelerateInterpolator());
|
squashAnim2.setInterpolator(new DecelerateInterpolator());
|
||||||
ValueAnimator stretchAnim1 = new ObjectAnimator(duration/4, newBall, "y", endY,
|
ValueAnimator stretchAnim1 = ObjectAnimator.ofFloat(newBall, "y", endY,
|
||||||
endY + 25f);
|
endY + 25f);
|
||||||
|
stretchAnim1.setDuration(duration/4);
|
||||||
stretchAnim1.setRepeatCount(1);
|
stretchAnim1.setRepeatCount(1);
|
||||||
stretchAnim1.setInterpolator(new DecelerateInterpolator());
|
stretchAnim1.setInterpolator(new DecelerateInterpolator());
|
||||||
stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);
|
stretchAnim1.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
ValueAnimator stretchAnim2 = new ObjectAnimator(duration/4, newBall, "height",
|
ValueAnimator stretchAnim2 = ObjectAnimator.ofFloat(newBall, "height",
|
||||||
newBall.getHeight(), newBall.getHeight() - 25);
|
newBall.getHeight(), newBall.getHeight() - 25);
|
||||||
|
stretchAnim2.setDuration(duration/4);
|
||||||
stretchAnim2.setRepeatCount(1);
|
stretchAnim2.setRepeatCount(1);
|
||||||
stretchAnim2.setInterpolator(new DecelerateInterpolator());
|
stretchAnim2.setInterpolator(new DecelerateInterpolator());
|
||||||
stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);
|
stretchAnim2.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
ValueAnimator bounceBackAnim = new ObjectAnimator(duration, newBall, "y", endY,
|
ValueAnimator bounceBackAnim = ObjectAnimator.ofFloat(newBall, "y", endY,
|
||||||
startY);
|
startY);
|
||||||
|
bounceBackAnim.setDuration(duration);
|
||||||
bounceBackAnim.setInterpolator(new DecelerateInterpolator());
|
bounceBackAnim.setInterpolator(new DecelerateInterpolator());
|
||||||
// Sequence the down/squash&stretch/up animations
|
// Sequence the down/squash&stretch/up animations
|
||||||
AnimatorSet bouncer = new AnimatorSet();
|
AnimatorSet bouncer = new AnimatorSet();
|
||||||
@@ -126,7 +134,8 @@ 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
|
||||||
ValueAnimator fadeAnim = new ObjectAnimator(250, newBall, "alpha", 1f, 0f);
|
ValueAnimator fadeAnim = ObjectAnimator.ofFloat(newBall, "alpha", 1f, 0f);
|
||||||
|
fadeAnim.setDuration(250);
|
||||||
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
|
||||||
|
|||||||
@@ -130,9 +130,9 @@ 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 ObjectAnimator(1500, ballHolder, "xY",
|
bounceAnim = ObjectAnimator.ofObject(ballHolder, "xY",
|
||||||
endXY);
|
new XYEvaluator(), endXY);
|
||||||
bounceAnim.setEvaluator(new XYEvaluator());
|
bounceAnim.setDuration(1500);
|
||||||
bounceAnim.addUpdateListener(this);
|
bounceAnim.addUpdateListener(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,21 +146,21 @@ public class LayoutAnimations extends Activity {
|
|||||||
|
|
||||||
private void createCustomAnimations(LayoutTransition transition) {
|
private void createCustomAnimations(LayoutTransition transition) {
|
||||||
// Changing while Adding
|
// Changing while Adding
|
||||||
PropertyValuesHolder<Integer> pvhLeft =
|
PropertyValuesHolder pvhLeft =
|
||||||
new PropertyValuesHolder<Integer>("left", 0, 1);
|
PropertyValuesHolder.ofInt("left", 0, 1);
|
||||||
PropertyValuesHolder<Integer> pvhTop =
|
PropertyValuesHolder pvhTop =
|
||||||
new PropertyValuesHolder<Integer>("top", 0, 1);
|
PropertyValuesHolder.ofInt("top", 0, 1);
|
||||||
PropertyValuesHolder<Integer> pvhRight =
|
PropertyValuesHolder pvhRight =
|
||||||
new PropertyValuesHolder<Integer>("right", 0, 1);
|
PropertyValuesHolder.ofInt("right", 0, 1);
|
||||||
PropertyValuesHolder<Integer> pvhBottom =
|
PropertyValuesHolder pvhBottom =
|
||||||
new PropertyValuesHolder<Integer>("bottom", 0, 1);
|
PropertyValuesHolder.ofInt("bottom", 0, 1);
|
||||||
PropertyValuesHolder<Float> pvhScaleX =
|
PropertyValuesHolder pvhScaleX =
|
||||||
new PropertyValuesHolder<Float>("scaleX", 1f, 0f, 1f);
|
PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
|
||||||
PropertyValuesHolder<Float> pvhScaleY =
|
PropertyValuesHolder pvhScaleY =
|
||||||
new PropertyValuesHolder<Float>("scaleY", 1f, 0f, 1f);
|
PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
|
||||||
customChangingAppearingAnim =
|
customChangingAppearingAnim = ObjectAnimator.ofPropertyValuesHolder(
|
||||||
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_APPEARING),
|
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY).
|
||||||
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY);
|
setDuration(transition.getDuration(LayoutTransition.CHANGE_APPEARING));
|
||||||
customChangingAppearingAnim.addListener(new AnimatorListenerAdapter() {
|
customChangingAppearingAnim.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
View view = (View) ((ObjectAnimator) anim).getTarget();
|
View view = (View) ((ObjectAnimator) anim).getTarget();
|
||||||
@@ -173,11 +173,11 @@ public class LayoutAnimations extends Activity {
|
|||||||
Keyframe kf0 = new Keyframe(0f, 0f);
|
Keyframe kf0 = new Keyframe(0f, 0f);
|
||||||
Keyframe kf1 = new Keyframe(.9999f, 360f);
|
Keyframe kf1 = new Keyframe(.9999f, 360f);
|
||||||
Keyframe kf2 = new Keyframe(1f, 0f);
|
Keyframe kf2 = new Keyframe(1f, 0f);
|
||||||
PropertyValuesHolder<Keyframe> pvhRotation =
|
PropertyValuesHolder pvhRotation =
|
||||||
new PropertyValuesHolder<Keyframe>("rotation", kf0, kf1, kf2);
|
PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
|
||||||
customChangingDisappearingAnim =
|
customChangingDisappearingAnim = ObjectAnimator.ofPropertyValuesHolder(
|
||||||
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING),
|
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation).
|
||||||
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation);
|
setDuration(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING));
|
||||||
customChangingDisappearingAnim.addListener(new AnimatorListenerAdapter() {
|
customChangingDisappearingAnim.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
View view = (View) ((ObjectAnimator) anim).getTarget();
|
View view = (View) ((ObjectAnimator) anim).getTarget();
|
||||||
@@ -186,9 +186,8 @@ public class LayoutAnimations extends Activity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Adding
|
// Adding
|
||||||
customAppearingAnim =
|
customAppearingAnim = ObjectAnimator.ofFloat(null, "rotationY", 90f, 0f).
|
||||||
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.APPEARING),
|
setDuration(transition.getDuration(LayoutTransition.APPEARING));
|
||||||
null, "rotationY", 90f, 0f);
|
|
||||||
customAppearingAnim.addListener(new AnimatorListenerAdapter() {
|
customAppearingAnim.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
View view = (View) ((ObjectAnimator) anim).getTarget();
|
View view = (View) ((ObjectAnimator) anim).getTarget();
|
||||||
@@ -197,9 +196,8 @@ public class LayoutAnimations extends Activity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Removing
|
// Removing
|
||||||
customDisappearingAnim =
|
customDisappearingAnim = ObjectAnimator.ofFloat(null, "rotationX", 0f, 90f).
|
||||||
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.DISAPPEARING),
|
setDuration(transition.getDuration(LayoutTransition.DISAPPEARING));
|
||||||
null, "rotationX", 0f, 90f);
|
|
||||||
customDisappearingAnim.addListener(new AnimatorListenerAdapter() {
|
customDisappearingAnim.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
View view = (View) ((ObjectAnimator) anim).getTarget();
|
View view = (View) ((ObjectAnimator) anim).getTarget();
|
||||||
|
|||||||
@@ -111,21 +111,21 @@ public class LayoutAnimationsHideShow extends Activity {
|
|||||||
|
|
||||||
private void setupAnimations(LayoutTransition transition) {
|
private void setupAnimations(LayoutTransition transition) {
|
||||||
// Changing while Adding
|
// Changing while Adding
|
||||||
PropertyValuesHolder<Integer> pvhLeft =
|
PropertyValuesHolder pvhLeft =
|
||||||
new PropertyValuesHolder<Integer>("left", 0, 1);
|
PropertyValuesHolder.ofInt("left", 0, 1);
|
||||||
PropertyValuesHolder<Integer> pvhTop =
|
PropertyValuesHolder pvhTop =
|
||||||
new PropertyValuesHolder<Integer>("top", 0, 1);
|
PropertyValuesHolder.ofInt("top", 0, 1);
|
||||||
PropertyValuesHolder<Integer> pvhRight =
|
PropertyValuesHolder pvhRight =
|
||||||
new PropertyValuesHolder<Integer>("right", 0, 1);
|
PropertyValuesHolder.ofInt("right", 0, 1);
|
||||||
PropertyValuesHolder<Integer> pvhBottom =
|
PropertyValuesHolder pvhBottom =
|
||||||
new PropertyValuesHolder<Integer>("bottom", 0, 1);
|
PropertyValuesHolder.ofInt("bottom", 0, 1);
|
||||||
PropertyValuesHolder<Float> pvhScaleX =
|
PropertyValuesHolder pvhScaleX =
|
||||||
new PropertyValuesHolder<Float>("scaleX", 1f, 0f, 1f);
|
PropertyValuesHolder.ofFloat("scaleX", 1f, 0f, 1f);
|
||||||
PropertyValuesHolder<Float> pvhScaleY =
|
PropertyValuesHolder pvhScaleY =
|
||||||
new PropertyValuesHolder<Float>("scaleY", 1f, 0f, 1f);
|
PropertyValuesHolder.ofFloat("scaleY", 1f, 0f, 1f);
|
||||||
final ObjectAnimator changeIn =
|
final ObjectAnimator changeIn = ObjectAnimator.ofPropertyValuesHolder(
|
||||||
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_APPEARING),
|
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY).
|
||||||
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhScaleX, pvhScaleY);
|
setDuration(transition.getDuration(LayoutTransition.CHANGE_APPEARING));
|
||||||
transition.setAnimator(LayoutTransition.CHANGE_APPEARING, changeIn);
|
transition.setAnimator(LayoutTransition.CHANGE_APPEARING, changeIn);
|
||||||
changeIn.addListener(new AnimatorListenerAdapter() {
|
changeIn.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
@@ -139,11 +139,11 @@ public class LayoutAnimationsHideShow extends Activity {
|
|||||||
Keyframe kf0 = new Keyframe(0f, 0f);
|
Keyframe kf0 = new Keyframe(0f, 0f);
|
||||||
Keyframe kf1 = new Keyframe(.9999f, 360f);
|
Keyframe kf1 = new Keyframe(.9999f, 360f);
|
||||||
Keyframe kf2 = new Keyframe(1f, 0f);
|
Keyframe kf2 = new Keyframe(1f, 0f);
|
||||||
PropertyValuesHolder<Keyframe> pvhRotation =
|
PropertyValuesHolder pvhRotation =
|
||||||
new PropertyValuesHolder<Keyframe>("rotation", kf0, kf1, kf2);
|
PropertyValuesHolder.ofKeyframe("rotation", kf0, kf1, kf2);
|
||||||
final ObjectAnimator changeOut =
|
final ObjectAnimator changeOut = ObjectAnimator.ofPropertyValuesHolder(
|
||||||
new ObjectAnimator(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING),
|
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation).
|
||||||
this, pvhLeft, pvhTop, pvhRight, pvhBottom, pvhRotation);
|
setDuration(transition.getDuration(LayoutTransition.CHANGE_DISAPPEARING));
|
||||||
transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, changeOut);
|
transition.setAnimator(LayoutTransition.CHANGE_DISAPPEARING, changeOut);
|
||||||
changeOut.addListener(new AnimatorListenerAdapter() {
|
changeOut.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
@@ -153,9 +153,8 @@ public class LayoutAnimationsHideShow extends Activity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Adding
|
// Adding
|
||||||
ObjectAnimator<Float> animIn =
|
ObjectAnimator animIn = ObjectAnimator.ofFloat(null, "rotationY", 90f, 0f).
|
||||||
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.APPEARING),
|
setDuration(transition.getDuration(LayoutTransition.APPEARING));
|
||||||
null, "rotationY", 90f, 0f);
|
|
||||||
transition.setAnimator(LayoutTransition.APPEARING, animIn);
|
transition.setAnimator(LayoutTransition.APPEARING, animIn);
|
||||||
animIn.addListener(new AnimatorListenerAdapter() {
|
animIn.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
@@ -165,9 +164,8 @@ public class LayoutAnimationsHideShow extends Activity {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Removing
|
// Removing
|
||||||
ObjectAnimator<Float> animOut =
|
ObjectAnimator animOut = ObjectAnimator.ofFloat(null, "rotationX", 0f, 90f).
|
||||||
new ObjectAnimator<Float>(transition.getDuration(LayoutTransition.DISAPPEARING),
|
setDuration(transition.getDuration(LayoutTransition.DISAPPEARING));
|
||||||
null, "rotationX", 0f, 90f);
|
|
||||||
transition.setAnimator(LayoutTransition.DISAPPEARING, animOut);
|
transition.setAnimator(LayoutTransition.DISAPPEARING, animOut);
|
||||||
animIn.addListener(new AnimatorListenerAdapter() {
|
animIn.addListener(new AnimatorListenerAdapter() {
|
||||||
public void onAnimationEnd(Animator anim) {
|
public void onAnimationEnd(Animator anim) {
|
||||||
|
|||||||
@@ -106,9 +106,12 @@ public class ListFlipper extends Activity {
|
|||||||
invisibleList = mFrenchList;
|
invisibleList = mFrenchList;
|
||||||
visibleList = mEnglishList;
|
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);
|
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);
|
invisToVis.setInterpolator(decelerator);
|
||||||
visToInvis.addListener(new AnimatorListenerAdapter() {
|
visToInvis.addListener(new AnimatorListenerAdapter() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -86,43 +86,45 @@ public class MultiPropertyAnimation extends Activity {
|
|||||||
if (bounceAnim == null) {
|
if (bounceAnim == null) {
|
||||||
ShapeHolder ball;
|
ShapeHolder ball;
|
||||||
ball = balls.get(0);
|
ball = balls.get(0);
|
||||||
ObjectAnimator yBouncer = new ObjectAnimator(DURATION, ball, "y",
|
ObjectAnimator yBouncer = ObjectAnimator.ofFloat(ball, "y",
|
||||||
ball.getY(), getHeight() - BALL_SIZE);
|
ball.getY(), getHeight() - BALL_SIZE).setDuration(DURATION);
|
||||||
yBouncer.setInterpolator(new BounceInterpolator());
|
yBouncer.setInterpolator(new BounceInterpolator());
|
||||||
yBouncer.addUpdateListener(this);
|
yBouncer.addUpdateListener(this);
|
||||||
|
|
||||||
ball = balls.get(1);
|
ball = balls.get(1);
|
||||||
PropertyValuesHolder pvhY = new PropertyValuesHolder("y", ball.getY(),
|
PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat("y", ball.getY(),
|
||||||
getHeight() - BALL_SIZE);
|
getHeight() - BALL_SIZE);
|
||||||
PropertyValuesHolder pvhAlpha = new PropertyValuesHolder("alpha", 1.0f,
|
PropertyValuesHolder pvhAlpha = PropertyValuesHolder.ofFloat("alpha", 1.0f, 0f);
|
||||||
0f);
|
ObjectAnimator yAlphaBouncer = ObjectAnimator.ofPropertyValuesHolder(ball,
|
||||||
ObjectAnimator yAlphaBouncer = new ObjectAnimator(DURATION/2, ball, pvhY, pvhAlpha);
|
pvhY, pvhAlpha).setDuration(DURATION/2);
|
||||||
yAlphaBouncer.setInterpolator(new AccelerateInterpolator());
|
yAlphaBouncer.setInterpolator(new AccelerateInterpolator());
|
||||||
yAlphaBouncer.setRepeatCount(1);
|
yAlphaBouncer.setRepeatCount(1);
|
||||||
yAlphaBouncer.setRepeatMode(ValueAnimator.REVERSE);
|
yAlphaBouncer.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
|
|
||||||
|
|
||||||
ball = balls.get(2);
|
ball = balls.get(2);
|
||||||
PropertyValuesHolder pvhW = new PropertyValuesHolder("width", ball.getWidth(),
|
PropertyValuesHolder pvhW = PropertyValuesHolder.ofFloat("width", ball.getWidth(),
|
||||||
ball.getWidth() * 2);
|
ball.getWidth() * 2);
|
||||||
PropertyValuesHolder pvhH = new PropertyValuesHolder("height", ball.getHeight(),
|
PropertyValuesHolder pvhH = PropertyValuesHolder.ofFloat("height", ball.getHeight(),
|
||||||
ball.getHeight() * 2);
|
ball.getHeight() * 2);
|
||||||
PropertyValuesHolder pvTX = new PropertyValuesHolder("x", ball.getX(), ball.getX() - BALL_SIZE/2f);
|
PropertyValuesHolder pvTX = PropertyValuesHolder.ofFloat("x", ball.getX(),
|
||||||
PropertyValuesHolder pvTY = new PropertyValuesHolder("y", 0f, ball.getY(), ball.getY() - BALL_SIZE/2f);
|
ball.getX() - BALL_SIZE/2f);
|
||||||
ObjectAnimator whxyBouncer = new ObjectAnimator(DURATION/2, ball, pvhW, pvhH,
|
PropertyValuesHolder pvTY = PropertyValuesHolder.ofFloat("y", 0f, ball.getY(),
|
||||||
pvTX, pvTY);
|
ball.getY() - BALL_SIZE/2f);
|
||||||
|
ObjectAnimator whxyBouncer = ObjectAnimator.ofPropertyValuesHolder(ball, pvhW, pvhH,
|
||||||
|
pvTX, pvTY).setDuration(DURATION/2);
|
||||||
whxyBouncer.setRepeatCount(1);
|
whxyBouncer.setRepeatCount(1);
|
||||||
whxyBouncer.setRepeatMode(ValueAnimator.REVERSE);
|
whxyBouncer.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
|
|
||||||
ball = balls.get(3);
|
ball = balls.get(3);
|
||||||
pvhY = new PropertyValuesHolder("y", ball.getY(),
|
pvhY = PropertyValuesHolder.ofFloat("y", ball.getY(), getHeight() - BALL_SIZE);
|
||||||
getHeight() - BALL_SIZE);
|
|
||||||
float ballX = ball.getX();
|
float ballX = ball.getX();
|
||||||
Keyframe kf0 = new Keyframe(0f, ballX);
|
Keyframe kf0 = new Keyframe(0f, ballX);
|
||||||
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 = PropertyValuesHolder.ofKeyframe("x", kf0, kf1, kf2);
|
||||||
ObjectAnimator yxBouncer = new ObjectAnimator(DURATION/2, ball, pvhY, pvhX);
|
ObjectAnimator yxBouncer = ObjectAnimator.ofPropertyValuesHolder(ball, pvhY,
|
||||||
|
pvhX).setDuration(DURATION/2);
|
||||||
yxBouncer.setRepeatCount(1);
|
yxBouncer.setRepeatCount(1);
|
||||||
yxBouncer.setRepeatMode(ValueAnimator.REVERSE);
|
yxBouncer.setRepeatMode(ValueAnimator.REVERSE);
|
||||||
|
|
||||||
|
|||||||
@@ -81,8 +81,8 @@ public class ReversingAnimation extends Activity {
|
|||||||
|
|
||||||
private void createAnimation() {
|
private void createAnimation() {
|
||||||
if (bounceAnim == null) {
|
if (bounceAnim == null) {
|
||||||
bounceAnim = new ObjectAnimator(1500, ball, "y",
|
bounceAnim = ObjectAnimator.ofFloat(ball, "y", ball.getY(), getHeight() - 50f).
|
||||||
ball.getY(), getHeight() - 50f);
|
setDuration(1500);
|
||||||
bounceAnim.setInterpolator(new AccelerateInterpolator(2f));
|
bounceAnim.setInterpolator(new AccelerateInterpolator(2f));
|
||||||
bounceAnim.addUpdateListener(this);
|
bounceAnim.addUpdateListener(this);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user