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

Commit f212b6ba authored by Todd Lee's avatar Todd Lee
Browse files

Add background dimming for launchable UI

Bug: b/352729488
Test: manual verification/complication launch UX
Flag: NONE exempt minor change to wear UX impl

Change-Id: I88d571dedd5bc2adc14454d0a776bd8b7d0e7372
parent 8fe8ac09
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -441,7 +441,8 @@ public class OriginRemoteTransition extends IRemoteTransition.Stub implements
                /* alpha= */ 1.0f,
                /* visible= */ true,
                /* bounds= */ maxBounds,
                /* baseBounds= */ maxBounds);
                /* baseBounds= */ maxBounds,
                /* enableBackgroundDimming= */ false);
    }

    private static void applyWindowAnimationStates(
+52 −10
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.animation;

import android.annotation.Nullable;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
@@ -31,17 +32,29 @@ import java.util.concurrent.Executor;
 * @hide
 */
public class SurfaceUIComponent implements UIComponent {
    private final Collection<SurfaceControl> mSurfaces;
    private final ArrayList<SurfaceControl> mSurfaces = new ArrayList<>();
    private final Rect mBaseBounds;
    private final float[] mFloat9 = new float[9];

    private float mAlpha;
    private boolean mVisible;
    private Rect mBounds;
    @Nullable
    private final SurfaceControl mBackgroundDimmingSurface;

    public SurfaceUIComponent(
            SurfaceControl sc, float alpha, boolean visible, Rect bounds, Rect baseBounds) {
        this(Arrays.asList(sc), alpha, visible, bounds, baseBounds);
            SurfaceControl sc,
            float alpha,
            boolean visible,
            Rect bounds,
            Rect baseBounds,
            boolean enableBackgroundDimming) {
        this(Arrays.asList(sc),
                alpha,
                visible,
                bounds,
                baseBounds,
                enableBackgroundDimming);
    }

    public SurfaceUIComponent(
@@ -49,12 +62,34 @@ public class SurfaceUIComponent implements UIComponent {
            float alpha,
            boolean visible,
            Rect bounds,
            Rect baseBounds) {
        mSurfaces = surfaces;
            Rect baseBounds,
            boolean enableBackgroundDimming) {
        mSurfaces.addAll(surfaces);
        mAlpha = alpha;
        mVisible = visible;
        mBounds = bounds;
        mBaseBounds = baseBounds;
        if (enableBackgroundDimming) {
          mBackgroundDimmingSurface = new SurfaceControl.Builder()
                  .setName("SurfaceUIComponent-BackgroundDimming")
                  .setColorLayer()
                  .setBufferSize(baseBounds.width(), baseBounds.height())
                  .setHidden(!visible)
                  .build();
          if (!bounds.equals(baseBounds)) {
              Matrix matrix = new Matrix();
              matrix.setRectToRect(
                  new RectF(baseBounds),
                  new RectF(bounds),
                  Matrix.ScaleToFit.CENTER);
              new SurfaceControl.Transaction()
                  .setMatrix(mBackgroundDimmingSurface, matrix, mFloat9).apply();
          }

            mSurfaces.add(mBackgroundDimmingSurface);
        } else {
            mBackgroundDimmingSurface = null;
        }
    }

    @Override
@@ -109,7 +144,9 @@ public class SurfaceUIComponent implements UIComponent {
            mChanges.add(
                    () -> {
                        ui.mAlpha = alpha;
                        ui.mSurfaces.forEach(s -> mTransaction.setAlpha(s, alpha));
                        ui.mSurfaces.forEach(
                                s -> mTransaction.setAlpha(
                                        s, s != ui.mBackgroundDimmingSurface ? alpha : 1));
                    });
            return this;
        }
@@ -140,8 +177,9 @@ public class SurfaceUIComponent implements UIComponent {
                        matrix.setRectToRect(
                                new RectF(ui.mBaseBounds),
                                new RectF(ui.mBounds),
                                Matrix.ScaleToFit.FILL);
                        ui.mSurfaces.forEach(s -> mTransaction.setMatrix(s, matrix, ui.mFloat9));
                                Matrix.ScaleToFit.CENTER);
                        ui.mSurfaces.forEach(
                                s -> mTransaction.setMatrix(s, matrix, ui.mFloat9));
                    });
            return this;
        }
@@ -150,7 +188,10 @@ public class SurfaceUIComponent implements UIComponent {
        public Transaction attachToTransitionLeash(
                SurfaceUIComponent ui, SurfaceControl transitionLeash, int w, int h) {
            mChanges.add(
                    () -> ui.mSurfaces.forEach(s -> mTransaction.reparent(s, transitionLeash)));
                    () -> {
                        ui.mSurfaces.forEach(
                                s -> mTransaction.reparent(s, transitionLeash));
                    });
            return this;
        }

@@ -159,7 +200,8 @@ public class SurfaceUIComponent implements UIComponent {
                SurfaceUIComponent ui, Executor executor, Runnable onDone) {
            mChanges.add(
                    () -> {
                        ui.mSurfaces.forEach(s -> mTransaction.reparent(s, null));
                        ui.mSurfaces.forEach(
                                s -> mTransaction.reparent(s, null));
                        mTransaction.addTransactionCommittedListener(executor, onDone::run);
                    });
            return this;
+21 −2
Original line number Diff line number Diff line
@@ -18,7 +18,9 @@ package com.android.systemui.animation;

import android.annotation.Nullable;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.Rect;
@@ -56,16 +58,18 @@ public class ViewUIComponent implements UIComponent {
    private final LifecycleListener mLifecycleListener = new LifecycleListener();
    private final View mView;
    private final Handler mMainHandler;

    @Nullable private SurfaceControl mSurfaceControl;
    @Nullable private Surface mSurface;
    @Nullable private Rect mViewBoundsOverride;
    private boolean mVisibleOverride;
    private final boolean mEnableBackgroundDimming;
    private final Paint mPaint = new Paint();
    private boolean mDirty;

    public ViewUIComponent(View view) {
    public ViewUIComponent(View view, boolean enableBackgroundDimming) {
        mView = view;
        mMainHandler = new Handler(Looper.getMainLooper());
        mEnableBackgroundDimming = enableBackgroundDimming;
    }

    /**
@@ -209,6 +213,21 @@ public class ViewUIComponent implements UIComponent {
                    (float) renderBounds.width() / realBounds.width(),
                    (float) renderBounds.height() / realBounds.height());

            if (mEnableBackgroundDimming) {
                // draw backing layer for background dimming using bounds/radius
                mPaint.setColor(Color.BLACK);
                mPaint.setStyle(Paint.Style.FILL);
                // TODO: use corner radius for drawing
                canvas.drawRoundRect(
                        renderBounds.left,
                        renderBounds.top,
                        renderBounds.right,
                        renderBounds.bottom,
                        renderBounds.width() / 2,
                        renderBounds.height() / 2,
                        mPaint);
            }

            if (mView.getClipToOutline()) {
                mView.getOutlineProvider().getOutline(mView, mClippingOutline);
                mClippingPath.reset();