[Decor] Split RoundedCornerResDelegate into impl and interface

In order to support a new debug corner res delegate, we should split out
the RoundedCornerResDelegate into an interface + implementation. This
will allow us to create a DebugCornerDelegate that can be reused by the
RoundedCornerDecorProvider without needing to duplicate that class
definition.

Test: RoundedCornerDecorProviderFactoryTest
Test: RoundedCornerResDelegateTest
Test: adb shell setprop debug.screenshot_rounded_corners 1 && restart-sysui
Bug: 285941724
Change-Id: I68fbe1a7d0662781b611c84ae81dd526381aad22
This commit is contained in:
Evan Laird
2023-06-07 12:33:37 -04:00
parent 76a732f8e5
commit eba0b0f0df
4 changed files with 39 additions and 24 deletions

View File

@@ -78,7 +78,7 @@ import com.android.systemui.decor.FaceScanningProviderFactory;
import com.android.systemui.decor.OverlayWindow;
import com.android.systemui.decor.PrivacyDotDecorProviderFactory;
import com.android.systemui.decor.RoundedCornerDecorProviderFactory;
import com.android.systemui.decor.RoundedCornerResDelegate;
import com.android.systemui.decor.RoundedCornerResDelegateImpl;
import com.android.systemui.log.ScreenDecorationsLogger;
import com.android.systemui.qs.SettingObserver;
import com.android.systemui.settings.DisplayTracker;
@@ -142,7 +142,7 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
public final int mFaceScanningViewId;
@VisibleForTesting
protected RoundedCornerResDelegate mRoundedCornerResDelegate;
protected RoundedCornerResDelegateImpl mRoundedCornerResDelegate;
@VisibleForTesting
protected DecorProviderFactory mRoundedCornerFactory;
private CutoutDecorProviderFactory mCutoutFactory;
@@ -429,8 +429,8 @@ public class ScreenDecorations implements CoreStartable, Dumpable {
mDisplayMode = mDisplayInfo.getMode();
mDisplayUniqueId = mDisplayInfo.uniqueId;
mDisplayCutout = mDisplayInfo.displayCutout;
mRoundedCornerResDelegate = new RoundedCornerResDelegate(mContext.getResources(),
mDisplayUniqueId);
mRoundedCornerResDelegate =
new RoundedCornerResDelegateImpl(mContext.getResources(), mDisplayUniqueId);
mRoundedCornerResDelegate.setPhysicalPixelDisplaySizeRatio(
getPhysicalPixelDisplaySizeRatio());
mRoundedCornerFactory = new RoundedCornerDecorProviderFactory(mRoundedCornerResDelegate);

View File

@@ -27,35 +27,50 @@ import com.android.systemui.Dumpable
import com.android.systemui.R
import java.io.PrintWriter
class RoundedCornerResDelegate(
interface RoundedCornerResDelegate {
val hasTop: Boolean
val topRoundedDrawable: Drawable?
val topRoundedSize: Size
val hasBottom: Boolean
val bottomRoundedDrawable: Drawable?
val bottomRoundedSize: Size
var physicalPixelDisplaySizeRatio: Float
fun updateDisplayUniqueId(newDisplayUniqueId: String?, newReloadToken: Int?)
}
/**
* Delegate for the device-default rounded corners. These will always be loaded from the config
* values `R.array.config_roundedCornerTopDrawableArray` and `R.drawable.rounded_corner_top`
*/
class RoundedCornerResDelegateImpl(
private val res: Resources,
private var displayUniqueId: String?
) : Dumpable {
private val density: Float
get() = res.displayMetrics.density
) : RoundedCornerResDelegate, Dumpable {
private var reloadToken: Int = 0
var hasTop: Boolean = false
override var hasTop: Boolean = false
private set
var hasBottom: Boolean = false
override var hasBottom: Boolean = false
private set
var topRoundedDrawable: Drawable? = null
override var topRoundedDrawable: Drawable? = null
private set
var bottomRoundedDrawable: Drawable? = null
override var bottomRoundedDrawable: Drawable? = null
private set
var topRoundedSize = Size(0, 0)
override var topRoundedSize = Size(0, 0)
private set
var bottomRoundedSize = Size(0, 0)
override var bottomRoundedSize = Size(0, 0)
private set
var physicalPixelDisplaySizeRatio: Float = 1f
override var physicalPixelDisplaySizeRatio: Float = 1f
set(value) {
if (field == value) {
return
@@ -69,7 +84,7 @@ class RoundedCornerResDelegate(
reloadMeasures()
}
fun updateDisplayUniqueId(newDisplayUniqueId: String?, newReloadToken: Int?) {
override fun updateDisplayUniqueId(newDisplayUniqueId: String?, newReloadToken: Int?) {
if (displayUniqueId != newDisplayUniqueId) {
displayUniqueId = newDisplayUniqueId
newReloadToken ?.let { reloadToken = it }

View File

@@ -39,7 +39,7 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {
@Before
fun setUp() {
roundedCornerResDelegate = spy(RoundedCornerResDelegate(mContext.resources, null))
roundedCornerResDelegate = spy(RoundedCornerResDelegateImpl(mContext.resources, null))
}
@Test

View File

@@ -48,7 +48,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
@Test
fun testTopAndBottomRoundedCornerExist() {
setupResources(radius = 5)
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
roundedCornerResDelegate = RoundedCornerResDelegateImpl(mContext.resources, null)
assertEquals(true, roundedCornerResDelegate.hasTop)
assertEquals(true, roundedCornerResDelegate.hasBottom)
}
@@ -56,7 +56,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
@Test
fun testTopRoundedCornerExist() {
setupResources(radiusTop = 10)
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
roundedCornerResDelegate = RoundedCornerResDelegateImpl(mContext.resources, null)
assertEquals(true, roundedCornerResDelegate.hasTop)
assertEquals(false, roundedCornerResDelegate.hasBottom)
}
@@ -64,7 +64,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
@Test
fun testBottomRoundedCornerExist() {
setupResources(radiusBottom = 15)
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
roundedCornerResDelegate = RoundedCornerResDelegateImpl(mContext.resources, null)
assertEquals(false, roundedCornerResDelegate.hasTop)
assertEquals(true, roundedCornerResDelegate.hasBottom)
}
@@ -75,7 +75,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
roundedCornerResDelegate = RoundedCornerResDelegateImpl(mContext.resources, null)
assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
@@ -96,7 +96,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
roundedTopDrawable = getTestsDrawable(R.drawable.rounded3px),
roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
roundedCornerResDelegate = RoundedCornerResDelegateImpl(mContext.resources, null)
assertEquals(Size(3, 3), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)
@@ -114,7 +114,7 @@ class RoundedCornerResDelegateTest : SysuiTestCase() {
roundedTopDrawable = getTestsDrawable(R.drawable.rounded4px),
roundedBottomDrawable = getTestsDrawable(R.drawable.rounded4px))
roundedCornerResDelegate = RoundedCornerResDelegate(mContext.resources, null)
roundedCornerResDelegate = RoundedCornerResDelegateImpl(mContext.resources, null)
assertEquals(Size(4, 4), roundedCornerResDelegate.topRoundedSize)
assertEquals(Size(4, 4), roundedCornerResDelegate.bottomRoundedSize)