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

Commit 7e803329 authored by Shawn Lin's avatar Shawn Lin Committed by Automerger Merge Worker
Browse files

Merge "Fixed incorrect rounded corner size" into rvc-dev am: ae370867 am: cc47c44c

Change-Id: Ie80306087c48d5c05f874a3e8e13c5b878b54ed8
parents a3f4c3b6 cc47c44c
Loading
Loading
Loading
Loading
+33 −12
Original line number Diff line number Diff line
@@ -409,6 +409,7 @@ public class ScreenDecorations extends SystemUI implements Tunable {
        // update rounded corner view rotation
        updateRoundedCornerView(pos, R.id.left);
        updateRoundedCornerView(pos, R.id.right);
        updateRoundedCornerSize(mRoundedDefault, mRoundedDefaultTop, mRoundedDefaultBottom);

        // update cutout view rotation
        if (mCutoutViews != null && mCutoutViews[pos] != null) {
@@ -717,26 +718,46 @@ public class ScreenDecorations extends SystemUI implements Tunable {
                    } catch (Exception e) {
                    }
                }
                updateRoundedCornerSize(size, sizeTop, sizeBottom);
            }
        });
    }

    private void updateRoundedCornerSize(int sizeDefault, int sizeTop, int sizeBottom) {
        if (mOverlays == null) {
            return;
        }
        if (sizeTop == 0) {
                    sizeTop = size;
            sizeTop = sizeDefault;
        }
        if (sizeBottom == 0) {
                    sizeBottom = size;
            sizeBottom = sizeDefault;
        }

        for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
            if (mOverlays[i] == null) {
                continue;
            }
            if (i == BOUNDS_POSITION_LEFT || i == BOUNDS_POSITION_RIGHT) {
                if (mRotation == ROTATION_270) {
                    setSize(mOverlays[i].findViewById(R.id.left), sizeBottom);
                    setSize(mOverlays[i].findViewById(R.id.right), sizeTop);
                } else {
                    setSize(mOverlays[i].findViewById(R.id.left), sizeTop);
                    setSize(mOverlays[i].findViewById(R.id.right), sizeBottom);
                }
            } else if (i == BOUNDS_POSITION_TOP) {
                setSize(mOverlays[i].findViewById(R.id.left), sizeTop);
                setSize(mOverlays[i].findViewById(R.id.right), sizeTop);
            } else if (i == BOUNDS_POSITION_BOTTOM) {
                setSize(mOverlays[i].findViewById(R.id.left), sizeBottom);
                setSize(mOverlays[i].findViewById(R.id.right), sizeBottom);
            }
        }
        });
    }

    private void setSize(View view, int pixelSize) {
    @VisibleForTesting
    protected void setSize(View view, int pixelSize) {
        LayoutParams params = view.getLayoutParams();
        params.width = pixelSize;
        params.height = pixelSize;
+74 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -52,6 +53,7 @@ import android.testing.TestableLooper;
import android.testing.TestableLooper.RunWithLooper;
import android.view.Display;
import android.view.DisplayCutout;
import android.view.View;
import android.view.WindowManager;
import android.view.WindowMetrics;

@@ -212,6 +214,78 @@ public class ScreenDecorationsTest extends SysuiTestCase {
        assertThat(mScreenDecorations.mRoundedDefaultBottom).isEqualTo(testRadius);
    }

    @Test
    public void testRoundingTopBottomRadius_OnTopBottomOverlay() {
        final int testTopRadius = 1;
        final int testBottomRadius = 5;
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.dimen.rounded_corner_radius, testTopRadius);
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.dimen.rounded_corner_radius_top, testTopRadius);
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.dimen.rounded_corner_radius_bottom, testBottomRadius);
        mContext.getOrCreateTestableResources()
                .addOverride(R.bool.config_roundedCornerMultipleRadius, false);

        // no cutout
        doReturn(null).when(mScreenDecorations).getCutout();

        mScreenDecorations.start();
        View leftRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP].findViewById(R.id.left);
        View rightRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_TOP].findViewById(R.id.right);
        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testTopRadius);
        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testTopRadius);
        leftRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM].findViewById(R.id.left);
        rightRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_BOTTOM].findViewById(R.id.right);
        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testBottomRadius);
        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testBottomRadius);
    }

    @Test
    public void testRoundingTopBottomRadius_OnLeftRightOverlay() {
        final int testTopRadius = 1;
        final int testBottomRadius = 5;
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.dimen.rounded_corner_radius, testTopRadius);
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.dimen.rounded_corner_radius_top, testTopRadius);
        mContext.getOrCreateTestableResources().addOverride(
                com.android.internal.R.dimen.rounded_corner_radius_bottom, testBottomRadius);
        mContext.getOrCreateTestableResources()
                .addOverride(R.bool.config_roundedCornerMultipleRadius, false);

        // left cutout
        doReturn(new DisplayCutout(
                Insets.of(0, 10, 0, 0),
                new Rect(0, 200, 1, 210),
                ZERO_RECT,
                ZERO_RECT,
                ZERO_RECT,
                Insets.NONE)).when(mScreenDecorations).getCutout();

        mScreenDecorations.start();
        View leftRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.left);
        View rightRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_LEFT].findViewById(R.id.right);
        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testTopRadius);
        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testBottomRadius);
        leftRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.left);
        rightRoundedCorner =
                mScreenDecorations.mOverlays[BOUNDS_POSITION_RIGHT].findViewById(R.id.right);
        verify(mScreenDecorations, atLeastOnce()).setSize(leftRoundedCorner, testTopRadius);
        verify(mScreenDecorations, atLeastOnce()).setSize(rightRoundedCorner, testBottomRadius);
    }

    @Test
    public void testRoundingMultipleRadius_NoCutout() {
        final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);