Java Code Examples for android.animation.ValueAnimator#setRepeatMode()

The following examples show how to use android.animation.ValueAnimator#setRepeatMode() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java    From journaldev with MIT License 6 votes vote down vote up
private ValueAnimator animatePointer(long orbitDuration) {
    ValueAnimator anim = ValueAnimator.ofInt(0, 359);

    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int val = (Integer) valueAnimator.getAnimatedValue();
            ConstraintLayout.LayoutParams layoutParams = (ConstraintLayout.LayoutParams) imgPointer.getLayoutParams();
            layoutParams.circleAngle = val;
            imgPointer.setLayoutParams(layoutParams);
        }
    });
    anim.setDuration(orbitDuration);
    anim.setInterpolator(new LinearInterpolator());
    anim.setRepeatMode(ValueAnimator.RESTART);
    anim.setRepeatCount(ValueAnimator.INFINITE);

    return anim;
}
 
Example 2
Source File: TextViewLinkActivity.java    From zone-sdk with MIT License 6 votes vote down vote up
public ForegroundColorSpanAni(View view) {
    this.view = view;

    ValueAnimator animator = ValueAnimator.ofInt(Color.RED, Color.BLUE);
    animator.setEvaluator(new ArgbEvaluator());
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            color = (int) animation.getAnimatedValue();
            view.invalidate();
        }
    });
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(-1);
    animator.start();
}
 
Example 3
Source File: MiEntryFragment.java    From SAI with GNU General Public License v3.0 6 votes vote down vote up
private void setupMD3Animations() {
    TextView title = findViewById(R.id.tv_mi_entry_title);

    MutableLiveData<Integer> titleColorLiveData = new MutableLiveData<>(title.getCurrentTextColor());
    MutableLiveData<Float> titleScaleLiveData = new MutableLiveData<>(1f);
    titleColorLiveData.observe(getViewLifecycleOwner(), title::setTextColor);
    titleScaleLiveData.observe(getViewLifecycleOwner(), scale -> {
        title.setScaleX(scale);
        title.setScaleY(scale);
    });

    ValueAnimator textColorAnimator = ValueAnimator.ofArgb(Color.parseColor("#FF0000"), Color.parseColor("#FF7F00"),
            Color.parseColor("#FFFF00"), Color.parseColor("#00FF00"), Color.parseColor("#0000FF"), Color.parseColor("#2E2B5F"), Color.parseColor("#8B00FF"), Color.parseColor("#FF0000"));
    textColorAnimator.setDuration(3000);
    textColorAnimator.setRepeatMode(ValueAnimator.RESTART);
    textColorAnimator.setRepeatCount(ValueAnimator.INFINITE);
    textColorAnimator.addUpdateListener(animation -> titleColorLiveData.setValue((Integer) animation.getAnimatedValue()));
    textColorAnimator.start();

    ValueAnimator titleScaleAnimator = ValueAnimator.ofFloat(1f, 0.75f);
    titleScaleAnimator.setDuration(400);
    titleScaleAnimator.setRepeatMode(ValueAnimator.REVERSE);
    titleScaleAnimator.setRepeatCount(ValueAnimator.INFINITE);
    titleScaleAnimator.addUpdateListener(animation -> titleScaleLiveData.setValue((float) animation.getAnimatedValue()));
    titleScaleAnimator.start();
}
 
Example 4
Source File: PropertyAnimationActivity.java    From Android-Animation-Set with Apache License 2.0 6 votes vote down vote up
/**
 * ValueAnimator usage
 *
 * @return
 */

public ValueAnimator getValueAnimator() {
    final int height = mPuppet.getLayoutParams().height;
    final int width = mPuppet.getLayoutParams().width;

    ValueAnimator sizeValueAnimator = ValueAnimator.ofFloat(1f, 3f);
    sizeValueAnimator.setDuration(3000);
    sizeValueAnimator.setRepeatCount(1);
    sizeValueAnimator.setRepeatMode(ValueAnimator.REVERSE);
    sizeValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            mPuppet.getLayoutParams().height = (int) (height * animatedValue);
            mPuppet.getLayoutParams().width = (int) (width * animatedValue);
            mPuppet.requestLayout();
        }
    });
    return sizeValueAnimator;
}
 
