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 1531982d1e
)
This commit is contained in:
parent
fbe9182b75
commit
7b42d2287a
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue