Enforce system radius instead of separate value for widgets in launcher
The change is behind a flag. This is to get to the stage of having
consistent corner radius across rectangular widgets.
Bug: 373351337
Test: Unit test and manual
Flag: com.android.launcher3.enforce_system_radius_for_app_widgets
Change-Id: I23d8d3bb2561b4fc3f780fc4ddce62e8b9293192
diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig
index fca1647..c71b833 100644
--- a/aconfig/launcher.aconfig
+++ b/aconfig/launcher.aconfig
@@ -485,3 +485,10 @@
description: "Enables launcher recents opening inside of a window instead of being hosted in launcher activity."
bug: "292269949"
}
+
+flag {
+ name: "enforce_system_radius_for_app_widgets"
+ namespace: "launcher"
+ description: "Enforce system radius for widget corners instead of a separate 16.dp value"
+ bug: "370950552"
+}
diff --git a/src/com/android/launcher3/widget/RoundedCornerEnforcement.java b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java
index cadaf89..e190dc3 100644
--- a/src/com/android/launcher3/widget/RoundedCornerEnforcement.java
+++ b/src/com/android/launcher3/widget/RoundedCornerEnforcement.java
@@ -16,6 +16,8 @@
package com.android.launcher3.widget;
+import static com.android.launcher3.Flags.enforceSystemRadiusForAppWidgets;
+
import android.appwidget.AppWidgetHostView;
import android.content.Context;
import android.content.res.Resources;
@@ -97,6 +99,10 @@
public static float computeEnforcedRadius(@NonNull Context context) {
Resources res = context.getResources();
float systemRadius = res.getDimension(android.R.dimen.system_app_widget_background_radius);
+ if (enforceSystemRadiusForAppWidgets()) {
+ return systemRadius;
+ }
+
float defaultRadius = res.getDimension(R.dimen.enforced_rounded_corner_max_radius);
return Math.min(defaultRadius, systemRadius);
}
diff --git a/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt b/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt
index db77702..c82e84c 100644
--- a/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt
+++ b/tests/multivalentTests/src/com/android/launcher3/widget/RoundedCornerEnforcementTest.kt
@@ -19,14 +19,19 @@
import android.content.Context
import android.content.res.Resources
import android.graphics.Rect
+import android.platform.test.annotations.DisableFlags
+import android.platform.test.annotations.EnableFlags
+import android.platform.test.flag.junit.SetFlagsRule
import android.view.View
import android.view.ViewGroup
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.filters.SmallTest
+import com.android.launcher3.Flags
import com.android.launcher3.R
import org.junit.Assert.assertEquals
import org.junit.Assert.assertSame
import org.junit.Assert.assertTrue
+import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mockito.mock
@@ -38,6 +43,8 @@
@RunWith(AndroidJUnit4::class)
class RoundedCornerEnforcementTest {
+ @get:Rule val setFlagsRule: SetFlagsRule = SetFlagsRule()
+
@Test
fun `Widget view has one background`() {
val mockWidgetView = mock(LauncherAppWidgetHostView::class.java)
@@ -72,14 +79,15 @@
RoundedCornerEnforcement.computeRoundedRectangle(
mockWidgetView,
mockBackgroundView,
- testRect
+ testRect,
)
assertEquals(Rect(50, 75, 250, 275), testRect)
}
@Test
- fun `Compute system radius`() {
+ @DisableFlags(Flags.FLAG_ENFORCE_SYSTEM_RADIUS_FOR_APP_WIDGETS)
+ fun `Compute system radius when smaller`() {
val mockContext = mock(Context::class.java)
val mockRes = mock(Resources::class.java)
@@ -94,6 +102,41 @@
assertEquals(RADIUS, RoundedCornerEnforcement.computeEnforcedRadius(mockContext))
}
+ @Test
+ @DisableFlags(Flags.FLAG_ENFORCE_SYSTEM_RADIUS_FOR_APP_WIDGETS)
+ fun `Compute launcher radius when smaller`() {
+ val mockContext = mock(Context::class.java)
+ val mockRes = mock(Resources::class.java)
+
+ doReturn(mockRes).whenever(mockContext).resources
+ doReturn(LAUNCHER_RADIUS + 8f)
+ .whenever(mockRes)
+ .getDimension(eq(android.R.dimen.system_app_widget_background_radius))
+ doReturn(LAUNCHER_RADIUS)
+ .whenever(mockRes)
+ .getDimension(eq(R.dimen.enforced_rounded_corner_max_radius))
+
+ assertEquals(LAUNCHER_RADIUS, RoundedCornerEnforcement.computeEnforcedRadius(mockContext))
+ }
+
+ @Test
+ @EnableFlags(Flags.FLAG_ENFORCE_SYSTEM_RADIUS_FOR_APP_WIDGETS)
+ fun `Compute system radius ignoring launcher radius`() {
+ val mockContext = mock(Context::class.java)
+ val mockRes = mock(Resources::class.java)
+
+ doReturn(mockRes).whenever(mockContext).resources
+ val systemRadius = LAUNCHER_RADIUS + 8f
+ doReturn(systemRadius)
+ .whenever(mockRes)
+ .getDimension(eq(android.R.dimen.system_app_widget_background_radius))
+ doReturn(LAUNCHER_RADIUS)
+ .whenever(mockRes)
+ .getDimension(eq(R.dimen.enforced_rounded_corner_max_radius))
+
+ assertEquals(systemRadius, RoundedCornerEnforcement.computeEnforcedRadius(mockContext))
+ }
+
companion object {
const val WIDTH = 200
const val HEIGHT = 200