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

Commit 61b023c4 authored by Mariia Sandrikova's avatar Mariia Sandrikova Committed by Android (Google) Code Review
Browse files

Merge "Support dynamic material color for letterbox background." into sc-v2-dev

parents 5088c490 8f06d2e2
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -4862,9 +4862,8 @@
            - Option 3 is selected for R.integer.config_letterboxBackgroundType and blur requested
            but isn't supported on the device or both dark scrim alpha and blur radius aren't
            provided.
        Defaults to black if not specified.
     -->
    <color name="config_letterboxBackgroundColor">#000</color>
    <color name="config_letterboxBackgroundColor">@android:color/system_neutral2_500</color>

    <!-- Horizonal position of a center of the letterboxed app window.
        0 corresponds to the left side of the screen and 1 to the right side. If given value < 0
+35 −16
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
package com.android.server.wm;

import android.annotation.IntDef;
import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Color;

@@ -63,7 +64,10 @@ final class LetterboxConfiguration {
    private int mLetterboxActivityCornersRadius;

    // Color for {@link #LETTERBOX_BACKGROUND_SOLID_COLOR} letterbox background type.
    private Color mLetterboxBackgroundColor;
    @Nullable private Color mLetterboxBackgroundColorOverride;

    // Color resource id for {@link #LETTERBOX_BACKGROUND_SOLID_COLOR} letterbox background type.
    @Nullable private Integer mLetterboxBackgroundColorResourceIdOverride;

    @LetterboxBackgroundType
    private int mLetterboxBackgroundType;
@@ -81,20 +85,18 @@ final class LetterboxConfiguration {
    // side of the screen and 1.0 to the right side.
    private float mLetterboxHorizontalPositionMultiplier;

    LetterboxConfiguration(Context context) {
        mContext = context;
        mFixedOrientationLetterboxAspectRatio = context.getResources().getFloat(
    LetterboxConfiguration(Context systemUiContext) {
        mContext = systemUiContext;
        mFixedOrientationLetterboxAspectRatio = mContext.getResources().getFloat(
                R.dimen.config_fixedOrientationLetterboxAspectRatio);
        mLetterboxActivityCornersRadius = context.getResources().getInteger(
        mLetterboxActivityCornersRadius = mContext.getResources().getInteger(
                R.integer.config_letterboxActivityCornersRadius);
        mLetterboxBackgroundColor = Color.valueOf(context.getResources().getColor(
                R.color.config_letterboxBackgroundColor));
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(context);
        mLetterboxBackgroundWallpaperBlurRadius = context.getResources().getDimensionPixelSize(
        mLetterboxBackgroundType = readLetterboxBackgroundTypeFromConfig(mContext);
        mLetterboxBackgroundWallpaperBlurRadius = mContext.getResources().getDimensionPixelSize(
                R.dimen.config_letterboxBackgroundWallpaperBlurRadius);
        mLetterboxBackgroundWallpaperDarkScrimAlpha = context.getResources().getFloat(
        mLetterboxBackgroundWallpaperDarkScrimAlpha = mContext.getResources().getFloat(
                R.dimen.config_letterboxBackgroundWallaperDarkScrimAlpha);
        mLetterboxHorizontalPositionMultiplier = context.getResources().getFloat(
        mLetterboxHorizontalPositionMultiplier = mContext.getResources().getFloat(
                R.dimen.config_letterboxHorizontalPositionMultiplier);
    }

@@ -163,7 +165,15 @@ final class LetterboxConfiguration {
     * fallback for other backfround types.
     */
    Color getLetterboxBackgroundColor() {
        return mLetterboxBackgroundColor;
        if (mLetterboxBackgroundColorOverride != null) {
            return mLetterboxBackgroundColorOverride;
        }
        int colorId = mLetterboxBackgroundColorResourceIdOverride != null
                ? mLetterboxBackgroundColorResourceIdOverride
                : R.color.config_letterboxBackgroundColor;
        // Query color dynamically because material colors extracted from wallpaper are updated
        // when wallpaper is changed.
        return Color.valueOf(mContext.getResources().getColor(colorId));
    }


@@ -173,7 +183,16 @@ final class LetterboxConfiguration {
     * fallback for other backfround types.
     */
    void setLetterboxBackgroundColor(Color color) {
        mLetterboxBackgroundColor = color;
        mLetterboxBackgroundColorOverride = color;
    }

    /**
     * Sets color ID of letterbox background which is used when {@link
     * #getLetterboxBackgroundType()} is {@link #LETTERBOX_BACKGROUND_SOLID_COLOR} or as
     * fallback for other backfround types.
     */
    void setLetterboxBackgroundColorResourceId(int colorId) {
        mLetterboxBackgroundColorResourceIdOverride = colorId;
    }

    /**
@@ -181,8 +200,8 @@ final class LetterboxConfiguration {
     * com.android.internal.R.color.config_letterboxBackgroundColor}.
     */
    void resetLetterboxBackgroundColor() {
        mLetterboxBackgroundColor = Color.valueOf(mContext.getResources().getColor(
                com.android.internal.R.color.config_letterboxBackgroundColor));
        mLetterboxBackgroundColorOverride = null;
        mLetterboxBackgroundColorResourceIdOverride = null;
    }

    /**
+3 −1
Original line number Diff line number Diff line
@@ -1217,7 +1217,9 @@ public class WindowManagerService extends IWindowManager.Stub
        mAssistantOnTopOfDream = context.getResources().getBoolean(
                com.android.internal.R.bool.config_assistantOnTopOfDream);

        mLetterboxConfiguration = new LetterboxConfiguration(context);
        mLetterboxConfiguration = new LetterboxConfiguration(
                // Using SysUI context to have access to Material colors extracted from Wallpaper.
                ActivityThread.currentActivityThread().getSystemUiContext());

        mInputManager = inputManager; // Must be before createDisplayContentLocked.
        mDisplayManagerInternal = LocalServices.getService(DisplayManagerInternal.class);
+35 −8
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_SOLID_COLOR;
import static com.android.server.wm.LetterboxConfiguration.LETTERBOX_BACKGROUND_WALLPAPER;

import android.content.res.Resources.NotFoundException;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
@@ -606,7 +607,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        } catch (IllegalArgumentException  e) {
            getErrPrintWriter().println(
                    "Error: 'reset' or aspect ratio should be provided as an argument " + e);
                    "Error: aspect ratio should be provided as an argument " + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
@@ -625,7 +626,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        } catch (IllegalArgumentException  e) {
            getErrPrintWriter().println(
                    "Error: 'reset' or corners radius should be provided as an argument " + e);
                    "Error: corners radius should be provided as an argument " + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
@@ -653,13 +654,13 @@ public class WindowManagerShellCommand extends ShellCommand {
                    break;
                default:
                    getErrPrintWriter().println(
                            "Error: 'reset', 'solid_color', 'app_color_background' or "
                            "Error: 'solid_color', 'app_color_background' or "
                            + "'wallpaper' should be provided as an argument");
                    return -1;
            }
        } catch (IllegalArgumentException  e) {
            getErrPrintWriter().println(
                    "Error: 'reset', 'solid_color', 'app_color_background' or "
                    "Error: 'solid_color', 'app_color_background' or "
                        + "'wallpaper' should be provided as an argument" + e);
            return -1;
        }
@@ -669,6 +670,24 @@ public class WindowManagerShellCommand extends ShellCommand {
        return 0;
    }

    private int runSetLetterboxBackgroundColorResource(PrintWriter pw) throws RemoteException {
        final int colorId;
        try {
            String arg = getNextArgRequired();
            colorId = mInternal.mContext.getResources()
                    .getIdentifier(arg, "color", "com.android.internal");
        } catch (NotFoundException e) {
            getErrPrintWriter().println(
                    "Error: color in '@android:color/resource_name' format should be provided as "
                            + "an argument " + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
            mLetterboxConfiguration.setLetterboxBackgroundColorResourceId(colorId);
        }
        return 0;
    }

    private int runSetLetterboxBackgroundColor(PrintWriter pw) throws RemoteException {
        final Color color;
        try {
@@ -676,7 +695,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            color = Color.valueOf(Color.parseColor(arg));
        } catch (IllegalArgumentException  e) {
            getErrPrintWriter().println(
                    "Error: 'reset' or color in #RRGGBB format should be provided as "
                    "Error: color in #RRGGBB format should be provided as "
                            + "an argument " + e);
            return -1;
        }
@@ -697,7 +716,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        } catch (IllegalArgumentException  e) {
            getErrPrintWriter().println(
                    "Error: 'reset' or blur radius should be provided as an argument " + e);
                    "Error: blur radius should be provided as an argument " + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
@@ -717,7 +736,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        } catch (IllegalArgumentException  e) {
            getErrPrintWriter().println(
                    "Error: 'reset' or alpha should be provided as an argument " + e);
                    "Error: alpha should be provided as an argument " + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
@@ -736,7 +755,7 @@ public class WindowManagerShellCommand extends ShellCommand {
            return -1;
        } catch (IllegalArgumentException  e) {
            getErrPrintWriter().println(
                    "Error: 'reset' or multiplier should be provided as an argument " + e);
                    "Error: multiplier should be provided as an argument " + e);
            return -1;
        }
        synchronized (mInternal.mGlobalLock) {
@@ -764,6 +783,9 @@ public class WindowManagerShellCommand extends ShellCommand {
                case "--backgroundColor":
                    runSetLetterboxBackgroundColor(pw);
                    break;
                case "--backgroundColorResource":
                    runSetLetterboxBackgroundColorResource(pw);
                    break;
                case "--wallpaperBlurRadius":
                    runSetLetterboxBackgroundWallpaperBlurRadius(pw);
                    break;
@@ -1031,6 +1053,11 @@ public class WindowManagerShellCommand extends ShellCommand {
        pw.println("        is 'solid-color'. Use (set)get-letterbox-style to check and control");
        pw.println("        letterbox background type. See Color#parseColor for allowed color");
        pw.println("        formats (#RRGGBB and some colors by name, e.g. magenta or olive).");
        pw.println("      --backgroundColorResource resource_name");
        pw.println("        Color resource name of letterbox background which is used when");
        pw.println("        background type is 'solid-color'. Use (set)get-letterbox-style to");
        pw.println("        check and control background type. Parameter is a color resource");
        pw.println("        name, for example, @android:color/system_accent2_50.");
        pw.println("      --wallpaperBlurRadius radius");
        pw.println("        Blur radius for 'wallpaper' letterbox background. If radius <= 0");
        pw.println("        both it and R.dimen.config_letterboxBackgroundWallpaperBlurRadius");