Skip to content

Instantly share code, notes, and snippets.

@shubham08gupta
Created August 27, 2017 17:04
Show Gist options
  • Save shubham08gupta/992f64c391c9a9994d5bdb03c43e00fd to your computer and use it in GitHub Desktop.
Save shubham08gupta/992f64c391c9a9994d5bdb03c43e00fd to your computer and use it in GitHub Desktop.
/*
create a new circular reaveal on the give view. This view is initially invisible. In this case the view covers full screen
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void createCircularReveal(final View view) {
// to get the center of FAB
int centerX = (int) mFab.getX() + mFab.getWidth() / 2;
int centerY = (int) mFab.getY();
float finalRadius = (float) Math.hypot(view.getWidth(), view.getHeight());
// starts the effect at centerX, center Y and covers final radius
Animator revealAnimator = ViewAnimationUtils.createCircularReveal(view,
centerX, centerY, 0, finalRadius);
view.setVisibility(View.VISIBLE);
revealAnimator.start();
}
/*
hides the circular view
*/
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void hideCircularReveal(final View myView) {
// get the center for the clipping circle
int cx = (int) mFab.getX() + mFab.getWidth() / 2;
int cy = (int) mFab.getY();
// get the initial radius for the clipping circle
float initialRadius = (float) Math.hypot(myView.getWidth(), myView.getHeight());
// create the animation (the final radius is zero)
Animator anim =
ViewAnimationUtils.createCircularReveal(myView, cx, cy, initialRadius, 0);
// make the view invisible when the animation is done
anim.addListener(new Animator.AnimatorListener() {
@Override
public void onAnimationStart(Animator animation) {
}
@Override
public void onAnimationEnd(Animator animation) {
myView.setVisibility(View.INVISIBLE);
}
@Override
public void onAnimationCancel(Animator animation) {
}
@Override
public void onAnimationRepeat(Animator animation) {
}
});
// start the animation
anim.start();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment