From b713bb693604a021e23d861c95877863b4c1c7bd Mon Sep 17 00:00:00 2001 From: Grace Han Date: Sat, 20 Aug 2022 01:15:31 +0000 Subject: [PATCH] Fix Region Sampling Bounds This change updates the sampling bounds used for region sampling. Bug: 202758428 Test: Manual Change-Id: I7a33bb6ce27fdbd8891434c627a3b10545086272 --- .../regionsampling/RegionSamplingInstance.kt | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt index 0146795f49882..dd2e55d4e7d7f 100644 --- a/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt +++ b/packages/SystemUI/shared/src/com/android/systemui/shared/regionsampling/RegionSamplingInstance.kt @@ -35,6 +35,7 @@ open class RegionSamplingInstance( ) { private var isDark = RegionDarkness.DEFAULT private var samplingBounds = Rect() + private val tmpScreenLocation = IntArray(2) @VisibleForTesting var regionSampler: RegionSamplingHelper? = null /** @@ -99,10 +100,21 @@ open class RegionSamplingInstance( isDark = convertToClockDarkness(isRegionDark) updateFun.updateColors() } - + /** + * 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 { - samplingBounds = Rect(sampledView.left, sampledView.top, - sampledView.right, sampledView.bottom) + val screenLocation = tmpScreenLocation + sampledView.getLocationOnScreen(screenLocation) + val left = screenLocation[0] + val top = screenLocation[1] + samplingBounds.left = left + samplingBounds.top = top + samplingBounds.right = left + sampledView.width + samplingBounds.bottom = top + sampledView.height return samplingBounds }