diff options
| -rw-r--r-- | packages/SystemUI/ktfmt_includes.txt | 4 | ||||
| -rw-r--r-- | packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt (renamed from packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt) | 71 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/keyguard/ClockEventController.kt | 26 | ||||
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt | 33 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplerTest.kt (renamed from packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt) | 55 |
5 files changed, 78 insertions, 111 deletions
diff --git a/packages/SystemUI/ktfmt_includes.txt b/packages/SystemUI/ktfmt_includes.txt index da612a9276a3..9f211c92c7c0 100644 --- a/packages/SystemUI/ktfmt_includes.txt +++ b/packages/SystemUI/ktfmt_includes.txt @@ -27,8 +27,6 @@ -packages/SystemUI/shared/src/com/android/systemui/shared/clocks/AnimatableClockView.kt -packages/SystemUI/shared/src/com/android/systemui/shared/clocks/ClockRegistry.kt -packages/SystemUI/shared/src/com/android/systemui/shared/clocks/DefaultClockProvider.kt --packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionDarkness.kt --packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt -packages/SystemUI/shared/src/com/android/systemui/shared/rotation/FloatingRotationButtonPositionCalculator.kt -packages/SystemUI/shared/src/com/android/systemui/shared/system/UncaughtExceptionPreHandlerManager.kt -packages/SystemUI/shared/src/com/android/systemui/shared/system/smartspace/SmartspaceState.kt @@ -683,8 +681,6 @@ -packages/SystemUI/tests/src/com/android/systemui/shared/animation/UnfoldConstantTranslateAnimatorTest.kt -packages/SystemUI/tests/src/com/android/systemui/shared/animation/UnfoldMoveFromCenterAnimatorTest.kt -packages/SystemUI/tests/src/com/android/systemui/shared/clocks/ClockRegistryTest.kt --packages/SystemUI/tests/src/com/android/systemui/shared/navigationbar/RegionSamplingHelperTest.kt --packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt -packages/SystemUI/tests/src/com/android/systemui/shared/rotation/RotationButtonControllerTest.kt -packages/SystemUI/tests/src/com/android/systemui/shared/system/UncaughtExceptionPreHandlerTest.kt -packages/SystemUI/tests/src/com/android/systemui/smartspace/DreamSmartspaceControllerTest.kt diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt index cd4b9994ccca..0ee813b84402 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt @@ -24,15 +24,13 @@ import com.android.systemui.shared.navigationbar.RegionSamplingHelper.SamplingCa import java.io.PrintWriter import java.util.concurrent.Executor -/** - * Class for instance of RegionSamplingHelper - */ -open class RegionSamplingInstance( - sampledView: View?, - mainExecutor: Executor?, - bgExecutor: Executor?, - regionSamplingEnabled: Boolean, - updateFun: UpdateColorCallback +/** Class for instance of RegionSamplingHelper */ +open class RegionSampler( + sampledView: View?, + mainExecutor: Executor?, + bgExecutor: Executor?, + regionSamplingEnabled: Boolean, + updateFun: UpdateColorCallback ) { private var regionDarkness = RegionDarkness.DEFAULT private var samplingBounds = Rect() @@ -40,23 +38,13 @@ open class RegionSamplingInstance( @VisibleForTesting var regionSampler: RegionSamplingHelper? = null private var lightForegroundColor = Color.WHITE private var darkForegroundColor = Color.BLACK - /** - * Interface for method to be passed into RegionSamplingHelper - */ - @FunctionalInterface - interface UpdateColorCallback { - /** - * Method to update the foreground colors after clock darkness changed. - */ - fun updateColors() - } @VisibleForTesting open fun createRegionSamplingHelper( - sampledView: View, - callback: SamplingCallback, - mainExecutor: Executor?, - bgExecutor: Executor? + sampledView: View, + callback: SamplingCallback, + mainExecutor: Executor?, + bgExecutor: Executor? ): RegionSamplingHelper { return RegionSamplingHelper(sampledView, callback, mainExecutor, bgExecutor) } @@ -77,7 +65,7 @@ open class RegionSamplingInstance( * * @return the determined foreground color */ - fun currentForegroundColor(): Int{ + fun currentForegroundColor(): Int { return if (regionDarkness.isDark) { lightForegroundColor } else { @@ -97,41 +85,37 @@ open class RegionSamplingInstance( return regionDarkness } - /** - * Start region sampler - */ + /** Start region sampler */ fun startRegionSampler() { regionSampler?.start(samplingBounds) } - /** - * Stop region sampler - */ + /** Stop region sampler */ fun stopRegionSampler() { regionSampler?.stop() } - /** - * Dump region sampler - */ + /** Dump region sampler */ fun dump(pw: PrintWriter) { regionSampler?.dump(pw) } init { if (regionSamplingEnabled && sampledView != null) { - regionSampler = createRegionSamplingHelper(sampledView, + regionSampler = + createRegionSamplingHelper( + sampledView, object : SamplingCallback { override fun onRegionDarknessChanged(isRegionDark: Boolean) { regionDarkness = convertToClockDarkness(isRegionDark) - updateFun.updateColors() + updateFun() } /** - * The method getLocationOnScreen is used to obtain the view coordinates - * relative to its left and top edges on the device screen. - * Directly accessing the X and Y coordinates of the view returns the - * location relative to its parent view instead. - */ + * The method getLocationOnScreen is used to obtain the view coordinates + * relative to its left and top edges on the device screen. Directly + * accessing the X and Y coordinates of the view returns the location + * relative to its parent view instead. + */ override fun getSampledRegion(sampledView: View): Rect { val screenLocation = tmpScreenLocation sampledView.getLocationOnScreen(screenLocation) @@ -147,8 +131,13 @@ open class RegionSamplingInstance( override fun isSamplingEnabled(): Boolean { return regionSamplingEnabled } - }, mainExecutor, bgExecutor) + }, + mainExecutor, + bgExecutor + ) } regionSampler?.setWindowVisible(true) } } + +typealias UpdateColorCallback = () -> Unit diff --git a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt index b59b17448ba4..930798143aa5 100644 --- a/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt +++ b/packages/SystemUI/src/com/android/keyguard/ClockEventController.kt @@ -38,21 +38,21 @@ import com.android.systemui.lifecycle.repeatWhenAttached import com.android.systemui.log.dagger.KeyguardClockLog import com.android.systemui.plugins.ClockController import com.android.systemui.plugins.log.LogBuffer -import com.android.systemui.shared.regionsampling.RegionSamplingInstance +import com.android.systemui.shared.regionsampling.RegionSampler import com.android.systemui.statusbar.policy.BatteryController import com.android.systemui.statusbar.policy.BatteryController.BatteryStateChangeCallback import com.android.systemui.statusbar.policy.ConfigurationController -import java.io.PrintWriter -import java.util.Locale -import java.util.TimeZone -import java.util.concurrent.Executor -import javax.inject.Inject import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DisposableHandle import kotlinx.coroutines.Job import kotlinx.coroutines.flow.collect import kotlinx.coroutines.flow.combine import kotlinx.coroutines.launch +import java.io.PrintWriter +import java.util.Locale +import java.util.TimeZone +import java.util.concurrent.Executor +import javax.inject.Inject /** * Controller for a Clock provided by the registry and used on the keyguard. Instantiated by @@ -142,21 +142,17 @@ open class ClockEventController @Inject constructor( bgExecutor: Executor?, regionSamplingEnabled: Boolean, updateColors: () -> Unit - ): RegionSamplingInstance { - return RegionSamplingInstance( + ): RegionSampler { + return RegionSampler( sampledView, mainExecutor, bgExecutor, regionSamplingEnabled, - object : RegionSamplingInstance.UpdateColorCallback { - override fun updateColors() { - updateColors() - } - }) + updateFun = { updateColors() } ) } - var smallRegionSampler: RegionSamplingInstance? = null - var largeRegionSampler: RegionSamplingInstance? = null + var smallRegionSampler: RegionSampler? = null + var largeRegionSampler: RegionSampler? = null private var smallClockIsDark = true private var largeClockIsDark = true diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt index 842204bbf621..e4a8f219236c 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt @@ -48,7 +48,8 @@ import com.android.systemui.plugins.BcSmartspaceDataPlugin.SmartspaceView import com.android.systemui.plugins.FalsingManager import com.android.systemui.plugins.statusbar.StatusBarStateController import com.android.systemui.settings.UserTracker -import com.android.systemui.shared.regionsampling.RegionSamplingInstance +import com.android.systemui.shared.regionsampling.RegionSampler +import com.android.systemui.shared.regionsampling.UpdateColorCallback import com.android.systemui.statusbar.phone.KeyguardBypassController import com.android.systemui.statusbar.policy.ConfigurationController import com.android.systemui.statusbar.policy.DeviceProvisionedController @@ -90,8 +91,8 @@ class LockscreenSmartspaceController @Inject constructor( // Smartspace can be used on multiple displays, such as when the user casts their screen private var smartspaceViews = mutableSetOf<SmartspaceView>() - private var regionSamplingInstances = - mutableMapOf<SmartspaceView, RegionSamplingInstance>() + private var regionSamplers = + mutableMapOf<SmartspaceView, RegionSampler>() private val regionSamplingEnabled = featureFlags.isEnabled(Flags.REGION_SAMPLING) @@ -101,26 +102,22 @@ class LockscreenSmartspaceController @Inject constructor( private var showSensitiveContentForManagedUser = false private var managedUserHandle: UserHandle? = null - private val updateFun = object : RegionSamplingInstance.UpdateColorCallback { - override fun updateColors() { - updateTextColorFromRegionSampler() - } - } + private val updateFun: UpdateColorCallback = { updateTextColorFromRegionSampler() } var stateChangeListener = object : View.OnAttachStateChangeListener { override fun onViewAttachedToWindow(v: View) { smartspaceViews.add(v as SmartspaceView) - var regionSamplingInstance = RegionSamplingInstance( + var regionSampler = RegionSampler( v, uiExecutor, bgExecutor, regionSamplingEnabled, updateFun ) - initializeTextColors(regionSamplingInstance) - regionSamplingInstance.startRegionSampler() - regionSamplingInstances.put(v, regionSamplingInstance) + initializeTextColors(regionSampler) + regionSampler.startRegionSampler() + regionSamplers.put(v, regionSampler) connectSession() updateTextColorFromWallpaper() @@ -130,9 +127,9 @@ class LockscreenSmartspaceController @Inject constructor( override fun onViewDetachedFromWindow(v: View) { smartspaceViews.remove(v as SmartspaceView) - var regionSamplingInstance = regionSamplingInstances.getValue(v) - regionSamplingInstance.stopRegionSampler() - regionSamplingInstances.remove(v) + var regionSampler = regionSamplers.getValue(v) + regionSampler.stopRegionSampler() + regionSamplers.remove(v) if (smartspaceViews.isEmpty()) { disconnect() @@ -362,19 +359,19 @@ class LockscreenSmartspaceController @Inject constructor( } } - private fun initializeTextColors(regionSamplingInstance: RegionSamplingInstance) { + private fun initializeTextColors(regionSampler: RegionSampler) { val lightThemeContext = ContextThemeWrapper(context, R.style.Theme_SystemUI_LightWallpaper) val darkColor = Utils.getColorAttrDefaultColor(lightThemeContext, R.attr.wallpaperTextColor) val darkThemeContext = ContextThemeWrapper(context, R.style.Theme_SystemUI) val lightColor = Utils.getColorAttrDefaultColor(darkThemeContext, R.attr.wallpaperTextColor) - regionSamplingInstance.setForegroundColors(lightColor, darkColor) + regionSampler.setForegroundColors(lightColor, darkColor) } private fun updateTextColorFromRegionSampler() { smartspaceViews.forEach { - val textColor = regionSamplingInstances.getValue(it).currentForegroundColor() + val textColor = regionSamplers.getValue(it).currentForegroundColor() it.setPrimaryTextColor(textColor) } } diff --git a/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt b/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplerTest.kt index 09d51f6447b0..5a62cc18cae3 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplingInstanceTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/shared/regionsampling/RegionSamplerTest.kt @@ -21,61 +21,55 @@ import org.mockito.junit.MockitoJUnit @RunWith(AndroidTestingRunner::class) @SmallTest -class RegionSamplingInstanceTest : SysuiTestCase() { +class RegionSamplerTest : SysuiTestCase() { - @JvmField @Rule - val mockito = MockitoJUnit.rule() + @JvmField @Rule val mockito = MockitoJUnit.rule() @Mock private lateinit var sampledView: View @Mock private lateinit var mainExecutor: Executor @Mock private lateinit var bgExecutor: Executor @Mock private lateinit var regionSampler: RegionSamplingHelper - @Mock private lateinit var updateFun: RegionSamplingInstance.UpdateColorCallback @Mock private lateinit var pw: PrintWriter @Mock private lateinit var callback: RegionSamplingHelper.SamplingCallback - private lateinit var regionSamplingInstance: RegionSamplingInstance + private lateinit var mRegionSampler: RegionSampler + private var updateFun: UpdateColorCallback = {} @Before fun setUp() { whenever(sampledView.isAttachedToWindow).thenReturn(true) - whenever(regionSampler.callback).thenReturn(this@RegionSamplingInstanceTest.callback) - - regionSamplingInstance = object : RegionSamplingInstance( - sampledView, - mainExecutor, - bgExecutor, - true, - updateFun - ) { - override fun createRegionSamplingHelper( + whenever(regionSampler.callback).thenReturn(this@RegionSamplerTest.callback) + + mRegionSampler = + object : RegionSampler(sampledView, mainExecutor, bgExecutor, true, updateFun) { + override fun createRegionSamplingHelper( sampledView: View, callback: RegionSamplingHelper.SamplingCallback, mainExecutor: Executor?, bgExecutor: Executor? - ): RegionSamplingHelper { - return this@RegionSamplingInstanceTest.regionSampler + ): RegionSamplingHelper { + return this@RegionSamplerTest.regionSampler + } } - } } @Test fun testStartRegionSampler() { - regionSamplingInstance.startRegionSampler() + mRegionSampler.startRegionSampler() verify(regionSampler).start(Rect(0, 0, 0, 0)) } @Test fun testStopRegionSampler() { - regionSamplingInstance.stopRegionSampler() + mRegionSampler.stopRegionSampler() verify(regionSampler).stop() } @Test fun testDump() { - regionSamplingInstance.dump(pw) + mRegionSampler.dump(pw) verify(regionSampler).dump(pw) } @@ -91,23 +85,18 @@ class RegionSamplingInstanceTest : SysuiTestCase() { @Test fun testFlagFalse() { - regionSamplingInstance = object : RegionSamplingInstance( - sampledView, - mainExecutor, - bgExecutor, - false, - updateFun - ) { - override fun createRegionSamplingHelper( + mRegionSampler = + object : RegionSampler(sampledView, mainExecutor, bgExecutor, false, updateFun) { + override fun createRegionSamplingHelper( sampledView: View, callback: RegionSamplingHelper.SamplingCallback, mainExecutor: Executor?, bgExecutor: Executor? - ): RegionSamplingHelper { - return this@RegionSamplingInstanceTest.regionSampler + ): RegionSamplingHelper { + return this@RegionSamplerTest.regionSampler + } } - } - Assert.assertEquals(regionSamplingInstance.regionSampler, null) + Assert.assertEquals(mRegionSampler.regionSampler, null) } } |