Added new xml anim capabilities to AnimationLoading demo
New xml capabilities for animators, so I added new functionality to the existing xml loading demo app Change-Id: Iba30dce28059031744ce23d1f79f41072a6a1e78
This commit is contained in:
@@ -24,7 +24,6 @@
|
|||||||
android:repeatMode="reverse"/>
|
android:repeatMode="reverse"/>
|
||||||
<objectAnimator 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:valueTo="400"
|
android:valueTo="400"
|
||||||
android:valueType="floatType"
|
android:valueType="floatType"
|
||||||
android:propertyName="y"
|
android:propertyName="y"
|
||||||
|
|||||||
23
samples/ApiDemos/res/anim/color_animator.xml
Normal file
23
samples/ApiDemos/res/anim/color_animator.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!-- Copyright (C) 2010 The Android Open Source Project
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<objectAnimator xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:duration="1000"
|
||||||
|
android:valueFrom="#0f0"
|
||||||
|
android:valueTo="#00ffff"
|
||||||
|
android:propertyName="color"
|
||||||
|
android:repeatCount="1"
|
||||||
|
android:repeatMode="reverse"/>
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
<objectAnimator 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:valueTo="200"
|
android:valueTo="200"
|
||||||
android:valueType="floatType"
|
android:valueType="floatType"
|
||||||
android:propertyName="y"
|
android:propertyName="y"
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ package com.example.android.apis.animation;
|
|||||||
import android.animation.AnimatorInflater;
|
import android.animation.AnimatorInflater;
|
||||||
import android.animation.AnimatorSet;
|
import android.animation.AnimatorSet;
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
|
import android.graphics.Color;
|
||||||
import com.example.android.apis.R;
|
import com.example.android.apis.R;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -73,22 +74,21 @@ public class AnimationLoading extends Activity {
|
|||||||
|
|
||||||
public MyAnimationView(Context context) {
|
public MyAnimationView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
addBall(100, 0);
|
addBall(50, 50);
|
||||||
addBall(250, 0);
|
addBall(200, 50);
|
||||||
addBall(400, 0);
|
addBall(350, 50);
|
||||||
|
addBall(500, 50, Color.GREEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void createAnimation() {
|
private void createAnimation() {
|
||||||
if (animation == null) {
|
if (animation == null) {
|
||||||
ObjectAnimator anim =
|
ObjectAnimator anim = (ObjectAnimator) AnimatorInflater.
|
||||||
(ObjectAnimator) AnimatorInflater.
|
loadAnimator(getApplicationContext(), R.anim.object_animator);
|
||||||
loadAnimator(getApplicationContext(), R.anim.object_animator);
|
|
||||||
anim.addUpdateListener(this);
|
anim.addUpdateListener(this);
|
||||||
anim.setTarget(balls.get(0));
|
anim.setTarget(balls.get(0));
|
||||||
|
|
||||||
ValueAnimator fader =
|
ValueAnimator fader = (ValueAnimator) AnimatorInflater.
|
||||||
(ValueAnimator) AnimatorInflater.loadAnimator(getApplicationContext(),
|
loadAnimator(getApplicationContext(), R.anim.animator);
|
||||||
R.anim.animator);
|
|
||||||
fader.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
fader.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
balls.get(1).setAlpha((Float) animation.getAnimatedValue());
|
balls.get(1).setAlpha((Float) animation.getAnimatedValue());
|
||||||
@@ -100,8 +100,12 @@ public class AnimationLoading extends Activity {
|
|||||||
R.anim.animator_set);
|
R.anim.animator_set);
|
||||||
seq.setTarget(balls.get(2));
|
seq.setTarget(balls.get(2));
|
||||||
|
|
||||||
|
ObjectAnimator colorizer = (ObjectAnimator) AnimatorInflater.
|
||||||
|
loadAnimator(getApplicationContext(), R.anim.color_animator);
|
||||||
|
colorizer.setTarget(balls.get(3));
|
||||||
|
|
||||||
animation = new AnimatorSet();
|
animation = new AnimatorSet();
|
||||||
((AnimatorSet) animation).playTogether(anim, fader, seq);
|
((AnimatorSet) animation).playTogether(anim, fader, seq, colorizer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,25 +114,34 @@ public class AnimationLoading extends Activity {
|
|||||||
animation.start();
|
animation.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShapeHolder addBall(float x, float y) {
|
private ShapeHolder createBall(float x, float y) {
|
||||||
OvalShape circle = new OvalShape();
|
OvalShape circle = new OvalShape();
|
||||||
circle.resize(BALL_SIZE, BALL_SIZE);
|
circle.resize(BALL_SIZE, BALL_SIZE);
|
||||||
ShapeDrawable drawable = new ShapeDrawable(circle);
|
ShapeDrawable drawable = new ShapeDrawable(circle);
|
||||||
ShapeHolder shapeHolder = new ShapeHolder(drawable);
|
ShapeHolder shapeHolder = new ShapeHolder(drawable);
|
||||||
shapeHolder.setX(x);
|
shapeHolder.setX(x);
|
||||||
shapeHolder.setY(y);
|
shapeHolder.setY(y);
|
||||||
|
return shapeHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addBall(float x, float y, int color) {
|
||||||
|
ShapeHolder shapeHolder = createBall(x, y);
|
||||||
|
shapeHolder.setColor(color);
|
||||||
|
balls.add(shapeHolder);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addBall(float x, float y) {
|
||||||
|
ShapeHolder shapeHolder = createBall(x, y);
|
||||||
int red = (int)(100 + Math.random() * 155);
|
int red = (int)(100 + Math.random() * 155);
|
||||||
int green = (int)(100 + Math.random() * 155);
|
int green = (int)(100 + Math.random() * 155);
|
||||||
int blue = (int)(100 + Math.random() * 155);
|
int blue = (int)(100 + Math.random() * 155);
|
||||||
int color = 0xff000000 | red << 16 | green << 8 | blue;
|
int color = 0xff000000 | red << 16 | green << 8 | blue;
|
||||||
Paint paint = drawable.getPaint();
|
Paint paint = shapeHolder.getShape().getPaint();
|
||||||
int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
|
int darkColor = 0xff000000 | red/4 << 16 | green/4 << 8 | blue/4;
|
||||||
RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
|
RadialGradient gradient = new RadialGradient(37.5f, 12.5f,
|
||||||
50f, color, darkColor, Shader.TileMode.CLAMP);
|
50f, color, darkColor, Shader.TileMode.CLAMP);
|
||||||
paint.setShader(gradient);
|
paint.setShader(gradient);
|
||||||
shapeHolder.setPaint(paint);
|
|
||||||
balls.add(shapeHolder);
|
balls.add(shapeHolder);
|
||||||
return shapeHolder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ public class ShapeHolder {
|
|||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
public void setColor(int value) {
|
public void setColor(int value) {
|
||||||
|
shape.getPaint().setColor(value);
|
||||||
color = value;
|
color = value;
|
||||||
}
|
}
|
||||||
public void setGradient(RadialGradient value) {
|
public void setGradient(RadialGradient value) {
|
||||||
|
|||||||
Reference in New Issue
Block a user