Merge "Use explicit resource IDs for assist corner radii" into tm-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
d70608c126
@@ -1569,4 +1569,9 @@
|
|||||||
<dimen name="dream_overlay_status_bar_ambient_text_shadow_dx">0.5dp</dimen>
|
<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_dy">0.5dp</dimen>
|
||||||
<dimen name="dream_overlay_status_bar_ambient_text_shadow_radius">2dp</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>
|
</resources>
|
||||||
|
|||||||
@@ -21,6 +21,8 @@ import android.util.DisplayMetrics;
|
|||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.Surface;
|
import android.view.Surface;
|
||||||
|
|
||||||
|
import com.android.systemui.R;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility class for determining screen and corner dimensions.
|
* Utility class for determining screen and corner dimensions.
|
||||||
*/
|
*/
|
||||||
@@ -82,17 +84,13 @@ public class DisplayUtils {
|
|||||||
* where the curve ends), in pixels.
|
* where the curve ends), in pixels.
|
||||||
*/
|
*/
|
||||||
public static int getCornerRadiusBottom(Context context) {
|
public static int getCornerRadiusBottom(Context context) {
|
||||||
int radius = 0;
|
int radius = context.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.config_rounded_mask_size_bottom);
|
||||||
int resourceId = context.getResources().getIdentifier("config_rounded_mask_size_bottom",
|
|
||||||
"dimen", "com.android.systemui");
|
|
||||||
if (resourceId > 0) {
|
|
||||||
radius = context.getResources().getDimensionPixelSize(resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radius == 0) {
|
if (radius == 0) {
|
||||||
radius = getCornerRadiusDefault(context);
|
radius = getCornerRadiusDefault(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return radius;
|
return radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,28 +99,17 @@ public class DisplayUtils {
|
|||||||
* the curve ends), in pixels.
|
* the curve ends), in pixels.
|
||||||
*/
|
*/
|
||||||
public static int getCornerRadiusTop(Context context) {
|
public static int getCornerRadiusTop(Context context) {
|
||||||
int radius = 0;
|
int radius = context.getResources().getDimensionPixelSize(
|
||||||
|
R.dimen.config_rounded_mask_size_top);
|
||||||
int resourceId = context.getResources().getIdentifier("config_rounded_mask_size_top",
|
|
||||||
"dimen", "com.android.systemui");
|
|
||||||
if (resourceId > 0) {
|
|
||||||
radius = context.getResources().getDimensionPixelSize(resourceId);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (radius == 0) {
|
if (radius == 0) {
|
||||||
radius = getCornerRadiusDefault(context);
|
radius = getCornerRadiusDefault(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
return radius;
|
return radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getCornerRadiusDefault(Context context) {
|
private static int getCornerRadiusDefault(Context context) {
|
||||||
int radius = 0;
|
return context.getResources().getDimensionPixelSize(R.dimen.config_rounded_mask_size);
|
||||||
|
|
||||||
int resourceId = context.getResources().getIdentifier("config_rounded_mask_size",
|
|
||||||
"dimen", "com.android.systemui");
|
|
||||||
if (resourceId > 0) {
|
|
||||||
radius = context.getResources().getDimensionPixelSize(resourceId);
|
|
||||||
}
|
|
||||||
return radius;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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