From e9440ab1a07f9536a23ff014d7d4a1f1660be55a Mon Sep 17 00:00:00 2001 From: Milton Wu Date: Thu, 14 Apr 2022 21:11:24 +0800 Subject: [PATCH] Passing info to RoundedCornerResDelegate directly 1. Move rounded corners tint color into RoundedCornerResDelegate, and RoundedCornerDecorProviderImpl uses it to draw image. 2. After display changed, pass display unique id to RoundedCornerResDelegate directly. 3. Cache tuning size inside RoundedCornerResDelegate Bug: 229234279 Bug: 218951516 Test: atest ScreenDecorationsTest PrivacyDotDecorProviderFactoryTest \ RoundedCornerDecorProviderFactoryTest RoundedCornerResDelegateTest Change-Id: I7edd16db06f6023a3c3dfd10b430a5002b9ee942 --- .../android/systemui/ScreenDecorations.java | 35 ++++++++--------- .../systemui/decor/DecorProviderFactory.kt | 1 - .../decor/PrivacyDotDecorProviderFactory.kt | 4 -- .../RoundedCornerDecorProviderFactory.kt | 4 -- .../decor/RoundedCornerDecorProviderImpl.kt | 4 +- .../decor/RoundedCornerResDelegate.kt | 38 ++++++++++++------- .../decor/RoundedCornerResDelegateTest.kt | 4 +- 7 files changed, 43 insertions(+), 47 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java index 7cc738a4e437a..4b9288c6c56f0 100644 --- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java +++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java @@ -64,7 +64,6 @@ import android.view.ViewGroup.LayoutParams; import android.view.ViewTreeObserver; import android.view.WindowManager; import android.widget.FrameLayout; -import android.widget.ImageView; import androidx.annotation.VisibleForTesting; @@ -292,11 +291,6 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab return decorProviders; } - private void updateDisplayIdToProviderFactories() { - mDotFactory.onDisplayUniqueIdChanged(mDisplayUniqueId); - mRoundedCornerFactory.onDisplayUniqueIdChanged(mDisplayUniqueId); - } - /** * Check that newProviders is the same list with decorProviders inside mOverlay. * @param newProviders expected comparing DecorProviders @@ -389,7 +383,7 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab final DisplayDecorationSupport newScreenDecorationSupport = mContext.getDisplay().getDisplayDecorationSupport(); - updateDisplayIdToProviderFactories(); + mRoundedCornerResDelegate.updateDisplayUniqueId(newUniqueId, null); // When providers or the value of mSupportHwcScreenDecoration is changed, // re-setup the whole screen decoration. @@ -857,6 +851,15 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab } ColorStateList tintList = ColorStateList.valueOf(mTintColor); + mRoundedCornerResDelegate.setColorTintList(tintList); + + Integer[] roundedCornerIds = { + R.id.rounded_corner_top_left, + R.id.rounded_corner_top_right, + R.id.rounded_corner_bottom_left, + R.id.rounded_corner_bottom_right + }; + for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) { if (mOverlays[i] == null) { continue; @@ -866,19 +869,12 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab View child; for (int j = 0; j < size; j++) { child = overlayView.getChildAt(j); - if (child.getId() == R.id.privacy_dot_top_left_container - || child.getId() == R.id.privacy_dot_top_right_container - || child.getId() == R.id.privacy_dot_bottom_left_container - || child.getId() == R.id.privacy_dot_bottom_right_container) { - // Exclude privacy dot from color inversion (for now?) - continue; - } - if (child instanceof ImageView) { - ((ImageView) child).setImageTintList(tintList); - } else if (child instanceof DisplayCutoutView) { + if (child instanceof DisplayCutoutView) { ((DisplayCutoutView) child).setColor(mTintColor); } } + mOverlays[i].onReloadResAndMeasure(roundedCornerIds, mProviderRefreshToken, mRotation, + mDisplayUniqueId); } } @@ -1067,12 +1063,11 @@ public class ScreenDecorations extends CoreStartable implements Tunable , Dumpab if (mOverlays == null || !SIZE.equals(key)) { return; } - ++mProviderRefreshToken; try { final int sizeFactor = Integer.parseInt(newValue); - mRoundedCornerResDelegate.updateTuningSizeFactor(sizeFactor, mProviderRefreshToken); + mRoundedCornerResDelegate.setTuningSizeFactor(sizeFactor); } catch (NumberFormatException e) { - mRoundedCornerResDelegate.updateTuningSizeFactor(null, mProviderRefreshToken); + mRoundedCornerResDelegate.setTuningSizeFactor(null); } Integer[] filterIds = { R.id.rounded_corner_top_left, diff --git a/packages/SystemUI/src/com/android/systemui/decor/DecorProviderFactory.kt b/packages/SystemUI/src/com/android/systemui/decor/DecorProviderFactory.kt index cc4096fb3b196..c60cad8419d29 100644 --- a/packages/SystemUI/src/com/android/systemui/decor/DecorProviderFactory.kt +++ b/packages/SystemUI/src/com/android/systemui/decor/DecorProviderFactory.kt @@ -19,5 +19,4 @@ package com.android.systemui.decor abstract class DecorProviderFactory { abstract val providers: List abstract val hasProviders: Boolean - abstract fun onDisplayUniqueIdChanged(displayUniqueId: String?) } \ No newline at end of file diff --git a/packages/SystemUI/src/com/android/systemui/decor/PrivacyDotDecorProviderFactory.kt b/packages/SystemUI/src/com/android/systemui/decor/PrivacyDotDecorProviderFactory.kt index d16d9604c0026..136f135af7599 100644 --- a/packages/SystemUI/src/com/android/systemui/decor/PrivacyDotDecorProviderFactory.kt +++ b/packages/SystemUI/src/com/android/systemui/decor/PrivacyDotDecorProviderFactory.kt @@ -39,10 +39,6 @@ class PrivacyDotDecorProviderFactory @Inject constructor( override val hasProviders: Boolean get() = isPrivacyDotEnabled - override fun onDisplayUniqueIdChanged(displayUniqueId: String?) { - // Do nothing for privacy dot - } - override val providers: List get() { return if (hasProviders) { diff --git a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt index 4f075da7aaa70..0ffb4fb5b4563 100644 --- a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt +++ b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderFactory.kt @@ -28,10 +28,6 @@ class RoundedCornerDecorProviderFactory( hasTop || hasBottom } - override fun onDisplayUniqueIdChanged(displayUniqueId: String?) { - roundedCornerResDelegate.updateDisplayUniqueId(displayUniqueId, null) - } - override val providers: List get() { val hasTop = roundedCornerResDelegate.hasTop diff --git a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderImpl.kt b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderImpl.kt index 90ff950406b46..9dbeb77ebc005 100644 --- a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderImpl.kt +++ b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerDecorProviderImpl.kt @@ -65,7 +65,7 @@ class RoundedCornerDecorProviderImpl( private fun initView(view: ImageView, @Surface.Rotation rotation: Int) { view.setRoundedCornerImage(roundedCornerResDelegate, isTop) view.adjustRotation(alignedBounds, rotation) - view.setColorFilter(IMAGE_TINT_COLOR) + view.imageTintList = roundedCornerResDelegate.colorTintList } override fun onReloadResAndMeasure( @@ -93,8 +93,6 @@ class RoundedCornerDecorProviderImpl( } } -private const val IMAGE_TINT_COLOR: Int = 0xFF000000.toInt() - @DisplayCutout.BoundsPosition private fun Int.toLayoutGravity(@Surface.Rotation rotation: Int): Int = when (rotation) { Surface.ROTATION_0 -> when (this) { diff --git a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt index 3ab2f08818071..3731eca4ee86b 100644 --- a/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt +++ b/packages/SystemUI/src/com/android/systemui/decor/RoundedCornerResDelegate.kt @@ -18,7 +18,9 @@ package com.android.systemui.decor import android.annotation.ArrayRes import android.annotation.DrawableRes +import android.content.res.ColorStateList import android.content.res.Resources +import android.graphics.Color import android.graphics.drawable.Drawable import android.util.DisplayUtils import android.util.Size @@ -55,6 +57,17 @@ class RoundedCornerResDelegate( var bottomRoundedSize = Size(0, 0) private set + var colorTintList = ColorStateList.valueOf(Color.BLACK) + + var tuningSizeFactor: Int? = null + set(value) { + if (field == value) { + return + } + field = value + reloadMeasures() + } + init { reloadRes() reloadMeasures() @@ -101,7 +114,7 @@ class RoundedCornerResDelegate( ) } - private fun reloadMeasures(roundedSizeFactor: Int? = null) { + private fun reloadMeasures() { topRoundedDrawable?.let { topRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) } @@ -109,21 +122,20 @@ class RoundedCornerResDelegate( bottomRoundedSize = Size(it.intrinsicWidth, it.intrinsicHeight) } - if (roundedSizeFactor != null && roundedSizeFactor > 0) { - val length: Int = (roundedSizeFactor * density).toInt() - topRoundedSize = Size(length, length) - bottomRoundedSize = Size(length, length) + tuningSizeFactor?.let { + if (it <= 0) { + return + } + val length: Int = (it * density).toInt() + if (topRoundedSize.width > 0) { + topRoundedSize = Size(length, length) + } + if (bottomRoundedSize.width > 0) { + bottomRoundedSize = Size(length, length) + } } } - fun updateTuningSizeFactor(factor: Int?, newReloadToken: Int) { - if (reloadToken == newReloadToken) { - return - } - reloadToken = newReloadToken - reloadMeasures(factor) - } - private fun getDrawable( displayConfigIndex: Int, @ArrayRes arrayResId: Int, diff --git a/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt b/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt index f629b3b9b97a3..adb9c4d206e15 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt +++ b/packages/SystemUI/tests/src/com/android/systemui/decor/RoundedCornerResDelegateTest.kt @@ -121,13 +121,13 @@ class RoundedCornerResDelegateTest : SysuiTestCase() { roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null) val factor = 5 - roundedCornerResDelegate.updateTuningSizeFactor(factor, 1) + roundedCornerResDelegate.tuningSizeFactor = factor val length = (factor * mContext.resources.displayMetrics.density).toInt() assertEquals(Size(length, length), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(length, length), roundedCornerResDelegate.bottomRoundedSize) - roundedCornerResDelegate.updateTuningSizeFactor(null, 2) + roundedCornerResDelegate.tuningSizeFactor = null assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize) assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)