Use explicit resource IDs for assist corner radii
Bug: 249320624 Test: atest DisplayUtilsTest Change-Id: I19790a40af574021dd5e90d89bfa4416eb4f9f09
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user