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

Commit 59ac876a authored by Catherine Liang's avatar Catherine Liang
Browse files

Clock Carousel Card Color Fix

Fix color of background card for the card carousel, so that clocks don't
completely blend into the background card.

Bug: 296453868
Test: manually verified
Change-Id: I5f239d56cefede41c1d4ab13cfa1c7e0e0b9261e
parent c81b5ce3
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
@@ -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 @@ object ClockCarouselViewBinder {
                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))
                    }
                }
            }
        }

+11 −0
Original line number Diff line number Diff line
@@ -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 @@ class ClockCarouselView(
        }
    }

    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(
+36 −0
Original line number Diff line number Diff line
@@ -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 @@ class ClockCarouselViewModel(

    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 @@ class ClockCarouselViewModel(

    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
    }
}