Skip to content

Instantly share code, notes, and snippets.

@thrashedbrain
Last active January 13, 2021 03:32
Show Gist options
  • Save thrashedbrain/1a0440b781d91a6892bfd47d98588e36 to your computer and use it in GitHub Desktop.
Save thrashedbrain/1a0440b781d91a6892bfd47d98588e36 to your computer and use it in GitHub Desktop.
public class Anim {
public void fadeIn(View view){
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
view,
PropertyValuesHolder.ofFloat("alpha", 0f, 1f)
);
animator.setDuration(4500);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
public void fadeOut(View view){
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
view,
PropertyValuesHolder.ofFloat("alpha", 1f, 0f)
);
animator.setDuration(3000);
animator.setInterpolator(new FastOutSlowInInterpolator());
animator.start();
}
public void colorAnim(ImageView view, int color1, int color2){
ObjectAnimator animator = ObjectAnimator.ofObject(view,
"colorFilter",
new ArgbEvaluator(),
color1,
color2);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(300);
animator.start();
}
public void colorAnimInOut(ImageView view, int color1, int color2){
ObjectAnimator animator = ObjectAnimator.ofObject(view,
"colorFilter",
new ArgbEvaluator(),
color1,
color2);
animator.setInterpolator(new LinearInterpolator());
animator.setRepeatCount(ObjectAnimator.RESTART);
animator.setRepeatMode(ObjectAnimator.REVERSE);
animator.setDuration(600);
animator.start();
}
public void setSizeInAnim(View v){
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
v,
PropertyValuesHolder.ofFloat("scaleX", 0f, 1),
PropertyValuesHolder.ofFloat("scaleY", 0f, 1)
);
animator.setDuration(1000);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
}
public void setSizeOutAnim(final View v){
ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(
v,
PropertyValuesHolder.ofFloat("scaleX", 1, 0f),
PropertyValuesHolder.ofFloat("scaleY", 1, 0f)
);
animator.setDuration(800);
animator.setInterpolator(new AccelerateInterpolator());
animator.start();
animator.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animator) {
}
@Override
public void onAnimationEnd(Animator animator) {
v.setVisibility(View.GONE);
}
@Override
public void onAnimationCancel(Animator animator) {
}
@Override
public void onAnimationRepeat(Animator animator) {
}
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment