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

Commit 6262dc3b authored by Marcelo Arteiro's avatar Marcelo Arteiro
Browse files

Refactor monet.Style to ThemeStyle

Deprecates `monet.Style` in favor of the new `ThemeStyle` class in preparation for the upcoming `ThemeManagerService`.

This change is purely a refactoring, moving the existing `monet.Style` class to a new location and name with no functional changes. All existing usages in SystemUI have been updated to the new class.

Bug: 441912053
Test: Existing tests updated.
Flag: EXEMPT mechanical refactoring
Change-Id: Id8656abd800facd288663ef452207cfc8108728d
parent 196b1102
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -1340,6 +1340,27 @@ package android.content.rollback {

}

package android.content.theming {

  @FlaggedApi("android.server.enable_theme_service") public final class ThemeStyle {
    method @NonNull public static String name(int);
    method @NonNull public static String toString(int);
    method public static int valueOf(@NonNull String);
    method @NonNull public static int[] values();
    field public static final int CLOCK = 8; // 0x8
    field public static final int CLOCK_VIBRANT = 9; // 0x9
    field public static final int CONTENT = 6; // 0x6
    field public static final int EXPRESSIVE = 3; // 0x3
    field public static final int FRUIT_SALAD = 5; // 0x5
    field public static final int MONOCHROMATIC = 7; // 0x7
    field public static final int RAINBOW = 4; // 0x4
    field public static final int SPRITZ = 0; // 0x0
    field public static final int TONAL_SPOT = 1; // 0x1
    field public static final int VIBRANT = 2; // 0x2
  }

}

