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:chao.widget.tablayout.TabLayout.java

/**
 *
 */
private ValueAnimator createAnimator() {
    return new ValueAnimator();
}

From source file:org.xjy.android.nova.widget.ColorTabLayout.java

private void animateToTab(int newPosition) {
    if (newPosition == Tab.INVALID_POSITION) {
        return;/*from   w ww  .j a  va2s  .  c  o m*/
    }

    if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || mTabStrip.childrenNeedLayout()) {
        // If we don't have a window token, or we haven't been laid out yet just draw the new
        // position now
        setScrollPosition(newPosition, 0f, true);
        return;
    }

    final int startScrollX = getScrollX();
    final int targetScrollX = calculateScrollXForTab(newPosition, 0);

    if (startScrollX != targetScrollX) {
        if (mScrollAnimator == null) {
            mScrollAnimator = new ValueAnimator();
            mScrollAnimator.setInterpolator(new FastOutSlowInInterpolator());
            mScrollAnimator.setDuration(ANIMATION_DURATION);
            mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    scrollTo((Integer) animation.getAnimatedValue(), 0);
                }
            });
        }

        mScrollAnimator.setIntValues(startScrollX, targetScrollX);
        mScrollAnimator.start();
    }

    // Now animate the indicator
    mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION);
}

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

private void ensureScrollAnimator() {
    if (mScrollAnimator == null) {
        mScrollAnimator = new ValueAnimator();
        mScrollAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        mScrollAnimator.setDuration(ANIMATION_DURATION);
        mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override// w  w  w  .j  av a 2  s. c o  m
            public void onAnimationUpdate(ValueAnimator animator) {
                scrollTo((int) animator.getAnimatedValue(), 0);
            }
        });
    }
}

From source file:android.support.design.widget.RaeTabLayout.java

private void animateToTab(int newPosition) {
    if (newPosition == Tab.INVALID_POSITION) {
        return;//from   w  w  w  .j  ava 2  s  .c  o m
    }

    if (getWindowToken() == null || !ViewCompat.isLaidOut(this) || mTabStrip.childrenNeedLayout()) {
        // If we don't have a window token, or we haven't been laid out yet just draw the new
        // position now
        setScrollPosition(newPosition, 0f, true);
        return;
    }

    final int startScrollX = getScrollX();
    final int targetScrollX = calculateScrollXForTab(newPosition, 0);

    if (startScrollX != targetScrollX) {
        if (this.mScrollAnimator == null) {
            this.mScrollAnimator = new ValueAnimator();
            this.mScrollAnimator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
            this.mScrollAnimator.setDuration(300L);
            this.mScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                public void onAnimationUpdate(ValueAnimator animator) {
                    scrollTo(((Integer) animator.getAnimatedValue()).intValue(), 0);
                }
            });
        }

        mScrollAnimator.setIntValues(startScrollX, targetScrollX);
        mScrollAnimator.start();
    }

    // Now animate the indicator
    mTabStrip.animateIndicatorToPosition(newPosition, ANIMATION_DURATION);
}

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  .j a 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:ticwear.design.widget.CoordinatorLayout.java

private void animateScrollingOffsetTo(final int offset) {
    final int currentOffset = getUnconsumedScrollingOffset();

    if (currentOffset == offset) {
        if (mAnimator != null && mAnimator.isRunning()) {
            mAnimator.cancel();//from   w  w w. j  a  va  2  s  . c  o  m
        }
        return;
    }

    if (mAnimator == null) {
        mAnimator = new ValueAnimator();
        mAnimator.setInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);
        mAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int offset = (int) animator.getAnimatedValue();
                setScrollingOffset(offset);
            }
        });
    } else {
        mAnimator.cancel();
    }

    mAnimator.setDuration(getResources().getInteger(android.R.integer.config_shortAnimTime));

    mAnimator.setIntValues(currentOffset, offset);
    mAnimator.start();
}

From source file:cc.flydev.launcher.Page.java

public void onFlingToDelete(PointF vel) {
    final long startTime = AnimationUtils.currentAnimationTimeMillis();

    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {
        private int mCount = -1;
        private long mStartTime;
        private float mOffset;
        /* Anonymous inner class ctor */ {
            mStartTime = startTime;/*w w w  . jav  a 2 s .  co  m*/
        }

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime)
                        / FLING_TO_DELETE_FADE_OUT_DURATION);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };

    final Rect from = new Rect();
    final View dragView = mDragView;
    from.left = (int) dragView.getTranslationX();
    from.top = (int) dragView.getTranslationY();
    AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime,
            FLING_TO_DELETE_FRICTION);

    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);

    // Create and start the animation
    ValueAnimator mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(tInterpolator);
    mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    mDropAnim.start();
    mDeferringForDelete = true;
}

From source file:saftyos.android.launcher3.Page.java

public void onFlingToDelete(PointF vel) {
    final long startTime = AnimationUtils.currentAnimationTimeMillis();

    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {
        private int mCount = -1;
        private long mStartTime;
        private float mOffset;

        /* Anonymous inner class ctor */ {
            mStartTime = startTime;//from w w w. j  a v  a 2 s . c  om
        }

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime)
                        / FLING_TO_DELETE_FADE_OUT_DURATION);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };

    final Rect from = new Rect();
    final View dragView = mDragView;
    from.left = (int) dragView.getTranslationX();
    from.top = (int) dragView.getTranslationY();
    AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime,
            FLING_TO_DELETE_FRICTION);

    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);

    // Create and start the animation
    ValueAnimator mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(tInterpolator);
    mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    mDropAnim.start();
    mDeferringForDelete = true;
}

From source file:com.n2hsu.launcher.Page.java

public void onFlingToDelete(PointF vel) {
    final long startTime = AnimationUtils.currentAnimationTimeMillis();

    // NOTE: Because it takes time for the first frame of animation to
    // actually be
    // called and we expect the animation to be a continuation of the fling,
    // we have//w w  w . j av  a  2 s .c o m
    // to account for the time that has elapsed since the fling finished.
    // And since
    // we don't have a startDelay, we will always get call to update when we
    // call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {
        private int mCount = -1;
        private long mStartTime;
        private float mOffset;
        /* Anonymous inner class ctor */ {
            mStartTime = startTime;
        }

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - mStartTime)
                        / FLING_TO_DELETE_FADE_OUT_DURATION);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };

    final Rect from = new Rect();
    final View dragView = mDragView;
    from.left = (int) dragView.getTranslationX();
    from.top = (int) dragView.getTranslationY();
    AnimatorUpdateListener updateCb = new FlingAlongVectorAnimatorUpdateListener(dragView, vel, from, startTime,
            FLING_TO_DELETE_FRICTION);

    final Runnable onAnimationEndRunnable = createPostDeleteAnimationRunnable(dragView);

    // Create and start the animation
    ValueAnimator mDropAnim = new ValueAnimator();
    mDropAnim.setInterpolator(tInterpolator);
    mDropAnim.setDuration(FLING_TO_DELETE_FADE_OUT_DURATION);
    mDropAnim.setFloatValues(0f, 1f);
    mDropAnim.addUpdateListener(updateCb);
    mDropAnim.addListener(new AnimatorListenerAdapter() {
        public void onAnimationEnd(Animator animation) {
            onAnimationEndRunnable.run();
        }
    });
    mDropAnim.start();
    mDeferringForDelete = true;
}