summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/SystemUI/res/values/dimens.xml5
-rw-r--r--packages/SystemUI/src/com/android/systemui/assist/ui/DisplayUtils.java31
-rw-r--r--packages/SystemUI/tests/src/com/android/systemui/assist/ui/DisplayUtilsTest.java78
3 files changed, 92 insertions, 22 deletions
diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml
index 8fdfc892cf52..3d4638ffd0da 100644
--- a/packages/SystemUI/res/values/dimens.xml
+++ b/packages/SystemUI/res/values/dimens.xml
@@ -1565,4 +1565,9 @@
<dimen name="dream_overlay_status_bar_ambient_text_shadow_dx">0.5dp</dimen>
<dimen name="dream_overlay_status_bar_ambient_text_shadow_dy">0.5dp</dimen>
<dimen name="dream_overlay_status_bar_ambient_text_shadow_radius">2dp</dimen>
+
+ <!-- Default device corner radius, used for assist UI -->
+ <dimen name="config_rounded_mask_size">0px</dimen>
+ <dimen name="config_rounded_mask_size_top">0px</dimen>
+ <dimen name="config_rounded_mask_size_bottom">0px</dimen>
</resources>
diff --git a/packages/SystemUI/src/com/android/systemui/assist/ui/DisplayUtils.java b/packages/SystemUI/src/com/android/systemui/assist/ui/DisplayUtils.java
index 33e6ca49ddd5..9b441ad1d75c 100644
--- a/packages/SystemUI/src/com/android/systemui/assist/ui/DisplayUtils.java
+++ b/packages/SystemUI/src/com/android/systemui/assist/ui/DisplayUtils.java
@@ -21,6 +21,8 @@ import android.util.DisplayMetrics;
import android.view.Display;
import android.view.Surface;
+import com.android.systemui.R;
+
/**
* Utility class for determining screen and corner dimensions.
*/
@@ -82,17 +84,13 @@ public class DisplayUtils {
* where the curve ends), in pixels.
*/
public static int getCornerRadiusBottom(Context context) {
- int radius = 0;
-
- int resourceId = context.getResources().getIdentifier("config_rounded_mask_size_bottom",
- "dimen", "com.android.systemui");
- if (resourceId > 0) {
- radius = context.getResources().getDimensionPixelSize(resourceId);
- }
+ int radius = context.getResources().getDimensionPixelSize(
+ R.dimen.config_rounded_mask_size_bottom);
if (radius == 0) {
radius = getCornerRadiusDefault(context);
}
+
return radius;
}
@@ -101,28 +99,17 @@ public class DisplayUtils {
* the curve ends), in pixels.
*/
public static int getCornerRadiusTop(Context context) {
- int radius = 0;
-
- int resourceId = context.getResources().getIdentifier("config_rounded_mask_size_top",
- "dimen", "com.android.systemui");
- if (resourceId > 0) {
- radius = context.getResources().getDimensionPixelSize(resourceId);
- }
+ int radius = context.getResources().getDimensionPixelSize(
+ R.dimen.config_rounded_mask_size_top);
if (radius == 0) {
radius = getCornerRadiusDefault(context);
}
+
return radius;
}
private static int getCornerRadiusDefault(Context context) {
- int radius = 0;
-
- int resourceId = context.getResources().getIdentifier("config_rounded_mask_size",
- "dimen", "com.android.systemui");
- if (resourceId > 0) {
- radius = context.getResources().getDimensionPixelSize(resourceId);
- }
- return radius;
+ return context.getResources().getDimensionPixelSize(R.dimen.config_rounded_mask_size);
}
}
diff --git a/packages/SystemUI/tests/src/com/android/systemui/assist/ui/DisplayUtilsTest.java b/packages/SystemUI/tests/src/com/android/systemui/assist/ui/DisplayUtilsTest.java
new file mode 100644
index 000000000000..dd9683f83c37
--- /dev/null
+++ b/packages/SystemUI/tests/src/com/android/systemui/assist/ui/DisplayUtilsTest.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2022 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.systemui.assist.ui;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.when;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.testing.AndroidTestingRunner;
+
+import androidx.test.filters.SmallTest;
+
+import com.android.systemui.R;
+import com.android.systemui.SysuiTestCase;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+
+@SmallTest
+@RunWith(AndroidTestingRunner.class)
+public class DisplayUtilsTest extends SysuiTestCase {
+
+ @Mock
+ Resources mResources;
+ @Mock
+ Context mMockContext;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testGetCornerRadii_noOverlay() {
+ assertEquals(0, DisplayUtils.getCornerRadiusBottom(mContext));
+ assertEquals(0, DisplayUtils.getCornerRadiusTop(mContext));
+ }
+
+ @Test
+ public void testGetCornerRadii_onlyDefaultOverridden() {
+ when(mResources.getDimensionPixelSize(R.dimen.config_rounded_mask_size)).thenReturn(100);
+ when(mMockContext.getResources()).thenReturn(mResources);
+
+ assertEquals(100, DisplayUtils.getCornerRadiusBottom(mMockContext));
+ assertEquals(100, DisplayUtils.getCornerRadiusTop(mMockContext));
+ }
+
+ @Test
+ public void testGetCornerRadii_allOverridden() {
+ when(mResources.getDimensionPixelSize(R.dimen.config_rounded_mask_size)).thenReturn(100);
+ when(mResources.getDimensionPixelSize(R.dimen.config_rounded_mask_size_top)).thenReturn(
+ 150);
+ when(mResources.getDimensionPixelSize(R.dimen.config_rounded_mask_size_bottom)).thenReturn(
+ 200);
+ when(mMockContext.getResources()).thenReturn(mResources);
+
+ assertEquals(200, DisplayUtils.getCornerRadiusBottom(mMockContext));
+ assertEquals(150, DisplayUtils.getCornerRadiusTop(mMockContext));
+ }
+}