Merge "DO NOT MERGE Respect rounded.xml size in ScreenDecorations" into qt-qpr1-dev
This commit is contained in:
@@ -488,4 +488,7 @@
|
|||||||
<!-- Preferred refresh rate at keyguard, if supported by the display -->
|
<!-- Preferred refresh rate at keyguard, if supported by the display -->
|
||||||
<integer name="config_keyguardRefreshRate">-1</integer>
|
<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>
|
</resources>
|
||||||
|
|||||||
@@ -45,6 +45,7 @@ import android.graphics.Path;
|
|||||||
import android.graphics.PixelFormat;
|
import android.graphics.PixelFormat;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.Region;
|
import android.graphics.Region;
|
||||||
|
import android.graphics.drawable.VectorDrawable;
|
||||||
import android.hardware.display.DisplayManager;
|
import android.hardware.display.DisplayManager;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.HandlerThread;
|
import android.os.HandlerThread;
|
||||||
@@ -129,6 +130,7 @@ public class ScreenDecorations extends SystemUI implements Tunable,
|
|||||||
private boolean mAssistHintBlocked = false;
|
private boolean mAssistHintBlocked = false;
|
||||||
private boolean mIsReceivingNavBarColor = false;
|
private boolean mIsReceivingNavBarColor = false;
|
||||||
private boolean mInGesturalMode;
|
private boolean mInGesturalMode;
|
||||||
|
private boolean mIsRoundedCornerMultipleRadius;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a set of {@link Rect}s into a {@link Region}
|
* 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() {
|
private void startOnScreenDecorationsThread() {
|
||||||
mRotation = RotationUtils.getExactRotation(mContext);
|
mRotation = RotationUtils.getExactRotation(mContext);
|
||||||
mWindowManager = mContext.getSystemService(WindowManager.class);
|
mWindowManager = mContext.getSystemService(WindowManager.class);
|
||||||
|
mIsRoundedCornerMultipleRadius = mContext.getResources().getBoolean(
|
||||||
|
R.bool.config_roundedCornerMultipleRadius);
|
||||||
updateRoundedCornerRadii();
|
updateRoundedCornerRadii();
|
||||||
if (hasRoundedCorners() || shouldDrawCutout() || shouldHostHandles()) {
|
if (hasRoundedCorners() || shouldDrawCutout() || shouldHostHandles()) {
|
||||||
setupDecorations();
|
setupDecorations();
|
||||||
@@ -528,17 +532,24 @@ public class ScreenDecorations extends SystemUI implements Tunable,
|
|||||||
com.android.internal.R.dimen.rounded_corner_radius_top);
|
com.android.internal.R.dimen.rounded_corner_radius_top);
|
||||||
final int newRoundedDefaultBottom = mContext.getResources().getDimensionPixelSize(
|
final int newRoundedDefaultBottom = mContext.getResources().getDimensionPixelSize(
|
||||||
com.android.internal.R.dimen.rounded_corner_radius_bottom);
|
com.android.internal.R.dimen.rounded_corner_radius_bottom);
|
||||||
|
|
||||||
final boolean roundedCornersChanged = mRoundedDefault != newRoundedDefault
|
final boolean roundedCornersChanged = mRoundedDefault != newRoundedDefault
|
||||||
|| mRoundedDefaultBottom != newRoundedDefaultBottom
|
|| mRoundedDefaultBottom != newRoundedDefaultBottom
|
||||||
|| mRoundedDefaultTop != newRoundedDefaultTop;
|
|| mRoundedDefaultTop != newRoundedDefaultTop;
|
||||||
|
|
||||||
if (roundedCornersChanged) {
|
if (roundedCornersChanged) {
|
||||||
mRoundedDefault = newRoundedDefault;
|
// If config_roundedCornerMultipleRadius set as true, ScreenDecorations respect the
|
||||||
mRoundedDefaultTop = newRoundedDefaultTop;
|
// max(width, height) size of drawable/rounded.xml instead of rounded_corner_radius
|
||||||
mRoundedDefaultBottom = newRoundedDefaultBottom;
|
if (mIsRoundedCornerMultipleRadius) {
|
||||||
onTuningChanged(SIZE, null);
|
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() {
|
private void updateViews() {
|
||||||
@@ -637,7 +648,8 @@ public class ScreenDecorations extends SystemUI implements Tunable,
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean hasRoundedCorners() {
|
private boolean hasRoundedCorners() {
|
||||||
return mRoundedDefault > 0 || mRoundedDefaultBottom > 0 || mRoundedDefaultTop > 0;
|
return mRoundedDefault > 0 || mRoundedDefaultBottom > 0 || mRoundedDefaultTop > 0
|
||||||
|
|| mIsRoundedCornerMultipleRadius;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldDrawCutout() {
|
private boolean shouldDrawCutout() {
|
||||||
|
|||||||
@@ -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_END;
|
||||||
import static com.android.systemui.tuner.TunablePadding.FLAG_START;
|
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.hamcrest.Matchers.is;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertThat;
|
import static org.junit.Assert.assertThat;
|
||||||
@@ -38,6 +40,7 @@ import static org.mockito.Mockito.when;
|
|||||||
import android.app.Fragment;
|
import android.app.Fragment;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
import android.graphics.drawable.VectorDrawable;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.testing.AndroidTestingRunner;
|
import android.testing.AndroidTestingRunner;
|
||||||
import android.testing.TestableLooper;
|
import android.testing.TestableLooper;
|
||||||
@@ -148,6 +151,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
|
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
|
||||||
mContext.getOrCreateTestableResources()
|
mContext.getOrCreateTestableResources()
|
||||||
.addOverride(dimen.rounded_corner_content_padding, 0);
|
.addOverride(dimen.rounded_corner_content_padding, 0);
|
||||||
|
mContext.getOrCreateTestableResources()
|
||||||
|
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
// No views added.
|
// No views added.
|
||||||
@@ -166,6 +171,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
com.android.internal.R.dimen.rounded_corner_radius, 20);
|
com.android.internal.R.dimen.rounded_corner_radius, 20);
|
||||||
mContext.getOrCreateTestableResources()
|
mContext.getOrCreateTestableResources()
|
||||||
.addOverride(dimen.rounded_corner_content_padding, 20);
|
.addOverride(dimen.rounded_corner_content_padding, 20);
|
||||||
|
mContext.getOrCreateTestableResources()
|
||||||
|
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
// Add 2 windows for rounded corners (top and bottom).
|
// 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());
|
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
|
@Test
|
||||||
public void testCutout() {
|
public void testCutout() {
|
||||||
mContext.getOrCreateTestableResources().addOverride(
|
mContext.getOrCreateTestableResources().addOverride(
|
||||||
@@ -224,6 +282,9 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
|
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
|
||||||
mContext.getOrCreateTestableResources()
|
mContext.getOrCreateTestableResources()
|
||||||
.addOverride(dimen.rounded_corner_content_padding, 0);
|
.addOverride(dimen.rounded_corner_content_padding, 0);
|
||||||
|
mContext.getOrCreateTestableResources()
|
||||||
|
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
|
||||||
|
|
||||||
when(mNavigationModeController.addListener(any())).thenReturn(
|
when(mNavigationModeController.addListener(any())).thenReturn(
|
||||||
WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL);
|
WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL);
|
||||||
|
|
||||||
@@ -245,6 +306,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
|
com.android.internal.R.dimen.rounded_corner_radius_bottom, 0);
|
||||||
mContext.getOrCreateTestableResources()
|
mContext.getOrCreateTestableResources()
|
||||||
.addOverride(dimen.rounded_corner_content_padding, 0);
|
.addOverride(dimen.rounded_corner_content_padding, 0);
|
||||||
|
mContext.getOrCreateTestableResources()
|
||||||
|
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
|
||||||
when(mNavigationModeController.addListener(any())).thenReturn(
|
when(mNavigationModeController.addListener(any())).thenReturn(
|
||||||
WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON);
|
WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON);
|
||||||
|
|
||||||
@@ -296,6 +359,8 @@ public class ScreenDecorationsTest extends SysuiTestCase {
|
|||||||
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
|
com.android.internal.R.bool.config_fillMainBuiltInDisplayCutout, false);
|
||||||
mContext.getOrCreateTestableResources().addOverride(
|
mContext.getOrCreateTestableResources().addOverride(
|
||||||
com.android.internal.R.dimen.rounded_corner_radius, 20);
|
com.android.internal.R.dimen.rounded_corner_radius, 20);
|
||||||
|
mContext.getOrCreateTestableResources()
|
||||||
|
.addOverride(R.bool.config_roundedCornerMultipleRadius, false);
|
||||||
|
|
||||||
mScreenDecorations.start();
|
mScreenDecorations.start();
|
||||||
assertEquals(mScreenDecorations.mRoundedDefault, 20);
|
assertEquals(mScreenDecorations.mRoundedDefault, 20);
|
||||||
|
|||||||
Reference in New Issue
Block a user