Example usage for android.animation ValueAnimator getAnimatedValue

List of usage examples for android.animation ValueAnimator getAnimatedValue

Introduction

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

Prototype

public Object getAnimatedValue() 

Source Link

Document

The most recent value calculated by this ValueAnimator when there is just one property being animated.

Usage

From source file:de.dreier.mytargets.views.MaterialTapTargetPrompt.java

@TargetApi(11)
private void startIdleAnimations() {
    if (mAnimationCurrent != null) {
        mAnimationCurrent.removeAllUpdateListeners();
        mAnimationCurrent.cancel();//from   w  w  w  .j a  v a  2  s  .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));
        }
    });
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

/**
 * Set the thumb to be in the pressed state and calls invalidate() to redraw
 * the canvas to reflect the updated state.
 *
 * @param thumb the thumb to press//from   w w  w  .ja va  2 s. c  o m
 */
private void pressPin(final PinView thumb) {
    if (mArePinsTemporary) {
        ValueAnimator animator = ValueAnimator.ofFloat(0, mExpandedPinRadius);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mPinRadius = (Float) animation.getAnimatedValue();
                thumb.setSize(mPinRadius, mPinPadding * animation.getAnimatedFraction());
                invalidate();
            }
        });
        animator.start();
        thumb.press();
    } else {
        thumb.setSize(mExpandedPinRadius, mPinPadding);
    }
}

From source file:com.dgmltn.ranger.internal.AbsRangeBar.java

/**
 * Set the thumb to be in the normal/un-pressed state and calls invalidate()
 * to redraw the canvas to reflect the updated state.
 *
 * @param pinView the thumb to release/*from   ww w .  j a va  2  s  . co m*/
 */
private void releasePin(final PinView pinView) {
    PointF point = new PointF();
    getNearestIndexPosition(pinView.getPosition(), point);
    pinView.setPosition(point);
    int tickIndex = getNearestIndex(pinView);

    pinView.setLabel(getPinLabel(tickIndex));

    if (mArePinsTemporary) {
        ValueAnimator animator = ValueAnimator.ofFloat(mExpandedPinRadius, 0);
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mPinRadius = (Float) (animation.getAnimatedValue());
                pinView.setSize(mPinRadius, mPinPadding - (mPinPadding * animation.getAnimatedFraction()));
                invalidate();
            }
        });
        animator.start();
        pinView.release();
    } else {
        invalidate();
    }
}

From source file:io.authme.sdk.widget.LockPatternView.java

private void startLineEndAnimation(final CellState state, final float startX, final float startY,
        final float targetX, final float targetY) {
    /*/* w  ww. ja  v a  2  s.c o  m*/
     * Currently this animation looks unclear, we don't really need it...
     */
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        return;

    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float t = (Float) animation.getAnimatedValue();
            state.lineEndX = (1 - t) * startX + t * targetX;
            state.lineEndY = (1 - t) * startY + t * targetY;
            invalidate();
        }

    });
    valueAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            state.lineAnimator = null;
        }

    });
    valueAnimator.setInterpolator(mFastOutSlowInInterpolator);
    valueAnimator.setDuration(100);
    valueAnimator.start();
    state.lineAnimator = valueAnimator;
}

From source file:com.android.nobug.view.pattern.PatternView.java

private void startLineEndAnimation(final CellState state, final float startX, final float startY,
        final float targetX, final float targetY) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0, 1);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   w w w .  j  av a 2  s. com*/
        public void onAnimationUpdate(ValueAnimator animation) {
            float t = (float) animation.getAnimatedValue();
            state.lineEndX = (1 - t) * startX + t * targetX;
            state.lineEndY = (1 - t) * startY + t * targetY;
            invalidate();
        }
    });
    valueAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            state.lineAnimator = null;
        }
    });
    valueAnimator.setInterpolator(mFastOutSlowInInterpolator);
    valueAnimator.setDuration(100);
    valueAnimator.start();
    state.lineAnimator = valueAnimator;
}

From source file:com.android.nobug.view.pattern.PatternView.java

