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

Commit 6cb9e197 authored by Cairn Overturf's avatar Cairn Overturf
Browse files

Add box shadows to PiP 1

See go/box-shadows-integration

Dark Theme: snipit/3eE4wydt8t4LVpT
Light Theme: snipit/YrrWVxVvT9QqTcA

Bug: b/367464660
Test: with the flag enabled, PiP shadows should match the spec above.
Flag: com.android.wm.shell.enable_pip_box_shadows
Change-Id: Ice543370cbc517fdbd5de1e1011eb788fe08443d
parent dceb5089
Loading
Loading
Loading
Loading
+42 −0
Original line number Diff line number Diff line
@@ -177,6 +177,38 @@
        <item name="boxShadowSpreadRadius">0dp</item>
    </style>

    <style name="BoxShadowParamsPIPLight1">
        <item name="boxShadowColor">#0A000000</item>
        <item name="boxShadowOffsetX">0dp</item>
        <item name="boxShadowOffsetY">0dp</item>
        <item name="boxShadowBlurRadius">14dp</item>
        <item name="boxShadowSpreadRadius">0dp</item>
    </style>

    <style name="BoxShadowParamsPIPLight2">
        <item name="boxShadowColor">#1A000000</item>
        <item name="boxShadowOffsetX">0dp</item>
        <item name="boxShadowOffsetY">2dp</item>
        <item name="boxShadowBlurRadius">8dp</item>
        <item name="boxShadowSpreadRadius">0dp</item>
    </style>

    <style name="BoxShadowParamsPIPDark1">
        <item name="boxShadowColor">#33000000</item>
        <item name="boxShadowOffsetX">0dp</item>
        <item name="boxShadowOffsetY">0dp</item>
        <item name="boxShadowBlurRadius">14dp</item>
        <item name="boxShadowSpreadRadius">0dp</item>
    </style>

    <style name="BoxShadowParamsPIPDark2">
        <item name="boxShadowColor">#33000000</item>
        <item name="boxShadowOffsetX">0dp</item>
        <item name="boxShadowOffsetY">2dp</item>
        <item name="boxShadowBlurRadius">8dp</item>
        <item name="boxShadowSpreadRadius">0dp</item>
    </style>

    <style name="BorderSettingsUnfocusedLight">
        <item name="borderStrokeWidth">1dp</item>
        <item name="borderColor">#32BDC1C6</item>
@@ -197,4 +229,14 @@
        <item name="borderColor">#579AA0A6</item>
    </style>

    <style name="BorderSettingsPIPLight">
        <item name="borderStrokeWidth">1dp</item>
        <item name="borderColor">#27BDC1C6</item>
    </style>

    <style name="BorderSettingsPIPDark">
        <item name="borderStrokeWidth">1dp</item>
        <item name="borderColor">#339AA0A6</item>
    </style>

</resources>
+83 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell.common;

import android.content.Context;
import android.content.res.TypedArray;
import android.gui.BorderSettings;
import android.gui.BoxShadowSettings;

import com.android.wm.shell.R;

/**
 * This class has helper functions for obtaining box shadow and border parameters from
 * resource ids.
 */
public class BoxShadowHelper {
    /**
     * Gets border settings from an id.
     *
     * @return the border settings.
     */
    public static BorderSettings getBorderSettings(Context context, int borderSettingsId) {
        final TypedArray attr = context.obtainStyledAttributes(
                borderSettingsId, R.styleable.BorderSettings);
        final BorderSettings result = new BorderSettings();
        result.strokeWidth =
                attr.getDimension(
                        R.styleable.BorderSettings_borderStrokeWidth, 0f);
        result.color =
                attr.getColor(
                        R.styleable.BorderSettings_borderColor, 0);
        attr.recycle();
        return result;
    }

    /**
     * Gets box shadow settings from an id.
     *
     * @return the box shadow settings.
     */
    public static BoxShadowSettings getBoxShadowSettings(Context context,
            int[] boxShadowSettingsIds) {
        final BoxShadowSettings result = new BoxShadowSettings();
        result.boxShadows =
                new BoxShadowSettings.BoxShadowParams[boxShadowSettingsIds.length];
        for (int i = 0; i < boxShadowSettingsIds.length; i++) {
            final TypedArray attr = context.obtainStyledAttributes(
                    boxShadowSettingsIds[i], R.styleable.BoxShadowSettings);

            final BoxShadowSettings.BoxShadowParams box =
                    new BoxShadowSettings.BoxShadowParams();
            box.blurRadius = attr.getDimension(
                    R.styleable.BoxShadowSettings_boxShadowBlurRadius, 0f);
            box.spreadRadius = attr.getDimension(
                    R.styleable.BoxShadowSettings_boxShadowSpreadRadius, 0f);
            box.offsetX = attr.getDimension(
                    R.styleable.BoxShadowSettings_boxShadowOffsetX, 0f);
            box.offsetY = attr.getDimension(
                    R.styleable.BoxShadowSettings_boxShadowOffsetY, 0f);
            box.color = attr.getColor(
                    R.styleable.BoxShadowSettings_boxShadowColor, 0);

            result.boxShadows[i] = box;

            attr.recycle();
        }
        return result;
    }
}
+11 −0
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.app.WindowConfiguration
import android.content.ComponentName
import android.content.Context
import android.content.pm.PackageManager
import android.content.res.Configuration
import android.content.res.Configuration.UI_MODE_NIGHT_MASK
import android.graphics.PointF
import android.graphics.Rect
import android.os.RemoteException
@@ -322,4 +324,13 @@ object PipUtils {
        }
        return isPip2ExperimentEnabled as Boolean
    }

    /**
     * Returns true if the system theme is the dark theme.
     */
    @JvmStatic
    fun Context.isDarkSystemTheme(): Boolean {
        return (resources.configuration.uiMode and UI_MODE_NIGHT_MASK) ==
                Configuration.UI_MODE_NIGHT_YES
    }
}
+43 −1
Original line number Diff line number Diff line
@@ -22,12 +22,17 @@ import android.graphics.Matrix;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.gui.BorderSettings;
import android.gui.BoxShadowSettings;
import android.view.Choreographer;
import android.view.SurfaceControl;

import androidx.annotation.Nullable;

import com.android.wm.shell.Flags;
import com.android.wm.shell.R;
import com.android.wm.shell.common.BoxShadowHelper;
import com.android.wm.shell.common.pip.PipUtils;
import com.android.wm.shell.transition.Transitions;

/**
@@ -44,8 +49,12 @@ public class PipSurfaceTransactionHelper {
    private int mCornerRadius;
    private int mShadowRadius;

    private BoxShadowSettings mBoxShadowSettings;
    private BorderSettings mBorderSettings;

    public PipSurfaceTransactionHelper(Context context) {
        onDensityOrFontScaleChanged(context);
        onThemeChanged(context);
    }

    /**
@@ -322,10 +331,43 @@ public class PipSurfaceTransactionHelper {
     */
    public PipSurfaceTransactionHelper shadow(SurfaceControl.Transaction tx, SurfaceControl leash,
            boolean applyShadowRadius) {
        if (Flags.enablePipBoxShadows()) {
            if (applyShadowRadius) {
                tx.setBoxShadowSettings(leash, mBoxShadowSettings);
                tx.setBorderSettings(leash, mBorderSettings);
            } else {
                tx.setBoxShadowSettings(leash, new BoxShadowSettings());
                tx.setBorderSettings(leash, new BorderSettings());
            }
        } else {
            tx.setShadowRadius(leash, applyShadowRadius ? mShadowRadius : 0);
        }
        return this;
    }

    /**
     * Called when theme changes.
     *
     * @param context the current context
     */
    public void onThemeChanged(Context context) {
        if (PipUtils.isDarkSystemTheme(context)) {
            mBoxShadowSettings = BoxShadowHelper.getBoxShadowSettings(context,
                    new int[]{R.style.BoxShadowParamsPIPDark1,
                            R.style.BoxShadowParamsPIPDark2});
            mBorderSettings = BoxShadowHelper.getBorderSettings(context,
                    R.style.BorderSettingsPIPDark);
        } else {

            mBoxShadowSettings = BoxShadowHelper.getBoxShadowSettings(context,
                    new int[]{R.style.BoxShadowParamsPIPLight1,
                            R.style.BoxShadowParamsPIPLight2});

            mBorderSettings = BoxShadowHelper.getBorderSettings(context,
                    R.style.BorderSettingsPIPLight);
        }
    }

    public interface SurfaceControlTransactionFactory {
        SurfaceControl.Transaction getTransaction();
    }
+12 −0
Original line number Diff line number Diff line
@@ -1939,4 +1939,16 @@ public class PipTaskOrganizer implements ShellTaskOrganizer.TaskListener,
    public String toString() {
        return TAG + ":" + taskListenerTypeToString(TASK_LISTENER_TYPE_PIP);
    }

    /**
     * Called when the theme changes.
     */
    public void onThemeChanged(Context context) {
        if (isInPip()) {
            mSurfaceTransactionHelper.onThemeChanged(context);
            SurfaceControl.Transaction tx = mSurfaceControlTransactionFactory.getTransaction();
            mSurfaceTransactionHelper.shadow(tx, mLeash, true /* applyShadowRadius */);
            tx.apply();
        }
    }
}
Loading