Example usage for android.animation ValueAnimator addUpdateListener

List of usage examples for android.animation ValueAnimator addUpdateListener

Introduction

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

Prototype

public void addUpdateListener(AnimatorUpdateListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent update events through the life of an animation.

Usage

From source file:com.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE ?
        final int viewHeight = -mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {//from   w w  w  . j a va  2s .  co  m
            mView.setTranslationY(viewHeight);
        }

        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @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 = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_in);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.github.shareme.gwsinkpageindicator.library.InkPageIndicator.java

private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) {

    // create the actual move animator
    ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);

    // also set up a pending retreat anim  this starts when the move is 75% complete
    retreatAnimation = new PendingRetreatAnimator(was, now, steps,
            now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f))
                    : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
    retreatAnimation.addListener(new AnimatorListenerAdapter() {
        @Override//from  w  w w  .j a  va  2s  . c o m
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // todo avoid autoboxing
            selectedDotX = (Float) valueAnimator.getAnimatedValue();
            retreatAnimation.startIfNecessary(selectedDotX);
            postInvalidateOnAnimation();
        }
    });
    moveSelected.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            // set a flag so that we continue to draw the unselected dot in the target position
            // until the selected dot has finished moving into place
            selectedDotInPosition = false;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // set a flag when anim finishes so that we don't draw both selected & unselected
            // page dots
            selectedDotInPosition = true;
        }
    });
    // slightly delay the start to give the joins a chance to run
    // unless dot isn't in position yet  then don't delay!
    moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l);
    moveSelected.setDuration(animDuration * 3l / 4l);
    moveSelected.setInterpolator(interpolator);
    return moveSelected;
}

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  ww w  . j  a  v  a  2  s .co  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   w w  w.j a  va2s  .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) {
    /*//from w  ww.  j  a  v a  2  s . co  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  . co m*/
        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// www. j a va 2  s .  com
        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.xelitexirish.scammerbingo.ui.widget.InkPageIndicator.java

private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) {

    // create the actual move animator
    ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);

    // also set up a pending retreat anim  this starts when the move is 75% complete
    retreatAnimation = new PendingRetreatAnimator(was, now, steps,
            now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f))
                    : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
    retreatAnimation.addListener(new AnimatorListenerAdapter() {
        @Override/* www.j  a v a 2 s  .  c  o m*/
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // todo avoid autoboxing
            selectedDotX = (Float) valueAnimator.getAnimatedValue();
            retreatAnimation.startIfNecessary(selectedDotX);
            ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
        }
    });
    moveSelected.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            // set a flag so that we continue to draw the unselected dot in the target position
            // until the selected dot has finished moving into place
            selectedDotInPosition = false;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // set a flag when anim finishes so that we don't draw both selected & unselected
            // page dots
            selectedDotInPosition = true;
        }
    });
    // slightly delay the start to give the joins a chance to run
    // unless dot isn't in position yet  then don't delay!
    moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4L : 0L);
    moveSelected.setDuration(animDuration * 3L / 4L);
    moveSelected.setInterpolator(interpolator);
    return moveSelected;
}

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  w  w w.  j av a2  s  .c  o  m*/
            }

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

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  ww. j a va  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+
}