Merge "Fixed incorrect rounded corner size" into rvc-dev

This commit is contained in:
Shawn Lin
2020-03-31 08:17:29 +00:00
committed by Android (Google) Code Review
2 changed files with 111 additions and 16 deletions

View File

@@ -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) {
}
}
if (sizeTop == 0) {
sizeTop = size;
}
if (sizeBottom == 0) {
sizeBottom = size;
}
for (int i = 0; i < BOUNDS_POSITION_LENGTH; i++) {
if (mOverlays[i] == null) {
continue;
}
setSize(mOverlays[i].findViewById(R.id.left), sizeTop);
setSize(mOverlays[i].findViewById(R.id.right), sizeBottom);
}
updateRoundedCornerSize(size, sizeTop, sizeBottom);
}
});
}
private void setSize(View view, int pixelSize) {
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;
}
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);
}
}
}
@VisibleForTesting
protected void setSize(View view, int pixelSize) {
LayoutParams params = view.getLayoutParams();
params.width = pixelSize;
params.height = pixelSize;

View File

@@ -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);