Example usage for android.animation ValueAnimator setRepeatCount

List of usage examples for android.animation ValueAnimator setRepeatCount

Introduction

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

Prototype

public void setRepeatCount(int value) 

Source Link

Document

Sets how many times the animation should be repeated.

Usage

From source file:org.mythtv.client.ui.BackendStatusFragment.java

private void animateCardLinearLayout(final LinearLayout linearLayout, long startDelay) {
    linearLayout.setAlpha(1);//from   w ww .j  ava 2s. c  o m

    // animator that translates linearlayout
    AnimatorUpdateListener translationAnimatorListener = new AnimatorUpdateListener() {

        /* (non-Javadoc)
         * @see android.animation.ValueAnimator.AnimatorUpdateListener#onAnimationUpdate(android.animation.ValueAnimator)
         */
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            Float w = (Float) animation.getAnimatedValue();
            linearLayout.setTranslationY(w);
        }

    };

    ValueAnimator scaleAnimator = ValueAnimator.ofFloat(linearLayout.getTranslationY(), 0f);
    scaleAnimator.setDuration(500);
    scaleAnimator.setRepeatCount(0);
    scaleAnimator.setStartDelay(startDelay);
    scaleAnimator.addUpdateListener(translationAnimatorListener);

    scaleAnimator.start();
}

From source file:com.nihaskalam.progressbuttonlibrary.CircularProgressButton.java

private void animateIdleStateButtonAfterClick() {
    int textColorChangeDuration = 10;
    ObjectAnimator colorAnim = ObjectAnimator.ofInt(this, "textColor", getNormalColor(this.getTextColors()),
            mIdleStateTextColorAfterClick);
    colorAnim.setDuration(textColorChangeDuration);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.start();//from  w w w . j  a v  a  2s . c o m

    ObjectAnimator colorAnim1 = ObjectAnimator.ofInt(this, "textColor", mIdleStateTextColorAfterClick,
            getNormalColor(this.getTextColors()));
    colorAnim1.setDuration(0);
    colorAnim1.setStartDelay(IDLE_STATE_ANIMATION_DURATION_AFTER_CLICK - textColorChangeDuration);
    colorAnim1.setEvaluator(new ArgbEvaluator());
    colorAnim1.setInterpolator(new BounceInterpolator());
    colorAnim1.start();

    ObjectAnimator bgAnim = ObjectAnimator.ofInt(this, "backgroundColor", getNormalColor(mIdleColorState),
            mIdleStateBackgroundColorAfterClick);
    bgAnim.setDuration(0);
    bgAnim.setEvaluator(new ArgbEvaluator());
    bgAnim.start();

    int textSizeAnimationDuration = 150;
    ValueAnimator animator = ValueAnimator.ofFloat(textSize, textSize - textSize / 4);
    animator.setDuration(textSizeAnimationDuration);
    animator.setRepeatCount(1);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            setTextSize(animatedValue);
        }
    });

    animator.start();
}

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.
 *//*from   w  ww . j a  v  a  2  s  .  co  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   w w  w. j  av  a2  s.  c  o  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;
}