package android.credentials {

  public final class CredentialManager {
+11 −2
Original line number Diff line number Diff line
@@ -22,8 +22,10 @@ import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.PARAMETER;
import static java.lang.annotation.RetentionPolicy.SOURCE;

import android.annotation.FlaggedApi;
import android.annotation.IntDef;
import android.annotation.NonNull;
import android.annotation.TestApi;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
@@ -34,7 +36,13 @@ import java.lang.annotation.Target;
 *
 * @hide
 */
@TestApi
@FlaggedApi(android.server.Flags.FLAG_ENABLE_THEME_SERVICE)
public final class ThemeStyle {
    private ThemeStyle() {
        // Utility class
    }

    /**
     * @hide
     */
@@ -106,7 +114,7 @@ public final class ThemeStyle {
     * @throws NullPointerException if the style value is null.
     */
    @NonNull
    public static String toString(@Type Integer style) {
    public static String toString(@Type int style) {
        return switch (style) {
            case SPRITZ -> "SPRITZ";
            case TONAL_SPOT -> "TONAL_SPOT";
@@ -131,7 +139,7 @@ public final class ThemeStyle {
     * @throws NullPointerException if the style name is null.
     */
    @Type
    public static  int valueOf(String styleName) {
    public static  int valueOf(@NonNull String styleName) {
        return switch (styleName) {
            case "SPRITZ" -> SPRITZ;
            case "TONAL_SPOT" -> TONAL_SPOT;
@@ -163,6 +171,7 @@ public final class ThemeStyle {
     *
     * @return An array of all style values.
     */
    @NonNull
    public static int[] values() {
        return new int[]{
                SPRITZ,
+14 −10
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import android.content.Intent;
import android.content.om.FabricatedOverlay;
import android.content.om.OverlayIdentifier;
import android.content.res.Resources;
import android.content.theming.ThemeStyle;
import android.database.ContentObserver;
import android.graphics.Color;
import android.os.Handler;
@@ -68,7 +69,6 @@ import com.android.systemui.flags.SystemPropertiesHelper;
import com.android.systemui.keyguard.WakefulnessLifecycle;
import com.android.systemui.keyguard.domain.interactor.KeyguardTransitionInteractor;
import com.android.systemui.monet.DynamicColors;
import com.android.systemui.monet.Style;
import com.android.systemui.settings.UserTracker;
import com.android.systemui.statusbar.policy.DeviceProvisionedController;
import com.android.systemui.statusbar.policy.DeviceProvisionedController.DeviceProvisionedListener;
@@ -253,7 +253,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        registrationRunnable.getValue().run();
        verify(mWallpaperManager, never()).getWallpaperColors(anyInt());

        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(Style.MONOCHROMATIC);
        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(ThemeStyle.MONOCHROMATIC);
        assertThat(mThemeOverlayController.mCurrentColors.get(0).getMainColors().get(
                0).toArgb()).isEqualTo(Color.RED);
    }
@@ -271,7 +271,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        registrationRunnable.getValue().run();
        verify(mWallpaperManager).getWallpaperColors(eq(WallpaperManager.FLAG_SYSTEM));

        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(Style.VIBRANT);
        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(ThemeStyle.VIBRANT);
    }

    @Test
@@ -284,8 +284,9 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        registrationRunnable.getValue().run();
        verify(mWallpaperManager).getWallpaperColors(eq(WallpaperManager.FLAG_SYSTEM));

        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(Style.TONAL_SPOT);
        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(ThemeStyle.TONAL_SPOT);
    }

    @Test
    @HardwareColors(color = "BLK", options = {
            "BLK|MONOCHROMATIC|#FF0000",
@@ -299,7 +300,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
        registrationRunnable.getValue().run();
        verify(mWallpaperManager, never()).getWallpaperColors(anyInt());

        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(Style.MONOCHROMATIC);
        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(ThemeStyle.MONOCHROMATIC);
        assertThat(mThemeOverlayController.mCurrentColors.get(0).getMainColors().get(
                0).toArgb()).isEqualTo(Color.RED);

@@ -514,13 +515,16 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {
    @Test
    public void onSettingChanged_honorThemeStyle() {
        when(mDeviceProvisionedController.isUserSetup(anyInt())).thenReturn(true);
        @Style.Type List<Integer> validStyles = Arrays.asList(Style.EXPRESSIVE, Style.SPRITZ,
                Style.TONAL_SPOT, Style.FRUIT_SALAD, Style.RAINBOW, Style.VIBRANT);
        for (@Style.Type int style : validStyles) {
        @ThemeStyle.Type List<Integer> validStyles = Arrays.asList(
                ThemeStyle.EXPRESSIVE, ThemeStyle.SPRITZ,
                ThemeStyle.TONAL_SPOT, ThemeStyle.FRUIT_SALAD, ThemeStyle.RAINBOW,
                ThemeStyle.VIBRANT);
        for (@ThemeStyle.Type int style : validStyles) {
            reset(mSecureSettings);

            String jsonString = "{\"android.theme.customization.system_palette\":\"A16B00\","
                    + "\"android.theme.customization.theme_style\":\"" + Style.name(style) + "\"}";
                    + "\"android.theme.customization.theme_style\":\"" + ThemeStyle.name(style)
                    + "\"}";

            when(mSecureSettings.getStringForUser(
                    eq(Settings.Secure.THEME_CUSTOMIZATION_OVERLAY_PACKAGES), anyInt()))
@@ -544,7 +548,7 @@ public class ThemeOverlayControllerTest extends SysuiTestCase {

        mSettingsObserver.getValue().onChange(true, null, 0, mUserTracker.getUserId());

        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(Style.TONAL_SPOT);
        assertThat(mThemeOverlayController.mThemeStyle).isEqualTo(ThemeStyle.TONAL_SPOT);
    }

    @Test
+8 −8
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@ import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.content.res.Resources
import android.content.theming.ThemeStyle
import android.graphics.Rect
import android.hardware.display.DisplayManager
import android.os.Handler
@@ -64,7 +65,6 @@ import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewSmartspaceViewM
import com.android.systemui.keyguard.ui.viewmodel.KeyguardPreviewViewModel
import com.android.systemui.keyguard.ui.viewmodel.KeyguardQuickAffordancesCombinedViewModel
import com.android.systemui.monet.ColorScheme
import com.android.systemui.monet.Style
import com.android.systemui.plugins.keyguard.data.model.WeatherData
import com.android.systemui.plugins.keyguard.ui.clocks.ClockController
import com.android.systemui.plugins.keyguard.ui.clocks.ThemeConfig
@@ -136,7 +136,7 @@ constructor(

    private val shortcutsBindings = mutableSetOf<KeyguardQuickAffordanceViewBinder.Binding>()

    @Style.Type private var themeStyle: Int? = null
    @ThemeStyle.Type private var themeStyle: Int? = null

    init {
        clockController.isPreview = true
@@ -492,7 +492,7 @@ constructor(
            // Seed color null means users do not override any color on the clock. The default
            // color will need to use wallpaper's extracted color and consider if the
            // wallpaper's color is dark or light.
            @Style.Type
            @ThemeStyle.Type
            val style = themeStyle ?: fetchThemeStyleFromSetting().also { themeStyle = it }
            val wallpaperColorScheme = ColorScheme(colors, false, style)
            val lightClockColor = wallpaperColorScheme.accent1.s100
@@ -520,7 +520,7 @@ constructor(
        )
    }

    @Style.Type
    @ThemeStyle.Type
    private suspend fun fetchThemeStyleFromSetting(): Int {
        val overlayPackageJson =
            withContext(backgroundDispatcher) {
@@ -529,16 +529,16 @@ constructor(
        return if (!overlayPackageJson.isNullOrEmpty()) {
            try {
                val jsonObject = JSONObject(overlayPackageJson)
                Style.valueOf(jsonObject.getString(OVERLAY_CATEGORY_THEME_STYLE))
                ThemeStyle.valueOf(jsonObject.getString(OVERLAY_CATEGORY_THEME_STYLE))
            } catch (e: (JSONException)) {
                Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e)
                Style.TONAL_SPOT
                ThemeStyle.TONAL_SPOT
            } catch (e: IllegalArgumentException) {
                Log.i(TAG, "Failed to parse THEME_CUSTOMIZATION_OVERLAY_PACKAGES.", e)
                Style.TONAL_SPOT
                ThemeStyle.TONAL_SPOT
            }
        } else {
            Style.TONAL_SPOT
            ThemeStyle.TONAL_SPOT
        }
    }

+11 −9
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.app.WallpaperColors;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.theming.ThemeStyle;
import android.graphics.Bitmap;
import android.graphics.BlendMode;
import android.graphics.Color;
@@ -102,7 +103,6 @@ import com.android.systemui.media.controls.util.MediaDataUtils;
import com.android.systemui.media.controls.util.MediaUiEventLogger;
import com.android.systemui.media.dialog.MediaOutputDialogManager;
import com.android.systemui.monet.ColorScheme;
import com.android.systemui.monet.Style;
import com.android.systemui.plugins.ActivityStarter;
import com.android.systemui.plugins.FalsingManager;
import com.android.systemui.res.R;
@@ -233,7 +233,8 @@ public class MediaControlPanel {
    private TurbulenceNoiseAnimationConfig mTurbulenceNoiseAnimationConfig;
    private boolean mWasPlaying = false;
    private boolean mButtonClicked = false;
    @Nullable private Runnable mOnSuggestionSpaceVisibleRunnable = null;
    @Nullable
    private Runnable mOnSuggestionSpaceVisibleRunnable = null;

    private final PaintDrawCallback mNoiseDrawCallback =
            new PaintDrawCallback() {
@@ -891,7 +892,8 @@ public class MediaControlPanel {
            WallpaperColors wallpaperColors = getWallpaperColor(artworkIcon);
            boolean darkTheme = false;
            if (wallpaperColors != null) {
                mutableColorScheme = new ColorScheme(wallpaperColors, darkTheme, Style.CONTENT);
                mutableColorScheme = new ColorScheme(wallpaperColors, darkTheme,
                        ThemeStyle.CONTENT);
                artwork = addGradientToPlayerAlbum(artworkIcon, mutableColorScheme, finalWidth,
                        finalHeight);
                isArtworkBound = true;
@@ -903,7 +905,7 @@ public class MediaControlPanel {
                    Drawable icon = mContext.getPackageManager()
                            .getApplicationIcon(data.getPackageName());
                    mutableColorScheme = new ColorScheme(WallpaperColors.fromDrawable(icon),
                            darkTheme, Style.CONTENT);
                            darkTheme, ThemeStyle.CONTENT);
                } catch (PackageManager.NameNotFoundException e) {
                    Log.w(TAG, "Cannot find icon for package " + data.getPackageName(), e);
                }
Loading