From 076f2c6d695e3d657f587a46b6e5347137f7321f Mon Sep 17 00:00:00 2001 From: Florence Yang Date: Wed, 31 May 2023 23:37:14 +0000 Subject: [PATCH] Fix LS Smartspace Text Color The LS Smartspace was applying the wrong text color because the views were out of bounds due to incorrect calculations with the actual on-screen coordinates. This fix now restricts the view to be within the device width and height. This fix also addresses an issue where the region samplers would not persist on the lockscreen smartspace because they were only being created once and immediately removed when the view was detached from window but never recreated. Now, the region samplers are recreated when the view is re-attached so that text protection on the LS smartspace will persist. Flag: region_sampling Fixes: 283620770 Test: manual, atest RegionSamplerTest Change-Id: Id6bb46c35dcb9e37c9825ba9836a7d5152384844 --- .../shared/regionsampling/RegionSampler.kt | 6 ++-- .../LockscreenSmartspaceController.kt | 30 ++++++++----------- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt index 9a00447615049..23232fc6a1dda 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSampler.kt @@ -202,8 +202,6 @@ constructor( fun calculateScreenLocation(sampledView: View): RectF? { - if (!sampledView.isLaidOut) return null - val screenLocation = tmpScreenLocation /** * The method getLocationOnScreen is used to obtain the view coordinates relative to its @@ -219,6 +217,10 @@ constructor( samplingBounds.right = left + sampledView.width samplingBounds.bottom = top + sampledView.height + // ensure never go out of bounds + if (samplingBounds.right > displaySize.x) samplingBounds.right = displaySize.x + if (samplingBounds.bottom > displaySize.y) samplingBounds.bottom = displaySize.y + return RectF(samplingBounds) } 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 7cc917f3b0b86..68e8722e0a57f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt +++ b/packages/SystemUI/src/com/android/systemui/statusbar/lockscreen/LockscreenSmartspaceController.kt @@ -136,6 +136,19 @@ constructor( updateTextColorFromWallpaper() statusBarStateListener.onDozeAmountChanged(0f, statusBarStateController.dozeAmount) + + if (regionSamplingEnabled && (!regionSamplers.containsKey(v))) { + var regionSampler = RegionSampler( + v as View, + uiExecutor, + bgExecutor, + regionSamplingEnabled, + isLockscreen = true, + ) { updateTextColorFromRegionSampler() } + initializeTextColors(regionSampler) + regionSamplers[v] = regionSampler + regionSampler.startRegionSampler() + } } override fun onViewDetachedFromWindow(v: View) { @@ -170,23 +183,6 @@ constructor( val filteredTargets = targets.filter(::filterSmartspaceTarget) plugin?.onTargetsAvailable(filteredTargets) - if (!isRegionSamplersCreated) { - for (v in smartspaceViews) { - if (regionSamplingEnabled) { - var regionSampler = RegionSampler( - v as View, - uiExecutor, - bgExecutor, - regionSamplingEnabled, - isLockscreen = true, - ) { updateTextColorFromRegionSampler() } - initializeTextColors(regionSampler) - regionSamplers[v] = regionSampler - regionSampler.startRegionSampler() - } - } - isRegionSamplersCreated = true - } } private val userTrackerCallback = object : UserTracker.Callback {