Example 5
Source File: PropertyAnimationActivity.java    From Study_Android_Demo with Apache License 2.0 6 votes vote down vote up
/**
 * ValueAnimator usage
 *
 * @return
 */

public ValueAnimator getValueAnimator() {
    final int height = mPuppet.getLayoutParams().height;
    final int width = mPuppet.getLayoutParams().width;

    ValueAnimator sizeValueAnimator = ValueAnimator.ofFloat(1f, 3f);
    sizeValueAnimator.setDuration(3000);
    sizeValueAnimator.setRepeatCount(1);
    sizeValueAnimator.setRepeatMode(ValueAnimator.REVERSE);
    sizeValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float animatedValue = (float) valueAnimator.getAnimatedValue();
            mPuppet.getLayoutParams().height = (int) (height * animatedValue);
            mPuppet.getLayoutParams().width = (int) (width * animatedValue);
            mPuppet.requestLayout();
        }
    });
    return sizeValueAnimator;
}
 
Example 6
Source File: ChrysanthemumLoadingView.java    From KotlinMVPRxJava2Dagger2GreenDaoRetrofitDemo with Apache License 2.0 6 votes vote down vote up
@Override
protected void onFinishInflate() {
    super.onFinishInflate();
    ValueAnimator valueAnimator = ValueAnimator.ofInt(12, 1);
    valueAnimator.setDuration(1000);
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    valueAnimator.setRepeatMode(ValueAnimator.RESTART);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            control = (int) animation.getAnimatedValue();
            invalidate();
        }
    });
    valueAnimator.start();
}
 
Example 7
Source File: RecordingThrobberView.java    From science-journal with Apache License 2.0 6 votes vote down vote up
public void startAnimation() {
  for (int i = 0; i < NUMBER_BARS; i++) {
    final int index = i;
    ValueAnimator animator = ValueAnimator.ofFloat(0, 100);
    animator.setDuration(MS_PER_CYCLE);
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    // Get sorta random starts using some prime numbers and modulo math
    animator.setCurrentPlayTime(
        (long) (MS_PER_CYCLE * (i * 3 + 7 * 1.0 % NUMBER_BARS) / NUMBER_BARS));
    animator.addUpdateListener(
        valueAnimator -> {
          animatedFraction[index] = valueAnimator.getAnimatedFraction();
          // Coordinate the invalidates for performance.
          postInvalidateOnAnimation();
        });
    animator.start();
    stopped.happensNext().subscribe(() -> animator.end());
  }
}
 
Example 8
Source File: DynamicPieChartView.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private Animator b()
{
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
        0.0F, 1.0F
    });
    valueanimator.addListener(new i(this));
    valueanimator.addUpdateListener(new j(this));
    valueanimator.setDuration(3500L);
    valueanimator.setInterpolator(new LinearInterpolator());
    valueanimator.setRepeatMode(1);
    valueanimator.setRepeatCount(-1);
    return valueanimator;
}
 
Example 9
Source File: LoadingView.java    From star-zone-android with Apache License 2.0 5 votes vote down vote up
private ValueAnimator createAnimator(Interpolator interpolator, long duration) {
    ValueAnimator animator = ValueAnimator.ofFloat(0, 180f);
    animator.setInterpolator(interpolator == null ? defaultInterpolator : interpolator);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setDuration(duration == 0 ? DEFAULT_DURATION : duration);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            currentDegree = (float) animation.getAnimatedValue();
            invalidate();
        }
    });
    return animator;
}
 
Example 10
Source File: DynamicPieChartViewOld.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private Animator b()
{
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
        0.0F, 1.0F
    });
    valueanimator.addListener(new m(this));
    valueanimator.addUpdateListener(new n(this));
    valueanimator.setDuration(3500L);
    valueanimator.setInterpolator(new LinearInterpolator());
    valueanimator.setRepeatMode(1);
    valueanimator.setRepeatCount(-1);
    return valueanimator;
}
 
