ObjectAnimator on ProgressWheel by Todd-Davies - android

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?

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();
}

Related

android setBackground animation

Currently I set background of a LinearLayout using
BitmapDrawable bd = new BitmapDrawable(getResources(), mBlurredMap);
mLytProfileCover.setBackground(bd);
How can I animation this? For example, a fade-in animation where the background's alpha changes from 0 to 1 in 500ms.
Thanks.
ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mLytProfileCover, View.ALPHA, 0.0f, 1.0f);
alphaAnimator.addListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationStart(final Animator animation) {
mLytProfileCover.setBackground(bd);
}
});
alphaAnimator.setDuration(500);
alphaAnimator.start();

Can not change background in view

I'm trying to change the background color of my view. I wrote some code and i can change color with animation, but first time my view is freezing before color changes. This is my code
private void changeBackgroundColorWithAnimation(int duration, final View view, int startColor, int endColor) {
ValueAnimator anim = new ValueAnimator();
anim.setIntValues(startColor, endColor);
anim.setEvaluator(new ArgbEvaluator());
anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(final ValueAnimator valueAnimator) {
view.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
}
});
anim.setDuration(duration);
anim.start();
}
I call my function like this:
changeBackgroundColorWithAnimation(300, TransferFragmentNewVersion.rootLayout,
Color.parseColor("#E6000000"), Color.WHITE);
As I said the background color has changed, but first time View is freezing(only first time)l
How can I solve my problem? Thanks everyone.
Why aren't you sending your view's initial color as a starting color?
You can replace Color.parseColor("#E6000000") with TransferFragmentNewVersion.rootLayout.getSolidColor().
Can you post more of your code?

Smooth color animation

I'm trying to create smooth color animation in my WaveView. Unfortunatelly animation is creating rainbow effect spamming through every color from start to end.
I'll need it to go from Red to Green with just (Red -> Orange - > Yellow - > Greenish -> Green) like on RGB tables.
Here's my ObjectAnimator:
ObjectAnimator waveColor = ObjectAnimator.ofInt(
mWaveView, "waveColor",Color.parseColor("#64ff0000"),Color.parseColor("#6400ff00"));
waveColor.setDuration(7000);
waveColor.setInterpolator(new LinearInterpolator());
animators.add(waveColor);
I have no idea how to make it to just go through that colors.
Check this Link:
Hope I have understood your question properly and it helps
ColorDrawable[] color = {new ColorDrawable(Color.RED), new ColorDrawable(Color.GREEN)};
TransitionDrawable trans = new TransitionDrawable(color);
//This will work also on old devices. The latest API says you have to use setBackground instead.
mWaveView.setBackgroundDrawable(trans);
trans.startTransition(7000);
best way use ValueAnimator and ColorUtils.blendARGB
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
valueAnimator.setDuration(325);
valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
float fractionAnim = (float) valueAnimator.getAnimatedValue();
view.setColorBackground(ColorUtils.blendARGB(Color.parseColor("#FFFFFF")
, Color.parseColor("#000000")
, fractionAnim));
}
});
valueAnimator.start();

FloatingActionButton backgroundTint animation

I'd like to animate the backgroundTint value (and ideally the alpha value too) of a FloatingActionButton, so that the FAB background color continuously switches between two colors.
My noob approach would be to use a timer that calls a function that updates this property when it fires. I'm sure there's a better way of doing this?
I got this to work using ObjectAnimator as suggested by #MH. above, but I had to override the onAnimationUpdate() callback:
final ValueAnimator animator = ValueAnimator.ofInt(Color.rgb(0, 121, 107), Color.rgb(226, 143, 34));
animator.setDuration(2000L);
animator.setEvaluator(new ArgbEvaluator());
animator.setInterpolator(new DecelerateInterpolator(2));
animator.addUpdateListener(new ObjectAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
int animatedValue = (int) animation.getAnimatedValue();
fab.setBackgroundTintList(ColorStateList.valueOf(animatedValue));
}
});
animator.start();

Android ViewOverlay animate during remove() of Drawable

I have a ViewOverlay that I use to show a Drawable on the screen. When I want to add or remove the overlay drawable on top of my view I do something like this:
ViewOverlay overlay = mView.getOverlay();
overlay.add(mDrawable);
...sometime later...
ViewOverlay overlay = mView.getOverlay();
overlay.remove(mDrawable);
However, this instantly removes my drawable from the screen. Is there a way to fade away the drawable in the overlay instead of just instantly removing it?
You have to apply the animation directly to the Drawable first and as soon as the animation is done you can call remove() to remove the overlay.
ValueAnimator animator = ValueAnimator.ofInt(255, 0);
animator.setInterpolator(new LinearInterpolator());
animator.setDuration(ANIMATION_DURATION);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator animation) {
int alpha = (int) animation.getAnimatedValue();
mDrawable.setAlpha(alpha);
mViewThatHasOverlay.invalidate();
}
});
animator.addListener(new AnimatorListenerAdapter() {
#Override
public void onAnimationEnd(Animator animation) {
ViewOverlay overlay = mViewThatHasOverlay.getOverlay();
overlay.remove(mDrawable);
}
});
animator.start();

Categories

Resources