Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit eba0b0f0 authored by Evan Laird's avatar Evan Laird
Browse files

[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
parent 76a732f8
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -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);
+28 −13
Original line number Diff line number Diff line
@@ -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 }
+1 −1
Original line number Diff line number Diff line
@@ -39,7 +39,7 @@ class RoundedCornerDecorProviderFactoryTest : SysuiTestCase() {

    @Before
    fun setUp() {
        roundedCornerResDelegate = spy(RoundedCornerResDelegate(mContext.resources, null))
        roundedCornerResDelegate = spy(RoundedCornerResDelegateImpl(mContext.resources, null))
    }

    @Test
+6 −6
Original line number Diff line number Diff line
@@ -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)