Loading packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/icon/ui/viewmodel/NotificationIconContainerStatusBarViewModelTest.kt +7 −12 Original line number Diff line number Diff line Loading @@ -225,16 +225,12 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati val displayId = 123 darkIconRepository.darkState(displayId).value = SysuiDarkIconDispatcher.DarkChange(emptyList(), 0f, 0xAABBCC) val iconColorsLookup by collectLastValue(underTest.iconColors(displayId)) assertThat(iconColorsLookup).isNotNull() val iconColors = iconColorsLookup?.iconColors(Rect()) val iconColors by collectLastValue(underTest.iconColors(displayId)) assertThat(iconColors).isNotNull() iconColors!! assertThat(iconColors.tint).isEqualTo(0xAABBCC) assertThat(iconColors!!.tint).isEqualTo(0xAABBCC) val staticDrawableColor = iconColors.staticDrawableColor(Rect()) val staticDrawableColor = iconColors!!.staticDrawableColor(Rect()) assertThat(staticDrawableColor).isEqualTo(0xAABBCC) } Loading @@ -245,8 +241,7 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati val displayId = 321 darkIconRepository.darkState(displayId).value = SysuiDarkIconDispatcher.DarkChange(listOf(Rect(0, 0, 5, 5)), 0f, 0xAABBCC) val iconColorsLookup by collectLastValue(underTest.iconColors(displayId)) val iconColors = iconColorsLookup?.iconColors(Rect(1, 1, 4, 4)) val iconColors by collectLastValue(underTest.iconColors(displayId)) val staticDrawableColor = iconColors?.staticDrawableColor(Rect(6, 6, 7, 7)) assertThat(staticDrawableColor).isEqualTo(DarkIconDispatcher.DEFAULT_ICON_TINT) } Loading @@ -257,9 +252,9 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati val displayId = 987 darkIconRepository.darkState(displayId).value = SysuiDarkIconDispatcher.DarkChange(listOf(Rect(0, 0, 5, 5)), 0f, 0xAABBCC) val iconColorsLookup by collectLastValue(underTest.iconColors(displayId)) val iconColors = iconColorsLookup?.iconColors(Rect(6, 6, 7, 7)) assertThat(iconColors).isNull() val iconColors by collectLastValue(underTest.iconColors(displayId)) assertThat(iconColors!!.staticDrawableColor(Rect(6, 6, 7, 7))) .isEqualTo(DarkIconDispatcher.DEFAULT_ICON_TINT) } @Test Loading packages/SystemUI/multivalentTests/src/com/android/systemui/util/view/ViewUtilTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,20 @@ class ViewUtilTest : SysuiTestCase() { assertThat(outRect.top).isEqualTo(VIEW_TOP) assertThat(outRect.bottom).isEqualTo(VIEW_BOTTOM) } @Test fun viewBoundsOnScreen_viewAnchoredAtOriginInWindow() { // view is anchored at 0,0 in its window view.setLeftTopRightBottom(0, 0, VIEW_RIGHT - VIEW_LEFT, VIEW_BOTTOM - VIEW_TOP) val outRect = Rect() view.viewBoundsOnScreen(outRect) assertThat(outRect.left).isEqualTo(VIEW_LEFT) assertThat(outRect.right).isEqualTo(VIEW_RIGHT) assertThat(outRect.top).isEqualTo(VIEW_TOP) assertThat(outRect.bottom).isEqualTo(VIEW_BOTTOM) } } private const val VIEW_LEFT = 30 Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/ui/viewbinder/NotificationIconContainerViewBinder.kt +1 −18 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.notification.icon.ui.viewbinder import android.graphics.Color import android.graphics.Rect import android.util.Log import android.view.View import android.view.ViewGroup Loading Loading @@ -53,7 +52,6 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.stateIn /** Binds a view-model to a [NotificationIconContainer]. */ Loading @@ -71,10 +69,7 @@ object NotificationIconContainerViewBinder { launch { val contrastColorUtil = ContrastColorUtil.getInstance(view.context) val iconColors: StateFlow<NotificationIconColors> = viewModel .iconColors(displayId) .mapNotNull { it.iconColors(view.viewBounds) } .stateIn(this) viewModel.iconColors(displayId).stateIn(this) viewModel.icons.bindIcons( logTag = "statusbar", view = view, Loading Loading @@ -374,18 +369,6 @@ fun NotifCollection.iconViewStoreBy(block: (IconPack) -> StatusBarIconView?) = getEntry(key)?.icons?.let(block) } private val View.viewBounds: Rect get() { val tmpArray = intArrayOf(0, 0) getLocationOnScreen(tmpArray) return Rect( /* left = */ tmpArray[0], /* top = */ tmpArray[1], /* right = */ left + width, /* bottom = */ top + height, ) } private suspend inline fun <T> Flow<T>.collectTracingEach( tag: String, crossinline collector: (T) -> Unit, Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/ui/viewbinder/StatusBarIconViewBinder.kt +2 −15 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.systemui.statusbar.notification.icon.ui.viewbinder import android.graphics.Rect import android.view.View import com.android.app.tracing.traceSection import com.android.internal.util.ContrastColorUtil import com.android.systemui.res.R Loading @@ -25,6 +23,7 @@ import com.android.systemui.statusbar.StatusBarIconView import com.android.systemui.statusbar.StatusBarIconView.NO_COLOR import com.android.systemui.statusbar.notification.NotificationUtils import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconColors import com.android.systemui.util.view.viewBoundsOnScreen import kotlinx.coroutines.flow.Flow object StatusBarIconViewBinder { Loading Loading @@ -60,25 +59,13 @@ object StatusBarIconViewBinder { val isPreL = java.lang.Boolean.TRUE == view.getTag(R.id.icon_is_pre_L) val isColorized = !isPreL || NotificationUtils.isGrayscale(view, contrastColorUtil) view.staticDrawableColor = if (isColorized) colors.staticDrawableColor(view.viewBounds) else NO_COLOR if (isColorized) colors.staticDrawableColor(view.viewBoundsOnScreen()) else NO_COLOR // Set the color for the overflow dot view.setDecorColor(colors.tint) } } } private val View.viewBounds: Rect get() { val tmpArray = intArrayOf(0, 0) getLocationOnScreen(tmpArray) return Rect( /* left = */ tmpArray[0], /* top = */ tmpArray[1], /* right = */ left + width, /* bottom = */ top + height, ) } private suspend inline fun <T> Flow<T>.collectTracingEach( tag: String, crossinline collector: (T) -> Unit, Loading packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/ui/viewmodel/NotificationIconColors.kt +0 −8 Original line number Diff line number Diff line Loading @@ -17,14 +17,6 @@ package com.android.systemui.statusbar.notification.icon.ui.viewmodel import android.graphics.Rect /** * Lookup the colors to use for the notification icons based on the bounds of the icon container. A * result of `null` indicates that no color changes should be applied. */ fun interface NotificationIconColorLookup { fun iconColors(viewBounds: Rect): NotificationIconColors? } /** Colors to apply to notification icons. */ interface NotificationIconColors { Loading Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/statusbar/notification/icon/ui/viewmodel/NotificationIconContainerStatusBarViewModelTest.kt +7 −12 Original line number Diff line number Diff line Loading @@ -225,16 +225,12 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati val displayId = 123 darkIconRepository.darkState(displayId).value = SysuiDarkIconDispatcher.DarkChange(emptyList(), 0f, 0xAABBCC) val iconColorsLookup by collectLastValue(underTest.iconColors(displayId)) assertThat(iconColorsLookup).isNotNull() val iconColors = iconColorsLookup?.iconColors(Rect()) val iconColors by collectLastValue(underTest.iconColors(displayId)) assertThat(iconColors).isNotNull() iconColors!! assertThat(iconColors.tint).isEqualTo(0xAABBCC) assertThat(iconColors!!.tint).isEqualTo(0xAABBCC) val staticDrawableColor = iconColors.staticDrawableColor(Rect()) val staticDrawableColor = iconColors!!.staticDrawableColor(Rect()) assertThat(staticDrawableColor).isEqualTo(0xAABBCC) } Loading @@ -245,8 +241,7 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati val displayId = 321 darkIconRepository.darkState(displayId).value = SysuiDarkIconDispatcher.DarkChange(listOf(Rect(0, 0, 5, 5)), 0f, 0xAABBCC) val iconColorsLookup by collectLastValue(underTest.iconColors(displayId)) val iconColors = iconColorsLookup?.iconColors(Rect(1, 1, 4, 4)) val iconColors by collectLastValue(underTest.iconColors(displayId)) val staticDrawableColor = iconColors?.staticDrawableColor(Rect(6, 6, 7, 7)) assertThat(staticDrawableColor).isEqualTo(DarkIconDispatcher.DEFAULT_ICON_TINT) } Loading @@ -257,9 +252,9 @@ class NotificationIconContainerStatusBarViewModelTest(flags: FlagsParameterizati val displayId = 987 darkIconRepository.darkState(displayId).value = SysuiDarkIconDispatcher.DarkChange(listOf(Rect(0, 0, 5, 5)), 0f, 0xAABBCC) val iconColorsLookup by collectLastValue(underTest.iconColors(displayId)) val iconColors = iconColorsLookup?.iconColors(Rect(6, 6, 7, 7)) assertThat(iconColors).isNull() val iconColors by collectLastValue(underTest.iconColors(displayId)) assertThat(iconColors!!.staticDrawableColor(Rect(6, 6, 7, 7))) .isEqualTo(DarkIconDispatcher.DEFAULT_ICON_TINT) } @Test Loading
packages/SystemUI/multivalentTests/src/com/android/systemui/util/view/ViewUtilTest.kt +14 −0 Original line number Diff line number Diff line Loading @@ -105,6 +105,20 @@ class ViewUtilTest : SysuiTestCase() { assertThat(outRect.top).isEqualTo(VIEW_TOP) assertThat(outRect.bottom).isEqualTo(VIEW_BOTTOM) } @Test fun viewBoundsOnScreen_viewAnchoredAtOriginInWindow() { // view is anchored at 0,0 in its window view.setLeftTopRightBottom(0, 0, VIEW_RIGHT - VIEW_LEFT, VIEW_BOTTOM - VIEW_TOP) val outRect = Rect() view.viewBoundsOnScreen(outRect) assertThat(outRect.left).isEqualTo(VIEW_LEFT) assertThat(outRect.right).isEqualTo(VIEW_RIGHT) assertThat(outRect.top).isEqualTo(VIEW_TOP) assertThat(outRect.bottom).isEqualTo(VIEW_BOTTOM) } } private const val VIEW_LEFT = 30 Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/ui/viewbinder/NotificationIconContainerViewBinder.kt +1 −18 Original line number Diff line number Diff line Loading @@ -16,7 +16,6 @@ package com.android.systemui.statusbar.notification.icon.ui.viewbinder import android.graphics.Color import android.graphics.Rect import android.util.Log import android.view.View import android.view.ViewGroup Loading Loading @@ -53,7 +52,6 @@ import kotlinx.coroutines.coroutineScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.mapNotNull import kotlinx.coroutines.flow.stateIn /** Binds a view-model to a [NotificationIconContainer]. */ Loading @@ -71,10 +69,7 @@ object NotificationIconContainerViewBinder { launch { val contrastColorUtil = ContrastColorUtil.getInstance(view.context) val iconColors: StateFlow<NotificationIconColors> = viewModel .iconColors(displayId) .mapNotNull { it.iconColors(view.viewBounds) } .stateIn(this) viewModel.iconColors(displayId).stateIn(this) viewModel.icons.bindIcons( logTag = "statusbar", view = view, Loading Loading @@ -374,18 +369,6 @@ fun NotifCollection.iconViewStoreBy(block: (IconPack) -> StatusBarIconView?) = getEntry(key)?.icons?.let(block) } private val View.viewBounds: Rect get() { val tmpArray = intArrayOf(0, 0) getLocationOnScreen(tmpArray) return Rect( /* left = */ tmpArray[0], /* top = */ tmpArray[1], /* right = */ left + width, /* bottom = */ top + height, ) } private suspend inline fun <T> Flow<T>.collectTracingEach( tag: String, crossinline collector: (T) -> Unit, Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/ui/viewbinder/StatusBarIconViewBinder.kt +2 −15 Original line number Diff line number Diff line Loading @@ -16,8 +16,6 @@ package com.android.systemui.statusbar.notification.icon.ui.viewbinder import android.graphics.Rect import android.view.View import com.android.app.tracing.traceSection import com.android.internal.util.ContrastColorUtil import com.android.systemui.res.R Loading @@ -25,6 +23,7 @@ import com.android.systemui.statusbar.StatusBarIconView import com.android.systemui.statusbar.StatusBarIconView.NO_COLOR import com.android.systemui.statusbar.notification.NotificationUtils import com.android.systemui.statusbar.notification.icon.ui.viewmodel.NotificationIconColors import com.android.systemui.util.view.viewBoundsOnScreen import kotlinx.coroutines.flow.Flow object StatusBarIconViewBinder { Loading Loading @@ -60,25 +59,13 @@ object StatusBarIconViewBinder { val isPreL = java.lang.Boolean.TRUE == view.getTag(R.id.icon_is_pre_L) val isColorized = !isPreL || NotificationUtils.isGrayscale(view, contrastColorUtil) view.staticDrawableColor = if (isColorized) colors.staticDrawableColor(view.viewBounds) else NO_COLOR if (isColorized) colors.staticDrawableColor(view.viewBoundsOnScreen()) else NO_COLOR // Set the color for the overflow dot view.setDecorColor(colors.tint) } } } private val View.viewBounds: Rect get() { val tmpArray = intArrayOf(0, 0) getLocationOnScreen(tmpArray) return Rect( /* left = */ tmpArray[0], /* top = */ tmpArray[1], /* right = */ left + width, /* bottom = */ top + height, ) } private suspend inline fun <T> Flow<T>.collectTracingEach( tag: String, crossinline collector: (T) -> Unit, Loading
packages/SystemUI/src/com/android/systemui/statusbar/notification/icon/ui/viewmodel/NotificationIconColors.kt +0 −8 Original line number Diff line number Diff line Loading @@ -17,14 +17,6 @@ package com.android.systemui.statusbar.notification.icon.ui.viewmodel import android.graphics.Rect /** * Lookup the colors to use for the notification icons based on the bounds of the icon container. A * result of `null` indicates that no color changes should be applied. */ fun interface NotificationIconColorLookup { fun iconColors(viewBounds: Rect): NotificationIconColors? } /** Colors to apply to notification icons. */ interface NotificationIconColors { Loading