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

Commit 0ba7b646 authored by Jiaming Liu's avatar Jiaming Liu
Browse files

[Divider] Read veil color from DividerAttributes

If the veil color is configured (non-transparent) in DividerAttributes,
we use the configured color. Otherwise, we use the window background
color of the top activity in the container. Alpha is ignored.

Bug: 293654166
Test: atest DividerPresenterTest
Flag: com.android.window.flags.activity_embedding_interactive_divider_flag
Change-Id: Idc05eb5f249720f4a2471e209f7957755a39fc6b
parent 8d908683
Loading
Loading
Loading
Loading
+24 −4
Original line number Diff line number Diff line
@@ -39,6 +39,7 @@ import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSI
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ValueAnimator;
import android.annotation.ColorInt;
import android.annotation.Nullable;
import android.app.Activity;
import android.app.ActivityThread;
@@ -1394,10 +1395,14 @@ class DividerPresenter implements View.OnTouchListener {
        }

        private void showVeils(@NonNull SurfaceControl.Transaction t) {
            final Color primaryVeilColor = getContainerBackgroundColor(
                    mProperties.mPrimaryContainer, DEFAULT_PRIMARY_VEIL_COLOR);
            final Color secondaryVeilColor = getContainerBackgroundColor(
                    mProperties.mSecondaryContainer, DEFAULT_SECONDARY_VEIL_COLOR);
            final Color primaryVeilColor = getVeilColor(
                    mProperties.mDividerAttributes.getPrimaryVeilColor(),
                    mProperties.mPrimaryContainer,
                    DEFAULT_PRIMARY_VEIL_COLOR);
            final Color secondaryVeilColor = getVeilColor(
                    mProperties.mDividerAttributes.getSecondaryVeilColor(),
                    mProperties.mSecondaryContainer,
                    DEFAULT_SECONDARY_VEIL_COLOR);
            t.setColor(mPrimaryVeil, colorToFloatArray(primaryVeilColor))
                    .setColor(mSecondaryVeil, colorToFloatArray(secondaryVeilColor))
                    .setLayer(mDividerSurface, DIVIDER_LAYER)
@@ -1444,6 +1449,21 @@ class DividerPresenter implements View.OnTouchListener {
            }
        }

        /**
         * Returns the veil color.
         *
         * If the configured color is not transparent, we use the configured color, otherwise we use
         * the window background color of the top activity. If the background color of the top
         * activity is unavailable, the default color is used.
         */
        @NonNull
        private static Color getVeilColor(@ColorInt int configuredColor,
                @NonNull TaskFragmentContainer container, @NonNull Color defaultColor) {
            return configuredColor != Color.TRANSPARENT
                    ? Color.valueOf(configuredColor)
                    : getContainerBackgroundColor(container, defaultColor);
        }

        private static float[] colorToFloatArray(@NonNull Color color) {
            return new float[]{color.red(), color.green(), color.blue()};
        }