• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2024 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 package com.android.permissioncontroller.wear.permission.components.material3
17 
18 import androidx.compose.runtime.Composable
19 import androidx.compose.ui.graphics.Color
20 import androidx.wear.compose.material.ChipColors
21 import androidx.wear.compose.material.ChipDefaults
22 import androidx.wear.compose.material3.ButtonColors
23 import androidx.wear.compose.material3.ButtonDefaults
24 import com.android.permissioncontroller.wear.permission.components.material2.chipDefaultColors
25 import com.android.permissioncontroller.wear.permission.components.material2.chipDisabledColors
26 import com.android.permissioncontroller.wear.permission.components.material3.WearPermissionButtonStyle.DisabledLike
27 import com.android.permissioncontroller.wear.permission.components.material3.WearPermissionButtonStyle.Primary
28 import com.android.permissioncontroller.wear.permission.components.material3.WearPermissionButtonStyle.Secondary
29 import com.android.permissioncontroller.wear.permission.components.material3.WearPermissionButtonStyle.Transparent
30 import com.android.permissioncontroller.wear.permission.components.material3.WearPermissionButtonStyle.Warning
31 
32 /**
33  * This component is wrapper on material control colors, It applies the right colors based material
34  * ui version.
35  */
36 enum class WearPermissionButtonStyle {
37     Primary,
38     Secondary,
39     Transparent,
40     DisabledLike,
41     Warning,
42 }
43 
44 @Composable
material2ChipColorsnull45 internal fun WearPermissionButtonStyle.material2ChipColors(): ChipColors {
46     return when (this) {
47         Primary -> chipDefaultColors()
48         Secondary -> ChipDefaults.secondaryChipColors()
49         Transparent -> ChipDefaults.childChipColors()
50         DisabledLike -> chipDisabledColors()
51         Warning ->
52             ChipDefaults.secondaryChipColors(
53                 backgroundColor =
54                     Color(red = 65, green = 14, blue = 11, alpha = (0.8f * 255).toInt())
55             )
56     }
57 }
58 
59 @Composable
material3ButtonColorsnull60 internal fun WearPermissionButtonStyle.material3ButtonColors(): ButtonColors {
61     return when (this) {
62         Primary -> ButtonDefaults.buttonColors()
63         Secondary -> ButtonDefaults.filledTonalButtonColors()
64         Transparent -> ButtonDefaults.childButtonColors()
65         DisabledLike -> ButtonDefaults.disabledLikeColors()
66         Warning ->
67             ButtonDefaults.buttonColors(
68                 containerColor =
69                     Color(red = 65, green = 14, blue = 11, alpha = (0.8f * 255).toInt())
70             )
71     }
72 }
73 
74 @Composable
disabledLikeColorsnull75 private fun ButtonDefaults.disabledLikeColors() =
76     filledTonalButtonColors().run {
77         ButtonColors(
78             containerPainter = disabledContainerPainter,
79             contentColor = disabledContentColor,
80             secondaryContentColor = disabledSecondaryContentColor,
81             iconColor = disabledIconColor,
82             disabledContainerPainter = disabledContainerPainter,
83             disabledContentColor = disabledContentColor,
84             disabledSecondaryContentColor = disabledSecondaryContentColor,
85             disabledIconColor = disabledIconColor,
86         )
87     }
88