Example usage for android.animation ValueAnimator RESTART

List of usage examples for android.animation ValueAnimator RESTART

Introduction

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

Prototype

int RESTART

To view the source code for android.animation ValueAnimator RESTART.

Click Source Link

Document

When the animation reaches the end and repeatCount is INFINITE or a positive value, the animation restarts from the beginning.

Usage

From source file:io.github.sin3hz.wifispinnerview.WifiSpinnerDrawable.java

private void setupAnimators() {
    AnimatorSet set = new AnimatorSet();
    for (int i = 0; i < mSpinnerCount; i++) {
        final int index = i;
        final ValueAnimator sweepAnimator = ValueAnimator.ofFloat(0, MAX_SWEEP_ANGLE);
        sweepAnimator.setInterpolator(SWEEP_ANIMATOR_INTERPOLATOR);
        sweepAnimator.setDuration(mSweepAnimatorDuration);
        sweepAnimator.setRepeatMode(ValueAnimator.RESTART);
        sweepAnimator.setRepeatCount(ValueAnimator.INFINITE);
        sweepAnimator.setStartDelay(index * SWEEP_ANIMATOR_DELAY);
        sweepAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override//  w  ww .  j  ava2  s  . co  m
            public void onAnimationUpdate(ValueAnimator animation) {
                mSpinners[index].sweepAngle = (float) animation.getAnimatedValue();
                mSpinners[index].updatePath();
                invalidateSelf();
            }
        });
        sweepAnimator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationRepeat(Animator animation) {
                mSpinners[index].sweepAngleOffset = (mSpinners[index].sweepAngleOffset + MAX_SWEEP_ANGLE) % 360;
                mSpinners[index].updatePath();
            }
        });
        set.playTogether(sweepAnimator);
    }
    mSweepAnimator = set;

    mAngleAnimator = ValueAnimator.ofFloat(0, 360);
    mAngleAnimator.setInterpolator(ANGLE_ANIMATOR_INTERPOLATOR);
    mAngleAnimator.setRepeatCount(ValueAnimator.INFINITE);
    mAngleAnimator.setRepeatMode(ValueAnimator.RESTART);
    mAngleAnimator.setDuration(ANGLE_ANIMATOR_DURATION);
    mAngleAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mGlobalAngle = (float) animation.getAnimatedValue();
            updatePath();
            invalidateSelf();
        }
    });
}

From source file:com.arsy.maps_library.MapRipple.java

private void startAnimation(final int numberOfRipple) {
    ValueAnimator animator = ValueAnimator.ofInt(0, (int) mDistance);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setDuration(mRippleDuration);
    animator.setEvaluator(new IntEvaluator());
    animator.setInterpolator(new LinearInterpolator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from ww w .j  a v a2s. co  m*/
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int animated = (int) valueAnimator.getAnimatedValue();
            mGroundOverlays[numberOfRipple].setDimensions(animated);
            if (mDistance - animated <= 10) {
                if (mLatLng != mPrevLatLng) {
                    mGroundOverlays[numberOfRipple].setPosition(mLatLng);
                }
            }
        }
    });
    animator.start();
    mAnimators[numberOfRipple] = animator;
}

From source file:ch.berta.fabio.fabprogress.FabProgress.java

private void setupRotateAnimation() {
    mRotateAnim = ValueAnimator.ofFloat(0f, 360f);
    mRotateAnim.setInterpolator(LINEAR_INTERPOLATOR);
    mRotateAnim.setDuration(ROTATE_ANIMATOR_DURATION);
    mRotateAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from   w w w. j av  a 2s  . co m
        public void onAnimationUpdate(ValueAnimator animation) {
            float angle = getAnimatedFraction(animation) * 360f;
            updateCurrentRotationAngle(angle);
        }
    });
    mRotateAnim.setRepeatCount(ValueAnimator.INFINITE);
    mRotateAnim.setRepeatMode(ValueAnimator.RESTART);
}

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

/**
 * @param anim                The animator, must not be null
 * @param arrayAnimator       Incoming typed array for Animator's attributes.
 * @param arrayObjectAnimator Incoming typed array for Object Animator's
 *                            attributes.
 * @param pixelSize           The relative pixel size, used to calculate the
 *                            maximum error for path animations.
 *//* w  w w.j a va 2  s  .  c o m*/
