From ef0c537925369192cd84b0c4e3df29691c455d83 Mon Sep 17 00:00:00 2001 From: Tony Wickham Date: Mon, 22 Aug 2016 15:23:01 -0700 Subject: Cancel hotseat color animator before setting a new color. There was a race condition that caused the new color to not be applied. For example, here's how the hotseat would become transparent: 1 Launcher is loaded for the first time; as such, there is not yet a color defined for the hotseat, so we start animating to the provided default (Color.TRANSPARENT). Meanwhile we start the color extraction. 2 When the color extraction finishes, we set the hotseat to the new color. However, if launcher is paused at the time (perhaps some retail mode content is showing), then we don't animate the change. 3 If 2 happens before the animation in 1 is complete, the color from 2 will be overriden by subsequent animation frames and thus the hotseat remains transparent until the wallpaper changes. Bug: 30956221 Change-Id: Iddf72379b0162f1b32883ad26ce267473e172849 --- src/com/android/launcher3/Hotseat.java | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/com/android/launcher3/Hotseat.java') diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java index 660565425..7c0ed10d0 100644 --- a/src/com/android/launcher3/Hotseat.java +++ b/src/com/android/launcher3/Hotseat.java @@ -16,6 +16,8 @@ package com.android.launcher3; +import android.animation.Animator; +import android.animation.AnimatorListenerAdapter; import android.animation.ArgbEvaluator; import android.animation.ValueAnimator; import android.content.Context; @@ -52,6 +54,7 @@ public class Hotseat extends FrameLayout private int mBackgroundColor; @ViewDebug.ExportedProperty(category = "launcher") private ColorDrawable mBackground; + private ValueAnimator mBackgroundColorAnimator; public Hotseat(Context context) { this(context, null); @@ -179,18 +182,27 @@ public class Hotseat extends FrameLayout public void updateColor(ExtractedColors extractedColors, boolean animate) { if (!mHasVerticalHotseat) { int color = extractedColors.getColor(ExtractedColors.HOTSEAT_INDEX, Color.TRANSPARENT); + if (mBackgroundColorAnimator != null) { + mBackgroundColorAnimator.cancel(); + } if (!animate) { setBackgroundColor(color); } else { - ValueAnimator animator = ValueAnimator.ofInt(mBackgroundColor, color); - animator.setEvaluator(new ArgbEvaluator()); - animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { + mBackgroundColorAnimator = ValueAnimator.ofInt(mBackgroundColor, color); + mBackgroundColorAnimator.setEvaluator(new ArgbEvaluator()); + mBackgroundColorAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { mBackground.setColor((Integer) animation.getAnimatedValue()); } }); - animator.start(); + mBackgroundColorAnimator.addListener(new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mBackgroundColorAnimator = null; + } + }); + mBackgroundColorAnimator.start(); } mBackgroundColor = color; } -- cgit v1.2.3