Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 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 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 19 | import android.content.res.Resources; |
| 20 | |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 21 | import com.android.internal.R; |
| 22 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 23 | /** |
| 24 | * Utility functions for screen decorations used by both window manager and System UI. |
| 25 | */ |
| 26 | public class ScreenDecorationsUtils { |
| 27 | |
| 28 | /** |
| 29 | * Corner radius that should be used on windows in order to cover the display. |
| 30 | * These values are expressed in pixels because they should not respect display or font |
| 31 | * scaling, this means that we don't have to reload them on config changes. |
| 32 | */ |
| 33 | public static float getWindowCornerRadius(Resources resources) { |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 34 | if (!supportsRoundedCornersOnWindows(resources)) { |
| 35 | return 0f; |
| 36 | } |
| 37 | |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 38 | // Radius that should be used in case top or bottom aren't defined. |
Beverly | 72dbd11 | 2019-07-08 15:39:58 -0400 | [diff] [blame] | 39 | float defaultRadius = resources.getDimension(R.dimen.rounded_corner_radius) |
| 40 | - resources.getDimension(R.dimen.rounded_corner_radius_adjustment); |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 41 | |
Beverly | 72dbd11 | 2019-07-08 15:39:58 -0400 | [diff] [blame] | 42 | float topRadius = resources.getDimension(R.dimen.rounded_corner_radius_top) |
| 43 | - resources.getDimension(R.dimen.rounded_corner_radius_top_adjustment); |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 44 | if (topRadius == 0f) { |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 45 | topRadius = defaultRadius; |
| 46 | } |
Beverly | 72dbd11 | 2019-07-08 15:39:58 -0400 | [diff] [blame] | 47 | float bottomRadius = resources.getDimension(R.dimen.rounded_corner_radius_bottom) |
| 48 | - resources.getDimension(R.dimen.rounded_corner_radius_bottom_adjustment); |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 49 | if (bottomRadius == 0f) { |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 50 | bottomRadius = defaultRadius; |
| 51 | } |
| 52 | |
| 53 | // Always use the smallest radius to make sure the rounded corners will |
| 54 | // completely cover the display. |
| 55 | return Math.min(topRadius, bottomRadius); |
| 56 | } |
Lucas Dupin | f36d0dc | 2019-01-09 09:07:50 -0800 | [diff] [blame] | 57 | |
| 58 | /** |
| 59 | * If live rounded corners are supported on windows. |
| 60 | */ |
| 61 | public static boolean supportsRoundedCornersOnWindows(Resources resources) { |
| 62 | return resources.getBoolean(R.bool.config_supportsRoundedCornersOnWindows); |
| 63 | } |
Lucas Dupin | 086c6fc | 2018-10-16 18:06:43 -0700 | [diff] [blame] | 64 | } |