android.animation.ValueAnimator#setRepeatMode ( )源码实例Demo

下面列出了android.animation.ValueAnimator#setRepeatMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: zone-sdk   文件: TextViewLinkActivity.java
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();
}
 
源代码2 项目: SAI   文件: MiEntryFragment.java
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();
}
 
/**
 * 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;
}
 
/**
 * 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;
}
 
@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();
}
 
源代码6 项目: science-journal   文件: RecordingThrobberView.java
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());
  }
}
 
源代码7 项目: journaldev   文件: MainActivity.java
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;
}
 
源代码8 项目: star-zone-android   文件: LoadingView.java
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;
}
 
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;
}
 
源代码10 项目: ImageBlurring   文件: AnimFragment.java
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();
    }

}
 
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;
}
 
源代码12 项目: AndroidStudyDemo   文件: PropertyAnimActivity.java
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();
}
 
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();
}
 
源代码14 项目: SuntimesWidget   文件: AlarmDismissActivity.java
@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();
    }
}
 
源代码15 项目: MiBandDecompiled   文件: LinePieChartView.java
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;
}
 
源代码16 项目: CompositionAvatar   文件: SampleActivity.java
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;
}
 
源代码17 项目: ElasticProgressBar   文件: PathAnimatorInflater.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.
 */
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);
    }
}
 
源代码18 项目: AndroidAnimationExercise   文件: WaveDrawable.java
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;
}
 
源代码19 项目: MiBandDecompiled   文件: DynamicPieChartViewOld.java
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;
}
 
源代码20 项目: MiBandDecompiled   文件: DynamicPieChartView.java
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;
}