List of usage examples for android.animation ValueAnimator addUpdateListener
public void addUpdateListener(AnimatorUpdateListener listener)
From source file:bottombar.BottomBarTab.java
private void animateColors(int previousColor, int color) { ValueAnimator anim = new ValueAnimator(); anim.setIntValues(previousColor, color); anim.setEvaluator(new ArgbEvaluator()); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w w w. j a va 2s. c o m*/ public void onAnimationUpdate(ValueAnimator valueAnimator) { setColors((Integer) valueAnimator.getAnimatedValue()); } }); anim.setDuration(150); anim.start(); }
From source file:com.github.shareme.gwsswwipetodismiss.library.SwipeDismissTouchListener.java
private void performDismiss() { // Animate the dismissed view to zero-height and then fire the dismiss // callback./*www. jav a2 s .co m*/ // This triggers layout on each animation frame; in the future we may // want to do something // smarter and more performant. final ViewGroup.LayoutParams lp = mView.getLayoutParams(); final int originalHeight = mView.getHeight(); ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime); animator.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { mCallback.onDismiss(mView, mToken); // Reset view presentation setAlpha(mView, 1f); setTranslationX(mView, 0); lp.height = originalHeight; mView.setLayoutParams(lp); } }); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { lp.height = (Integer) valueAnimator.getAnimatedValue(); mView.setLayoutParams(lp); } }); animator.start(); }
From source file:com.ruesga.rview.wizard.WizardActivity.java
private Animator createHeaderAnimation(int from, int to) { final ValueAnimator animator = ValueAnimator.ofInt(from, to); animator.setInterpolator(new AccelerateDecelerateInterpolator()); animator.setDuration(250L);/*from www. j ava2 s . c om*/ animator.addUpdateListener(animation -> { final View v = mBinding.pageHeader; v.getLayoutParams().height = (Integer) animation.getAnimatedValue(); v.requestLayout(); }); animator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { mWorkflow.isBackEnabled = false; mWorkflow.isForwardEnabled = false; mBinding.setWorkflow(mWorkflow); mIsHeaderAnimatorRunning = true; } @Override public void onAnimationEnd(Animator animator) { if (mCurrentPageFragment != null) { onValidationChanged(mCurrentPageFragment); } mBinding.setWorkflow(mWorkflow); mIsHeaderAnimatorRunning = false; } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); return animator; }
From source file:com.nshmura.recyclertablayout.RecyclerTabLayout.java
@TargetApi(Build.VERSION_CODES.HONEYCOMB) protected void startAnimation(final int position) { float distance = 1; View view = mLinearLayoutManager.findViewByPosition(position); if (view != null) { float currentX = view.getX() + view.getMeasuredWidth() / 2.f; float centerX = getMeasuredWidth() / 2.f; distance = Math.abs(centerX - currentX) / view.getMeasuredWidth(); }//from ww w .ja v a 2 s . c o m ValueAnimator animator; if (position < mIndicatorPosition) { animator = ValueAnimator.ofFloat(distance, 0); } else { animator = ValueAnimator.ofFloat(-distance, 0); } animator.setDuration(DEFAULT_SCROLL_DURATION); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { scrollToTab(position, (float) animation.getAnimatedValue(), true); } }); animator.start(); }
From source file:com.roughike.bottombar.BottomBarTab.java
void updateWidth(float endWidth, boolean animated) { if (!animated) { getLayoutParams().width = (int) endWidth; if (!isActive && badge != null) { badge.adjustPositionAndSize(this); badge.show();/*from w w w . j a v a 2 s . c o m*/ } return; } float start = getWidth(); ValueAnimator animator = ValueAnimator.ofFloat(start, endWidth); animator.setDuration(150); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animator) { ViewGroup.LayoutParams params = getLayoutParams(); if (params == null) return; params.width = Math.round((float) animator.getAnimatedValue()); setLayoutParams(params); } }); // Workaround to avoid using faulty onAnimationEnd() listener postDelayed(new Runnable() { @Override public void run() { if (!isActive && badge != null) { clearAnimation(); badge.adjustPositionAndSize(BottomBarTab.this); badge.show(); } } }, animator.getDuration()); animator.start(); }
From source file:com.shopify.buy.ui.ProductDetailsFragmentView.java
@Override public void setImageAreaSize(final boolean grow) { final int finalHeight = grow ? getHeight() : imageAreaHeight; // hide or show the checkout button if (grow && !imageAreaIsExpanded) { hideCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION); } else if (!grow && imageAreaIsExpanded) { showCheckoutButton(IMAGE_AREA_FEATURES_ANIMATION_DURATION); }// ww w .j a v a 2 s . c o m // Animate the image changing size ValueAnimator anim = ValueAnimator.ofInt(imageAreaWrapper.getHeight(), finalHeight); anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int val = (Integer) valueAnimator.getAnimatedValue(); ViewGroup.LayoutParams containerLayoutParams = imageAreaWrapper.getLayoutParams(); containerLayoutParams.height = val; imageAreaWrapper.setLayoutParams(containerLayoutParams); } }); anim.setDuration(IMAGE_AREA_FEATURES_ANIMATION_DURATION); // Disable touch handler for duration of image resizing imagePager.setOnTouchListener(null); anim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { super.onAnimationEnd(animation); // Re-enable the touch handle on the image imagePager.setOnTouchListener(imageAreaTouchHandler); if (grow) { onExpandImageArea(); } else { onCollapseImageArea(); } } }); anim.start(); }
From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java
/** * /*from w ww . j ava 2 s . c om*/ * @param view */ @Override public void onClick(View view) { if (mTvExpandCollapse.getVisibility() != View.VISIBLE) { return; } mCollapsed = !mCollapsed; ///? if (showExpandCollapseDrawable) { mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null, mCollapsed ? mExpandDrawable : mCollapseDrawable, null); } mTvExpandCollapse.setText( mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink)); //??? if (mCollapsedStatus != null) { mCollapsedStatus.put(mPosition, mCollapsed); } // / mAnimating = true; ValueAnimator valueAnimator; if (mCollapsed) { // mTvContent.setMaxLines(mMaxCollapsedLines); valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight); } else { valueAnimator = new ValueAnimator().ofInt(getHeight(), getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight()); } valueAnimator.addUpdateListener(valueAnimator1 -> { int animatedValue = (int) valueAnimator1.getAnimatedValue(); mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom); getLayoutParams().height = animatedValue; requestLayout(); }); valueAnimator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { // ?????? /// clear the animation flag mAnimating = false; // notify the listener if (mListener != null) { mListener.onExpandStateChanged(mTvContent, !mCollapsed); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); valueAnimator.setDuration(mAnimationDuration); valueAnimator.start(); }
From source file:com.test.slidebutton.SlideButton.java
/** * max_leftmin_left(moveToboolean toRight) * @param toRight/* ww w. jav a2s . c o m*/ */ @Deprecated private void moveToDest(final boolean toRight) { ValueAnimator toDestAnim = ValueAnimator.ofInt(sliderCurrentLeft, toRight ? max_left : min_left); toDestAnim.setDuration(200); toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator()); // toDestAnim.setInterpolator(new OvershootInterpolator()); toDestAnim.start(); toDestAnim.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { sliderCurrentLeft = (Integer) animation.getAnimatedValue(); alpha = (int) (255 * (float) sliderCurrentLeft / (float) max_left); if (alpha < 0) alpha = 0; if (alpha > 255) alpha = 255; caculateColor(); invalidateView(); } }); toDestAnim.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { if (toRight) { isOpen = true; if (listener != null) { listener.open(); } sliderCurrentLeft = sliderMoveStartLeft = max_left; alpha = 255; } else { isOpen = false; if (listener != null) { listener.close(); } sliderCurrentLeft = sliderMoveStartLeft = min_left; alpha = 0; } invalidateView(); } }); }
From source file:com.github.shareme.gwsmaterialuikit.library.viewanimator.AnimationBuilder.java
/** * Custom animation builder./*w ww . j a v a 2 s .c om*/ * * @param update the update * @param values the values * @return the animation builder */ public AnimationBuilder custom(final AnimationListener.Update update, float... values) { for (final View view : views) { ValueAnimator valueAnimator = ValueAnimator.ofFloat(getValues(values)); if (update != null) valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { //noinspection unchecked update.update(view, (Float) animation.getAnimatedValue()); } }); add(valueAnimator); } return this; }
From source file:com.jaydenxiao.androidfire.ui.zone.widget.ExpandableTextView.java
/** * //from ww w . j a va 2s. c om * @param view */ @Override public void onClick(View view) { if (mTvExpandCollapse.getVisibility() != View.VISIBLE) { return; } mCollapsed = !mCollapsed; ///? if (showExpandCollapseDrawable) { mTvExpandCollapse.setCompoundDrawablesWithIntrinsicBounds(null, null, mCollapsed ? mExpandDrawable : mCollapseDrawable, null); } mTvExpandCollapse.setText( mCollapsed ? getResources().getString(R.string.expand) : getResources().getString(R.string.shink)); //??? if (mCollapsedStatus != null) { mCollapsedStatus.put(mPosition, mCollapsed); } // / mAnimating = true; ValueAnimator valueAnimator; if (mCollapsed) { // mTvContent.setMaxLines(mMaxCollapsedLines); valueAnimator = new ValueAnimator().ofInt(getHeight(), mCollapsedHeight); } else { valueAnimator = new ValueAnimator().ofInt(getHeight(), getHeight() + mTextHeightWithMaxLines - mTvContent.getHeight()); } valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { int animatedValue = (int) valueAnimator.getAnimatedValue(); mTvContent.setMaxHeight(animatedValue - mMarginBetweenTxtAndBottom); getLayoutParams().height = animatedValue; requestLayout(); } }); valueAnimator.addListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animator) { } @Override public void onAnimationEnd(Animator animator) { // ?????? /// clear the animation flag mAnimating = false; // notify the listener if (mListener != null) { mListener.onExpandStateChanged(mTvContent, !mCollapsed); } } @Override public void onAnimationCancel(Animator animator) { } @Override public void onAnimationRepeat(Animator animator) { } }); valueAnimator.setDuration(mAnimationDuration); valueAnimator.start(); }