Merge "DO NOT MERGE Respect rounded.xml size in ScreenDecorations" into qt-qpr1-dev

This commit is contained in:
Bill Lin
2020-02-24 16:27:20 +00:00
committed by Android (Google) Code Review
3 changed files with 86 additions and 6 deletions

View File

@@ -488,4 +488,7 @@
<!-- Preferred refresh rate at keyguard, if supported by the display -->
<integer name="config_keyguardRefreshRate">-1</integer>
<!-- Respect the drawable/rounded.xml that allow to customize as multiple radius corner path -->
<bool name="config_roundedCornerMultipleRadius">false</bool>
</resources>

View File

@@ -45,6 +45,7 @@ import android.graphics.Path;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.drawable.VectorDrawable;
import android.hardware.display.DisplayManager;
import android.os.Handler;
import android.os.HandlerThread;
@@ -129,6 +130,7 @@ public class ScreenDecorations extends SystemUI implements Tunable,
private boolean mAssistHintBlocked = false;
private boolean mIsReceivingNavBarColor = false;
private boolean mInGesturalMode;
private boolean mIsRoundedCornerMultipleRadius;
/**
* Converts a set of {@link Rect}s into a {@link Region}
@@ -323,6 +325,8 @@ public class ScreenDecorations extends SystemUI implements Tunable,
private void startOnScreenDecorationsThread() {
mRotation = RotationUtils.getExactRotation(mContext);
mWindowManager = mContext.getSystemService(WindowManager.class);
mIsRoundedCornerMultipleRadius = mContext.getResources().getBoolean(
R.bool.config_roundedCornerMultipleRadius);
updateRoundedCornerRadii();
if (hasRoundedCorners() || shouldDrawCutout() || shouldHostHandles()) {
setupDecorations();
@@ -528,17 +532,24 @@ public class ScreenDecorations extends SystemUI implements Tunable,
com.android.internal.R.dimen.rounded_corner_radius_top);
final int newRoundedDefaultBottom = mContext.getResources().getDimensionPixelSize(
com.android.internal.R.dimen.rounded_corner_radius_bottom);
final boolean roundedCornersChanged = mRoundedDefault != newRoundedDefault
|| mRoundedDefaultBottom != newRoundedDefaultBottom
|| mRoundedDefaultTop != newRoundedDefaultTop;
if (roundedCornersChanged) {
mRoundedDefault = newRoundedDefault;
mRoundedDefaultTop = newRoundedDefaultTop;
mRoundedDefaultBottom = newRoundedDefaultBottom;
onTuningChanged(SIZE, null);
// If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the
// max(width, height) size of drawable/rounded.xml instead of rounded_corner_radius
if (mIsRoundedCornerMultipleRadius) {
final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);
mRoundedDefault = Math.max(d.getIntrinsicWidth(), d.getIntrinsicHeight());
mRoundedDefaultTop = mRoundedDefaultBottom = mRoundedDefault;
} else {
mRoundedDefault = newRoundedDefault;
mRoundedDefaultTop = newRoundedDefaultTop;
mRoundedDefaultBottom = newRoundedDefaultBottom;
}
}
onTuningChanged(SIZE, null);
}
private void updateViews() {
@@ -637,7 +648,8 @@ public class ScreenDecorations extends SystemUI implements Tunable,
}
private boolean hasRoundedCorners() {
return mRoundedDefault > 0 || mRoundedDefaultBottom > 0 || mRoundedDefaultTop > 0;
return mRoundedDefault > 0 || mRoundedDefaultBottom > 0 || mRoundedDefaultTop > 0
|| mIsRoundedCornerMultipleRadius;
}
private boolean shouldDrawCutout() {

View File

@@ -20,6 +20,8 @@ import static com.android.systemui.ScreenDecorations.rectsToRegion;
import static com.android.systemui.tuner.TunablePadding.FLAG_END;
import static com.android.systemui.tuner.TunablePadding.FLAG_START;
import static com.google.common.truth.Truth.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
@@ -38,6 +40,7 @@ import static org.mockito.Mockito.when;
import android.app.Fragment;
import android.content.res.Configuration;
import android.graphics.Rect;
import android.graphics.drawable.VectorDrawable;
import android.os.Handler;
import android.testing.AndroidTestingRunner;
import android.testing.TestableLooper;
@@ -148,6 +151,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
mContext.getOrCreateTestableResources()
.addOverride(dimen.rounded_corner_content_padding, 0);
mContext.getOrCreateTestableResources()
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
mScreenDecorations.start();
// No views added.
@@ -166,6 +171,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
com.android.internal.R.dimen.rounded_corner_radius, 20);
mContext.getOrCreateTestableResources()
.addOverride(dimen.rounded_corner_content_padding, 20);
mContext.getOrCreateTestableResources()
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
mScreenDecorations.start();
// Add 2 windows for rounded corners (top and bottom).
@@ -179,6 +186,57 @@ public class ScreenDecorationsTest extends SysuiTestCase {
verify(mTunablePaddingService, times(1)).add(any(), anyString(), anyInt(), anyInt());
}
@Test
public void testRoundingRadius() {
final int testRadius = 1;
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius, testRadius);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius_top, testRadius);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius_bottom, testRadius);
mContext.getOrCreateTestableResources()
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
mScreenDecorations.start();
// Size of corner view should same as rounded_corner_radius{_top|_bottom}
assertThat(mScreenDecorations.mRoundedDefault).isEqualTo(testRadius);
assertThat(mScreenDecorations.mRoundedDefaultTop).isEqualTo(testRadius);
assertThat(mScreenDecorations.mRoundedDefaultBottom).isEqualTo(testRadius);
}
@Test
public void testRoundingMultipleRadius() {
final VectorDrawable d = (VectorDrawable) mContext.getDrawable(R.drawable.rounded);
final int multipleRadiusSize = Math.max(d.getIntrinsicWidth(), d.getIntrinsicHeight());
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius, 9999);
mContext.getOrCreateTestableResources()
.addOverride(dimen.rounded_corner_content_padding, 9999);
mContext.getOrCreateTestableResources()
.addOverride(R.bool.config_roundedCornerMultipleRadius, true);
mScreenDecorations.start();
// Add 2 windows for rounded corners (top and bottom).
verify(mWindowManager, times(2)).addView(any(), any());
// Add 2 tag listeners for each of the fragments that are needed.
verify(mFragmentHostManager, times(2)).addTagListener(any(), any());
// One tunable.
verify(mTunerService, times(1)).addTunable(any(), any());
// One TunablePadding.
verify(mTunablePaddingService, times(1)).add(any(), anyString(), anyInt(), anyInt());
// Size of corner view should exactly match max(width, height) of R.drawable.rounded
assertThat(mScreenDecorations.mRoundedDefault).isEqualTo(multipleRadiusSize);
assertThat(mScreenDecorations.mRoundedDefaultTop).isEqualTo(multipleRadiusSize);
assertThat(mScreenDecorations.mRoundedDefaultBottom).isEqualTo(multipleRadiusSize);
}
@Test
public void testCutout() {
mContext.getOrCreateTestableResources().addOverride(
@@ -224,6 +282,9 @@ public class ScreenDecorationsTest extends SysuiTestCase {
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
mContext.getOrCreateTestableResources()
.addOverride(dimen.rounded_corner_content_padding, 0);
mContext.getOrCreateTestableResources()
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
when(mNavigationModeController.addListener(any())).thenReturn(
WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL);
@@ -245,6 +306,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
mContext.getOrCreateTestableResources()
.addOverride(dimen.rounded_corner_content_padding, 0);
mContext.getOrCreateTestableResources()
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
when(mNavigationModeController.addListener(any())).thenReturn(
WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON);
@@ -296,6 +359,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
mContext.getOrCreateTestableResources().addOverride(
com.android.internal.R.dimen.rounded_corner_radius, 20);
mContext.getOrCreateTestableResources()
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
mScreenDecorations.start();
assertEquals(mScreenDecorations.mRoundedDefault, 20);