@Test public void testAnimate() { CoachmarkViewLayout layoutMock = Mockito.mock(CoachmarkViewLayout.class); AnimationListener animationListenerMock = Mockito.mock(AnimationListener.class); CircleView circleViewMock = Mockito.mock(CircleView.class); RectF rectFMock = Mockito.mock(RectF.class); RectF screenRectFMock = Mockito.mock(RectF.class); when(rectFMock.width()).thenReturn(10f); when(rectFMock.centerX()).thenReturn(3f); when(rectFMock.centerY()).thenReturn(3f); when(screenRectFMock.height()).thenReturn(100f); when(layoutMock.calcScreenRectF()).thenReturn(screenRectFMock); ValueAnimator valueAnimatorMock = Mockito.mock(ValueAnimator.class); PowerMockito.mockStatic(ValueAnimator.class); PowerMockito.when(ValueAnimator.ofFloat(100f, 5f)).thenReturn(valueAnimatorMock); when(valueAnimatorMock.getAnimatedValue()).thenReturn(2f); ArgumentCaptor<ValueAnimator.AnimatorUpdateListener> updateCaptor = ArgumentCaptor.forClass(ValueAnimator.AnimatorUpdateListener.class); ArgumentCaptor<Animator.AnimatorListener> listenerCaptor = ArgumentCaptor.forClass(Animator.AnimatorListener.class); when(layoutMock.calcCircleRectF()).thenReturn(rectFMock); new ConcentricCircleAnimationRenderer.Builder().build().animate(layoutMock, circleViewMock, animationListenerMock); verify(valueAnimatorMock).addUpdateListener(updateCaptor.capture()); verify(valueAnimatorMock).addListener(listenerCaptor.capture()); verify(layoutMock, times(1)).calcCircleRectF(); verify(layoutMock, times(1)).calcScreenRectF(); verify(circleViewMock).setCenterX(3f); verify(circleViewMock).setCenterY(3f); listenerCaptor.getValue().onAnimationEnd(null); verify(animationListenerMock, times(1)).onAnimationFinished(); updateCaptor.getValue().onAnimationUpdate(valueAnimatorMock); verify(circleViewMock, times(1)).setRadius(2f); verify(circleViewMock, times(1)).bringToFront(); verify(circleViewMock, times(1)).forceLayout(); }
@Override public void animate(CoachmarkViewLayout layout, final CircleView view, final AnimationListener animationListener) { RectF mCircleRectF = layout.calcCircleRectF(); view.setCenterX(mCircleRectF.centerX()); view.setCenterY(mCircleRectF.centerY()); ValueAnimator animatorX = ValueAnimator.ofFloat(layout.calcScreenRectF().height(), mCircleRectF.width() / 2); animatorX.setDuration(mAnimationDuration); animatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float val = (Float) valueAnimator.getAnimatedValue(); view.setRadius(val); view.bringToFront(); view.forceLayout(); } }); animatorX.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { animationListener.onAnimationFinished(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); animatorX.start(); }
ConcentricCircleAnimationRenderer implements AnimationRenderer { @Override public void animate(CoachmarkViewLayout layout, final CircleView view, final AnimationListener animationListener) { RectF mCircleRectF = layout.calcCircleRectF(); view.setCenterX(mCircleRectF.centerX()); view.setCenterY(mCircleRectF.centerY()); ValueAnimator animatorX = ValueAnimator.ofFloat(layout.calcScreenRectF().height(), mCircleRectF.width() / 2); animatorX.setDuration(mAnimationDuration); animatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float val = (Float) valueAnimator.getAnimatedValue(); view.setRadius(val); view.bringToFront(); view.forceLayout(); } }); animatorX.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { animationListener.onAnimationFinished(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); animatorX.start(); } }
ConcentricCircleAnimationRenderer implements AnimationRenderer { @Override public void animate(CoachmarkViewLayout layout, final CircleView view, final AnimationListener animationListener) { RectF mCircleRectF = layout.calcCircleRectF(); view.setCenterX(mCircleRectF.centerX()); view.setCenterY(mCircleRectF.centerY()); ValueAnimator animatorX = ValueAnimator.ofFloat(layout.calcScreenRectF().height(), mCircleRectF.width() / 2); animatorX.setDuration(mAnimationDuration); animatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float val = (Float) valueAnimator.getAnimatedValue(); view.setRadius(val); view.bringToFront(); view.forceLayout(); } }); animatorX.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { animationListener.onAnimationFinished(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); animatorX.start(); } private  ConcentricCircleAnimationRenderer(); }
ConcentricCircleAnimationRenderer implements AnimationRenderer { @Override public void animate(CoachmarkViewLayout layout, final CircleView view, final AnimationListener animationListener) { RectF mCircleRectF = layout.calcCircleRectF(); view.setCenterX(mCircleRectF.centerX()); view.setCenterY(mCircleRectF.centerY()); ValueAnimator animatorX = ValueAnimator.ofFloat(layout.calcScreenRectF().height(), mCircleRectF.width() / 2); animatorX.setDuration(mAnimationDuration); animatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float val = (Float) valueAnimator.getAnimatedValue(); view.setRadius(val); view.bringToFront(); view.forceLayout(); } }); animatorX.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { animationListener.onAnimationFinished(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); animatorX.start(); } private  ConcentricCircleAnimationRenderer(); @Override void animate(CoachmarkViewLayout layout, final CircleView view, final AnimationListener animationListener); }
ConcentricCircleAnimationRenderer implements AnimationRenderer { @Override public void animate(CoachmarkViewLayout layout, final CircleView view, final AnimationListener animationListener) { RectF mCircleRectF = layout.calcCircleRectF(); view.setCenterX(mCircleRectF.centerX()); view.setCenterY(mCircleRectF.centerY()); ValueAnimator animatorX = ValueAnimator.ofFloat(layout.calcScreenRectF().height(), mCircleRectF.width() / 2); animatorX.setDuration(mAnimationDuration); animatorX.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float val = (Float) valueAnimator.getAnimatedValue(); view.setRadius(val); view.bringToFront(); view.forceLayout(); } }); animatorX.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { animationListener.onAnimationFinished(); } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); animatorX.start(); } private  ConcentricCircleAnimationRenderer(); @Override void animate(CoachmarkViewLayout layout, final CircleView view, final AnimationListener animationListener);  }