Example usage for android.animation ValueAnimator ValueAnimator

List of usage examples for android.animation ValueAnimator ValueAnimator

Introduction

In this page you can find the example usage for android.animation ValueAnimator ValueAnimator.

Prototype

public ValueAnimator() 

Source Link

Document

Creates a new ValueAnimator object.

Usage

From source file:com.jaydenxiao.androidfire.ui.zone.widget.ExpandableTextView.java

/**
 * /*w w w. jav  a2 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(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();
}

From source file:com.waz.zclient.utils.ViewUtils.java

public static void fadeInView(@Nullable final View view) {
    fadeInView(view, 1, new ValueAnimator().getDuration(), 0);
}

From source file:com.waz.zclient.utils.ViewUtils.java

public static void fadeOutView(@Nullable final View view, boolean setToGoneWithEndAction) {
    fadeOutView(view, new ValueAnimator().getDuration(), 0, setToGoneWithEndAction);
}

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 ww w  .ja v a2s . c  o m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            setColors((Integer) valueAnimator.getAnimatedValue());
        }
    });

    anim.setDuration(150);
    anim.start();
}

From source file:com.lixplor.rocketpulltorefresh.RefreshLayout.java

/**
 * Perform header view shrink back animation
 * @param from animation start Y px/*w  w w.j  a  v  a 2  s  .c  o m*/
 * @param to animation stop Y px
 */
private void animHeader(int from, final int to) {
    if (mHeaderBackAnimator == null) {
        mHeaderBackAnimator = new ValueAnimator();
        mHeaderBackAnimator.setDuration(mBackAnimDuration);
        mHeaderBackAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int destY = (int) animation.getAnimatedValue();
                scrollTo(0, destY);
                if (destY == 0) {
                    // when back finished, reset header
                    mCurrentState = STATE_PULL_DOWN_TO_REFRESH;
                    mAbsHeader.reset();
                }
            }
        });
        mHeaderBackAnimator.setTarget(this);
    }
    mHeaderBackAnimator.setIntValues(from, to);
    mHeaderBackAnimator.start();
}

From source file:com.advaitaworld.widgets.SlidingTabLayout.java

private void updateTitleColors(int prevSelectedPosition, int newSelectedPosition) {
    if (mSelectedTabColor == 0 && mDefaultTabColor == 0) {
        return;/*from w  ww .  ja v  a  2 s .co  m*/
    }
    View tabViewPrev = mTabStrip.getChildAt(prevSelectedPosition);
    View tabViewNew = mTabStrip.getChildAt(newSelectedPosition);
    final TextView tabTitlePrev = getTabTitleView(tabViewPrev);
    final TextView tabTitleNew = getTabTitleView(tabViewNew);

    ArgbEvaluator evaluator = new ArgbEvaluator();
    ValueAnimator anim1 = new ValueAnimator();
    anim1.setIntValues(mDefaultTabColor, mSelectedTabColor);
    anim1.setEvaluator(evaluator);
    anim1.setDuration(300);
    anim1.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            tabTitleNew.setTextColor((Integer) valueAnimator.getAnimatedValue());
        }
    });

    ValueAnimator anim2 = new ValueAnimator();
    anim2.setIntValues(mSelectedTabColor, mDefaultTabColor);
    anim2.setEvaluator(evaluator);
    anim2.setDuration(300);
    anim2.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            tabTitlePrev.setTextColor((Integer) valueAnimator.getAnimatedValue());
        }
    });

    anim1.start();
    anim2.start();
}

From source file:com.lixplor.rocketpulltorefresh.RefreshLayout.java

/**
 * Perform footer view shrink back animation
 * @param from animation start Y px//w w w  . ja  v  a2 s .co m
 * @param to animation stop Y px
 */
private void animFooter(int from, int to) {
    if (mFooterBackAnimator == null) {
        mFooterBackAnimator = new ValueAnimator();
        mFooterBackAnimator.setDuration(mBackAnimDuration);
        mFooterBackAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                int destY = (int) animation.getAnimatedValue();
                scrollTo(0, destY);
                if (destY == 0) {
                    // when back finished, reset footer
                    mCurrentState = STATE_PULL_UP_TO_LOAD;
                    mAbsFooter.reset();
                }
            }
        });
        mFooterBackAnimator.setTarget(this);
    }
    mFooterBackAnimator.setIntValues(from, to);
    mFooterBackAnimator.start();
}

From source file:com.commonsware.cwac.crossport.design.widget.FloatingActionButtonImpl.java

private ValueAnimator createAnimator(@NonNull ShadowAnimatorImpl impl) {
    final ValueAnimator animator = new ValueAnimator();
    animator.setInterpolator(ANIM_INTERPOLATOR);
    animator.setDuration(PRESSED_ANIM_DURATION);
    animator.addListener(impl);/*from  www  .  jav a 2s  .com*/
    animator.addUpdateListener(impl);
    animator.setFloatValues(0, 1);
    return animator;
}

From source file:org.odk.collect.android.views.ODKView.java

public void highlightWidget(FormIndex formIndex) {
    QuestionWidget qw = getQuestionWidget(formIndex);

    if (qw != null) {
        // postDelayed is needed because otherwise scrolling may not work as expected in case when
        // answers are validated during form finalization.
        new Handler().postDelayed(() -> {
            findViewById(R.id.odk_view_container).scrollTo(0, qw.getTop());

            ValueAnimator va = new ValueAnimator();
            if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT) {
                va.setIntValues(getResources().getColor(R.color.red_500), getDrawingCacheBackgroundColor());
            } else {
                // Avoid fading to black on certain devices and Android versions that may not support transparency
                TypedValue typedValue = new TypedValue();
                getContext().getTheme().resolveAttribute(android.R.attr.windowBackground, typedValue, true);
                if (typedValue.type >= TypedValue.TYPE_FIRST_COLOR_INT
                        && typedValue.type <= TypedValue.TYPE_LAST_COLOR_INT) {
                    va.setIntValues(getResources().getColor(R.color.red_500), typedValue.data);
                } else {
                    va.setIntValues(getResources().getColor(R.color.red_500), getDrawingCacheBackgroundColor());
                }/*from ww w  . j a v a  2 s  .  co m*/
            }

            va.setEvaluator(new ArgbEvaluator());
            va.addUpdateListener(
                    valueAnimator -> qw.setBackgroundColor((int) valueAnimator.getAnimatedValue()));
            va.setDuration(2500);
            va.start();
        }, 100);
    }
}

From source file:io.digibyte.tools.animation.BRAnimator.java

public static void animateBackgroundDim(final ViewGroup backgroundLayout, boolean reverse) {
    int transColor = reverse ? R.color.black_trans : android.R.color.transparent;
    int blackTransColor = reverse ? android.R.color.transparent : R.color.black_trans;

    ValueAnimator anim = new ValueAnimator();
    anim.setIntValues(transColor, blackTransColor);
    anim.setEvaluator(new ArgbEvaluator());
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from   w  w w.ja  v  a 2 s.  c  om
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            backgroundLayout.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
        }
    });

    anim.setDuration(SLIDE_ANIMATION_DURATION);
    anim.start();
}