summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author shawnlin <shawnlin@google.com> 2020-03-24 16:45:47 +0800
committer shawnlin <shawnlin@google.com> 2020-03-27 16:29:45 +0800
commit0264a6cb29eb8c67d4cc4dff5b6d164807c20f56 (patch)
tree12ebd2c79d07286462a2217b920d16b55532b89e
parente5f640004209c77e90181f11170f304cf15f546c (diff)
Fixed incorrect rounded corner size
When top and bottom radius are different: 1. If rounded corners are shown by top and bottom overlays - Apply top radius to corners on top overlay - Apply bottom radius to corners on bottom overlay 2. If rounded corners are shown by left and right overlays - Apply top and bottom radius according to current rotation. Fixes: 152004675 Test: atest ScreenDecorationsTest Change-Id: I0251134cdd784fe3865d01ea6ad6cd2b7eee53db
-rw-r--r--packages/SystemUI/src/com/android/systemui/ScreenDecorations.java45
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java74
2 files changed, 107 insertions, 12 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
index 5f004a631e46..699d2dc79bed 100644
--- a/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
+++ b/packages/SystemUI/src/com/android/systemui/ScreenDecorations.java
@@ -393,6 +393,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) {
@@ -701,26 +702,46 @@ public class ScreenDecorations extends SystemUI implements Tunable {
} catch (Exception e) {
}
}
+ updateRoundedCornerSize(size, sizeTop, sizeBottom);
+ }
+ });
+ }
- if (sizeTop == 0) {
- sizeTop = size;
- }
- if (sizeBottom == 0) {
- sizeBottom = size;
- }
+ private void updateRoundedCornerSize(int sizeDefault, int sizeTop, int sizeBottom) {
+ if (mOverlays == null) {
+ return;
+ }
+ if (sizeTop == 0) {
+ sizeTop = sizeDefault;
+ }
+ if (sizeBottom == 0) {
+ sizeBottom = sizeDefault;
+ }
- for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
- if (mOverlays[i] == null) {
- continue;
- }
+ 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;
diff --git a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
index b6537bf8c615..b9ddff3a59ea 100644
--- a/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
+++ b/packages/SystemUI/tests/src/com/android/systemui/ScreenDecorationsTest.java
@@ -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;
@@ -213,6 +215,78 @@ public class ScreenDecorationsTest extends SysuiTestCase {
}
@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);
final int multipleRadiusSize = Math.max(d.getIntrinsicWidth(), d.getIntrinsicHeight());