package com.tywors.animacion;
import android.os.Bundle;
import android.animation.AnimatorSet;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationSet;
import android.view.animation.BounceInterpolator;
import android.view.animation.RotateAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
public class Animacion extends Activity {
private TextView texto_1;
private EditText ed_1;
private Button bt_girar, bt_mover_y_girar;
private ImageView imagen;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animacion);
texto_1 = (TextView)findViewById(R.id.texto_1);
ed_1 = (EditText)findViewById(R.id.ed_text1);
bt_girar = (Button)findViewById(R.id.bt_girar);
imagen = (ImageView)findViewById(R.id.imageView1);
bt_mover_y_girar = (Button)findViewById(R.id.bt_moverygirar);
Animacion_ida();
bt_girar.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
RotateAnimation anim_rotate = new RotateAnimation(0, 360, 0, 0);
anim_rotate.setDuration(1500);
ed_1.startAnimation(anim_rotate);
}
});
bt_mover_y_girar.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mover_y_girar();
}
});
}
private void Animacion_ida(){
TranslateAnimation trans_1 = new TranslateAnimation(-700, 700, 0, 0);
trans_1.setDuration(9000);
trans_1.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
Animacion_vuelta();
}
});
texto_1.startAnimation(trans_1);
}
private void Animacion_vuelta(){
TranslateAnimation trans_2 = new TranslateAnimation(700, -700, 0, 0);
trans_2.setDuration(9000);
trans_2.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {}
@Override
public void onAnimationRepeat(Animation animation) {}
@Override
public void onAnimationEnd(Animation animation) {
Animacion_ida();
}
});
texto_1.startAnimation(trans_2);
}
private void mover_y_girar(){
TranslateAnimation traslacion = new TranslateAnimation(0, 550, 0, 0);
traslacion.setDuration(4000);
RotateAnimation rotacion = new RotateAnimation(0, 360, imagen.getWidth()/2,imagen.getHeight()/2);
rotacion.setDuration(2000);
rotacion.setRepeatCount(2);
AnimationSet animacion_kid = new AnimationSet(true);
animacion_kid.setInterpolator(new BounceInterpolator());
animacion_kid.addAnimation(traslacion);
animacion_kid.addAnimation(rotacion);
imagen.startAnimation(animacion_kid);
}
}