Merge "Remove PreviewFragment (2/3)" into udc-qpr-dev
diff --git a/OWNERS b/OWNERS
new file mode 100644
index 0000000..04cedef
--- /dev/null
+++ b/OWNERS
@@ -0,0 +1,2 @@
+#Refer the WallpaperPicker2/ThemePicker owners here
+include platform/packages/apps/WallpaperPicker2:/OWNERS
diff --git a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
index 7880d82..b55464d 100644
--- a/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
+++ b/src/com/android/customization/picker/clock/ui/binder/ClockCarouselViewBinder.kt
@@ -16,6 +16,8 @@
package com.android.customization.picker.clock.ui.binder
import android.content.Context
+import android.content.res.Configuration
+import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleEventObserver
@@ -91,6 +93,15 @@
launch {
viewModel.seedColor.collect { clockViewFactory.updateColorForAllClocks(it) }
}
+
+ launch {
+ val night =
+ (context.resources.configuration.uiMode and
+ Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES)
+ viewModel.getClockCardColorResId(night).collect {
+ carouselView.setCarouselCardColor(ContextCompat.getColor(context, it))
+ }
+ }
}
}
diff --git a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
index 2d18ab3..0b62ffa 100644
--- a/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
+++ b/src/com/android/customization/picker/clock/ui/view/ClockCarouselView.kt
@@ -16,6 +16,7 @@
package com.android.customization.picker.clock.ui.view
import android.content.Context
+import android.content.res.ColorStateList
import android.content.res.Resources
import android.util.AttributeSet
import android.view.LayoutInflater
@@ -297,6 +298,16 @@
}
}
+ fun setCarouselCardColor(color: Int) {
+ itemViewIds.forEach { id ->
+ val cardViewId = getClockCardViewId(id)
+ cardViewId?.let {
+ val cardView = motionLayout.requireViewById<View>(it)
+ cardView.backgroundTintList = ColorStateList.valueOf(color)
+ }
+ }
+ }
+
private fun overrideScreenPreviewWidth() {
val overrideWidth =
context.resources.getDimensionPixelSize(
diff --git a/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModel.kt b/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModel.kt
index b2dfa61..27c25a2 100644
--- a/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModel.kt
+++ b/src/com/android/customization/picker/clock/ui/viewmodel/ClockCarouselViewModel.kt
@@ -15,11 +15,13 @@
*/
package com.android.customization.picker.clock.ui.viewmodel
+import android.graphics.Color
import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import androidx.lifecycle.viewModelScope
import com.android.customization.picker.clock.domain.interactor.ClockPickerInteractor
import com.android.customization.picker.clock.shared.ClockSize
+import com.android.wallpaper.R
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.Job
@@ -56,6 +58,38 @@
val seedColor: Flow<Int?> = interactor.seedColor
+ fun getClockCardColorResId(isDarkThemeEnabled: Boolean): Flow<Int> {
+ return interactor.seedColor.map {
+ it.let { seedColor ->
+ // if seedColor is null, default clock color is selected
+ if (seedColor == null) {
+ if (isDarkThemeEnabled) {
+ // In dark mode, use darkest surface container color
+ R.color.system_surface_container_high
+ } else {
+ // In light mode, use lightest surface container color
+ R.color.system_surface_bright
+ }
+ } else {
+ val luminance = Color.luminance(seedColor)
+ if (isDarkThemeEnabled) {
+ if (luminance <= CARD_COLOR_CHANGE_LUMINANCE_THRESHOLD_DARK_THEME) {
+ R.color.system_surface_bright
+ } else {
+ R.color.system_surface_container_high
+ }
+ } else {
+ if (luminance <= CARD_COLOR_CHANGE_LUMINANCE_THRESHOLD_LIGHT_THEME) {
+ R.color.system_surface_bright
+ } else {
+ R.color.system_surface_container_highest
+ }
+ }
+ }
+ }
+ }
+ }
+
@OptIn(ExperimentalCoroutinesApi::class)
val selectedIndex: Flow<Int> =
allClocks
@@ -96,5 +130,7 @@
companion object {
const val CLOCKS_EVENT_UPDATE_DELAY_MILLIS: Long = 100
+ const val CARD_COLOR_CHANGE_LUMINANCE_THRESHOLD_LIGHT_THEME: Float = 0.85f
+ const val CARD_COLOR_CHANGE_LUMINANCE_THRESHOLD_DARK_THEME: Float = 0.03f
}
}