private static void parseAnimatorFromTypeArray(ValueAnimator anim, TypedArray arrayAnimator,
        TypedArray arrayObjectAnimator, float pixelSize, XmlPullParser parser) {
    long duration = TypedArrayUtils.getNamedInt(arrayAnimator, parser, "duration",
            AndroidResources.STYLEABLE_ANIMATOR_DURATION, 300);
    long startDelay = TypedArrayUtils.getNamedInt(arrayAnimator, parser, "startOffset",
            AndroidResources.STYLEABLE_ANIMATOR_START_OFFSET, 0);
    int valueType = TypedArrayUtils.getNamedInt(arrayAnimator, parser, "valueType",
            AndroidResources.STYLEABLE_ANIMATOR_VALUE_TYPE, VALUE_TYPE_UNDEFINED);

    // Change to requiring both value from and to, otherwise, throw exception for now.
    if (TypedArrayUtils.hasAttribute(parser, "valueFrom") && TypedArrayUtils.hasAttribute(parser, "valueTo")) {
        if (valueType == VALUE_TYPE_UNDEFINED) {
            valueType = inferValueTypeFromValues(arrayAnimator, AndroidResources.STYLEABLE_ANIMATOR_VALUE_FROM,
                    AndroidResources.STYLEABLE_ANIMATOR_VALUE_TO);
        }
        PropertyValuesHolder pvh = getPVH(arrayAnimator, valueType,
                AndroidResources.STYLEABLE_ANIMATOR_VALUE_FROM, AndroidResources.STYLEABLE_ANIMATOR_VALUE_TO,
                "");
        if (pvh != null) {
            anim.setValues(pvh);
        }
    }
    anim.setDuration(duration);
    anim.setStartDelay(startDelay);

    anim.setRepeatCount(TypedArrayUtils.getNamedInt(arrayAnimator, parser, "repeatCount",
            AndroidResources.STYLEABLE_ANIMATOR_REPEAT_COUNT, 0));
    anim.setRepeatMode(TypedArrayUtils.getNamedInt(arrayAnimator, parser, "repeatMode",
            AndroidResources.STYLEABLE_ANIMATOR_REPEAT_MODE, ValueAnimator.RESTART));

    if (arrayObjectAnimator != null) {
        setupObjectAnimator(anim, arrayObjectAnimator, valueType, pixelSize, parser);
    }
}

From source file:com.gu.swiperefresh.ProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final ValueAnimator animator = ObjectAnimator.ofFloat(0f, 1f);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//from ww  w  . j a  v a 2 s . co  m
        public void onAnimationUpdate(ValueAnimator animation) {
            float interpolatedTime = Float.valueOf(animation.getAnimatedValue().toString());
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float endTrim = startingEndTrim
                            + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setEndTrim(endTrim);
                }

                final float rotation = startingRotation + (0.25f * interpolatedTime);
                ring.setRotation(rotation);

                float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime)
                        + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
                setRotation(groupRotation);
            }
        }
    });
    animator.setRepeatCount(Animation.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setInterpolator(LINEAR_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

        }

        @Override
        public void onAnimationStart(Animator animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
            }
        }
    });
    mAnimation = animator;
}

From source file:com.lovejjfg.demo.TouchCircleView.java

private void setupAnimations() {

    mObjectAnimatorAngle = ObjectAnimator.ofFloat(this, mAngleProperty, mCurrentGlobalAngle, 360f);
    mObjectAnimatorAngle.setInterpolator(ANGLE_INTERPOLATOR);
    mObjectAnimatorAngle.setDuration(ANGLE_ANIMATOR_DURATION);
    mObjectAnimatorAngle.setRepeatMode(ValueAnimator.RESTART);
    mObjectAnimatorAngle.setRepeatCount(ValueAnimator.INFINITE);
    mObjectAnimatorAngle.addListener(new AnimatorListenerAdapter() {
        @Override//from w  w w.  j av a 2s.c  om
        public void onAnimationRepeat(Animator animation) {
            mObjectAnimatorAngle.setFloatValues(360f);
        }
    });

    mObjectAnimatorSweep = ObjectAnimator.ofFloat(this, mSweepProperty, mCurrentSweepAngle,
            360f - MIN_SWEEP_ANGLE * 2);
    mObjectAnimatorSweep.setInterpolator(SWEEP_INTERPOLATOR);
    mObjectAnimatorSweep.setDuration(SWEEP_ANIMATOR_DURATION);
    mObjectAnimatorSweep.setRepeatMode(ValueAnimator.RESTART);
    mObjectAnimatorSweep.setRepeatCount(ValueAnimator.INFINITE);
    mObjectAnimatorSweep.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationRepeat(Animator animation) {
            mObjectAnimatorSweep.setFloatValues(360f - MIN_SWEEP_ANGLE * 2);
            toggleAppearingMode();
        }
    });

    fractionAnimator = ValueAnimator.ofInt(0, ALPHA_FULL);
    fractionAnimator.setInterpolator(ANGLE_INTERPOLATOR);
    fractionAnimator.setDuration(FRACTION_DURATION);
    fractionAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            fraction = animation.getAnimatedFraction();
            mHookPaint.setAlpha((Integer) animation.getAnimatedValue());
            invalidate();
        }
    });
    fractionAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mRunning = false;
            postDelayed(idleAction, 0);
        }
    });
    translateAnimator = ValueAnimator.ofFloat(0, 100);
    translateAnimator.setInterpolator(ANGLE_INTERPOLATOR);
    translateAnimator.setDuration(200);
    translateAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        private float tranlateFraction;

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Float animatedValue = (Float) animation.getAnimatedValue();
            updateState(STATE_TRANSLATE_PATH, false);
            tranlateFraction = animation.getAnimatedFraction();
            if (!isBack) {
                mixPaint.setColor(ColorUtils.blendARGB(Color.RED, Color.GREEN, tranlateFraction));
                mCurrentRadius = (int) (outCirRadius + tranlateFraction * (secondRadius - outCirRadius));
            } else {
                mixPaint.setColor(ColorUtils.blendARGB(Color.GREEN, Color.RED, tranlateFraction));
                mCurrentRadius = (int) (secondRadius - tranlateFraction * (secondRadius - outCirRadius));
            }
            mCurrentPaint = mixPaint;
            resetPoints(secondRectf.centerX(), animatedValue);
            invalidate();
        }
    });
    translateAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            updateState(isBack ? STATE_DRAW_ARROW : abortReset ? STATE_DRAW_BACK : STATE_DRAW_CIRCLE,
                    abortReset);

            updateRectF();
            invalidate();
        }
    });
}