Search in sources :

Example 1 with AnimationBuilder

use of com.github.florent37.viewanimator.AnimationBuilder in project ViewAnimator by florent37.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    image = (ImageView) findViewById(R.id.image);
    mountain = (ImageView) findViewById(R.id.mountain);
    text = (TextView) findViewById(R.id.text);
    percent = (TextView) findViewById(R.id.percent);
    findViewById(R.id.parallel).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            animateParallel();
        }
    });
    findViewById(R.id.mountain).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            simpleAnimation();
        }
    });
    findViewById(R.id.sequentially).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            animateSequentially();
        }
    });
    findViewById(R.id.enhanced).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            int random = new Random().nextInt(10);
            final ViewGroup viewGroup = (ViewGroup) v.getParent();
            final ImageView imageView = new ImageView(v.getContext());
            imageView.setImageResource(R.mipmap.ic_launcher);
            viewGroup.addView(imageView);
            AnimationBuilder builder;
            switch(random) {
                case 0:
                    builder = ViewAnimator.animate(imageView).shake().interpolator(new LinearInterpolator());
                    break;
                case 1:
                    builder = ViewAnimator.animate(imageView).bounceIn().interpolator(new BounceInterpolator());
                    break;
                case 2:
                    builder = ViewAnimator.animate(imageView).flash().repeatCount(4);
                    break;
                case 3:
                    builder = ViewAnimator.animate(imageView).flipHorizontal();
                    break;
                case 4:
                    builder = ViewAnimator.animate(imageView).wave().duration(5000);
                    break;
                case 5:
                    builder = ViewAnimator.animate(imageView).tada();
                    break;
                case 6:
                    builder = ViewAnimator.animate(imageView).pulse();
                    break;
                case 7:
                    builder = ViewAnimator.animate(imageView).standUp();
                    break;
                case 8:
                    builder = ViewAnimator.animate(imageView).swing();
                    break;
                default:
                    builder = ViewAnimator.animate(imageView).wobble();
                    break;
            }
            builder.onStop(new AnimationListener.Stop() {

                @Override
                public void onStop() {
                    viewGroup.removeView(imageView);
                }
            }).start();
        }
    });
    findViewById(R.id.path).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Path path = new Path();
            path.moveTo(START_POINT[0], START_POINT[1]);
            path.quadTo(RIGHT_CONTROL_POINT[0], RIGHT_CONTROL_POINT[1], BOTTOM_POINT[0], BOTTOM_POINT[1]);
            path.quadTo(LEFT_CONTROL_POINT[0], LEFT_CONTROL_POINT[1], START_POINT[0], START_POINT[1]);
            path.close();
            ViewAnimator.animate(v).path(path).repeatCount(2).start();
        }
    });
    findViewById(R.id.svgPath).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ViewAnimator.animate(v).svgPath(SVG_PATH).duration(10000).repeatCount(3).start();
            final View btnWave = findViewById(R.id.wave);
            btnWave.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ViewAnimator.animate(btnWave).wave().duration(3000).start();
                }
            });
            final View btnShake = findViewById(R.id.shake);
            btnShake.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View v) {
                    ViewAnimator.animate(btnShake).shake().duration(3000).start();
                }
            });
        }
    });
}
Also used : Path(android.graphics.Path) ViewGroup(android.view.ViewGroup) BounceInterpolator(android.view.animation.BounceInterpolator) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Random(java.util.Random) LinearInterpolator(android.view.animation.LinearInterpolator) ImageView(android.widget.ImageView) AnimationBuilder(com.github.florent37.viewanimator.AnimationBuilder) AnimationListener(com.github.florent37.viewanimator.AnimationListener)

Aggregations

Path (android.graphics.Path)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 BounceInterpolator (android.view.animation.BounceInterpolator)1 LinearInterpolator (android.view.animation.LinearInterpolator)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 AnimationBuilder (com.github.florent37.viewanimator.AnimationBuilder)1 AnimationListener (com.github.florent37.viewanimator.AnimationListener)1 Random (java.util.Random)1