Example 11
Source File: WaveDrawable.java    From AndroidAnimationExercise with Apache License 2.0 5 votes vote down vote up
private ValueAnimator getDefaultAnimator() {
    ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
    animator.setInterpolator(new DecelerateInterpolator());
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.setDuration(5000);
    return animator;
}
 
Example 12
Source File: PathAnimatorInflater.java    From ElasticProgressBar with Apache License 2.0 5 votes vote down vote up
/**
 * @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.
 */
private static void parseAnimatorFromTypeArray(ValueAnimator anim,
                                               TypedArray arrayAnimator, TypedArray arrayObjectAnimator) {
    long duration = arrayAnimator.getInt(R.styleable.Animator_android_duration, 300);

    long startDelay = arrayAnimator.getInt(R.styleable.Animator_android_startOffset, 0);

    int valueType = arrayAnimator.getInt(R.styleable.Animator_vc_valueType, 0);

    TypeEvaluator evaluator = null;

    // Must be a path animator by the time I reach here
    if (valueType == VALUE_TYPE_PATH) {
        evaluator = setupAnimatorForPath(anim, arrayAnimator);
    } else {
        throw new IllegalArgumentException("target is not a pathType target");
    }

    anim.setDuration(duration);
    anim.setStartDelay(startDelay);

    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatCount)) {
        anim.setRepeatCount(
                arrayAnimator.getInt(R.styleable.Animator_android_repeatCount, 0));
    }
    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatMode)) {
        anim.setRepeatMode(
                arrayAnimator.getInt(R.styleable.Animator_android_repeatMode,
                        ValueAnimator.RESTART));
    }
    if (evaluator != null) {
        anim.setEvaluator(evaluator);
    }

    if (arrayObjectAnimator != null) {
        setupObjectAnimator(anim, arrayObjectAnimator);
    }
}
 
Example 13
Source File: SampleActivity.java    From CompositionAvatar with MIT License 5 votes vote down vote up
private void dynamicGap(CompositionAvatarView view) {
    ValueAnimator animator = ValueAnimator.ofFloat(0f, 1f);
    animator.setDuration(2000);
    animator.setStartDelay(1000);
    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setRepeatMode(ValueAnimator.REVERSE);
    animator.setRepeatCount(ValueAnimator.INFINITE);
    animator.addUpdateListener(animation -> view.setGap((Float) animation.getAnimatedValue()));

    mGapAnimator = animator;
}
 
Example 14
Source File: LinePieChartView.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
private Animator b()
{
    ValueAnimator valueanimator = ValueAnimator.ofFloat(new float[] {
        0.0F, 1.0F
    });
    valueanimator.addListener(new l(this));
    valueanimator.addUpdateListener(new m(this));
    valueanimator.setDuration(3500L);
    valueanimator.setInterpolator(new LinearInterpolator());
    valueanimator.setRepeatMode(1);
    valueanimator.setRepeatCount(-1);
    return valueanimator;
}
 
Example 15
Source File: AlarmDismissActivity.java    From SuntimesWidget with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(12)
private void animateColors(final TextView[] labels, final Button[] buttons, final ImageView icon, int startColor, int endColor, long duration, @Nullable TimeInterpolator interpolator)
{
    if (icon != null && labels != null)
    {
        ValueAnimator animation = ValueAnimator.ofObject(new ArgbEvaluator(), startColor, endColor);
        animationObj = animation;
        animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener()
        {
            @Override
            public void onAnimationUpdate(ValueAnimator animator)
            {
                int animatedValue = (int) animator.getAnimatedValue();
                icon.setColorFilter(animatedValue);

                for (TextView label : labels) {
                    if (label != null) {
                        label.setTextColor(animatedValue);
                    }
                }

                for (Button button : buttons) {
                    if (button != null) {
                        button.setTextColor(animatedValue);
                        colorizeButtonCompoundDrawable(animatedValue, button);
                    }
                }
            }
        });
        if (Build.VERSION.SDK_INT >= 11) {
            animation.setRepeatCount(ValueAnimator.INFINITE);
            animation.setRepeatMode(ValueAnimator.REVERSE);
        }
        if (interpolator != null) {
            animation.setInterpolator(interpolator);
        }
        animation.setDuration(duration);
        animation.start();
    }
}
 
