Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LuiguiBalarezo/f109638136a59f79f3d8b634583a5ac3 to your computer and use it in GitHub Desktop.
Save LuiguiBalarezo/f109638136a59f79f3d8b634583a5ac3 to your computer and use it in GitHub Desktop.
package com.zetagas.zventas.animations;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.PropertyValuesHolder;
import android.content.Context;
import android.view.View;
import android.view.animation.Interpolator;
import com.ramijemli.easings.Easings;
import com.ramijemli.easings.Interpolators;
import com.zetagas.zventas.callbacks.AnimationCallback;
import com.zetagas.zventas.interpolators.ReverseInterpolator2;
public class Animation_Splash_Logo {
private static Animation_Splash_Logo animation_Splash_logo_instance;
private static AnimatorSet animatorSet;
private static View view;
private static Context ctx;
//region ObjectsAnimator
private ObjectAnimator animtraslate, animalpha;
//endregion
//region Property Animator
PropertyValuesHolder translationY, alphalogo;
//endregion
//region PropertyViews
private boolean statusonclick = true;
private static int alpha = 1;
private static int duration;
//endregion
//region Boolean status animation
private boolean isin = true, isout = false;
private boolean isinanimation = false;
//endregion
//region Interpolators
private static Interpolator interpolator;
//endregion
private AnimationCallback callback_in, callback_out;
private Animation_Splash_Logo() {
}
public static Animation_Splash_Logo getInstance(Context c, View v) {
if (animation_Splash_logo_instance == null) {
animation_Splash_logo_instance = new Animation_Splash_Logo();
ctx = c;
animatorSet = new AnimatorSet();
view = v;
interpolator = new Interpolators(Easings.BACK_IN_OUT);
duration = 2000;
}
return animation_Splash_logo_instance;
}
public Animation_Splash_Logo setAlpha(int a) {
alpha = a;
view.setAlpha(alpha);
return this;
}
public Animation_Splash_Logo setDuration(int d) {
duration = d;
return this;
}
public Animation_Splash_Logo setInterpolator(Interpolator i) {
interpolator = i;
return this;
}
public Animation_Splash_Logo statusOnClickBeforeEnd(boolean status) {
statusonclick = status;
return this;
}
AnimatorListenerAdapter callback = new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
statusCallbacks(animation, view, isinanimation, ConstantAnimations.CANCEL);
}
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
statusCallbacks(animation, view, isinanimation, ConstantAnimations.END);
}
@Override
public void onAnimationRepeat(Animator animation) {
super.onAnimationRepeat(animation);
statusCallbacks(animation, view, isinanimation, ConstantAnimations.REPEAT);
}
@Override
public void onAnimationStart(Animator animation) {
super.onAnimationStart(animation);
statusCallbacks(animation, view, isinanimation, ConstantAnimations.START);
if (!statusonclick) {
view.setOnClickListener(null);
}
}
@Override
public void onAnimationPause(Animator animation) {
super.onAnimationPause(animation);
statusCallbacks(animation, view, isinanimation, ConstantAnimations.PAUSE);
}
@Override
public void onAnimationResume(Animator animation) {
super.onAnimationResume(animation);
statusCallbacks(animation, view, isinanimation, ConstantAnimations.RESUME);
}
};
void statusCallbacks(Animator animation, View v, boolean isin, int status) {
switch (status) {
case ConstantAnimations.START:
if (isin) {
callback_in.onAnimationStart(animation, v, isinanimation);
} else {
callback_out.onAnimationStart(animation, v, isinanimation);
}
break;
case ConstantAnimations.END:
if (isin) {
callback_in.onAnimationEnd(animation, v, isinanimation);
} else {
callback_out.onAnimationEnd(animation, v, isinanimation);
}
break;
case ConstantAnimations.PAUSE:
if (isin) {
callback_in.onAnimationPause(animation, v, isinanimation);
} else {
callback_out.onAnimationPause(animation, v, isinanimation);
}
break;
case ConstantAnimations.RESUME:
if (isin) {
callback_in.onAnimationResume(animation, v, isinanimation);
} else {
callback_out.onAnimationResume(animation, v, isinanimation);
}
break;
case ConstantAnimations.REPEAT:
if (isin) {
callback_in.onAnimationRepeat(animation, v, isinanimation);
} else {
callback_out.onAnimationRepeat(animation, v, isinanimation);
}
break;
case ConstantAnimations.ERROR:
break;
}
}
/*
* ANIMACIONES
* */
public void outAnimate(AnimationCallback back) {
this.callback_out = back;
this.isinanimation = isout;
animatorSet.removeAllListeners();
animatorSet.end();
animatorSet.cancel();
try {
animatorSet.setInterpolator(new ReverseInterpolator2(interpolator));
animatorSet.addListener(callback);
animatorSet.start();
} catch (Exception e) {
callback_out.onError(e.getMessage(), isinanimation);
}
}
public void inAnimate(AnimationCallback back) {
this.callback_in = back;
this.isinanimation = isin;
if (view != null) {
try {
translationY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, 1000 /*Posicion actual*/, 0 /*Posicion final*/);
alphalogo = PropertyValuesHolder.ofFloat(View.ALPHA, 0 /*Alpha inicial*/, 1 /*Alpha Final*/);
animtraslate = ObjectAnimator.ofPropertyValuesHolder(view, translationY);
animalpha = ObjectAnimator.ofPropertyValuesHolder(view, alphalogo);
animatorSet.playTogether(
animtraslate,
animalpha
);
animatorSet.setInterpolator(interpolator);
animatorSet.setDuration(duration);
animatorSet.addListener(callback);
animatorSet.start();
} catch (Exception e) {
callback_in.onError(e.getMessage(), isinanimation);
}
} else {
callback_in.onError("View Null!!", isinanimation);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment