Loading src/com/android/customization/model/color/ColorOption.java +21 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE; import android.content.Context; import android.graphics.Color; import android.text.TextUtils; import android.util.Log; Loading @@ -27,6 +28,7 @@ import androidx.annotation.VisibleForTesting; import com.android.customization.model.CustomizationManager; import com.android.customization.model.CustomizationOption; import com.android.customization.model.color.ColorOptionsProvider.ColorSource; import com.android.customization.module.logging.ThemesUserEventLogger; import com.android.systemui.monet.Style; import com.android.wallpaper.R; Loading Loading @@ -100,6 +102,19 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> { } } /** * Gets the seed color from the overlay packages for logging. * * @return an int representing the seed color, or NULL_SEED_COLOR */ public int getSeedColorForLogging() { String seedColor = mPackagesByCategory.get(OVERLAY_CATEGORY_SYSTEM_PALETTE); if (seedColor == null || seedColor.isEmpty()) { return ThemesUserEventLogger.NULL_SEED_COLOR; } return Color.parseColor(seedColor); } /** * This is similar to #equals() but it only compares this theme's packages with the other, that * is, it will return true if applying this theme has the same effect of applying the given one. Loading Loading @@ -208,6 +223,12 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> { @ColorSource public abstract String getSource(); /** * @return the source of this color option for logging */ @ThemesUserEventLogger.ColorSource public abstract int getSourceForLogging(); /** * @return the style of this color option */ Loading src/com/android/customization/model/color/ColorOptionImpl.kt +10 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.customization.model.color import android.content.Context import android.stats.style.StyleEnums import android.view.View import androidx.annotation.ColorInt import com.android.customization.model.color.ColorOptionsProvider.ColorSource Loading Loading @@ -68,6 +69,15 @@ class ColorOptionImpl( return source } override fun getSourceForLogging(): Int { return when (getSource()) { ColorOptionsProvider.COLOR_SOURCE_PRESET -> StyleEnums.COLOR_SOURCE_PRESET_COLOR ColorOptionsProvider.COLOR_SOURCE_HOME -> StyleEnums.COLOR_SOURCE_HOME_SCREEN_WALLPAPER ColorOptionsProvider.COLOR_SOURCE_LOCK -> StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER else -> StyleEnums.COLOR_SOURCE_UNSPECIFIED } } class Builder { var title: String? = null Loading src/com/android/customization/module/ThemePickerInjector.kt +1 −0 Original line number Diff line number Diff line Loading @@ -423,6 +423,7 @@ internal constructor( ?: ColorPickerViewModel.Factory( context.applicationContext, getColorPickerInteractor(context, wallpaperColorsRepository), userEventLogger, ) .also { colorPickerViewModelFactory = it } } Loading src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt +81 −0 Original line number Diff line number Diff line Loading @@ -19,10 +19,12 @@ package com.android.customization.picker.color.data.repository import android.content.Context import android.graphics.Color import android.text.TextUtils import com.android.customization.model.ResourceConstants import com.android.customization.model.color.ColorOptionImpl import com.android.customization.model.color.ColorOptionsProvider import com.android.customization.picker.color.shared.model.ColorOptionModel import com.android.customization.picker.color.shared.model.ColorType import com.android.systemui.monet.Style import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow Loading @@ -48,6 +50,53 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos setOptions(4, 4, ColorType.WALLPAPER_COLOR, 0) } fun setOptions( wallpaperOptions: List<ColorOptionImpl>, presetOptions: List<ColorOptionImpl>, selectedColorOptionType: ColorType, selectedColorOptionIndex: Int ) { _colorOptions.value = mapOf( ColorType.WALLPAPER_COLOR to buildList { for ((index, colorOption) in wallpaperOptions.withIndex()) { val isSelected = selectedColorOptionType == ColorType.WALLPAPER_COLOR && selectedColorOptionIndex == index val colorOptionModel = ColorOptionModel( key = "${ColorType.WALLPAPER_COLOR}::$index", colorOption = colorOption, isSelected = isSelected ) if (isSelected) { selectedColorOption = colorOptionModel } add(colorOptionModel) } }, ColorType.PRESET_COLOR to buildList { for ((index, colorOption) in presetOptions.withIndex()) { val isSelected = selectedColorOptionType == ColorType.PRESET_COLOR && selectedColorOptionIndex == index val colorOptionModel = ColorOptionModel( key = "${ColorType.PRESET_COLOR}::$index", colorOption = colorOption, isSelected = isSelected ) if (isSelected) { selectedColorOption = colorOptionModel } add(colorOptionModel) } }, ) } fun setOptions( numWallpaperOptions: Int, numPresetOptions: Int, Loading Loading @@ -111,6 +160,22 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos return builder.build() } fun buildPresetOption(style: Style, seedColor: String): ColorOptionImpl { val builder = ColorOptionImpl.Builder() builder.lightColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.darkColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.type = ColorType.PRESET_COLOR builder.source = ColorOptionsProvider.COLOR_SOURCE_PRESET builder.style = style builder.title = "Preset" builder .addOverlayPackage("TEST_PACKAGE_TYPE", "preset_color") .addOverlayPackage(ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE, seedColor) return builder.build() } private fun buildWallpaperOption(index: Int): ColorOptionImpl { val builder = ColorOptionImpl.Builder() builder.lightColors = Loading @@ -127,6 +192,22 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos return builder.build() } fun buildWallpaperOption(source: String, style: Style, seedColor: String): ColorOptionImpl { val builder = ColorOptionImpl.Builder() builder.lightColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.darkColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.type = ColorType.WALLPAPER_COLOR builder.source = source builder.style = style builder.title = "Dynamic" builder .addOverlayPackage("TEST_PACKAGE_TYPE", "wallpaper_color") .addOverlayPackage(ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE, seedColor) return builder.build() } override suspend fun select(colorOptionModel: ColorOptionModel) { val colorOptions = _colorOptions.value val wallpaperColorOptions = colorOptions[ColorType.WALLPAPER_COLOR]!! Loading src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt +12 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.android.customization.model.color.ColorOptionImpl import com.android.customization.module.logging.ThemesUserEventLogger import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor import com.android.customization.picker.color.shared.model.ColorType import com.android.wallpaper.R Loading @@ -43,6 +44,7 @@ class ColorPickerViewModel private constructor( context: Context, private val interactor: ColorPickerInteractor, private val logger: ThemesUserEventLogger, ) : ViewModel() { private val selectedColorTypeTabId = MutableStateFlow<ColorType?>(null) Loading Loading @@ -142,6 +144,14 @@ private constructor( { viewModelScope.launch { interactor.select(colorOptionModel) logger.logThemeColorApplied( colorOptionModel.colorOption .sourceForLogging, colorOptionModel.colorOption.style .ordinal + 1, colorOptionModel.colorOption .seedColorForLogging, ) } } } Loading Loading @@ -205,12 +215,14 @@ private constructor( class Factory( private val context: Context, private val interactor: ColorPickerInteractor, private val logger: ThemesUserEventLogger, ) : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { @Suppress("UNCHECKED_CAST") return ColorPickerViewModel( context = context, interactor = interactor, logger = logger, ) as T } Loading Loading
src/com/android/customization/model/color/ColorOption.java +21 −0 Original line number Diff line number Diff line Loading @@ -19,6 +19,7 @@ import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY import static com.android.customization.model.ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE; import android.content.Context; import android.graphics.Color; import android.text.TextUtils; import android.util.Log; Loading @@ -27,6 +28,7 @@ import androidx.annotation.VisibleForTesting; import com.android.customization.model.CustomizationManager; import com.android.customization.model.CustomizationOption; import com.android.customization.model.color.ColorOptionsProvider.ColorSource; import com.android.customization.module.logging.ThemesUserEventLogger; import com.android.systemui.monet.Style; import com.android.wallpaper.R; Loading Loading @@ -100,6 +102,19 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> { } } /** * Gets the seed color from the overlay packages for logging. * * @return an int representing the seed color, or NULL_SEED_COLOR */ public int getSeedColorForLogging() { String seedColor = mPackagesByCategory.get(OVERLAY_CATEGORY_SYSTEM_PALETTE); if (seedColor == null || seedColor.isEmpty()) { return ThemesUserEventLogger.NULL_SEED_COLOR; } return Color.parseColor(seedColor); } /** * This is similar to #equals() but it only compares this theme's packages with the other, that * is, it will return true if applying this theme has the same effect of applying the given one. Loading Loading @@ -208,6 +223,12 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> { @ColorSource public abstract String getSource(); /** * @return the source of this color option for logging */ @ThemesUserEventLogger.ColorSource public abstract int getSourceForLogging(); /** * @return the style of this color option */ Loading
src/com/android/customization/model/color/ColorOptionImpl.kt +10 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.customization.model.color import android.content.Context import android.stats.style.StyleEnums import android.view.View import androidx.annotation.ColorInt import com.android.customization.model.color.ColorOptionsProvider.ColorSource Loading Loading @@ -68,6 +69,15 @@ class ColorOptionImpl( return source } override fun getSourceForLogging(): Int { return when (getSource()) { ColorOptionsProvider.COLOR_SOURCE_PRESET -> StyleEnums.COLOR_SOURCE_PRESET_COLOR ColorOptionsProvider.COLOR_SOURCE_HOME -> StyleEnums.COLOR_SOURCE_HOME_SCREEN_WALLPAPER ColorOptionsProvider.COLOR_SOURCE_LOCK -> StyleEnums.COLOR_SOURCE_LOCK_SCREEN_WALLPAPER else -> StyleEnums.COLOR_SOURCE_UNSPECIFIED } } class Builder { var title: String? = null Loading
src/com/android/customization/module/ThemePickerInjector.kt +1 −0 Original line number Diff line number Diff line Loading @@ -423,6 +423,7 @@ internal constructor( ?: ColorPickerViewModel.Factory( context.applicationContext, getColorPickerInteractor(context, wallpaperColorsRepository), userEventLogger, ) .also { colorPickerViewModelFactory = it } } Loading
src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt +81 −0 Original line number Diff line number Diff line Loading @@ -19,10 +19,12 @@ package com.android.customization.picker.color.data.repository import android.content.Context import android.graphics.Color import android.text.TextUtils import com.android.customization.model.ResourceConstants import com.android.customization.model.color.ColorOptionImpl import com.android.customization.model.color.ColorOptionsProvider import com.android.customization.picker.color.shared.model.ColorOptionModel import com.android.customization.picker.color.shared.model.ColorType import com.android.systemui.monet.Style import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.asStateFlow Loading @@ -48,6 +50,53 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos setOptions(4, 4, ColorType.WALLPAPER_COLOR, 0) } fun setOptions( wallpaperOptions: List<ColorOptionImpl>, presetOptions: List<ColorOptionImpl>, selectedColorOptionType: ColorType, selectedColorOptionIndex: Int ) { _colorOptions.value = mapOf( ColorType.WALLPAPER_COLOR to buildList { for ((index, colorOption) in wallpaperOptions.withIndex()) { val isSelected = selectedColorOptionType == ColorType.WALLPAPER_COLOR && selectedColorOptionIndex == index val colorOptionModel = ColorOptionModel( key = "${ColorType.WALLPAPER_COLOR}::$index", colorOption = colorOption, isSelected = isSelected ) if (isSelected) { selectedColorOption = colorOptionModel } add(colorOptionModel) } }, ColorType.PRESET_COLOR to buildList { for ((index, colorOption) in presetOptions.withIndex()) { val isSelected = selectedColorOptionType == ColorType.PRESET_COLOR && selectedColorOptionIndex == index val colorOptionModel = ColorOptionModel( key = "${ColorType.PRESET_COLOR}::$index", colorOption = colorOption, isSelected = isSelected ) if (isSelected) { selectedColorOption = colorOptionModel } add(colorOptionModel) } }, ) } fun setOptions( numWallpaperOptions: Int, numPresetOptions: Int, Loading Loading @@ -111,6 +160,22 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos return builder.build() } fun buildPresetOption(style: Style, seedColor: String): ColorOptionImpl { val builder = ColorOptionImpl.Builder() builder.lightColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.darkColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.type = ColorType.PRESET_COLOR builder.source = ColorOptionsProvider.COLOR_SOURCE_PRESET builder.style = style builder.title = "Preset" builder .addOverlayPackage("TEST_PACKAGE_TYPE", "preset_color") .addOverlayPackage(ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE, seedColor) return builder.build() } private fun buildWallpaperOption(index: Int): ColorOptionImpl { val builder = ColorOptionImpl.Builder() builder.lightColors = Loading @@ -127,6 +192,22 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos return builder.build() } fun buildWallpaperOption(source: String, style: Style, seedColor: String): ColorOptionImpl { val builder = ColorOptionImpl.Builder() builder.lightColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.darkColors = intArrayOf(Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT, Color.TRANSPARENT) builder.type = ColorType.WALLPAPER_COLOR builder.source = source builder.style = style builder.title = "Dynamic" builder .addOverlayPackage("TEST_PACKAGE_TYPE", "wallpaper_color") .addOverlayPackage(ResourceConstants.OVERLAY_CATEGORY_SYSTEM_PALETTE, seedColor) return builder.build() } override suspend fun select(colorOptionModel: ColorOptionModel) { val colorOptions = _colorOptions.value val wallpaperColorOptions = colorOptions[ColorType.WALLPAPER_COLOR]!! Loading
src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt +12 −0 Original line number Diff line number Diff line Loading @@ -21,6 +21,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import com.android.customization.model.color.ColorOptionImpl import com.android.customization.module.logging.ThemesUserEventLogger import com.android.customization.picker.color.domain.interactor.ColorPickerInteractor import com.android.customization.picker.color.shared.model.ColorType import com.android.wallpaper.R Loading @@ -43,6 +44,7 @@ class ColorPickerViewModel private constructor( context: Context, private val interactor: ColorPickerInteractor, private val logger: ThemesUserEventLogger, ) : ViewModel() { private val selectedColorTypeTabId = MutableStateFlow<ColorType?>(null) Loading Loading @@ -142,6 +144,14 @@ private constructor( { viewModelScope.launch { interactor.select(colorOptionModel) logger.logThemeColorApplied( colorOptionModel.colorOption .sourceForLogging, colorOptionModel.colorOption.style .ordinal + 1, colorOptionModel.colorOption .seedColorForLogging, ) } } } Loading Loading @@ -205,12 +215,14 @@ private constructor( class Factory( private val context: Context, private val interactor: ColorPickerInteractor, private val logger: ThemesUserEventLogger, ) : ViewModelProvider.Factory { override fun <T : ViewModel> create(modelClass: Class<T>): T { @Suppress("UNCHECKED_CAST") return ColorPickerViewModel( context = context, interactor = interactor, logger = logger, ) as T } Loading