List of usage examples for android.animation ValueAnimator getAnimatedFraction
public float getAnimatedFraction()
From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java
@TargetApi(11) void startIdleAnimations() { if (mAnimationCurrent != null) { mAnimationCurrent.removeAllUpdateListeners(); mAnimationCurrent.cancel();// w ww.j a v a2s . c o m mAnimationCurrent = null; } mAnimationCurrent = ValueAnimator.ofFloat(0, mFocalRadius10Percent, 0); mAnimationCurrent.setInterpolator(mAnimationInterpolator); mAnimationCurrent.setDuration(1000); mAnimationCurrent.setStartDelay(225); mAnimationCurrent.setRepeatCount(ValueAnimator.INFINITE); mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { boolean direction = true; @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onAnimationUpdate(ValueAnimator animation) { final float newFocalFraction = (Float) animation.getAnimatedValue(); boolean newDirection = direction; if (newFocalFraction < mFocalRippleProgress && direction) { newDirection = false; } else if (newFocalFraction > mFocalRippleProgress && !direction) { newDirection = true; } if (newDirection != direction && !newDirection) { mAnimationFocalRipple.start(); } direction = newDirection; mFocalRippleProgress = newFocalFraction; mView.mFocalRadius = mBaseFocalRadius + mFocalRippleProgress; mView.invalidate(); } }); mAnimationCurrent.start(); if (mAnimationFocalRipple != null) { mAnimationFocalRipple.removeAllUpdateListeners(); mAnimationFocalRipple.cancel(); mAnimationFocalRipple = null; } final float baseRadius = mBaseFocalRadius + mFocalRadius10Percent; mAnimationFocalRipple = ValueAnimator.ofFloat(baseRadius, baseRadius + (mFocalRadius10Percent * 6)); mAnimationFocalRipple.setInterpolator(mAnimationInterpolator); mAnimationFocalRipple.setDuration(500); mAnimationFocalRipple.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onAnimationUpdate(ValueAnimator animation) { mView.mFocalRippleSize = (float) animation.getAnimatedValue(); final float fraction; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR1) { fraction = animation.getAnimatedFraction(); } else { fraction = (mFocalRadius10Percent * 6) / (mView.mFocalRippleSize - mBaseFocalRadius - mFocalRadius10Percent); } mView.mFocalRippleAlpha = (int) (mBaseFocalRippleAlpha * (1f - fraction)); } }); }