summaryrefslogtreecommitdiff
path: root/src/com/android
diff options
context:
space:
mode:
authorCatherine Liang <cathliang@google.com>2023-08-30 18:04:44 +0000
committerCatherine Liang <cathliang@google.com>2023-09-01 15:45:22 +0000
commita9dc99bf26cc3af546c409fcb6bd5306bcb8b632 (patch)
tree72995b783514ee74a9052c55be724aa38008fe37 /src/com/android
parentfd6c1edb79687b447b0a44accef41d93e130e61e (diff)
downloadThemePicker-a9dc99bf26cc3af546c409fcb6bd5306bcb8b632.tar.gz
Pre-revamped UI color manager & provider cleanup
As part of the revamped UI flag removal process, clean up ColorCustomizationManager, ColorProvider, and color options that are no longer in use--ColorBundle and ColorSeedOption. Also updated and fixed previously failing and ignored tests. Bug: 262780002 Bug: 222433744 Bug: 260925899 Test: fixed and updated previously ignored ColorCustomizationManagerTest & ColorOptionTest, tests now pass Change-Id: Ia1892b4e1e0f48a1297c45fb1430f4e6562c6aad
Diffstat (limited to 'src/com/android')
-rw-r--r--src/com/android/customization/model/color/ColorBundle.java306
-rw-r--r--src/com/android/customization/model/color/ColorBundlePreviewExtractor.java77
-rw-r--r--src/com/android/customization/model/color/ColorCustomizationManager.java17
-rw-r--r--src/com/android/customization/model/color/ColorOption.java5
-rw-r--r--src/com/android/customization/model/color/ColorOptionImpl.kt2
-rw-r--r--src/com/android/customization/model/color/ColorOptionsProvider.java5
-rw-r--r--src/com/android/customization/model/color/ColorProvider.kt305
-rw-r--r--src/com/android/customization/model/color/ColorSeedOption.java252
-rw-r--r--src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt2
9 files changed, 87 insertions, 884 deletions
diff --git a/src/com/android/customization/model/color/ColorBundle.java b/src/com/android/customization/model/color/ColorBundle.java
deleted file mode 100644
index d34f3fc0..00000000
--- a/src/com/android/customization/model/color/ColorBundle.java
+++ /dev/null
@@ -1,306 +0,0 @@
-/*
- * Copyright (C) 2022 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.customization.model.color;
-
-import android.content.Context;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.Color;
-import android.graphics.PorterDuff;
-import android.view.View;
-import android.widget.ImageView;
-
-import androidx.annotation.ColorInt;
-import androidx.annotation.Dimension;
-import androidx.annotation.NonNull;
-import androidx.annotation.VisibleForTesting;
-
-import com.android.customization.model.ResourceConstants;
-import com.android.systemui.monet.Style;
-import com.android.wallpaper.R;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Represents a preset color available for the user to chose as their theming option.
- */
-public class ColorBundle extends ColorOption {
-
- private final PreviewInfo mPreviewInfo;
-
- @VisibleForTesting ColorBundle(String title,
- Map<String, String> overlayPackages, boolean isDefault, Style style, int index,
- PreviewInfo previewInfo) {
- super(title, overlayPackages, isDefault, style, index);
- mPreviewInfo = previewInfo;
- }
-
- @Override
- public void bindThumbnailTile(View view) {
- Resources res = view.getContext().getResources();
- int primaryColor = mPreviewInfo.resolvePrimaryColor(res);
- int secondaryColor = mPreviewInfo.resolveSecondaryColor(res);
-
- for (int i = 0; i < mPreviewColorIds.length; i++) {
- ImageView colorPreviewImageView = view.findViewById(mPreviewColorIds[i]);
- int color = i % 2 == 0 ? primaryColor : secondaryColor;
- colorPreviewImageView.getDrawable().setColorFilter(color, PorterDuff.Mode.SRC);
- }
- view.setContentDescription(getContentDescription(view.getContext()));
- }
-
- @Override
- public PreviewInfo getPreviewInfo() {
- return mPreviewInfo;
- }
-
- @Override
- public int getLayoutResId() {
- return R.layout.color_option;
- }
-
- @Override
- public String getSource() {
- return ColorOptionsProvider.COLOR_SOURCE_PRESET;
- }
-
- /**
- * The preview information of {@link ColorBundle}
- */
- public static class PreviewInfo implements ColorOption.PreviewInfo {
- @ColorInt
- public final int secondaryColorLight;
- @ColorInt public final int secondaryColorDark;
- // Monet system palette and accent colors
- @ColorInt public final int primaryColorLight;
- @ColorInt public final int primaryColorDark;
- @Dimension
- public final int bottomSheetCornerRadius;
-
- @ColorInt private int mOverrideSecondaryColorLight = Color.TRANSPARENT;
- @ColorInt private int mOverrideSecondaryColorDark = Color.TRANSPARENT;
- @ColorInt private int mOverridePrimaryColorLight = Color.TRANSPARENT;
- @ColorInt private int mOverridePrimaryColorDark = Color.TRANSPARENT;
-
- private PreviewInfo(
- int secondaryColorLight, int secondaryColorDark, int colorSystemPaletteLight,
- int primaryColorDark, @Dimension int cornerRadius) {
- this.secondaryColorLight = secondaryColorLight;
- this.secondaryColorDark = secondaryColorDark;
- this.primaryColorLight = colorSystemPaletteLight;
- this.primaryColorDark = primaryColorDark;
- this.bottomSheetCornerRadius = cornerRadius;
- }
-
- /**
- * Returns the accent color to be applied corresponding with the current configuration's
- * UI mode.
- * @return one of {@link #secondaryColorDark} or {@link #secondaryColorLight}
- */
- @ColorInt
- public int resolveSecondaryColor(Resources res) {
- boolean night = (res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
- == Configuration.UI_MODE_NIGHT_YES;
- if (mOverrideSecondaryColorDark != Color.TRANSPARENT
- || mOverrideSecondaryColorLight != Color.TRANSPARENT) {
- return night ? mOverrideSecondaryColorDark : mOverrideSecondaryColorLight;
- }
- return night ? secondaryColorDark : secondaryColorLight;
- }
-
- /**
- * Returns the palette (main) color to be applied corresponding with the current
- * configuration's UI mode.
- * @return one of {@link #secondaryColorDark} or {@link #secondaryColorLight}
- */
- @ColorInt
- public int resolvePrimaryColor(Resources res) {
- boolean night = (res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
- == Configuration.UI_MODE_NIGHT_YES;
- if (mOverridePrimaryColorDark != Color.TRANSPARENT
- || mOverridePrimaryColorLight != Color.TRANSPARENT) {
- return night ? mOverridePrimaryColorDark : mOverridePrimaryColorLight;
- }
- return night ? primaryColorDark
- : primaryColorLight;
- }
-
- /**
- * Sets accent colors to override the ones in this bundle
- */
- public void setOverrideAccentColors(int overrideColorAccentLight,
- int overrideColorAccentDark) {
- mOverrideSecondaryColorLight = overrideColorAccentLight;
- mOverrideSecondaryColorDark = overrideColorAccentDark;
- }
-
- /**
- * Sets palette colors to override the ones in this bundle
- */
- public void setOverridePaletteColors(int overrideColorPaletteLight,
- int overrideColorPaletteDark) {
- mOverridePrimaryColorLight = overrideColorPaletteLight;
- mOverridePrimaryColorDark = overrideColorPaletteDark;
- }
- }
-
- /**
- * The builder of ColorBundle
- */
- public static class Builder {
- protected String mTitle;
- @ColorInt private int mSecondaryColorLight = Color.TRANSPARENT;
- @ColorInt private int mSecondaryColorDark = Color.TRANSPARENT;
- // System and Monet colors
- @ColorInt private int mPrimaryColorLight = Color.TRANSPARENT;
- @ColorInt private int mPrimaryColorDark = Color.TRANSPARENT;
- private boolean mIsDefault;
- private Style mStyle = Style.TONAL_SPOT;
- private int mIndex;
- protected Map<String, String> mPackages = new HashMap<>();
-
- /**
- * Builds the ColorBundle
- * @param context {@link Context}
- * @return new {@link ColorBundle} object
- */
- public ColorBundle build(Context context) {
- if (mTitle == null) {
- mTitle = context.getString(R.string.adaptive_color_title);
- }
- return new ColorBundle(mTitle, mPackages, mIsDefault, mStyle, mIndex,
- createPreviewInfo(context));
- }
-
- /**
- * Creates preview information
- * @param context the {@link Context}
- * @return the {@link PreviewInfo} object
- */
- public PreviewInfo createPreviewInfo(@NonNull Context context) {
- Resources system = context.getResources().getSystem();
- return new PreviewInfo(mSecondaryColorLight,
- mSecondaryColorDark, mPrimaryColorLight, mPrimaryColorDark,
- system.getDimensionPixelOffset(
- system.getIdentifier(ResourceConstants.CONFIG_CORNERRADIUS, "dimen",
- ResourceConstants.ANDROID_PACKAGE)));
- }
-
- public Map<String, String> getPackages() {
- return Collections.unmodifiableMap(mPackages);
- }
-
- /**
- * Gets title of this {@link ColorBundle} object
- * @return title string
- */
- public String getTitle() {
- return mTitle;
- }
-
- /**
- * Sets title of bundle
- * @param title specified title
- * @return this of {@link Builder}
- */
- public Builder setTitle(String title) {
- mTitle = title;
- return this;
- }
-
- /**
- * Sets color accent (light)
- * @param colorSecondaryLight color accent light in {@link ColorInt}
- * @return this of {@link Builder}
- */
- public Builder setColorSecondaryLight(@ColorInt int colorSecondaryLight) {
- mSecondaryColorLight = colorSecondaryLight;
- return this;
- }
-
- /**
- * Sets color accent (dark)
- * @param colorSecondaryDark color accent dark in {@link ColorInt}
- * @return this of {@link Builder}
- */
- public Builder setColorSecondaryDark(@ColorInt int colorSecondaryDark) {
- mSecondaryColorDark = colorSecondaryDark;
- return this;
- }
-
- /**
- * Sets color system palette (light)
- * @param colorPrimaryLight color system palette in {@link ColorInt}
- * @return this of {@link Builder}
- */
- public Builder setColorPrimaryLight(@ColorInt int colorPrimaryLight) {
- mPrimaryColorLight = colorPrimaryLight;
- return this;
- }
-
- /**
- * Sets color system palette (dark)
- * @param colorPrimaryDark color system palette in {@link ColorInt}
- * @return this of {@link Builder}
- */
- public Builder setColorPrimaryDark(@ColorInt int colorPrimaryDark) {
- mPrimaryColorDark = colorPrimaryDark;
- return this;
- }
-
- /**
- * Sets overlay package for bundle
- * @param category the category of bundle
- * @param packageName tha name of package in the category
- * @return this of {@link Builder}
- */
- public Builder addOverlayPackage(String category, String packageName) {
- mPackages.put(category, packageName);
- return this;
- }
-
- /**
- * Sets the style of this color seed
- * @param style color style of {@link Style}
- * @return this of {@link Builder}
- */
- public Builder setStyle(Style style) {
- mStyle = style;
- return this;
- }
-
- /**
- * Sets color option index of bundle
- * @param index color option index
- * @return this of {@link Builder}
- */
- public Builder setIndex(int index) {
- mIndex = index;
- return this;
- }
-
- /**
- * Sets as default bundle
- * @return this of {@link Builder}
- */
- public Builder asDefault() {
- mIsDefault = true;
- return this;
- }
- }
-}
diff --git a/src/com/android/customization/model/color/ColorBundlePreviewExtractor.java b/src/com/android/customization/model/color/ColorBundlePreviewExtractor.java
deleted file mode 100644
index 55b637f6..00000000
--- a/src/com/android/customization/model/color/ColorBundlePreviewExtractor.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Copyright (C) 2022 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.customization.model.color;
-
-import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_COLOR;
-import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE;
-import static com.android.customization.model.color.ColorUtils.toColorString;
-
-import android.content.Context;
-import android.content.pm.PackageManager;
-import android.text.TextUtils;
-import android.util.Log;
-
-import androidx.annotation.ColorInt;
-
-import com.android.systemui.monet.ColorScheme;
-import com.android.systemui.monet.Style;
-
-/**
- * Utility class to read all the details of a color bundle for previewing it
- * (eg, actual color values)
- */
-class ColorBundlePreviewExtractor {
-
- private static final String TAG = "ColorBundlePreviewExtractor";
-
- private final PackageManager mPackageManager;
-
- ColorBundlePreviewExtractor(Context context) {
- mPackageManager = context.getPackageManager();
- }
-
- void addSecondaryColor(ColorBundle.Builder builder, @ColorInt int color) {
- ColorScheme darkColorScheme = new ColorScheme(color, true);
- ColorScheme lightColorScheme = new ColorScheme(color, false);
- int lightSecondary = lightColorScheme.getAccentColor();
- int darkSecondary = darkColorScheme.getAccentColor();
- builder.addOverlayPackage(OVERLAY_CATEGORY_COLOR, toColorString(color))
- .setColorSecondaryLight(lightSecondary)
- .setColorSecondaryDark(darkSecondary);
- }
-
- void addPrimaryColor(ColorBundle.Builder builder, @ColorInt int color) {
- ColorScheme darkColorScheme = new ColorScheme(color, true);
- ColorScheme lightColorScheme = new ColorScheme(color, false);
- int lightPrimary = lightColorScheme.getAccentColor();
- int darkPrimary = darkColorScheme.getAccentColor();
- builder.addOverlayPackage(OVERLAY_CATEGORY_SYSTEM_PALETTE, toColorString(color))
- .setColorPrimaryLight(lightPrimary)
- .setColorPrimaryDark(darkPrimary);
- }
-
- void addColorStyle(ColorBundle.Builder builder, String styleName) {
- Style s = Style.TONAL_SPOT;
- if (!TextUtils.isEmpty(styleName)) {
- try {
- s = Style.valueOf(styleName);
- } catch (IllegalArgumentException e) {
- Log.i(TAG, "Unknown style : " + styleName + ". Will default to TONAL_SPOT.");
- }
- }
- builder.setStyle(s);
- }
-}
diff --git a/src/com/android/customization/model/color/ColorCustomizationManager.java b/src/com/android/customization/model/color/ColorCustomizationManager.java
index 790c86f2..0f87a7b4 100644
--- a/src/com/android/customization/model/color/ColorCustomizationManager.java
+++ b/src/com/android/customization/model/color/ColorCustomizationManager.java
@@ -182,22 +182,7 @@ public class ColorCustomizationManager implements CustomizationManager<ColorOpti
lockWallpaperColors = null;
}
mProvider.fetch(callback, reload, mHomeWallpaperColors,
- lockWallpaperColors, /* shouldUseRevampedUi= */ false);
- }
-
- /**
- * Fetch options function for the customization hub revamped UI
- *
- * TODO (b/276417460): refactor to reduce code repetition with the other fetch options function
- */
- public void fetchRevampedUIOptions(OptionsFetchedListener<ColorOption> callback,
- boolean reload) {
- WallpaperColors lockWallpaperColors = mLockWallpaperColors;
- if (lockWallpaperColors != null && mLockWallpaperColors.equals(mHomeWallpaperColors)) {
- lockWallpaperColors = null;
- }
- mProvider.fetch(callback, reload, mHomeWallpaperColors,
- lockWallpaperColors, /* shouldUseRevampedUi= */ true);
+ lockWallpaperColors);
}
/**
diff --git a/src/com/android/customization/model/color/ColorOption.java b/src/com/android/customization/model/color/ColorOption.java
index 216bb9ba..5d2e9956 100644
--- a/src/com/android/customization/model/color/ColorOption.java
+++ b/src/com/android/customization/model/color/ColorOption.java
@@ -52,8 +52,6 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> {
static final String TIMESTAMP_FIELD = "_applied_timestamp";
protected final Map<String, String> mPackagesByCategory;
- protected final int[] mPreviewColorIds = {R.id.color_preview_0, R.id.color_preview_1,
- R.id.color_preview_2, R.id.color_preview_3};
private final String mTitle;
private final boolean mIsDefault;
private final Style mStyle;
@@ -86,6 +84,9 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> {
if (mIsDefault) {
String serializedOverlays = colorManager.getStoredOverlays();
+ // a default color option is active if the manager has no stored overlays or current
+ // overlays, or the stored overlay does not contain either category system palette or
+ // category color
return (TextUtils.isEmpty(serializedOverlays) || EMPTY_JSON.equals(serializedOverlays)
|| colorManager.getCurrentOverlays().isEmpty() || !(serializedOverlays.contains(
OVERLAY_CATEGORY_SYSTEM_PALETTE) || serializedOverlays.contains(
diff --git a/src/com/android/customization/model/color/ColorOptionImpl.kt b/src/com/android/customization/model/color/ColorOptionImpl.kt
index 3273ce26..b559e35b 100644
--- a/src/com/android/customization/model/color/ColorOptionImpl.kt
+++ b/src/com/android/customization/model/color/ColorOptionImpl.kt
@@ -53,7 +53,7 @@ class ColorOptionImpl(
}
override fun getLayoutResId(): Int {
- return R.layout.color_option
+ return R.layout.color_option_2
}
override fun getPreviewInfo(): PreviewInfo {
diff --git a/src/com/android/customization/model/color/ColorOptionsProvider.java b/src/com/android/customization/model/color/ColorOptionsProvider.java
index 166b4da7..9703907d 100644
--- a/src/com/android/customization/model/color/ColorOptionsProvider.java
+++ b/src/com/android/customization/model/color/ColorOptionsProvider.java
@@ -70,12 +70,9 @@ public interface ColorOptionsProvider {
* @param homeWallpaperColors to get seed colors from
* @param lockWallpaperColors WallpaperColors from the lockscreen wallpaper to get seeds from,
* if different than homeWallpaperColors
- * @param shouldUseRevampedUi fetches color options with new preview mappings for the revamped
- * UI if set to true
*/
void fetch(OptionsFetchedListener<ColorOption> callback, boolean reload,
@Nullable WallpaperColors homeWallpaperColors,
- @Nullable WallpaperColors lockWallpaperColors,
- boolean shouldUseRevampedUi
+ @Nullable WallpaperColors lockWallpaperColors
);
}
diff --git a/src/com/android/customization/model/color/ColorProvider.kt b/src/com/android/customization/model/color/ColorProvider.kt
index 74a4051b..339e558e 100644
--- a/src/com/android/customization/model/color/ColorProvider.kt
+++ b/src/com/android/customization/model/color/ColorProvider.kt
@@ -93,7 +93,6 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
reload: Boolean,
homeWallpaperColors: WallpaperColors?,
lockWallpaperColors: WallpaperColors?,
- shouldUseRevampedUi: Boolean
) {
val wallpaperColorsChanged =
this.homeWallpaperColors != homeWallpaperColors ||
@@ -106,13 +105,12 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
scope.launch {
try {
if (colorBundles == null || reload) {
- loadPreset(shouldUseRevampedUi)
+ loadPreset()
}
if (wallpaperColorsChanged || reload) {
loadSeedColors(
homeWallpaperColors,
lockWallpaperColors,
- shouldUseRevampedUi
)
}
} catch (e: Throwable) {
@@ -138,7 +136,6 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
private fun loadSeedColors(
homeWallpaperColors: WallpaperColors?,
lockWallpaperColors: WallpaperColors?,
- shouldUseRevampedUi: Boolean,
) {
if (homeWallpaperColors == null) return
@@ -159,7 +156,6 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
if (shouldLockColorsGoFirst) COLOR_SOURCE_LOCK else COLOR_SOURCE_HOME,
true,
bundles,
- shouldUseRevampedUi
)
// Second half of the colors
buildColorSeeds(
@@ -168,7 +164,6 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
if (shouldLockColorsGoFirst) COLOR_SOURCE_HOME else COLOR_SOURCE_LOCK,
false,
bundles,
- shouldUseRevampedUi
)
} else {
buildColorSeeds(
@@ -177,35 +172,20 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
COLOR_SOURCE_HOME,
true,
bundles,
- shouldUseRevampedUi
)
}
- if (shouldUseRevampedUi) {
- // Insert monochrome in the second position if it is enabled and included in preset
- // colors
- if (monochromeEnabled) {
- monochromeBundleName?.let {
- bundles.add(
- 1,
- buildRevampedUIPreset(
- it,
- -1,
- Style.MONOCHROMATIC,
- ColorType.WALLPAPER_COLOR
- )
- )
- }
+ // Insert monochrome in the second position if it is enabled and included in preset
+ // colors
+ if (monochromeEnabled) {
+ monochromeBundleName?.let {
+ bundles.add(1, buildPreset(it, -1, Style.MONOCHROMATIC, ColorType.WALLPAPER_COLOR))
}
- bundles.addAll(
- colorBundles?.filterNot {
- (it as ColorOptionImpl).type == ColorType.WALLPAPER_COLOR
- }
- ?: emptyList()
- )
- } else {
- bundles.addAll(colorBundles?.filterNot { it is ColorSeedOption } ?: emptyList())
}
+ bundles.addAll(
+ colorBundles?.filterNot { (it as ColorOptionImpl).type == ColorType.WALLPAPER_COLOR }
+ ?: emptyList()
+ )
colorBundles = bundles
}
@@ -215,13 +195,12 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
source: String,
containsDefault: Boolean,
bundles: MutableList<ColorOption>,
- shouldUseRevampedUi: Boolean,
) {
val seedColors = ColorScheme.getSeedColors(wallpaperColors)
val defaultSeed = seedColors.first()
- buildBundle(defaultSeed, 0, containsDefault, source, bundles, shouldUseRevampedUi)
+ buildBundle(defaultSeed, 0, containsDefault, source, bundles)
for ((i, colorInt) in seedColors.drop(1).take(maxColors - 1).withIndex()) {
- buildBundle(colorInt, i + 1, false, source, bundles, shouldUseRevampedUi)
+ buildBundle(colorInt, i + 1, false, source, bundles)
}
}
@@ -231,102 +210,41 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
isDefault: Boolean,
source: String,
bundles: MutableList<ColorOption>,
- shouldUseRevampedUi: Boolean,
) {
// TODO(b/202145216): Measure time cost in the loop.
- if (shouldUseRevampedUi) {
- for (style in styleList) {
- val lightColorScheme = ColorScheme(colorInt, /* darkTheme= */ false, style)
- val darkColorScheme = ColorScheme(colorInt, /* darkTheme= */ true, style)
- val builder = ColorOptionImpl.Builder()
- builder.lightColors = getRevampedUILightColorPreview(lightColorScheme)
- builder.darkColors = getRevampedUIDarkColorPreview(darkColorScheme)
- builder.addOverlayPackage(
- OVERLAY_CATEGORY_SYSTEM_PALETTE,
- if (isDefault) "" else toColorString(colorInt)
- )
- builder.title =
- when (style) {
- Style.TONAL_SPOT ->
- context.getString(R.string.content_description_dynamic_color_option)
- Style.SPRITZ ->
- context.getString(R.string.content_description_neutral_color_option)
- Style.VIBRANT ->
- context.getString(R.string.content_description_vibrant_color_option)
- Style.EXPRESSIVE ->
- context.getString(R.string.content_description_expressive_color_option)
- else -> context.getString(R.string.content_description_dynamic_color_option)
- }
- builder.source = source
- builder.style = style
- // Color option index value starts from 1.
- builder.index = i + 1
- builder.isDefault = isDefault
- builder.type = ColorType.WALLPAPER_COLOR
- bundles.add(builder.build())
- }
- } else {
- for (style in styleList) {
- val lightColorScheme = ColorScheme(colorInt, /* darkTheme= */ false, style)
- val darkColorScheme = ColorScheme(colorInt, /* darkTheme= */ true, style)
- val builder = ColorSeedOption.Builder()
- builder
- .setLightColors(lightColorScheme.getLightColorPreview())
- .setDarkColors(darkColorScheme.getDarkColorPreview())
- .addOverlayPackage(
- OVERLAY_CATEGORY_SYSTEM_PALETTE,
- if (isDefault) "" else toColorString(colorInt)
- )
- .addOverlayPackage(
- OVERLAY_CATEGORY_COLOR,
- if (isDefault) "" else toColorString(colorInt)
- )
- .setSource(source)
- .setStyle(style)
- // Color option index value starts from 1.
- .setIndex(i + 1)
-
- if (isDefault) builder.asDefault()
-
- bundles.add(builder.build())
- }
- }
- }
-
- /**
- * Returns the colors for the light theme version of the preview of a ColorScheme based on this
- * order: top left, top right, bottom left, bottom right
- */
- @ColorInt
- private fun ColorScheme.getLightColorPreview(): IntArray {
- return when (this.style) {
- Style.EXPRESSIVE ->
- intArrayOf(
- setAlphaComponent(this.accent1.s100, ALPHA_MASK),
- setAlphaComponent(this.accent1.s100, ALPHA_MASK),
- ColorStateList.valueOf(this.neutral2.s500).withLStar(80f).colors[0],
- setAlphaComponent(this.accent2.s500, ALPHA_MASK)
- )
- else ->
- intArrayOf(
- setAlphaComponent(this.accent1.s100, ALPHA_MASK),
- setAlphaComponent(this.accent1.s100, ALPHA_MASK),
- ColorStateList.valueOf(this.accent3.s500).withLStar(85f).colors[0],
- setAlphaComponent(this.accent1.s500, ALPHA_MASK)
- )
+ for (style in styleList) {
+ val lightColorScheme = ColorScheme(colorInt, /* darkTheme= */ false, style)
+ val darkColorScheme = ColorScheme(colorInt, /* darkTheme= */ true, style)
+ val builder = ColorOptionImpl.Builder()
+ builder.lightColors = getLightColorPreview(lightColorScheme)
+ builder.darkColors = getDarkColorPreview(darkColorScheme)
+ builder.addOverlayPackage(
+ OVERLAY_CATEGORY_SYSTEM_PALETTE,
+ if (isDefault) "" else toColorString(colorInt)
+ )
+ builder.title =
+ when (style) {
+ Style.TONAL_SPOT ->
+ context.getString(R.string.content_description_dynamic_color_option)
+ Style.SPRITZ ->
+ context.getString(R.string.content_description_neutral_color_option)
+ Style.VIBRANT ->
+ context.getString(R.string.content_description_vibrant_color_option)
+ Style.EXPRESSIVE ->
+ context.getString(R.string.content_description_expressive_color_option)
+ else -> context.getString(R.string.content_description_dynamic_color_option)
+ }
+ builder.source = source
+ builder.style = style
+ // Color option index value starts from 1.
+ builder.index = i + 1
+ builder.isDefault = isDefault
+ builder.type = ColorType.WALLPAPER_COLOR
+ bundles.add(builder.build())
}
}
/**
- * Returns the color for the dark theme version of the preview of a ColorScheme based on this
- * order: top left, top right, bottom left, bottom right
- */
- @ColorInt
- private fun ColorScheme.getDarkColorPreview(): IntArray {
- return getLightColorPreview()
- }
-
- /**
* Returns the light theme version of the Revamped UI preview of a ColorScheme based on this
* order: top left, top right, bottom left, bottom right
*
@@ -334,7 +252,7 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
* LStar 85, and Tertiary LStar 70
*/
@ColorInt
- private fun getRevampedUILightColorPreview(colorScheme: ColorScheme): IntArray {
+ private fun getLightColorPreview(colorScheme: ColorScheme): IntArray {
return intArrayOf(
setAlphaComponent(colorScheme.accent1.s600, ALPHA_MASK),
setAlphaComponent(colorScheme.accent1.s600, ALPHA_MASK),
@@ -351,7 +269,7 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
* 35, and Tertiary LStar 70
*/
@ColorInt
- private fun getRevampedUIDarkColorPreview(colorScheme: ColorScheme): IntArray {
+ private fun getDarkColorPreview(colorScheme: ColorScheme): IntArray {
return intArrayOf(
setAlphaComponent(colorScheme.accent1.s200, ALPHA_MASK),
setAlphaComponent(colorScheme.accent1.s200, ALPHA_MASK),
@@ -368,7 +286,7 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
* LStar 85, and Tertiary LStar 70
*/
@ColorInt
- private fun getRevampedUILightMonochromePreview(colorScheme: ColorScheme): IntArray {
+ private fun getLightMonochromePreview(colorScheme: ColorScheme): IntArray {
return intArrayOf(
setAlphaComponent(colorScheme.accent1.s1000, ALPHA_MASK),
setAlphaComponent(colorScheme.accent1.s1000, ALPHA_MASK),
@@ -385,7 +303,7 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
* LStar 35, and Tertiary LStar 70
*/
@ColorInt
- private fun getRevampedUIDarkMonochromePreview(colorScheme: ColorScheme): IntArray {
+ private fun getDarkMonochromePreview(colorScheme: ColorScheme): IntArray {
return intArrayOf(
setAlphaComponent(colorScheme.accent1.s10, ALPHA_MASK),
setAlphaComponent(colorScheme.accent1.s10, ALPHA_MASK),
@@ -398,7 +316,7 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
* Returns the Revamped UI preview of a preset ColorScheme based on this order: top left, top
* right, bottom left, bottom right
*/
- private fun getRevampedUIPresetColorPreview(colorScheme: ColorScheme, seed: Int): IntArray {
+ private fun getPresetColorPreview(colorScheme: ColorScheme, seed: Int): IntArray {
val colors =
when (colorScheme.style) {
Style.FRUIT_SALAD -> intArrayOf(seed, colorScheme.accent1.s200)
@@ -414,22 +332,8 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
)
}
- private fun ColorScheme.getPresetColorPreview(seed: Int): IntArray {
- return when (this.style) {
- Style.FRUIT_SALAD -> intArrayOf(seed, this.accent1.s100)
- Style.TONAL_SPOT -> intArrayOf(this.accentColor, this.accentColor)
- Style.MONOCHROMATIC ->
- intArrayOf(
- setAlphaComponent(0x000000, 255),
- setAlphaComponent(0xFFFFFF, 255),
- )
- else -> intArrayOf(this.accent1.s100, this.accent1.s100)
- }
- }
-
- private suspend fun loadPreset(shouldUseRevampedUi: Boolean) =
+ private suspend fun loadPreset() =
withContext(Dispatchers.IO) {
- val extractor = ColorBundlePreviewExtractor(mContext)
val bundles: MutableList<ColorOption> = ArrayList()
val bundleNames =
@@ -438,95 +342,46 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
var index = 1
val maxPresetColors = if (themeStyleEnabled) bundleNames.size else MAX_PRESET_COLORS
- if (shouldUseRevampedUi) {
- // keep track of whether monochrome is included in preset colors to determine
- // inclusion in wallpaper colors
- var hasMonochrome = false
- for (bundleName in bundleNames.take(maxPresetColors)) {
- if (themeStyleEnabled) {
- val styleName =
- try {
- getItemStringFromStub(COLOR_BUNDLE_STYLE_PREFIX, bundleName)
- } catch (e: Resources.NotFoundException) {
- null
- }
- val style =
- try {
- if (styleName != null) Style.valueOf(styleName)
- else Style.TONAL_SPOT
- } catch (e: IllegalArgumentException) {
- Style.TONAL_SPOT
- }
-
- if (style == Style.MONOCHROMATIC) {
- if (!monochromeEnabled) {
- continue
- }
- hasMonochrome = true
- monochromeBundleName = bundleName
+ // keep track of whether monochrome is included in preset colors to determine
+ // inclusion in wallpaper colors
+ var hasMonochrome = false
+ for (bundleName in bundleNames.take(maxPresetColors)) {
+ if (themeStyleEnabled) {
+ val styleName =
+ try {
+ getItemStringFromStub(COLOR_BUNDLE_STYLE_PREFIX, bundleName)
+ } catch (e: Resources.NotFoundException) {
+ null
+ }
+ val style =
+ try {
+ if (styleName != null) Style.valueOf(styleName) else Style.TONAL_SPOT
+ } catch (e: IllegalArgumentException) {
+ Style.TONAL_SPOT
}
- bundles.add(buildRevampedUIPreset(bundleName, index, style))
- } else {
- bundles.add(buildRevampedUIPreset(bundleName, index, null))
- }
-
- index++
- }
- if (!hasMonochrome) {
- monochromeBundleName = null
- }
- } else {
- for (bundleName in bundleNames.take(maxPresetColors)) {
- val builder = ColorBundle.Builder()
- builder.title = getItemStringFromStub(COLOR_BUNDLE_NAME_PREFIX, bundleName)
- builder.setIndex(index)
- val colorFromStub =
- getItemColorFromStub(COLOR_BUNDLE_MAIN_COLOR_PREFIX, bundleName)
- extractor.addPrimaryColor(builder, colorFromStub)
- extractor.addSecondaryColor(builder, colorFromStub)
- if (themeStyleEnabled) {
- val styleName =
- try {
- getItemStringFromStub(COLOR_BUNDLE_STYLE_PREFIX, bundleName)
- } catch (e: Resources.NotFoundException) {
- null
- }
- extractor.addColorStyle(builder, styleName)
- val style =
- try {
- if (styleName != null) Style.valueOf(styleName)
- else Style.TONAL_SPOT
- } catch (e: IllegalArgumentException) {
- Style.TONAL_SPOT
- }
- if (style == Style.MONOCHROMATIC && !monochromeEnabled) {
+ if (style == Style.MONOCHROMATIC) {
+ if (!monochromeEnabled) {
continue
}
-
- val darkColors =
- ColorScheme(colorFromStub, /* darkTheme= */ true, style)
- .getPresetColorPreview(colorFromStub)
- val lightColors =
- ColorScheme(colorFromStub, /* darkTheme= */ false, style)
- .getPresetColorPreview(colorFromStub)
- builder
- .setColorPrimaryDark(darkColors[0])
- .setColorSecondaryDark(darkColors[1])
- builder
- .setColorPrimaryLight(lightColors[0])
- .setColorSecondaryLight(lightColors[1])
+ hasMonochrome = true
+ monochromeBundleName = bundleName
}
-
- bundles.add(builder.build(mContext))
- index++
+ bundles.add(buildPreset(bundleName, index, style))
+ } else {
+ bundles.add(buildPreset(bundleName, index, null))
}
+
+ index++
+ }
+ if (!hasMonochrome) {
+ monochromeBundleName = null
}
colorBundles = bundles
}
- private fun buildRevampedUIPreset(
+ private fun buildPreset(
bundleName: String,
index: Int,
style: Style? = null,
@@ -554,12 +409,12 @@ class ColorProvider(private val context: Context, stubPackageName: String) :
when (style) {
Style.MONOCHROMATIC -> {
- darkColors = getRevampedUIDarkMonochromePreview(darkColorScheme)
- lightColors = getRevampedUILightMonochromePreview(lightColorScheme)
+ darkColors = getDarkMonochromePreview(darkColorScheme)
+ lightColors = getLightMonochromePreview(lightColorScheme)
}
else -> {
- darkColors = getRevampedUIPresetColorPreview(darkColorScheme, colorFromStub)
- lightColors = getRevampedUIPresetColorPreview(lightColorScheme, colorFromStub)
+ darkColors = getPresetColorPreview(darkColorScheme, colorFromStub)
+ lightColors = getPresetColorPreview(lightColorScheme, colorFromStub)
}
}
}
diff --git a/src/com/android/customization/model/color/ColorSeedOption.java b/src/com/android/customization/model/color/ColorSeedOption.java
deleted file mode 100644
index ed38049e..00000000
--- a/src/com/android/customization/model/color/ColorSeedOption.java
+++ /dev/null
@@ -1,252 +0,0 @@
-/*
- * Copyright (C) 2022 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.customization.model.color;
-
-import android.content.Context;
-import android.content.res.Configuration;
-import android.content.res.Resources;
-import android.graphics.PorterDuff.Mode;
-import android.view.View;
-import android.widget.ImageView;
-
-import androidx.annotation.ColorInt;
-import androidx.annotation.VisibleForTesting;
-
-import com.android.customization.model.color.ColorOptionsProvider.ColorSource;
-import com.android.systemui.monet.Style;
-import com.android.wallpaper.R;
-
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Represents a seed color obtained from WallpaperColors, for the user to chose as their theming
- * option.
- */
-public class ColorSeedOption extends ColorOption {
-
- private final PreviewInfo mPreviewInfo;
- @ColorSource
- private final String mSource;
-
- @VisibleForTesting
- ColorSeedOption(String title, Map<String, String> overlayPackages, boolean isDefault,
- @ColorSource String source, Style style, int index, PreviewInfo previewInfo) {
- super(title, overlayPackages, isDefault, style, index);
- mSource = source;
- mPreviewInfo = previewInfo;
- }
-
- @Override
- public PreviewInfo getPreviewInfo() {
- return mPreviewInfo;
- }
-
- @Override
- public String getSource() {
- return mSource;
- }
-
- @Override
- public int getLayoutResId() {
- return R.layout.color_option;
- }
-
- @Override
- public void bindThumbnailTile(View view) {
- Resources res = view.getContext().getResources();
- @ColorInt int[] colors = mPreviewInfo.resolveColors(res);
-
- for (int i = 0; i < mPreviewColorIds.length; i++) {
- ImageView colorPreviewImageView = view.findViewById(mPreviewColorIds[i]);
- colorPreviewImageView.getDrawable().setColorFilter(colors[i], Mode.SRC);
- }
-
- view.setContentDescription(getContentDescription(view.getContext()));
- }
-
- @Override
- public CharSequence getContentDescription(Context context) {
- // Override because we want all options with the same description.
- return context.getString(R.string.wallpaper_color_title);
- }
-
- /**
- * The preview information of {@link ColorOption}
- */
- public static class PreviewInfo implements ColorOption.PreviewInfo {
- @ColorInt public int[] lightColors;
- @ColorInt public int[] darkColors;
-
- private PreviewInfo(@ColorInt int[] lightColors, @ColorInt int[] darkColors) {
- this.lightColors = lightColors;
- this.darkColors = darkColors;
- }
-
- /**
- * Returns the colors to be applied corresponding with the current
- * configuration's UI mode.
- * @param res resources to read to the UI mode configuration from
- * @return one of {@link #lightColors} or {@link #darkColors}
- */
- @ColorInt
- public int[] resolveColors(Resources res) {
- boolean night = (res.getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK)
- == Configuration.UI_MODE_NIGHT_YES;
- return night ? darkColors : lightColors;
- }
-
- /**
- * Returns the preview colors based on whether dark theme or light theme colors are
- * requested.
- * @param darkTheme if true, returns dark theme colors, otherwise returns light theme colors
- * @return one of {@link #lightColors} or {@link #darkColors}
- */
- @ColorInt
- public int[] resolveColors(boolean darkTheme) {
- return darkTheme ? darkColors : lightColors;
- }
- }
-
- /**
- * The builder of ColorSeedOption
- */
- public static class Builder {
- protected String mTitle;
- @ColorInt
- private int[] mLightColors;
- @ColorInt
- private int[] mDarkColors;
- @ColorSource
- private String mSource;
- private boolean mIsDefault;
- private Style mStyle = Style.TONAL_SPOT;
- private int mIndex;
- protected Map<String, String> mPackages = new HashMap<>();
-
- /**
- * Builds the ColorSeedOption
- * @return new {@link ColorOption} object
- */
- public ColorSeedOption build() {
- return new ColorSeedOption(mTitle, mPackages, mIsDefault, mSource, mStyle, mIndex,
- createPreviewInfo());
- }
-
- /**
- * Creates preview information
- * @return the {@link PreviewInfo} object
- */
- public PreviewInfo createPreviewInfo() {
- return new PreviewInfo(mLightColors, mDarkColors);
- }
-
- public Map<String, String> getPackages() {
- return Collections.unmodifiableMap(mPackages);
- }
-
- /**
- * Gets title of {@link ColorOption} object
- * @return title string
- */
- public String getTitle() {
- return mTitle;
- }
-
- /**
- * Sets title of bundle
- * @param title specified title
- * @return this of {@link ColorBundle.Builder}
- */
- public Builder setTitle(String title) {
- mTitle = title;
- return this;
- }
-
- /**
- * Sets the colors for preview in light mode
- * @param lightColors {@link ColorInt} colors for light mode
- * @return this of {@link Builder}
- */
- public Builder setLightColors(@ColorInt int[] lightColors) {
- mLightColors = lightColors;
- return this;
- }
-
- /**
- * Sets the colors for preview in light mode
- * @param darkColors {@link ColorInt} colors for light mode
- * @return this of {@link Builder}
- */
- public Builder setDarkColors(@ColorInt int[] darkColors) {
- mDarkColors = darkColors;
- return this;
- }
-
-
- /**
- * Sets overlay package for bundle
- * @param category the category of bundle
- * @param packageName tha name of package in the category
- * @return this of {@link Builder}
- */
- public Builder addOverlayPackage(String category, String packageName) {
- mPackages.put(category, packageName);
- return this;
- }
-
- /**
- * Sets the source of this color seed
- * @param source typically either {@link ColorOptionsProvider#COLOR_SOURCE_HOME} or
- * {@link ColorOptionsProvider#COLOR_SOURCE_LOCK}
- * @return this of {@link Builder}
- */
- public Builder setSource(@ColorSource String source) {
- mSource = source;
- return this;
- }
-
- /**
- * Sets the source of this color seed
- * @param style color style of {@link Style}
- * @return this of {@link Builder}
- */
- public Builder setStyle(Style style) {
- mStyle = style;
- return this;
- }
-
- /**
- * Sets color option index of seed
- * @param index color option index
- * @return this of {@link ColorBundle.Builder}
- */
- public Builder setIndex(int index) {
- mIndex = index;
- return this;
- }
-
- /**
- * Sets as default bundle
- * @return this of {@link Builder}
- */
- public Builder asDefault() {
- mIsDefault = true;
- return this;
- }
- }
-}
diff --git a/src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt b/src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt
index ce5c0c43..94f17228 100644
--- a/src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt
+++ b/src/com/android/customization/picker/color/data/repository/ColorPickerRepositoryImpl.kt
@@ -80,7 +80,7 @@ class ColorPickerRepositoryImpl(
homeColorsLoaded.colors,
lockColorsLoaded.colors
)
- colorManager.fetchRevampedUIOptions(
+ colorManager.fetchOptions(
object : CustomizationManager.OptionsFetchedListener<ColorOption?> {
override fun onOptionsLoaded(options: MutableList<ColorOption?>?) {
val wallpaperColorOptions: MutableList<ColorOptionModel> =