Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 96eb6ca7 authored by George Mount's avatar George Mount
Browse files

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
parent 7f9d210e
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -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<String> 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);
            }
        }
    }

+1 −1
Original line number Diff line number Diff line
@@ -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;