Last active
March 3, 2016 21:58
-
-
Save pavlospt/e286f35436736d47607a to your computer and use it in GitHub Desktop.
Reveal from FAB or other UI Element
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
private void reveal(View sourceView, int colorRes) { | |
groupOverlay = | |
(ViewGroupOverlay) getWindow().getDecorView().getOverlay(); | |
final Rect displayRect = new Rect(); | |
mMainDisplay.getGlobalVisibleRect(displayRect); | |
// Make reveal cover the display and status bar. | |
revealView = new View(this); | |
revealView.setBottom(displayRect.bottom); | |
revealView.setLeft(displayRect.left); | |
revealView.setRight(displayRect.right); | |
revealView.setBackgroundColor(getResources().getColor(colorRes)); | |
groupOverlay.add(revealView); | |
final int[] clearLocation = new int[2]; | |
sourceView.getLocationInWindow(clearLocation); | |
clearLocation[0] += sourceView.getWidth() / 2; | |
clearLocation[1] += sourceView.getHeight() / 2; | |
final int revealCenterX = clearLocation[0] - revealView.getLeft(); | |
final int revealCenterY = clearLocation[1] - revealView.getTop(); | |
final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2); | |
final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2); | |
final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2); | |
final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2)); | |
final Animator revealAnimator = | |
ViewAnimationUtils.createCircularReveal(revealView, | |
revealCenterX, revealCenterY, 0.0f, revealRadius); | |
revealAnimator.setDuration( | |
getResources().getInteger(android.R.integer.config_longAnimTime)); | |
final AnimatorSet animatorSet = new AnimatorSet(); | |
animatorSet.play(revealAnimator); | |
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); | |
animatorSet.addListener(new AnimatorListenerAdapter() { | |
@Override | |
public void onAnimationEnd(Animator animator) { | |
startActivity( | |
new Intent(MainActivity.this, TweetActivity.class).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) | |
); | |
} | |
}); | |
animatorSet.start(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment