Cancel hotseat color animator before setting a new color.
am: ef0c537925
Change-Id: I1aea3e288d7e54e788ad95b8599e6d909458b220
This commit is contained in:
@@ -16,6 +16,8 @@
|
|||||||
|
|
||||||
package com.android.launcher3;
|
package com.android.launcher3;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
|
import android.animation.AnimatorListenerAdapter;
|
||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@@ -52,6 +54,7 @@ public class Hotseat extends FrameLayout
|
|||||||
private int mBackgroundColor;
|
private int mBackgroundColor;
|
||||||
@ViewDebug.ExportedProperty(category = "launcher")
|
@ViewDebug.ExportedProperty(category = "launcher")
|
||||||
private ColorDrawable mBackground;
|
private ColorDrawable mBackground;
|
||||||
|
private ValueAnimator mBackgroundColorAnimator;
|
||||||
|
|
||||||
public Hotseat(Context context) {
|
public Hotseat(Context context) {
|
||||||
this(context, null);
|
this(context, null);
|
||||||
@@ -177,18 +180,27 @@ public class Hotseat extends FrameLayout
|
|||||||
public void updateColor(ExtractedColors extractedColors, boolean animate) {
|
public void updateColor(ExtractedColors extractedColors, boolean animate) {
|
||||||
if (!mHasVerticalHotseat) {
|
if (!mHasVerticalHotseat) {
|
||||||
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
|
int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT);
|
||||||
|
if (mBackgroundColorAnimator != null) {
|
||||||
|
mBackgroundColorAnimator.cancel();
|
||||||
|
}
|
||||||
if (!animate) {
|
if (!animate) {
|
||||||
setBackgroundColor(color);
|
setBackgroundColor(color);
|
||||||
} else {
|
} else {
|
||||||
ValueAnimator animator = ValueAnimator.ofInt(mBackgroundColor, color);
|
mBackgroundColorAnimator = ValueAnimator.ofInt(mBackgroundColor, color);
|
||||||
animator.setEvaluator(new ArgbEvaluator());
|
mBackgroundColorAnimator.setEvaluator(new ArgbEvaluator());
|
||||||
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
mBackgroundColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onAnimationUpdate(ValueAnimator animation) {
|
public void onAnimationUpdate(ValueAnimator animation) {
|
||||||
mBackground.setColor((Integer) animation.getAnimatedValue());
|
mBackground.setColor((Integer) animation.getAnimatedValue());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
animator.start();
|
mBackgroundColorAnimator.addListener(new AnimatorListenerAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onAnimationEnd(Animator animation) {
|
||||||
|
mBackgroundColorAnimator = null;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
mBackgroundColorAnimator.start();
|
||||||
}
|
}
|
||||||
mBackgroundColor = color;
|
mBackgroundColor = color;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user