Last active
January 5, 2017 13:52
-
-
Save gabornovakp/33870af4c278094720d754003e8c81bf to your computer and use it in GitHub Desktop.
Circular exit animation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class AnimationUtils { | |
//... | |
public static void startCircularExitAnimation(final Context context, final View view, final RevealAnimationSetting revealSettings, final int startColor, final int endColor, final Dismissible.OnDismissedListener listener) { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
int cx = revealSettings.getCenterX(); | |
int cy = revealSettings.getCenterY(); | |
int width = revealSettings.getWidth(); | |
int height = revealSettings.getHeight(); | |
int duration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime); | |
float initRadius = (float) Math.sqrt(width * width + height * height); | |
Animator anim = ViewAnimationUtils.createCircularReveal(view, cx, cy, initRadius, 0); | |
anim.setDuration(duration); | |
anim.setInterpolator(new FastOutSlowInInterpolator()); | |
anim.addListener(new AnimatorListenerAdapter() { | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
listener.onDismissed(); | |
} | |
}); | |
anim.start(); | |
startColorAnimation(view, startColor, endColor, duration); | |
} else { | |
listener.onDismissed(); | |
} | |
} | |
} | |
//We use this to remove the Fragment only when the animation finished | |
interface Dismissible { | |
interface OnDismissedListener { | |
void onDismissed(); | |
} | |
void dismiss(OnDismissedListener listener); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment