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

Commit adf303d7 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Refactor monet.Style to ThemeStyle" into main

parents 5ba08af4 18985459
Loading
Loading
Loading
Loading
+22 −20
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.systemui.monet;

import android.annotation.ColorInt;
import android.app.WallpaperColors;
import android.content.theming.ThemeStyle;
import android.graphics.Color;

import com.android.internal.graphics.ColorUtils;
@@ -53,7 +54,7 @@ public class ColorScheme {
    @ColorInt
    private final int mSeed;
    private final boolean mIsDark;
    @Style.Type
    @ThemeStyle.Type
    private final int mStyle;
    private final DynamicScheme mMaterialScheme;
    private final TonalPalette mAccent1;
@@ -65,7 +66,7 @@ public class ColorScheme {
    private final Hct mProposedSeedHct;


    public ColorScheme(@ColorInt int seed, boolean isDark, @Style.Type int style,
    public ColorScheme(@ColorInt int seed, boolean isDark, @ThemeStyle.Type int style,
            double contrastLevel) {

        this.mSeed = seed;
@@ -76,23 +77,23 @@ public class ColorScheme {
        Hct seedHct = Hct.fromInt(
                seed == Color.TRANSPARENT
                        ? GOOGLE_BLUE
                        : (style != Style.CONTENT
                        : (style != ThemeStyle.CONTENT
                                && mProposedSeedHct.getChroma() < 5
                                ? GOOGLE_BLUE
                                : seed));

        mMaterialScheme = switch (style) {
            case Style.SPRITZ -> new SchemeNeutral(seedHct, isDark, contrastLevel);
            case Style.TONAL_SPOT -> new SchemeTonalSpot(seedHct, isDark, contrastLevel);
            case Style.VIBRANT -> new SchemeVibrant(seedHct, isDark, contrastLevel);
            case Style.EXPRESSIVE -> new SchemeExpressive(seedHct, isDark, contrastLevel);
            case Style.RAINBOW -> new SchemeRainbow(seedHct, isDark, contrastLevel);
            case Style.FRUIT_SALAD -> new SchemeFruitSalad(seedHct, isDark, contrastLevel);
            case Style.CONTENT -> new SchemeContent(seedHct, isDark, contrastLevel);
            case Style.MONOCHROMATIC -> new SchemeMonochrome(seedHct, isDark, contrastLevel);
            case ThemeStyle.SPRITZ -> new SchemeNeutral(seedHct, isDark, contrastLevel);
            case ThemeStyle.TONAL_SPOT -> new SchemeTonalSpot(seedHct, isDark, contrastLevel);
            case ThemeStyle.VIBRANT -> new SchemeVibrant(seedHct, isDark, contrastLevel);
            case ThemeStyle.EXPRESSIVE -> new SchemeExpressive(seedHct, isDark, contrastLevel);
            case ThemeStyle.RAINBOW -> new SchemeRainbow(seedHct, isDark, contrastLevel);
            case ThemeStyle.FRUIT_SALAD -> new SchemeFruitSalad(seedHct, isDark, contrastLevel);
            case ThemeStyle.CONTENT -> new SchemeContent(seedHct, isDark, contrastLevel);
            case ThemeStyle.MONOCHROMATIC -> new SchemeMonochrome(seedHct, isDark, contrastLevel);
            // SystemUI Schemes
            case Style.CLOCK -> new SchemeClock(seedHct, isDark, contrastLevel);
            case Style.CLOCK_VIBRANT -> new SchemeClockVibrant(seedHct, isDark, contrastLevel);
            case ThemeStyle.CLOCK -> new SchemeClock(seedHct, isDark, contrastLevel);
            case ThemeStyle.CLOCK_VIBRANT -> new SchemeClockVibrant(seedHct, isDark, contrastLevel);
            default -> throw new IllegalArgumentException("Unknown style: " + style);
        };

@@ -105,19 +106,20 @@ public class ColorScheme {
    }

    public ColorScheme(@ColorInt int seed, boolean darkTheme) {
        this(seed, darkTheme, Style.TONAL_SPOT);
        this(seed, darkTheme, ThemeStyle.TONAL_SPOT);
    }

    public ColorScheme(@ColorInt int seed, boolean darkTheme, @Style.Type int style) {
    public ColorScheme(@ColorInt int seed, boolean darkTheme, @ThemeStyle.Type int style) {
        this(seed, darkTheme, style, 0.0);
    }

    public ColorScheme(WallpaperColors wallpaperColors, boolean darkTheme, @Style.Type int style) {
        this(getSeedColor(wallpaperColors, style != Style.CONTENT), darkTheme, style);
    public ColorScheme(WallpaperColors wallpaperColors, boolean darkTheme,
            @ThemeStyle.Type int style) {
        this(getSeedColor(wallpaperColors, style != ThemeStyle.CONTENT), darkTheme, style);
    }

    public ColorScheme(WallpaperColors wallpaperColors, boolean darkTheme) {
        this(wallpaperColors, darkTheme, Style.TONAL_SPOT);
        this(wallpaperColors, darkTheme, ThemeStyle.TONAL_SPOT);
    }

    public int getBackgroundColor() {
@@ -140,7 +142,7 @@ public class ColorScheme {
        return mSeed;
    }

    @Style.Type
    @ThemeStyle.Type
    public int getStyle() {
        return mStyle;
    }
+0 −183
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.systemui.monet;

import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.Nullable;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

/**
 * A class defining the different styles available for theming.
 * This class replaces the previous enum implementation for improved performance and compatibility.
 */
public final class Style {

    private Style() {
    }

    /**
     * @hide
     */
    @IntDef({
            SPRITZ,
            TONAL_SPOT,
            VIBRANT,
            EXPRESSIVE,
            RAINBOW,
            FRUIT_SALAD,
            CONTENT,
            MONOCHROMATIC,
            CLOCK,
            CLOCK_VIBRANT
    })
    @Retention(RetentionPolicy.SOURCE)
    public @interface Type {
    }

    /**
     * Represents the SPRITZ style.
     */
    public static final int SPRITZ = 0;
    /**
     * Represents the TONAL_SPOT style.
     */
    public static final int TONAL_SPOT = 1;
    /**
     * Represents the VIBRANT style.
     */
    public static final int VIBRANT = 2;
    /**
     * Represents the EXPRESSIVE style.
     */
    public static final int EXPRESSIVE = 3;
    /**
     * Represents the RAINBOW style.
     */
    public static final int RAINBOW = 4;
    /**
     * Represents the FRUIT_SALAD style.
     */
    public static final int FRUIT_SALAD = 5;
    /**
     * Represents the CONTENT style.
     */
    public static final int CONTENT = 6;
    /**
     * Represents the MONOCHROMATIC style.
     */
    public static final int MONOCHROMATIC = 7;
    /**
     * Represents the CLOCK style.
     */
    public static final int CLOCK = 8;
    /**
     * Represents the CLOCK_VIBRANT style.
     */
    public static final int CLOCK_VIBRANT = 9;


    /**
     * Returns the string representation of the given style.
     *
     * @param style The style value.
     * @return The string representation of the style.
     * @throws IllegalArgumentException if the style value is invalid.
     */
    @NonNull
    public static String toString(@Nullable @Type Integer style) {
        // Throw an exception if style is null
        if (style == null) {
            throw new IllegalArgumentException("Invalid style value: null");
        }

        return switch (style) {
            case SPRITZ -> "SPRITZ";
            case TONAL_SPOT -> "TONAL_SPOT";
            case VIBRANT -> "VIBRANT";
            case EXPRESSIVE -> "EXPRESSIVE";
            case RAINBOW -> "RAINBOW";
            case FRUIT_SALAD -> "FRUIT_SALAD";
            case CONTENT -> "CONTENT";
            case MONOCHROMATIC -> "MONOCHROMATIC";
            case CLOCK -> "CLOCK";
            case CLOCK_VIBRANT -> "CLOCK_VIBRANT";
            default -> throw new IllegalArgumentException("Invalid style value: " + style);
        };
    }

    /**
     * Returns the style value corresponding to the given style name.
     *
     * @param styleName The name of the style.
     * @return The style value.
     * @throws IllegalArgumentException if the style name is invalid.
     */
    public static @Type int valueOf(@Nullable @NonNull String styleName) {
        if (styleName == null) {
            throw new IllegalArgumentException("Invalid style value: null");
        }

        return switch (styleName) {
            case "SPRITZ" -> SPRITZ;
            case "TONAL_SPOT" -> TONAL_SPOT;
            case "VIBRANT" -> VIBRANT;
            case "EXPRESSIVE" -> EXPRESSIVE;
            case "RAINBOW" -> RAINBOW;
            case "FRUIT_SALAD" -> FRUIT_SALAD;
            case "CONTENT" -> CONTENT;
            case "MONOCHROMATIC" -> MONOCHROMATIC;
            case "CLOCK" -> CLOCK;
            case "CLOCK_VIBRANT" -> CLOCK_VIBRANT;
            default -> throw new IllegalArgumentException("Invalid style name: " + styleName);
        };
    }

    /**
     * Returns the name of the given style. This method is equivalent to {@link #toString(int)}.
     *
     * @param style The style value.
     * @return The name of the style.
     */
    @NonNull
    public static String name(@Type int style) {
        return toString(style);
    }

    /**
     * Returns an array containing all the style values.
     *
     * @return An array of all style values.
     */
    public static int[] values() {
        return new int[]{
                SPRITZ,
                TONAL_SPOT,
                VIBRANT,
                EXPRESSIVE,
                RAINBOW,
                FRUIT_SALAD,
                CONTENT,
                MONOCHROMATIC,
                CLOCK,
                CLOCK_VIBRANT
        };
    }

}
 No newline at end of file
+6 −5
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@
package com.android.systemui.monet

import android.app.WallpaperColors
import android.content.theming.ThemeStyle
import android.graphics.Color
import android.util.Log
import androidx.test.ext.junit.runners.AndroidJUnit4
@@ -113,16 +114,16 @@ class ColorSchemeTest {
                theme.setAttribute("color", sourceColorHex)
                mode.appendChild(theme)

                for (styleValue in Style.values()) {
                for (styleValue in ThemeStyle.values()) {
                    if (
                        styleValue == Style.CLOCK ||
                            styleValue == Style.CLOCK_VIBRANT ||
                            styleValue == Style.CONTENT
                        styleValue == ThemeStyle.CLOCK ||
                            styleValue == ThemeStyle.CLOCK_VIBRANT ||
                            styleValue == ThemeStyle.CONTENT
                    ) {
                        continue
                    }

                    val style = document.createElement(Style.name(styleValue).lowercase())
                    val style = document.createElement(ThemeStyle.name(styleValue).lowercase())
                    val colorScheme =
                        ColorScheme(
                            WallpaperColors(sourceColor, sourceColor, sourceColor),