1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License 15 */ 16 17 package com.android.internal.policy; 18 19 import android.content.Context; 20 import android.content.res.Resources; 21 import android.view.RoundedCorners; 22 23 import com.android.internal.R; 24 25 /** 26 * Utility functions for screen decorations used by both window manager and System UI. 27 */ 28 public class ScreenDecorationsUtils { 29 30 /** 31 * Corner radius that should be used on windows in order to cover the display. 32 * These values are expressed in pixels because they should not respect display or font 33 * scaling, this means that we don't have to reload them on config changes. 34 * 35 * Note that if the context is not an UI context(not associated with Display), it will use 36 * default display. 37 */ getWindowCornerRadius(Context context)38 public static float getWindowCornerRadius(Context context) { 39 final Resources resources = context.getResources(); 40 if (!supportsRoundedCornersOnWindows(resources)) { 41 return 0f; 42 } 43 // Use Context#getDisplayNoVerify() in case the context is not an UI context. 44 final String displayUniqueId = context.getDisplayNoVerify().getUniqueId(); 45 // Radius that should be used in case top or bottom aren't defined. 46 float defaultRadius = RoundedCorners.getRoundedCornerRadius(resources, displayUniqueId) 47 - RoundedCorners.getRoundedCornerRadiusAdjustment(resources, displayUniqueId); 48 49 float topRadius = RoundedCorners.getRoundedCornerTopRadius(resources, displayUniqueId) 50 - RoundedCorners.getRoundedCornerRadiusTopAdjustment(resources, displayUniqueId); 51 if (topRadius == 0f) { 52 topRadius = defaultRadius; 53 } 54 float bottomRadius = RoundedCorners.getRoundedCornerBottomRadius(resources, displayUniqueId) 55 - RoundedCorners.getRoundedCornerRadiusBottomAdjustment(resources, displayUniqueId); 56 if (bottomRadius == 0f) { 57 bottomRadius = defaultRadius; 58 } 59 60 // Always use the smallest radius to make sure the rounded corners will 61 // completely cover the display. 62 return Math.min(topRadius, bottomRadius); 63 } 64 65 /** 66 * If live rounded corners are supported on windows. 67 */ supportsRoundedCornersOnWindows(Resources resources)68 public static boolean supportsRoundedCornersOnWindows(Resources resources) { 69 return resources.getBoolean(R.bool.config_supportsRoundedCornersOnWindows); 70 } 71 } 72