zakrodionov
9/24/2018 - 2:54 PM

AnimationUtils.java

package com.kevicsalazar.utils;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.view.View;

public class AnimationUtils {
    // Attention
    public static AnimatorSet loadBounceAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 1, 0, 1, 0, 1));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadFlashAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "translationY", 0, 0, -30, 0, -15, 0, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadPulseAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "scaleY", 1, 1.1f, 1))
                .with(ObjectAnimator.ofFloat(target, "scaleX", 1, 1.1f, 1));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadRubberBandAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "scaleX", 1, 1.25f, 0.75f, 1.15f, 1))
                .with(ObjectAnimator.ofFloat(target, "scaleY", 1, 0.75f, 1.25f, 0.85f, 1));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadShakeAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "translationX", 0, 25, -25, 25, -25, 15, -15, 6, -6, 0));
        animatorSet.setDuration(800);
        return animatorSet;
    }
    public static AnimatorSet loadStandUpAnimator(View target) {
        float x = (target.getWidth() - target.getPaddingLeft() - target.getPaddingRight()) / 2
                + target.getPaddingLeft();
        float y = target.getHeight() - target.getPaddingBottom();
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "pivotX", x, x, x, x, x))
                .with(ObjectAnimator.ofFloat(target, "pivotY", y, y, y, y, y))
                .with(ObjectAnimator.ofFloat(target, "rotationX", 55, -30, 15, -15, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadSwingAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "rotation", 0, 10, -10, 6, -6, 3, -3, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadTadaAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "scaleX", 1, 0.9f, 0.9f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1))
                .with(ObjectAnimator.ofFloat(target, "scaleY", 1, 0.9f, 0.9f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1.1f, 1))
                .with(ObjectAnimator.ofFloat(target, "rotation", 0, -3, -3, 3, -3, 3, -3, 3, -3, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadWaveAnimator(View target) {
        float x = (target.getWidth() - target.getPaddingLeft() - target.getPaddingRight()) / 2
                + target.getPaddingLeft();
        float y = target.getHeight() - target.getPaddingBottom();
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "rotation", 12, -12, 3, -3, 0))
                .with(ObjectAnimator.ofFloat(target, "pivotX", x, x, x, x, x))
                .with(ObjectAnimator.ofFloat(target, "pivotY", y, y, y, y, y));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadWobbleAnimator(View target) {
        float width = target.getWidth();
        float one = (float) (width / 100.0);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "translationX", 0 * one, -25 * one, 20 * one, -15 * one, 10 * one, -5 * one, 0 * one, 0))
                .with(ObjectAnimator.ofFloat(target, "rotation", 0, -5, 3, -3, 2, -1, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    // Bouncing Entrances
    public static AnimatorSet loadBounceInAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1))
                .with(ObjectAnimator.ofFloat(target, "scaleX", 0.3f, 1.05f, 0.9f, 1))
                .with(ObjectAnimator.ofFloat(target, "scaleY", 0.3f, 1.05f, 0.9f, 1));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadBounceInDownAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1))
                .with(ObjectAnimator.ofFloat(target, "scaleY", -target.getHeight(), 30, -10, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadBounceInLeftAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1))
                .with(ObjectAnimator.ofFloat(target, "translationX", -target.getWidth(), 30, -10, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadBounceInRightAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1))
                .with(ObjectAnimator.ofFloat(target, "translationX", target.getMeasuredWidth() + target.getWidth(), -30, 10, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadBounceInUpAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1, 1, 1))
                .with(ObjectAnimator.ofFloat(target, "translationY", target.getMeasuredHeight(), -30, 10, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    // Faiding Entrances
    public static AnimatorSet loadFadeInAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadFadeInDownAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1))
                .with(ObjectAnimator.ofFloat(target, "translationY", -target.getHeight() / 4, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadFadeInLeftAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1))
                .with(ObjectAnimator.ofFloat(target, "translationX", -target.getWidth() / 4, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadFadeInRightAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1))
                .with(ObjectAnimator.ofFloat(target, "translationX", target.getWidth() / 4, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
    public static AnimatorSet loadFadeInUpAnimator(View target) {
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.play(ObjectAnimator.ofFloat(target, "alpha", 0, 1))
                .with(ObjectAnimator.ofFloat(target, "translationY", target.getHeight() / 4, 0));
        animatorSet.setDuration(1000);
        return animatorSet;
    }
}