private void startRadiusAnimation(float start, float end, long duration, Interpolator interpolator,
        final CellState state, final Runnable endRunnable) {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(start, end);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from  ww  w.  j a v  a  2s .  c  om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            state.radius = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    if (endRunnable != null) {
        valueAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                endRunnable.run();
            }
        });
    }
    valueAnimator.setInterpolator(interpolator);
    valueAnimator.setDuration(duration);
    valueAnimator.start();
}

From source file:com.android.nobug.view.pattern.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;// ww  w  .  j  ava2 s. com
    cellState.translationY = startTranslationY;
    cellState.radius = mDotSize / 2 * 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 = mDotSize / 2 * ((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.klinker.android.sliding.MultiShrinkScroller.java

public void runExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {/*from w  ww.j a v  a2 s.co m*/
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(expansionViewHeight, getHeight());
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(expansionViewWidth, getWidth());
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, expansionLeftOffset, 0f);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, expansionTopOffset, 0f);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.start();
}

From source file:io.authme.sdk.widget.LockPatternView.java

private void startSizeAnimation(float start, float end, long duration, Interpolator interpolator,
        final CellState state, final Runnable endRunnable) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        FloatAnimator animator = new FloatAnimator(start, end, duration);
        animator.addEventListener(new FloatAnimator.SimpleEventListener() {

            @Override/*from  w w w . j a  v a  2 s .c om*/
            public void onAnimationUpdate(FloatAnimator animator) {
                state.size = (Float) animator.getAnimatedValue();
                invalidate();
            }// onAnimationUpdate()

            @Override
            public void onAnimationEnd(FloatAnimator animator) {
                if (endRunnable != null)
                    endRunnable.run();
            }// onAnimationEnd()

        });
        animator.start();
    } // API < 11
    else {
        ValueAnimator valueAnimator = ValueAnimator.ofFloat(start, end);
        valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                state.size = (Float) animation.getAnimatedValue();
                invalidate();
            }

        });
        if (endRunnable != null) {
            valueAnimator.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (endRunnable != null)
                        endRunnable.run();
                }

            });
        }
        valueAnimator.setInterpolator(interpolator);
        valueAnimator.setDuration(duration);
        valueAnimator.start();
    } // API 11+
}

From source file:com.klinker.android.sliding.MultiShrinkScroller.java

public void reverseExpansionAnimation() {

    final Interpolator interpolator;

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        interpolator = AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.linear_out_slow_in);
    } else {//w w w  .  j  a va2s.  com
        interpolator = new DecelerateInterpolator();
    }

    WindowManager wm = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    Display display = wm.getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    int screenHeight = size.y;
    int screenWidth = size.x;

    final ValueAnimator heightExpansion = ValueAnimator.ofInt(screenHeight, expansionViewHeight);
    heightExpansion.setInterpolator(interpolator);
    heightExpansion.setDuration(ANIMATION_DURATION);
    heightExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.height = val;
            setLayoutParams(params);
        }
    });
    heightExpansion.start();

    final ValueAnimator widthExpansion = ValueAnimator.ofInt(getWidth(), expansionViewWidth);
    widthExpansion.setInterpolator(interpolator);
    widthExpansion.setDuration(ANIMATION_DURATION);
    widthExpansion.addUpdateListener(new AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            int val = (int) animation.getAnimatedValue();

            ViewGroup.LayoutParams params = getLayoutParams();
            params.width = val;
            setLayoutParams(params);
        }
    });
    widthExpansion.start();

    ObjectAnimator translationX = ObjectAnimator.ofFloat(this, View.TRANSLATION_X, 0f, expansionLeftOffset);
    translationX.setInterpolator(interpolator);
    translationX.setDuration(ANIMATION_DURATION);
    translationX.start();

    ObjectAnimator translationY = ObjectAnimator.ofFloat(this, View.TRANSLATION_Y, 0f, expansionTopOffset);
    translationY.setInterpolator(interpolator);
    translationY.setDuration(ANIMATION_DURATION);
    translationY.addListener(exitAnimationListner);
    translationY.start();
}