Merge "[SB Refactor] Implement tinting in the new wifi view." into tm-qpr-dev

This commit is contained in:
TreeHugger Robot
2022-12-14 05:48:02 +00:00
committed by Android (Google) Code Review
4 changed files with 80 additions and 27 deletions

View File

@@ -46,6 +46,7 @@ import kotlinx.coroutines.launch
* view-model to be reused for multiple view/view-binder bindings. * view-model to be reused for multiple view/view-binder bindings.
*/ */
@OptIn(InternalCoroutinesApi::class) @OptIn(InternalCoroutinesApi::class)
@Suppress("EXPERIMENTAL_IS_NOT_ENABLED")
object WifiViewBinder { object WifiViewBinder {
/** /**
@@ -59,6 +60,12 @@ object WifiViewBinder {
/** Notifies that the visibility state has changed. */ /** Notifies that the visibility state has changed. */
fun onVisibilityStateChanged(@StatusBarIconView.VisibleState state: Int) fun onVisibilityStateChanged(@StatusBarIconView.VisibleState state: Int)
/** Notifies that the icon tint has been updated. */
fun onIconTintChanged(newTint: Int)
/** Notifies that the decor tint has been updated (used only for the dot). */
fun onDecorTintChanged(newTint: Int)
} }
/** Binds the view to the view-model, continuing to update the former based on the latter. */ /** Binds the view to the view-model, continuing to update the former based on the latter. */
@@ -82,6 +89,9 @@ object WifiViewBinder {
@StatusBarIconView.VisibleState @StatusBarIconView.VisibleState
val visibilityState: MutableStateFlow<Int> = MutableStateFlow(STATE_HIDDEN) val visibilityState: MutableStateFlow<Int> = MutableStateFlow(STATE_HIDDEN)
val iconTint: MutableStateFlow<Int> = MutableStateFlow(viewModel.defaultColor)
val decorTint: MutableStateFlow<Int> = MutableStateFlow(viewModel.defaultColor)
view.repeatWhenAttached { view.repeatWhenAttached {
repeatOnLifecycle(Lifecycle.State.STARTED) { repeatOnLifecycle(Lifecycle.State.STARTED) {
launch { launch {
@@ -101,7 +111,7 @@ object WifiViewBinder {
} }
launch { launch {
viewModel.tint.collect { tint -> iconTint.collect { tint ->
val tintList = ColorStateList.valueOf(tint) val tintList = ColorStateList.valueOf(tint)
iconView.imageTintList = tintList iconView.imageTintList = tintList
activityInView.imageTintList = tintList activityInView.imageTintList = tintList
@@ -110,6 +120,8 @@ object WifiViewBinder {
} }
} }
launch { decorTint.collect { tint -> dotView.setDecorColor(tint) } }
launch { launch {
viewModel.isActivityInViewVisible.distinctUntilChanged().collect { visible -> viewModel.isActivityInViewVisible.distinctUntilChanged().collect { visible ->
activityInView.isVisible = visible activityInView.isVisible = visible
@@ -144,6 +156,20 @@ object WifiViewBinder {
override fun onVisibilityStateChanged(@StatusBarIconView.VisibleState state: Int) { override fun onVisibilityStateChanged(@StatusBarIconView.VisibleState state: Int) {
visibilityState.value = state visibilityState.value = state
} }
override fun onIconTintChanged(newTint: Int) {
if (viewModel.useDebugColoring) {
return
}
iconTint.value = newTint
}
override fun onDecorTintChanged(newTint: Int) {
if (viewModel.useDebugColoring) {
return
}
decorTint.value = newTint
}
} }
} }
} }

View File

@@ -22,6 +22,7 @@ import android.util.AttributeSet
import android.view.Gravity import android.view.Gravity
import android.view.LayoutInflater import android.view.LayoutInflater
import com.android.systemui.R import com.android.systemui.R
import com.android.systemui.plugins.DarkIconDispatcher
import com.android.systemui.statusbar.BaseStatusBarFrameLayout import com.android.systemui.statusbar.BaseStatusBarFrameLayout
import com.android.systemui.statusbar.StatusBarIconView import com.android.systemui.statusbar.StatusBarIconView
import com.android.systemui.statusbar.StatusBarIconView.STATE_DOT import com.android.systemui.statusbar.StatusBarIconView.STATE_DOT
@@ -51,18 +52,20 @@ class ModernStatusBarWifiView(
binding.onVisibilityStateChanged(value) binding.onVisibilityStateChanged(value)
} }
override fun onDarkChanged(areas: ArrayList<Rect>?, darkIntensity: Float, tint: Int) {
// TODO(b/238425913)
}
override fun getSlot() = slot override fun getSlot() = slot
override fun onDarkChanged(areas: ArrayList<Rect>?, darkIntensity: Float, tint: Int) {
val newTint = DarkIconDispatcher.getTint(areas, this, tint)
binding.onIconTintChanged(newTint)
binding.onDecorTintChanged(newTint)
}
override fun setStaticDrawableColor(color: Int) { override fun setStaticDrawableColor(color: Int) {
// TODO(b/238425913) binding.onIconTintChanged(color)
} }
override fun setDecorColor(color: Int) { override fun setDecorColor(color: Int) {
// TODO(b/238425913) binding.onDecorTintChanged(color)
} }
override fun setVisibleState(@StatusBarIconView.VisibleState state: Int, animate: Boolean) { override fun setVisibleState(@StatusBarIconView.VisibleState state: Int, animate: Boolean) {

View File

@@ -21,7 +21,6 @@ import com.android.systemui.statusbar.pipeline.StatusBarPipelineFlags
import com.android.systemui.statusbar.pipeline.wifi.ui.model.WifiIcon import com.android.systemui.statusbar.pipeline.wifi.ui.model.WifiIcon
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.StateFlow import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.flowOf
/** /**
* A view model for a wifi icon in a specific location. This allows us to control parameters that * A view model for a wifi icon in a specific location. This allows us to control parameters that
@@ -48,24 +47,12 @@ abstract class LocationBasedWifiViewModel(
/** True if the airplane spacer view should be visible. */ /** True if the airplane spacer view should be visible. */
val isAirplaneSpacerVisible: Flow<Boolean>, val isAirplaneSpacerVisible: Flow<Boolean>,
) { ) {
/** The color that should be used to tint the icon. */ val useDebugColoring: Boolean = statusBarPipelineFlags.useWifiDebugColoring()
val tint: Flow<Int> =
flowOf( val defaultColor: Int =
if (statusBarPipelineFlags.useWifiDebugColoring()) { if (useDebugColoring) {
debugTint debugTint
} else { } else {
DEFAULT_TINT Color.WHITE
}
)
companion object {
/**
* A default icon tint.
*
* TODO(b/238425913): The tint is actually controlled by
* [com.android.systemui.statusbar.phone.StatusBarIconController.TintedIconManager]. We
* should use that logic instead of white as a default.
*/
private const val DEFAULT_TINT = Color.WHITE
} }
} }

View File

@@ -16,11 +16,14 @@
package com.android.systemui.statusbar.pipeline.wifi.ui.view package com.android.systemui.statusbar.pipeline.wifi.ui.view
import android.content.res.ColorStateList
import android.graphics.Rect
import android.testing.AndroidTestingRunner import android.testing.AndroidTestingRunner
import android.testing.TestableLooper import android.testing.TestableLooper
import android.testing.TestableLooper.RunWithLooper import android.testing.TestableLooper.RunWithLooper
import android.testing.ViewUtils import android.testing.ViewUtils
import android.view.View import android.view.View
import android.widget.ImageView
import androidx.test.filters.SmallTest import androidx.test.filters.SmallTest
import com.android.systemui.R import com.android.systemui.R
import com.android.systemui.SysuiTestCase import com.android.systemui.SysuiTestCase
@@ -44,6 +47,7 @@ import com.android.systemui.statusbar.pipeline.wifi.domain.interactor.WifiIntera
import com.android.systemui.statusbar.pipeline.wifi.shared.WifiConstants import com.android.systemui.statusbar.pipeline.wifi.shared.WifiConstants
import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.LocationBasedWifiViewModel import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.LocationBasedWifiViewModel
import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.WifiViewModel import com.android.systemui.statusbar.pipeline.wifi.ui.viewmodel.WifiViewModel
import com.android.systemui.util.mockito.whenever
import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
@@ -229,10 +233,43 @@ class ModernStatusBarWifiViewTest : SysuiTestCase() {
ViewUtils.detachView(view) ViewUtils.detachView(view)
} }
@Test
fun onDarkChanged_iconHasNewColor() {
whenever(statusBarPipelineFlags.useWifiDebugColoring()).thenReturn(false)
val view = ModernStatusBarWifiView.constructAndBind(context, SLOT_NAME, viewModel)
ViewUtils.attachView(view)
testableLooper.processAllMessages()
val areas = ArrayList(listOf(Rect(0, 0, 1000, 1000)))
val color = 0x12345678
view.onDarkChanged(areas, 1.0f, color)
testableLooper.processAllMessages()
assertThat(view.getIconView().imageTintList).isEqualTo(ColorStateList.valueOf(color))
}
@Test
fun setStaticDrawableColor_iconHasNewColor() {
whenever(statusBarPipelineFlags.useWifiDebugColoring()).thenReturn(false)
val view = ModernStatusBarWifiView.constructAndBind(context, SLOT_NAME, viewModel)
ViewUtils.attachView(view)
testableLooper.processAllMessages()
val color = 0x23456789
view.setStaticDrawableColor(color)
testableLooper.processAllMessages()
assertThat(view.getIconView().imageTintList).isEqualTo(ColorStateList.valueOf(color))
}
private fun View.getIconGroupView(): View { private fun View.getIconGroupView(): View {
return this.requireViewById(R.id.wifi_group) return this.requireViewById(R.id.wifi_group)
} }
private fun View.getIconView(): ImageView {
return this.requireViewById(R.id.wifi_signal)
}
private fun View.getDotView(): View { private fun View.getDotView(): View {
return this.requireViewById(R.id.status_bar_dot) return this.requireViewById(R.id.status_bar_dot)
} }