summaryrefslogtreecommitdiff
path: root/src/com
diff options
context:
space:
mode:
authorCatherine Liang <cathliang@google.com>2023-11-02 15:20:11 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2023-11-02 15:20:11 +0000
commit6cee1974dfed065c2105d46bd5c5e103e9ce4904 (patch)
treee003d823e40672360a463d37588f24ffec01783d /src/com
parent1643e94cbd32ebe7195c4f956b07d0a4709bea97 (diff)
parente1fbbed151bbc6f789b5dbe3d9abbf412158cd12 (diff)
downloadThemePicker-6cee1974dfed065c2105d46bd5c5e103e9ce4904.tar.gz
Merge "[WPP logging] Wire logThemeColorApplied" into main
Diffstat (limited to 'src/com')
-rw-r--r--src/com/android/customization/model/color/ColorOption.java21
-rw-r--r--src/com/android/customization/model/color/ColorOptionImpl.kt10
-rw-r--r--src/com/android/customization/module/ThemePickerInjector.kt1
-rw-r--r--src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt81
-rw-r--r--src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt12
5 files changed, 125 insertions, 0 deletions
diff --git a/src/com/android/customization/model/color/ColorOption.java b/src/com/android/customization/model/color/ColorOption.java
index 5d2e9956..30352217 100644
--- a/src/com/android/customization/model/color/ColorOption.java
+++ b/src/com/android/customization/model/color/ColorOption.java
@@ -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;
@@ -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;
@@ -101,6 +103,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.
*/
@@ -209,6 +224,12 @@ public abstract class ColorOption implements CustomizationOption<ColorOption> {
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
*/
public Style getStyle() {
diff --git a/src/com/android/customization/model/color/ColorOptionImpl.kt b/src/com/android/customization/model/color/ColorOptionImpl.kt
index 3273ce26..461d2a3a 100644
--- a/src/com/android/customization/model/color/ColorOptionImpl.kt
+++ b/src/com/android/customization/model/color/ColorOptionImpl.kt
@@ -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
@@ -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
diff --git a/src/com/android/customization/module/ThemePickerInjector.kt b/src/com/android/customization/module/ThemePickerInjector.kt
index d2781c23..4b2c899c 100644
--- a/src/com/android/customization/module/ThemePickerInjector.kt
+++ b/src/com/android/customization/module/ThemePickerInjector.kt
@@ -423,6 +423,7 @@ internal constructor(
?: ColorPickerViewModel.Factory(
context.applicationContext,
getColorPickerInteractor(context, wallpaperColorsRepository),
+ userEventLogger,
)
.also { colorPickerViewModelFactory = it }
}
diff --git a/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt b/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt
index bb2ef9d3..f35d934d 100644
--- a/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt
+++ b/src/com/android/customization/picker/color/data/repository/FakeColorPickerRepository.kt
@@ -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
@@ -49,6 +51,53 @@ class FakeColorPickerRepository(private val context: Context) : ColorPickerRepos
}
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,
selectedColorOptionType: ColorType,
@@ -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 =
@@ -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]!!
diff --git a/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt b/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt
index 67c68387..3c3d1143 100644
--- a/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt
+++ b/src/com/android/customization/picker/color/ui/viewmodel/ColorPickerViewModel.kt
@@ -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
@@ -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)
@@ -142,6 +144,14 @@ private constructor(
{
viewModelScope.launch {
interactor.select(colorOptionModel)
+ logger.logThemeColorApplied(
+ colorOptionModel.colorOption
+ .sourceForLogging,
+ colorOptionModel.colorOption.style
+ .ordinal + 1,
+ colorOptionModel.colorOption
+ .seedColorForLogging,
+ )
}
}
}
@@ -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
}