Example 16
Source File: ElevationAnimationDemoFragment.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void startTranslationZAnimation(
    View view, MaterialShapeDrawable materialShapeDrawable, float maxTranslationZ) {
  ValueAnimator animator = ValueAnimator.ofFloat(0, maxTranslationZ);
  animator.setDuration(ANIMATION_DURATION_MILLIS);
  animator.setStartDelay(ANIMATION_START_DELAY_MILLIS);
  animator.setRepeatMode(ValueAnimator.RESTART);
  animator.setRepeatCount(ValueAnimator.INFINITE);
  animator.addUpdateListener(
      animation ->
          setTranslationZ(view, materialShapeDrawable, (float) animation.getAnimatedValue()));
  animator.start();
}
 
Example 17
Source File: PropertyAnimActivity.java    From AndroidStudyDemo with GNU General Public License v2.0 5 votes vote down vote up
public void testColor(View v) {
    ValueAnimator colorAnim = ObjectAnimator.ofInt(v, "backgroundColor", /*Red*/0xFFFF8080, /*Blue*/0xFF8080FF);
    colorAnim.setDuration(C.Int.ANIM_DURATION * 3);
    colorAnim.setEvaluator(new ArgbEvaluator());
    colorAnim.setRepeatCount(ValueAnimator.INFINITE);
    colorAnim.setRepeatMode(ValueAnimator.REVERSE);
    colorAnim.start();
}
 
Example 18
Source File: ButtonSpinnerDrawable.java    From thunderboard-android with Apache License 2.0 5 votes vote down vote up
private ValueAnimator createRotateAnimator() {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 360.0f);
    valueAnimator.setDuration(rotationDuration);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            ButtonTrack.this.rotation = (float) animation.getAnimatedValue();
        }
    });
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.setRepeatCount(ValueAnimator.INFINITE);
    valueAnimator.setRepeatMode(ValueAnimator.RESTART);
    return valueAnimator;
}
 
Example 19
Source File: AnimFragment.java    From ImageBlurring with Apache License 2.0 5 votes vote down vote up
public void animView() {
    if (mSet == null) {
        View root = getView();
        if (root == null)
            return;

        mWidth = mText.getWidth();
        final ValueAnimator topAnim = ObjectAnimator.ofInt(mText, "left", 0, root.getRight() - mWidth);
        topAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mLeft = (int) animation.getAnimatedValue();
                blur();
            }
        });
        topAnim.setRepeatMode(ValueAnimator.REVERSE);
        topAnim.setRepeatCount(9);

        final ValueAnimator bottomAnim = ObjectAnimator.ofInt(mText, "right", mWidth, root.getRight());
        bottomAnim.setRepeatMode(ValueAnimator.REVERSE);
        bottomAnim.setRepeatCount(9);

        AnimatorSet set = new AnimatorSet();
        set.play(topAnim).with(bottomAnim);
        set.setDuration(2800);
        set.start();
        mSet = set;
    } else {
        mSet.start();
    }

}
 
Example 20
Source File: AnimatedDrawable2ValueAnimatorHelper.java    From fresco with MIT License 5 votes vote down vote up
public static ValueAnimator createValueAnimator(AnimatedDrawable2 animatedDrawable) {
  int loopCount = animatedDrawable.getLoopCount();
  ValueAnimator animator = new ValueAnimator();
  animator.setIntValues(0, (int) animatedDrawable.getLoopDurationMs());
  animator.setDuration(animatedDrawable.getLoopDurationMs());
  animator.setRepeatCount(
      loopCount != AnimationInformation.LOOP_COUNT_INFINITE ? loopCount : ValueAnimator.INFINITE);
  animator.setRepeatMode(ValueAnimator.RESTART);
  // Use a linear interpolator
  animator.setInterpolator(null);
  ValueAnimator.AnimatorUpdateListener animatorUpdateListener =
      createAnimatorUpdateListener(animatedDrawable);
  animator.addUpdateListener(animatorUpdateListener);
  return animator;
}