diff options
| author | 2023-12-12 13:42:22 +0000 | |
|---|---|---|
| committer | 2023-12-12 13:42:22 +0000 | |
| commit | 4d77190358b0af262f0c93f7d9e932f61c536ff0 (patch) | |
| tree | 6d95acd2740be54ff743421f9596b6bdfe523f4f | |
| parent | 89de725cbe44b19a3c84f174338e096500f1e27b (diff) | |
| parent | 22a57b8f8ecd204ca2200fb845110232dae3c745 (diff) | |
Merge "Use theme in the mapper to load icons" into main
15 files changed, 198 insertions, 60 deletions
diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapperTest.kt index 2b744ac8398a..00405d0a07e7 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapperTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapperTest.kt @@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles.impl.alarm.domain import android.app.AlarmManager +import android.graphics.drawable.TestStubDrawable import android.widget.Switch import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest @@ -40,7 +41,14 @@ class AlarmTileMapperTest : SysuiTestCase() { private val kosmos = Kosmos() private val alarmTileConfig = kosmos.qsAlarmTileConfig // Using lazy (versus =) to make sure we override the right context -- see b/311612168 - private val mapper by lazy { AlarmTileMapper(context.orCreateTestableResources.resources) } + private val mapper by lazy { + AlarmTileMapper( + context.orCreateTestableResources + .apply { addOverride(R.drawable.ic_alarm, TestStubDrawable()) } + .resources, + context.theme + ) + } @Test fun notAlarmSet() { @@ -100,7 +108,7 @@ class AlarmTileMapperTest : SysuiTestCase() { ): QSTileState { val label = context.getString(R.string.status_bar_alarm) return QSTileState( - { Icon.Resource(R.drawable.ic_alarm, null) }, + { Icon.Loaded(context.getDrawable(R.drawable.ic_alarm)!!, null) }, label, activationState, secondaryLabel, diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapperTest.kt index 7b2ac90b9766..b60f483cccbb 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapperTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapperTest.kt @@ -16,6 +16,7 @@ package com.android.systemui.qs.tiles.impl.flashlight.domain +import android.graphics.drawable.TestStubDrawable import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase @@ -35,7 +36,17 @@ import org.junit.runner.RunWith class FlashlightMapperTest : SysuiTestCase() { private val kosmos = Kosmos() private val qsTileConfig = kosmos.qsFlashlightTileConfig - private val mapper by lazy { FlashlightMapper(context.orCreateTestableResources.resources) } + private val mapper by lazy { + FlashlightMapper( + context.orCreateTestableResources + .apply { + addOverride(R.drawable.qs_flashlight_icon_off, TestStubDrawable()) + addOverride(R.drawable.qs_flashlight_icon_on, TestStubDrawable()) + } + .resources, + context.theme + ) + } @Test fun mapsDisabledDataToInactiveState() { @@ -56,20 +67,20 @@ class FlashlightMapperTest : SysuiTestCase() { @Test fun mapsEnabledDataToOnIconState() { - val expectedIcon = Icon.Resource(R.drawable.qs_flashlight_icon_on, null) - val tileState: QSTileState = mapper.map(qsTileConfig, FlashlightTileModel(true)) + val expectedIcon = + Icon.Loaded(context.getDrawable(R.drawable.qs_flashlight_icon_on)!!, null) val actualIcon = tileState.icon() assertThat(actualIcon).isEqualTo(expectedIcon) } @Test fun mapsDisabledDataToOffIconState() { - val expectedIcon = Icon.Resource(R.drawable.qs_flashlight_icon_off, null) - val tileState: QSTileState = mapper.map(qsTileConfig, FlashlightTileModel(false)) + val expectedIcon = + Icon.Loaded(context.getDrawable(R.drawable.qs_flashlight_icon_off)!!, null) val actualIcon = tileState.icon() assertThat(actualIcon).isEqualTo(expectedIcon) } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapperTest.kt index 8791877f8863..ea74a4c0d398 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapperTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapperTest.kt @@ -16,6 +16,7 @@ package com.android.systemui.qs.tiles.impl.location.domain +import android.graphics.drawable.TestStubDrawable import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest import com.android.systemui.SysuiTestCase @@ -36,7 +37,17 @@ class LocationTileMapperTest : SysuiTestCase() { private val kosmos = Kosmos() private val qsTileConfig = kosmos.qsLocationTileConfig - private val mapper by lazy { LocationTileMapper(context.orCreateTestableResources.resources) } + private val mapper by lazy { + LocationTileMapper( + context.orCreateTestableResources + .apply { + addOverride(R.drawable.qs_location_icon_off, TestStubDrawable()) + addOverride(R.drawable.qs_location_icon_on, TestStubDrawable()) + } + .resources, + context.theme + ) + } @Test fun mapsDisabledDataToInactiveState() { @@ -56,20 +67,18 @@ class LocationTileMapperTest : SysuiTestCase() { @Test fun mapsEnabledDataToOnIconState() { - val expectedIcon = Icon.Resource(R.drawable.qs_location_icon_on, null) - val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(true)) + val expectedIcon = Icon.Loaded(context.getDrawable(R.drawable.qs_location_icon_on)!!, null) val actualIcon = tileState.icon() Truth.assertThat(actualIcon).isEqualTo(expectedIcon) } @Test fun mapsDisabledDataToOffIconState() { - val expectedIcon = Icon.Resource(R.drawable.qs_location_icon_off, null) - val tileState: QSTileState = mapper.map(qsTileConfig, LocationTileModel(false)) + val expectedIcon = Icon.Loaded(context.getDrawable(R.drawable.qs_location_icon_off)!!, null) val actualIcon = tileState.icon() Truth.assertThat(actualIcon).isEqualTo(expectedIcon) } diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapperTest.kt index d1824129590b..d162c778f607 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapperTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapperTest.kt @@ -16,6 +16,7 @@ package com.android.systemui.qs.tiles.impl.saver.domain +import android.graphics.drawable.TestStubDrawable import android.widget.Switch import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.filters.SmallTest @@ -37,7 +38,17 @@ class DataSaverTileMapperTest : SysuiTestCase() { private val dataSaverTileConfig = kosmos.qsDataSaverTileConfig // Using lazy (versus =) to make sure we override the right context -- see b/311612168 - private val mapper by lazy { DataSaverTileMapper(context.orCreateTestableResources.resources) } + private val mapper by lazy { + DataSaverTileMapper( + context.orCreateTestableResources + .apply { + addOverride(R.drawable.qs_data_saver_icon_off, TestStubDrawable()) + addOverride(R.drawable.qs_data_saver_icon_on, TestStubDrawable()) + } + .resources, + context.theme + ) + } @Test fun activeStateMatchesEnabledModel() { @@ -80,7 +91,7 @@ class DataSaverTileMapperTest : SysuiTestCase() { else context.resources.getStringArray(R.array.tile_states_saver)[0] return QSTileState( - { Icon.Resource(iconRes, null) }, + { Icon.Loaded(context.getDrawable(iconRes)!!, null) }, label, activationState, secondaryLabel, diff --git a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapperTest.kt b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapperTest.kt index 87f50090e58b..a9776068b20c 100644 --- a/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapperTest.kt +++ b/packages/SystemUI/multivalentTests/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapperTest.kt @@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles.impl.uimodenight.domain import android.app.UiModeManager +import android.graphics.drawable.TestStubDrawable import android.text.TextUtils import android.view.View import android.widget.Switch @@ -41,7 +42,15 @@ class UiModeNightTileMapperTest : SysuiTestCase() { private val qsTileConfig = kosmos.qsUiModeNightTileConfig private val mapper by lazy { - UiModeNightTileMapper(context.orCreateTestableResources.resources) + UiModeNightTileMapper( + context.orCreateTestableResources + .apply { + addOverride(R.drawable.qs_light_dark_theme_icon_off, TestStubDrawable()) + addOverride(R.drawable.qs_light_dark_theme_icon_on, TestStubDrawable()) + } + .resources, + context.theme + ) } private fun createUiNightModeTileState( @@ -60,7 +69,7 @@ class UiModeNightTileMapperTest : SysuiTestCase() { expandedAccessibilityClass: KClass<out View>? = Switch::class, ): QSTileState { return QSTileState( - { Icon.Resource(iconRes, null) }, + { Icon.Loaded(context.getDrawable(iconRes)!!, null) }, label, activationState, secondaryLabel, diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileUserActionInteractor.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileUserActionInteractor.kt index 09d7a1f7142d..17b78ebf106c 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileUserActionInteractor.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/base/interactor/QSTileUserActionInteractor.kt @@ -24,7 +24,7 @@ interface QSTileUserActionInteractor<DATA_TYPE> { * [QSTileInput.data]. It's guaranteed that [QSTileInput.userId] is the same as the id passed to * [QSTileDataInteractor] to get [QSTileInput.data]. * - * It's safe to run long running computations inside this function in this. + * It's safe to run long running computations inside this function. */ @WorkerThread suspend fun handleInput(input: QSTileInput<DATA_TYPE>) } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/di/QSTilesModule.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/di/QSTilesModule.kt index 4a34276671c1..b325b4daeb81 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/di/QSTilesModule.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/di/QSTilesModule.kt @@ -16,6 +16,8 @@ package com.android.systemui.qs.tiles.di +import android.content.Context +import android.content.res.Resources.Theme import com.android.systemui.qs.external.CustomTileStatePersister import com.android.systemui.qs.external.CustomTileStatePersisterImpl import com.android.systemui.qs.tiles.base.actions.QSTileIntentUserInputHandler @@ -27,6 +29,7 @@ import com.android.systemui.qs.tiles.viewmodel.QSTileConfigProviderImpl import com.android.systemui.qs.tiles.viewmodel.QSTileViewModel import dagger.Binds import dagger.Module +import dagger.Provides import dagger.multibindings.Multibinds /** Module listing subcomponents */ @@ -57,4 +60,9 @@ interface QSTilesModule { @Binds fun bindCustomTileStatePersister(impl: CustomTileStatePersisterImpl): CustomTileStatePersister + + companion object { + + @Provides fun provideTilesTheme(context: Context): Theme = context.theme + } } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/airplane/domain/AirplaneModeMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/airplane/domain/AirplaneModeMapper.kt index cfb544226c83..9b8dba166274 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/airplane/domain/AirplaneModeMapper.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/airplane/domain/AirplaneModeMapper.kt @@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles.impl.airplane.domain import android.content.res.Resources +import android.content.res.Resources.Theme import com.android.systemui.common.shared.model.Icon import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper @@ -27,18 +28,25 @@ import com.android.systemui.res.R import javax.inject.Inject /** Maps [AirplaneModeTileModel] to [QSTileState]. */ -class AirplaneModeMapper @Inject constructor(@Main private val resources: Resources) : - QSTileDataToStateMapper<AirplaneModeTileModel> { +class AirplaneModeMapper +@Inject +constructor( + @Main private val resources: Resources, + val theme: Theme, +) : QSTileDataToStateMapper<AirplaneModeTileModel> { override fun map(config: QSTileConfig, data: AirplaneModeTileModel): QSTileState = - QSTileState.build(resources, config.uiConfig) { + QSTileState.build(resources, theme, config.uiConfig) { val icon = - Icon.Resource( - if (data.isEnabled) { - R.drawable.qs_airplane_icon_on - } else { - R.drawable.qs_airplane_icon_off - }, + Icon.Loaded( + resources.getDrawable( + if (data.isEnabled) { + R.drawable.qs_airplane_icon_on + } else { + R.drawable.qs_airplane_icon_off + }, + theme, + ), contentDescription = null ) this.icon = { icon } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapper.kt index 63865777e14f..e075e76595d4 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapper.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/alarm/domain/AlarmTileMapper.kt @@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles.impl.alarm.domain import android.content.res.Resources +import android.content.res.Resources.Theme import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper import com.android.systemui.qs.tiles.impl.alarm.domain.model.AlarmTileModel @@ -30,14 +31,18 @@ import java.util.TimeZone import javax.inject.Inject /** Maps [AlarmTileModel] to [QSTileState]. */ -class AlarmTileMapper @Inject constructor(@Main private val resources: Resources) : - QSTileDataToStateMapper<AlarmTileModel> { +class AlarmTileMapper +@Inject +constructor( + @Main private val resources: Resources, + private val theme: Theme, +) : QSTileDataToStateMapper<AlarmTileModel> { companion object { val formatter12Hour: DateTimeFormatter = DateTimeFormatter.ofPattern("E hh:mm a") val formatter24Hour: DateTimeFormatter = DateTimeFormatter.ofPattern("E HH:mm") } override fun map(config: QSTileConfig, data: AlarmTileModel): QSTileState = - QSTileState.build(resources, config.uiConfig) { + QSTileState.build(resources, theme, config.uiConfig) { when (data) { is AlarmTileModel.NextAlarmSet -> { activationState = QSTileState.ActivationState.ACTIVE diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapper.kt index 881a6bd156d2..1b3b5848a7ce 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapper.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/flashlight/domain/FlashlightMapper.kt @@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles.impl.flashlight.domain import android.content.res.Resources +import android.content.res.Resources.Theme import com.android.systemui.common.shared.model.Icon import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper @@ -27,18 +28,25 @@ import com.android.systemui.res.R import javax.inject.Inject /** Maps [FlashlightTileModel] to [QSTileState]. */ -class FlashlightMapper @Inject constructor(@Main private val resources: Resources) : - QSTileDataToStateMapper<FlashlightTileModel> { +class FlashlightMapper +@Inject +constructor( + @Main private val resources: Resources, + private val theme: Theme, +) : QSTileDataToStateMapper<FlashlightTileModel> { override fun map(config: QSTileConfig, data: FlashlightTileModel): QSTileState = - QSTileState.build(resources, config.uiConfig) { + QSTileState.build(resources, theme, config.uiConfig) { val icon = - Icon.Resource( - if (data.isEnabled) { - R.drawable.qs_flashlight_icon_on - } else { - R.drawable.qs_flashlight_icon_off - }, + Icon.Loaded( + resources.getDrawable( + if (data.isEnabled) { + R.drawable.qs_flashlight_icon_on + } else { + R.drawable.qs_flashlight_icon_off + }, + theme, + ), contentDescription = null ) this.icon = { icon } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapper.kt index 7e7034d65efd..fe5445d00670 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapper.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/location/domain/LocationTileMapper.kt @@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles.impl.location.domain import android.content.res.Resources +import android.content.res.Resources.Theme import com.android.systemui.common.shared.model.Icon import com.android.systemui.dagger.qualifiers.Main import com.android.systemui.qs.tiles.base.interactor.QSTileDataToStateMapper @@ -27,18 +28,25 @@ import com.android.systemui.res.R import javax.inject.Inject /** Maps [LocationTileModel] to [QSTileState]. */ -class LocationTileMapper @Inject constructor(@Main private val resources: Resources) : - QSTileDataToStateMapper<LocationTileModel> { +class LocationTileMapper +@Inject +constructor( + @Main private val resources: Resources, + private val theme: Theme, +) : QSTileDataToStateMapper<LocationTileModel> { override fun map(config: QSTileConfig, data: LocationTileModel): QSTileState = - QSTileState.build(resources, config.uiConfig) { + QSTileState.build(resources, theme, config.uiConfig) { val icon = - Icon.Resource( - if (data.isEnabled) { - R.drawable.qs_location_icon_on - } else { - R.drawable.qs_location_icon_off - }, + Icon.Loaded( + resources.getDrawable( + if (data.isEnabled) { + R.drawable.qs_location_icon_on + } else { + R.drawable.qs_location_icon_off + }, + theme, + ), contentDescription = null ) this.icon = { icon } diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapper.kt index 25b09131522b..df25600228a5 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapper.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/saver/domain/DataSaverTileMapper.kt @@ -27,20 +27,28 @@ import com.android.systemui.res.R import javax.inject.Inject /** Maps [DataSaverTileModel] to [QSTileState]. */ -class DataSaverTileMapper @Inject constructor(@Main private val resources: Resources) : - QSTileDataToStateMapper<DataSaverTileModel> { +class DataSaverTileMapper +@Inject +constructor( + @Main private val resources: Resources, + private val theme: Resources.Theme, +) : QSTileDataToStateMapper<DataSaverTileModel> { override fun map(config: QSTileConfig, data: DataSaverTileModel): QSTileState = - QSTileState.build(resources, config.uiConfig) { + QSTileState.build(resources, theme, config.uiConfig) { with(data) { + val iconRes: Int if (isEnabled) { activationState = QSTileState.ActivationState.ACTIVE - icon = { Icon.Resource(R.drawable.qs_data_saver_icon_on, null) } + iconRes = R.drawable.qs_data_saver_icon_on secondaryLabel = resources.getStringArray(R.array.tile_states_saver)[2] } else { activationState = QSTileState.ActivationState.INACTIVE - icon = { Icon.Resource(R.drawable.qs_data_saver_icon_off, null) } + iconRes = R.drawable.qs_data_saver_icon_off secondaryLabel = resources.getStringArray(R.array.tile_states_saver)[1] } + val loadedIcon = + Icon.Loaded(resources.getDrawable(iconRes, theme), contentDescription = null) + icon = { loadedIcon } contentDescription = label supportedActions = setOf(QSTileState.UserAction.CLICK, QSTileState.UserAction.LONG_CLICK) diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapper.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapper.kt index 3f30c75a6b6a..ffef2b6ecfb5 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapper.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/impl/uimodenight/domain/UiModeNightTileMapper.kt @@ -18,6 +18,7 @@ package com.android.systemui.qs.tiles.impl.uimodenight.domain import android.app.UiModeManager import android.content.res.Resources +import android.content.res.Resources.Theme import android.text.TextUtils import com.android.systemui.common.shared.model.Icon import com.android.systemui.dagger.qualifiers.Main @@ -31,15 +32,19 @@ import java.time.format.DateTimeFormatter import javax.inject.Inject /** Maps [UiModeNightTileModel] to [QSTileState]. */ -class UiModeNightTileMapper @Inject constructor(@Main private val resources: Resources) : - QSTileDataToStateMapper<UiModeNightTileModel> { +class UiModeNightTileMapper +@Inject +constructor( + @Main private val resources: Resources, + private val theme: Theme, +) : QSTileDataToStateMapper<UiModeNightTileModel> { companion object { val formatter12Hour: DateTimeFormatter = DateTimeFormatter.ofPattern("hh:mm a") val formatter24Hour: DateTimeFormatter = DateTimeFormatter.ofPattern("HH:mm") } override fun map(config: QSTileConfig, data: UiModeNightTileModel): QSTileState = with(data) { - QSTileState.build(resources, config.uiConfig) { + QSTileState.build(resources, theme, config.uiConfig) { var shouldSetSecondaryLabel = false if (isPowerSave) { @@ -116,8 +121,9 @@ class UiModeNightTileMapper @Inject constructor(@Main private val resources: Res if (activationState == QSTileState.ActivationState.ACTIVE) R.drawable.qs_light_dark_theme_icon_on else R.drawable.qs_light_dark_theme_icon_off - val iconResource = Icon.Resource(iconRes, null) - icon = { iconResource } + val loadedIcon = + Icon.Loaded(resources.getDrawable(iconRes, theme), contentDescription = null) + icon = { loadedIcon } supportedActions = if (activationState == QSTileState.ActivationState.UNAVAILABLE) diff --git a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileState.kt b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileState.kt index 23e0cb66bb6a..be1b7404314f 100644 --- a/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileState.kt +++ b/packages/SystemUI/src/com/android/systemui/qs/tiles/viewmodel/QSTileState.kt @@ -17,6 +17,7 @@ package com.android.systemui.qs.tiles.viewmodel import android.content.res.Resources +import android.content.res.Resources.Theme import android.service.quicksettings.Tile import android.view.View import android.widget.Switch @@ -47,14 +48,17 @@ data class QSTileState( fun build( resources: Resources, + theme: Theme, config: QSTileUIConfig, build: Builder.() -> Unit - ): QSTileState = - build( - { Icon.Resource(config.iconRes, null) }, + ): QSTileState { + val iconDrawable = resources.getDrawable(config.iconRes, theme) + return build( + { Icon.Loaded(iconDrawable, null) }, resources.getString(config.labelRes), build, ) + } fun build(icon: () -> Icon, label: CharSequence, build: Builder.() -> Unit): QSTileState = Builder(icon, label).apply(build).build() diff --git a/packages/SystemUI/tests/utils/src/android/graphics/drawable/TestStubDrawable.kt b/packages/SystemUI/tests/utils/src/android/graphics/drawable/TestStubDrawable.kt new file mode 100644 index 000000000000..b88f302cdfdd --- /dev/null +++ b/packages/SystemUI/tests/utils/src/android/graphics/drawable/TestStubDrawable.kt @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2023 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 android.graphics.drawable + +import android.graphics.Canvas +import android.graphics.ColorFilter +import android.graphics.PixelFormat + +/** + * Stub drawable that does nothing. It's to be used in tests as a mock drawable and checked for the + * same instance + */ +class TestStubDrawable : Drawable() { + + override fun draw(canvas: Canvas) = Unit + override fun setAlpha(alpha: Int) = Unit + override fun setColorFilter(colorFilter: ColorFilter?) = Unit + override fun getOpacity(): Int = PixelFormat.UNKNOWN + + override fun equals(other: Any?): Boolean = this === other +} |