1 /*
2  * Copyright (C) 2022 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.systemui.decor
18 
19 import android.view.DisplayCutout
20 import com.android.systemui.R
21 
22 class RoundedCornerDecorProviderFactory(
23     private val roundedCornerResDelegate: RoundedCornerResDelegate
24 ) : DecorProviderFactory() {
25 
26     override val hasProviders: Boolean
27         get() = roundedCornerResDelegate.run {
28             hasTop || hasBottom
29         }
30 
31     override val providers: List<DecorProvider>
32     get() {
33         val hasTop = roundedCornerResDelegate.hasTop
34         val hasBottom = roundedCornerResDelegate.hasBottom
35         return when {
36             hasTop && hasBottom -> listOf(
37                 RoundedCornerDecorProviderImpl(
38                     viewId = R.id.rounded_corner_top_left,
39                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_TOP,
40                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_LEFT,
41                     roundedCornerResDelegate = roundedCornerResDelegate),
42                 RoundedCornerDecorProviderImpl(
43                     viewId = R.id.rounded_corner_top_right,
44                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_TOP,
45                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_RIGHT,
46                     roundedCornerResDelegate = roundedCornerResDelegate),
47                 RoundedCornerDecorProviderImpl(
48                     viewId = R.id.rounded_corner_bottom_left,
49                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_BOTTOM,
50                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_LEFT,
51                     roundedCornerResDelegate = roundedCornerResDelegate),
52                 RoundedCornerDecorProviderImpl(
53                     viewId = R.id.rounded_corner_bottom_right,
54                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_BOTTOM,
55                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_RIGHT,
56                     roundedCornerResDelegate = roundedCornerResDelegate)
57             )
58             hasTop -> listOf(
59                 RoundedCornerDecorProviderImpl(
60                     viewId = R.id.rounded_corner_top_left,
61                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_TOP,
62                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_LEFT,
63                     roundedCornerResDelegate = roundedCornerResDelegate),
64                 RoundedCornerDecorProviderImpl(
65                     viewId = R.id.rounded_corner_top_right,
66                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_TOP,
67                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_RIGHT,
68                     roundedCornerResDelegate = roundedCornerResDelegate)
69             )
70             hasBottom -> listOf(
71                 RoundedCornerDecorProviderImpl(
72                     viewId = R.id.rounded_corner_bottom_left,
73                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_BOTTOM,
74                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_LEFT,
75                     roundedCornerResDelegate = roundedCornerResDelegate),
76                 RoundedCornerDecorProviderImpl(
77                     viewId = R.id.rounded_corner_bottom_right,
78                     alignedBound1 = DisplayCutout.BOUNDS_POSITION_BOTTOM,
79                     alignedBound2 = DisplayCutout.BOUNDS_POSITION_RIGHT,
80                     roundedCornerResDelegate = roundedCornerResDelegate)
81             )
82             else -> emptyList()
83         }
84     }
85 }