List of usage examples for android.animation ValueAnimator getAnimatedValue
public Object getAnimatedValue()
ValueAnimator
when there is just one property being animated. From source file:android.support.v17.leanback.app.PlaybackSupportFragment.java
private void loadControlRowAnimator() { final AnimatorUpdateListener updateListener = new AnimatorUpdateListener() { @Override// w w w.jav a 2 s . c om public void onAnimationUpdate(ValueAnimator arg0) { if (getVerticalGridView() == null) { return; } RecyclerView.ViewHolder vh = getVerticalGridView().findViewHolderForAdapterPosition(0); if (vh == null) { return; } View view = vh.itemView; if (view != null) { final float fraction = (Float) arg0.getAnimatedValue(); if (DEBUG) Log.v(TAG, "fraction " + fraction); view.setAlpha(fraction); view.setTranslationY((float) mAnimationTranslateY * (1f - fraction)); } } }; Context context = getContext(); mControlRowFadeInAnimator = loadAnimator(context, R.animator.lb_playback_controls_fade_in); mControlRowFadeInAnimator.addUpdateListener(updateListener); mControlRowFadeInAnimator.setInterpolator(mLogDecelerateInterpolator); mControlRowFadeOutAnimator = loadAnimator(context, R.animator.lb_playback_controls_fade_out); mControlRowFadeOutAnimator.addUpdateListener(updateListener); mControlRowFadeOutAnimator.setInterpolator(mLogAccelerateInterpolator); }
From source file:com.commonsware.cwac.crossport.design.widget.TextInputLayout.java
@VisibleForTesting void animateToExpansionFraction(final float target) { if (mCollapsingTextHelper.getExpansionFraction() == target) { return;/*from w ww . ja v a 2 s. c o m*/ } if (mAnimator == null) { mAnimator = new ValueAnimator(); mAnimator.setInterpolator(AnimationUtils.LINEAR_INTERPOLATOR); mAnimator.setDuration(ANIMATION_DURATION); mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { mCollapsingTextHelper.setExpansionFraction((float) animator.getAnimatedValue()); } }); } mAnimator.setFloatValues(mCollapsingTextHelper.getExpansionFraction(), target); mAnimator.start(); }
From source file:com.zwj.customview.gesturelock.PatternView.java
private void startCellStateAnimationSw(final CellState cellState, final float startAlpha, final float endAlpha, final float startTranslationY, final float endTranslationY, final float startScale, final float endScale, long delay, long duration, Interpolator interpolator, final Runnable finishRunnable) { cellState.alpha = startAlpha;// w w w .j a v a 2 s .c o m cellState.translationY = startTranslationY; cellState.radius = mDotRadius * startScale; ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f); animator.setDuration(duration); animator.setStartDelay(delay); animator.setInterpolator(interpolator); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float t = (float) animation.getAnimatedValue(); cellState.alpha = (1 - t) * startAlpha + t * endAlpha; cellState.translationY = (1 - t) * startTranslationY + t * endTranslationY; cellState.radius = mDotRadius * ((1 - t) * startScale + t * endScale); invalidate(); } }); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (finishRunnable != null) { finishRunnable.run(); } } }); animator.start(); }
From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java
/** * animate header view specific location * * @param isToStart true:move to the start location,false:move to the end location * @param listener {@link OnAnimateContentOffsetListener} *///from w w w . jav a 2 s . c om private void animateHeaderOffsetToPos(final boolean isToStart, final OnAnimateContentOffsetListener listener) { if (animatorOfHeader != null && animatorOfHeader.isRunning()) { animatorOfHeader.cancel(); } if (headerView.getVisibility() != VISIBLE) { headerView.setVisibility(VISIBLE); } if (isToStart) { animatorOfHeader = ObjectAnimator.ofInt(headerView.getCurrentOffset(), headerView.getStartOffset()) .setDuration(durationOfSwipeDown); } else { animatorOfHeader = ObjectAnimator.ofInt(headerView.getCurrentOffset(), headerView.getEndOffset()) .setDuration(durationOfSwipeDown); } final float currentPercent = headerView.getPercent(); animatorOfHeader.setInterpolator(headerInterpolator); animatorOfHeader.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { offsetHeader((int) animation.getAnimatedValue() - headerView.getCurrentOffset()); computeOffsetPercent(currentPercent, isToStart, animation.getAnimatedFraction()); } }); animatorOfHeader.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { if (listener != null) { listener.onOffsetEnd(); } if (isToStart) { headerView.setVisibility(INVISIBLE); footerView.setVisibility(INVISIBLE); } else { if (!headerView.isRunning()) { headerView.start(); } } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorOfHeader.start(); }
From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java
/** * animate footer view specific location * * @param isToStart true:move to the start location,false:move to the end location * @param listener {@link OnAnimateContentOffsetListener} *///w w w . ja v a 2s . c o m private void animateFooterOffsetToPos(final boolean isToStart, final OnAnimateContentOffsetListener listener) { if (animatorOfFooter != null && animatorOfFooter.isRunning()) { animatorOfFooter.cancel(); } if (footerView.getVisibility() != VISIBLE) { footerView.setVisibility(VISIBLE); } if (isToStart) { animatorOfFooter = ObjectAnimator.ofInt(footerView.getCurrentOffset(), footerView.getStartOffset()) .setDuration(durationOfSwipeUp); } else { animatorOfFooter = ObjectAnimator.ofInt(footerView.getCurrentOffset(), footerView.getEndOffset()) .setDuration(durationOfSwipeUp); } animatorOfFooter.setInterpolator(footerInterpolator); final float currentPercent = footerView.getPercent(); animatorOfFooter.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { offsetFooter((int) animation.getAnimatedValue() - footerView.getCurrentOffset()); computeOffsetPercent(currentPercent, isToStart, animation.getAnimatedFraction()); } }); animatorOfFooter.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { if (listener != null) { listener.onOffsetEnd(); } if (isToStart) { headerView.setVisibility(INVISIBLE); footerView.setVisibility(INVISIBLE); } else { if (!footerView.isRunning()) { footerView.start(); } } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorOfFooter.start(); }
From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java
@TargetApi(11) void startRevealAnimation() { mPaintSecondaryText.setAlpha(0);//from w ww . j a v a 2 s . c o m mPaintPrimaryText.setAlpha(0); mView.mPaintBackground.setAlpha(0); mView.mPaintFocal.setAlpha(0); mView.mFocalRadius = 0; mView.mBackgroundRadius = 0; if (mView.mIconDrawable != null) { mView.mIconDrawable.setAlpha(0); } mRevealedAmount = 0f; mAnimationCurrent = ValueAnimator.ofFloat(0f, 1f); mAnimationCurrent.setInterpolator(mAnimationInterpolator); mAnimationCurrent.setDuration(225); mAnimationCurrent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onAnimationUpdate(ValueAnimator animation) { mRevealedAmount = (float) animation.getAnimatedValue(); mView.mBackgroundRadius = mBaseBackgroundRadius * mRevealedAmount; mView.mFocalRadius = mBaseFocalRadius * mRevealedAmount; mView.mPaintFocal.setAlpha((int) (255 * mRevealedAmount)); mView.mPaintBackground.setAlpha((int) (244 * mRevealedAmount)); mPaintSecondaryText.setAlpha((int) (mSecondaryTextColourAlpha * mRevealedAmount)); mPaintPrimaryText.setAlpha((int) (mPrimaryTextColourAlpha * mRevealedAmount)); if (mView.mIconDrawable != null) { mView.mIconDrawable.setAlpha(mView.mPaintBackground.getAlpha()); } mView.invalidate(); } }); mAnimationCurrent.addListener(new AnimatorListener() { @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onAnimationEnd(Animator animation) { animation.removeAllListeners(); mAnimationCurrent = null; mRevealedAmount = 1; startIdleAnimations(); } @TargetApi(Build.VERSION_CODES.HONEYCOMB) @Override public void onAnimationCancel(Animator animation) { animation.removeAllListeners(); mRevealedAmount = 1; mAnimationCurrent = null; } }); mAnimationCurrent.start(); }
From source file:com.baitouwei.swiperefresh.ASwipeRefreshLayout.java
/** * animate content view specific location * * @param isToStart true:move to the start location,false:move to the end location * @param isSwipeDown true:current is swipe down,false:current is swipe up * @param listener {@link OnAnimateContentOffsetListener} */// www. j a va2 s .co m private void animateContentOffsetToPos(final boolean isToStart, final boolean isSwipeDown, final OnAnimateContentOffsetListener listener) { if (animatorOfContent != null && animatorOfContent.isRunning()) { animatorOfContent.cancel(); } if (isToStart) { if (isSwipeDown) { animatorOfContent = ObjectAnimator .ofInt((int) currentContentOffset, contentViewSwipeDownStartOffset) .setDuration(durationOfSwipeDown); animatorOfContent.setInterpolator(headerInterpolator); } else { animatorOfContent = ObjectAnimator.ofInt((int) currentContentOffset, contentViewSwipeUpStartOffset) .setDuration(durationOfSwipeUp); animatorOfContent.setInterpolator(footerInterpolator); } } else { if (isSwipeDown) { animatorOfContent = ObjectAnimator.ofInt((int) currentContentOffset, contentViewSwipeDownEndOffset) .setDuration(durationOfSwipeDown); animatorOfContent.setInterpolator(headerInterpolator); } else { animatorOfContent = ObjectAnimator.ofInt((int) currentContentOffset, contentViewSwipeUpEndOffset) .setDuration(durationOfSwipeUp); animatorOfContent.setInterpolator(footerInterpolator); } } final float currentPercent = headerView.getPercent(); animatorOfContent.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { if (isSwipeDown) { offsetContent((int) animation.getAnimatedValue() - currentContentOffset, parallaxFactorOfContentSwipeDown); } else { offsetContent((int) animation.getAnimatedValue() - currentContentOffset, parallaxFactorOfContentSwipeUp); } } }); animatorOfContent.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { if (listener != null) { listener.onOffsetEnd(); } } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }); animatorOfContent.start(); }
From source file:uk.co.samuelwall.materialtaptargetprompt.MaterialTapTargetPrompt.java
@TargetApi(11) void startIdleAnimations() { if (mAnimationCurrent != null) { mAnimationCurrent.removeAllUpdateListeners(); mAnimationCurrent.cancel();/*from w ww . j a v a 2 s . c om*/ 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)); } }); }
From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java
private void animateViewOut(final int event) { if (Build.VERSION.SDK_INT >= 12) { final ValueAnimator animator = new ValueAnimator(); animator.setIntValues(0, mView.getHeight()); animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); animator.setDuration(ANIMATION_DURATION); animator.addListener(new AnimatorListenerAdapter() { @Override//ww w . ja va 2 s .c o m public void onAnimationStart(Animator animator) { mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION); } @Override public void onAnimationEnd(Animator animator) { onViewHidden(event); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { private int mPreviousAnimatedIntValue = 0; @Override public void onAnimationUpdate(ValueAnimator animator) { int currentAnimatedIntValue = (int) animator.getAnimatedValue(); if (USE_OFFSET_API) { ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue); } else { mView.setTranslationY(currentAnimatedIntValue); } mPreviousAnimatedIntValue = currentAnimatedIntValue; } }); animator.start(); } else { final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_out); anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR); anim.setDuration(ANIMATION_DURATION); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationEnd(Animation animation) { onViewHidden(event); } @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); mView.startAnimation(anim); } }
From source file:com.arlib.floatingsearchview.FloatingSearchView.java
private void fadeOutBackground() { ValueAnimator anim = ValueAnimator.ofInt(BACKGROUND_DRAWABLE_ALPHA_SEARCH_ACTIVE, BACKGROUND_DRAWABLE_ALPHA_SEARCH_INACTIVE); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from ww w . ja va 2 s . c o m*/ public void onAnimationUpdate(ValueAnimator animation) { int value = (Integer) animation.getAnimatedValue(); mBackgroundDrawable.setAlpha(value); } }); anim.setDuration(BACKGROUND_FADE__ANIM_DURATION); anim.start(); }