From 96eb6ca719cd53ed1cdee1fc819979492d02e078 Mon Sep 17 00:00:00 2001 From: George Mount Date: Mon, 28 Nov 2016 15:08:19 -0800 Subject: [PATCH] Use transparent instead of null background during Activity Transitions Bug 32952142 When doing activity transitions, a window is temporarily translucent during the transition. When a view hierarchy completely covers the window, the background is never seen and applications can use a null background to avoid overdraw. However, during the activity transition, the underlying activity is seen during the transition. With a null background, the buffer isn't properly cleared and the uncleared buffer will show strange effects. This CL forces a transparent background temporarily during the activity transition to avoid this problem. Test: manual testing using test application Change-Id: I63f24dba3c2f810944bcbf07faf309f9f1c5889a --- .../android/app/EnterTransitionCoordinator.java | 15 +++++++++++++-- .../android/app/ExitTransitionCoordinator.java | 2 +- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/EnterTransitionCoordinator.java b/core/java/android/app/EnterTransitionCoordinator.java index 3464c4d8cbeb4..7e0486f87ab1e 100644 --- a/core/java/android/app/EnterTransitionCoordinator.java +++ b/core/java/android/app/EnterTransitionCoordinator.java @@ -19,6 +19,8 @@ import android.animation.Animator; import android.animation.AnimatorListenerAdapter; import android.animation.ObjectAnimator; import android.app.SharedElementCallback.OnSharedElementsReadyListener; +import android.graphics.Color; +import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.os.Bundle; import android.os.ResultReceiver; @@ -61,6 +63,7 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { private Transition mEnterViewsTransition; private OneShotPreDrawListener mViewsReadyListener; private final boolean mIsCrossTask; + private Drawable mReplacedBackground; public EnterTransitionCoordinator(Activity activity, ResultReceiver resultReceiver, ArrayList sharedElementNames, boolean isReturning, boolean isCrossTask) { @@ -332,12 +335,15 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { if (!mIsReturning) { mWasOpaque = mActivity.convertToTranslucent(null, null); Drawable background = decorView.getBackground(); - if (background != null) { + if (background == null) { + background = new ColorDrawable(Color.TRANSPARENT); + mReplacedBackground = background; + } else { getWindow().setBackgroundDrawable(null); background = background.mutate(); background.setAlpha(0); - getWindow().setBackgroundDrawable(background); } + getWindow().setBackgroundDrawable(background); } else { mActivity = null; // all done with it now. } @@ -553,6 +559,11 @@ class EnterTransitionCoordinator extends ActivityTransitionCoordinator { final ViewGroup decorView = getDecor(); if (decorView != null) { decorView.sendAccessibilityEvent(AccessibilityEvent.TYPE_WINDOW_CONTENT_CHANGED); + + Window window = getWindow(); + if (window != null && mReplacedBackground == decorView.getBackground()) { + window.setBackgroundDrawable(null); + } } } diff --git a/core/java/android/app/ExitTransitionCoordinator.java b/core/java/android/app/ExitTransitionCoordinator.java index 6a79e6cfdf9cf..21e3aeedf69f1 100644 --- a/core/java/android/app/ExitTransitionCoordinator.java +++ b/core/java/android/app/ExitTransitionCoordinator.java @@ -236,7 +236,7 @@ class ExitTransitionCoordinator extends ActivityTransitionCoordinator { delayCancel(); moveSharedElementsToOverlay(); if (decorView != null && decorView.getBackground() == null) { - getWindow().setBackgroundDrawable(new ColorDrawable(Color.BLACK)); + getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); } final boolean targetsM = decorView == null || decorView.getContext() .getApplicationInfo().targetSdkVersion >= VERSION_CODES.M;