Search code examples
androidprogress-barobjectanimator

ObjectAnimator on ProgressWheel by Todd-Davies


I am trying to make a ProgressWheel where the color change as the wheel fill up (the wheel start green at 0% and finish red at 100% with all the wheel become red over the time : not a rainbow). So I am using an ObjectAnimator, the wheel take the entry color but I cannot manage to make it change color over time...

final ObjectAnimator animator = ObjectAnimator.ofInt(progressBar, "barColor", Color.GREEN, Color.RED);
animator.setDuration(remainingTime);
animator.setEvaluator(new ArgbEvaluator());
animator.setInterpolator(new DecelerateInterpolator(2));
animator.start();

Any idea?


Solution

  • I finally did this (it comes from another post on StackOverflow):

    final ObjectAnimator colorAnimator = ObjectAnimator.ofObject(progressBar, "barColor", new ArgbEvaluator(), green, red);
    colorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                    progressBar.refreshWheel();
            }
    });
    colorAnimator.setInterpolator(new DecelerateInterpolator());            
    colorAnimator.setDuration(remainingTime);
    colorAnimator.start();
    

    and in ProgressWheel.java

    public void refreshWheel() {
        setupPaints();
    }