diff options
3 files changed, 97 insertions, 3 deletions
diff --git a/core/java/android/view/RoundedCorners.java b/core/java/android/view/RoundedCorners.java index f68cc691abeb..1f841bf53364 100644 --- a/core/java/android/view/RoundedCorners.java +++ b/core/java/android/view/RoundedCorners.java @@ -198,6 +198,12 @@ public class RoundedCorners implements Parcelable { radius = res.getDimensionPixelSize(R.dimen.rounded_corner_radius); } array.recycle(); + // For devices with round displays (e.g. watches) that don't otherwise provide the rounded + // corner radius via resource overlays, we can infer the corner radius directly from the + // display size. + if (radius == 0 && res.getConfiguration().isScreenRound()) { + radius = res.getDisplayMetrics().widthPixels / 2; + } return radius; } diff --git a/core/tests/coretests/src/android/view/RoundedCornersTest.java b/core/tests/coretests/src/android/view/RoundedCornersTest.java index 07ef33af3088..ec665ad042ae 100644 --- a/core/tests/coretests/src/android/view/RoundedCornersTest.java +++ b/core/tests/coretests/src/android/view/RoundedCornersTest.java @@ -16,6 +16,8 @@ package android.view; +import static android.content.res.Configuration.SCREENLAYOUT_ROUND_NO; +import static android.content.res.Configuration.SCREENLAYOUT_ROUND_YES; import static android.view.RoundedCorner.POSITION_BOTTOM_LEFT; import static android.view.RoundedCorner.POSITION_BOTTOM_RIGHT; import static android.view.RoundedCorner.POSITION_TOP_LEFT; @@ -28,22 +30,47 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.sameInstance; +import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertThat; +import static org.mockito.ArgumentMatchers.anyInt; +import static org.mockito.Mockito.when; +import android.content.res.Configuration; +import android.content.res.Resources; +import android.content.res.TypedArray; import android.platform.test.annotations.Presubmit; +import android.util.DisplayMetrics; import android.util.Pair; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; +import com.android.internal.R; + +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; @RunWith(AndroidJUnit4.class) @SmallTest @Presubmit public class RoundedCornersTest { + @Mock + DisplayMetrics mMockDisplayMetrics; + @Mock + Resources mMockResources; + @Mock TypedArray mMockTypedArray; + Configuration mConfiguration; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + mConfiguration = Configuration.EMPTY; + } + final RoundedCorners mRoundedCorners = new RoundedCorners( new RoundedCorner(POSITION_TOP_LEFT, 10, 10, 10), new RoundedCorner(POSITION_TOP_RIGHT, 10, 190, 10), @@ -199,4 +226,63 @@ public class RoundedCornersTest { assertThat(RoundedCorners.fromRadii(radius, 200, 300), not(sameInstance(cached))); } + + @Test + public void testGetRoundedCornerRadius_withRoundDevice_usesDisplayRadiusAsDefault() { + final int displayWidth = 400; + mConfiguration.screenLayout = SCREENLAYOUT_ROUND_YES; + mMockDisplayMetrics.widthPixels = displayWidth; + + when(mMockResources.getConfiguration()).thenReturn(mConfiguration); + when(mMockResources.getDisplayMetrics()).thenReturn(mMockDisplayMetrics); + when(mMockResources.getStringArray(R.array.config_displayUniqueIdArray)) + .thenReturn(new String[]{"0"}); + when(mMockTypedArray.length()).thenReturn(0); + when(mMockResources.obtainTypedArray(anyInt())).thenReturn(mMockTypedArray); + when(mMockResources.getDimensionPixelSize(R.dimen.rounded_corner_radius)) + .thenReturn(0); + + + int radius = RoundedCorners.getRoundedCornerRadius(mMockResources, "0"); + assertEquals((displayWidth / 2), radius); + } + + @Test + public void testGetRoundedCornerRadius_withRoundDevice_usesOverlayIfProvided() { + final int displayWidth = 400; + final int overlayValue = 199; + mConfiguration.screenLayout = SCREENLAYOUT_ROUND_YES; + mMockDisplayMetrics.widthPixels = displayWidth; + + when(mMockResources.getConfiguration()).thenReturn(mConfiguration); + when(mMockResources.getDisplayMetrics()).thenReturn(mMockDisplayMetrics); + when(mMockResources.getStringArray(R.array.config_displayUniqueIdArray)) + .thenReturn(new String[]{"0"}); + when(mMockTypedArray.length()).thenReturn(0); + when(mMockResources.obtainTypedArray(anyInt())).thenReturn(mMockTypedArray); + when(mMockResources.getDimensionPixelSize(R.dimen.rounded_corner_radius)) + .thenReturn(overlayValue); + + int radius = RoundedCorners.getRoundedCornerRadius(mMockResources, "0"); + assertEquals(overlayValue, radius); + } + + @Test + public void testGetRoundedCornerRadius_withNonRoundDevice_noDisplayDefault() { + final int displayWidth = 400; + mConfiguration.screenLayout = SCREENLAYOUT_ROUND_NO; + mMockDisplayMetrics.widthPixels = displayWidth; + + when(mMockResources.getConfiguration()).thenReturn(mConfiguration); + when(mMockResources.getDisplayMetrics()).thenReturn(mMockDisplayMetrics); + when(mMockResources.getStringArray(R.array.config_displayUniqueIdArray)) + .thenReturn(new String[]{"0"}); + when(mMockTypedArray.length()).thenReturn(0); + when(mMockResources.obtainTypedArray(anyInt())).thenReturn(mMockTypedArray); + when(mMockResources.getDimensionPixelSize(R.dimen.rounded_corner_radius)) + .thenReturn(0); + + int radius = RoundedCorners.getRoundedCornerRadius(mMockResources, "0"); + assertEquals(0, radius); + } } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java index c70a8219489e..9130edfa9f26 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/transition/DefaultTransitionHandler.java @@ -470,10 +470,12 @@ public class DefaultTransitionHandler implements Transitions.TransitionHandler { } final float cornerRadius; - if (a.hasRoundedCorners() && isTask) { - // hasRoundedCorners is currently only enabled for tasks + if (a.hasRoundedCorners()) { + final int displayId = isTask ? change.getTaskInfo().displayId + : info.getRoot(TransitionUtil.rootIndexFor(change, info)) + .getDisplayId(); final Context displayContext = - mDisplayController.getDisplayContext(change.getTaskInfo().displayId); + mDisplayController.getDisplayContext(displayId); cornerRadius = displayContext == null ? 0 : ScreenDecorationsUtils.getWindowCornerRadius(displayContext); } else { |