From 7b42d2287adaf9cca56ac2493f240cd22213b170 Mon Sep 17 00:00:00 2001 From: Kevin Date: Thu, 11 Apr 2019 11:16:06 -0700 Subject: [PATCH] Fix transition progress not applying to drawables TaskLayerDrawable should reapply UI changes from the transition progress when there is a new drawable. In addition, the transition should check if the drawable in the front and back are the same (i.e. on initialization when both are showing the empty drawable) so that it only applies the front-drawable alpha. Bug: 114136250 Test: Builds Change-Id: I74836b5043da555358742ba0a3f46f170f590904 (cherry picked from commit 1531982d1ed7c03cc1ec4c0a6d6069ff747de5b5) --- .../android/quickstep/views/TaskLayerDrawable.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/go/quickstep/src/com/android/quickstep/views/TaskLayerDrawable.java b/go/quickstep/src/com/android/quickstep/views/TaskLayerDrawable.java index 3a230482b7..98b66b995d 100644 --- a/go/quickstep/src/com/android/quickstep/views/TaskLayerDrawable.java +++ b/go/quickstep/src/com/android/quickstep/views/TaskLayerDrawable.java @@ -31,6 +31,7 @@ import com.android.launcher3.R; */ public final class TaskLayerDrawable extends LayerDrawable { private final Drawable mEmptyDrawable; + private float mProgress; public TaskLayerDrawable(Context context) { super(new Drawable[0]); @@ -50,6 +51,7 @@ public final class TaskLayerDrawable extends LayerDrawable { */ public void setCurrentDrawable(@NonNull Drawable drawable) { setDrawable(0, drawable); + applyTransitionProgress(mProgress); } /** @@ -82,9 +84,18 @@ public final class TaskLayerDrawable extends LayerDrawable { if (progress > 1 || progress < 0) { throw new IllegalArgumentException("Transition progress should be between 0 and 1"); } + mProgress = progress; + applyTransitionProgress(progress); + } + + private void applyTransitionProgress(float progress) { int drawableAlpha = (int) (progress * 255); getDrawable(0).setAlpha(drawableAlpha); - getDrawable(1).setAlpha(255 - drawableAlpha); + if (getDrawable(0) != getDrawable(1)) { + // Only do this if it's a different drawable so that it fades out. + // Otherwise, we'd just be overwriting the front drawable's alpha. + getDrawable(1).setAlpha(255 - drawableAlpha); + } invalidateSelf(); } }