static void setBackgroundWithRipple ( View clickedView , final View backgroundView , final View bgOverlay , final int newColor , int animationDuration ) { int centerX = ( int ) ( clickedView . getX ( ) + ( clickedView . getMeasuredWidth ( ) / 2 ) ) ; int centerY = clickedView . getMeasuredHeight ( ) / 2 ; int finalRadius = backgroundView . getWidth ( ) ; backgroundView . clearAnimation ( ) ; bgOverlay . clearAnimation ( ) ; Animator circularReveal ; if ( Build . VERSION . SDK_INT >= Build . VERSION_CODES . LOLLIPOP ) { circularReveal = ViewAnimationUtils . createCircularReveal ( bgOverlay , centerX , centerY , 0 , finalRadius ) ; } else { bgOverlay . setAlpha ( 0 ) ; circularReveal = ObjectAnimator . ofFloat ( bgOverlay , "alpha" , 0 , 1 ) ; } circularReveal . setDuration ( animationDuration ) ; circularReveal . addListener ( new AnimatorListenerAdapter ( ) { @ Override public void onAnimationEnd ( Animator animation ) { onCancel ( ) ; } @ Override public void onAnimationCancel ( Animator animation ) { onCancel ( ) ; } private void onCancel ( ) { backgroundView . setBackgroundColor ( newColor ) ; bgOverlay . setVisibility ( View . GONE ) ; } } ) ; bgOverlay . setBackgroundColor ( newColor ) ; bgOverlay . setVisibility ( View . VISIBLE ) ; circularReveal . start ( ) ; }
Used to set the ripple animation when a tab is selected