1 /*
2  * Copyright 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 androidx.glance.material
18 
19 import androidx.compose.material.Colors
20 import androidx.compose.material.primarySurface
21 import androidx.compose.ui.graphics.Color
22 import androidx.glance.GlanceTheme
23 import androidx.glance.color.ColorProvider
24 import androidx.glance.color.ColorProviders
25 import androidx.glance.color.colorProviders
26 import androidx.glance.unit.ColorProvider
27 
28 /** Given Material [Colors], creates a [ColorProviders] that can be passed to [GlanceTheme] */
ColorProvidersnull29 fun ColorProviders(light: Colors, dark: Colors): ColorProviders {
30 
31     val background = ColorProvider(light.background, dark.background)
32     val onBackground = ColorProvider(light.onBackground, dark.onBackground)
33     val primary = ColorProvider(light.primary, dark.primary)
34     val onPrimary = ColorProvider(light.onPrimary, dark.onPrimary)
35     val surface = ColorProvider(light.primarySurface, dark.primarySurface)
36     val onSurface = ColorProvider(light.onSurface, dark.onSurface)
37     val secondary = ColorProvider(light.secondary, dark.secondary)
38     val onSecondary = ColorProvider(light.onSecondary, dark.onSecondary)
39     val error = ColorProvider(light.error, dark.error)
40     val onError = ColorProvider(light.onError, dark.onError)
41 
42     return colorProviders(
43         primary = primary,
44         onPrimary = onPrimary,
45         surface = surface,
46         onSurface = onSurface,
47         secondary = secondary,
48         onSecondary = onSecondary,
49         error = error,
50         onError = onError,
51         background = background,
52         onBackground = onBackground,
53         primaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
54         onPrimaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
55         secondaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
56         onSecondaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
57         tertiary = ColorProvider(ColorNotDefined, ColorNotDefined),
58         onTertiary = ColorProvider(ColorNotDefined, ColorNotDefined),
59         tertiaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
60         onTertiaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
61         errorContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
62         onErrorContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
63         surfaceVariant = ColorProvider(ColorNotDefined, ColorNotDefined),
64         onSurfaceVariant = ColorProvider(ColorNotDefined, ColorNotDefined),
65         outline = ColorProvider(ColorNotDefined, ColorNotDefined),
66         inverseOnSurface = ColorProvider(ColorNotDefined, ColorNotDefined),
67         inverseSurface = ColorProvider(ColorNotDefined, ColorNotDefined),
68         inversePrimary = ColorProvider(ColorNotDefined, ColorNotDefined),
69         widgetBackground = background,
70     )
71 }
72 
73 /** Given Material [Colors], creates a [ColorProviders] that can be passed to [GlanceTheme] */
ColorProvidersnull74 fun ColorProviders(colors: Colors): ColorProviders {
75 
76     val background = ColorProvider(colors.background)
77     val onBackground = ColorProvider(colors.onBackground)
78     val primary = ColorProvider(colors.primary)
79     val onPrimary = ColorProvider(colors.onPrimary)
80     val surface = ColorProvider(colors.primarySurface)
81     val onSurface = ColorProvider(colors.onSurface)
82     val secondary = ColorProvider(colors.secondary)
83     val onSecondary = ColorProvider(colors.onSecondary)
84     val error = ColorProvider(colors.error)
85     val onError = ColorProvider(colors.onError)
86 
87     return colorProviders(
88         primary = primary,
89         onPrimary = onPrimary,
90         surface = surface,
91         onSurface = onSurface,
92         secondary = secondary,
93         onSecondary = onSecondary,
94         error = error,
95         onError = onError,
96         background = background,
97         onBackground = onBackground,
98         primaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
99         onPrimaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
100         secondaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
101         onSecondaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
102         tertiary = ColorProvider(ColorNotDefined, ColorNotDefined),
103         onTertiary = ColorProvider(ColorNotDefined, ColorNotDefined),
104         tertiaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
105         onTertiaryContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
106         errorContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
107         onErrorContainer = ColorProvider(ColorNotDefined, ColorNotDefined),
108         surfaceVariant = ColorProvider(ColorNotDefined, ColorNotDefined),
109         onSurfaceVariant = ColorProvider(ColorNotDefined, ColorNotDefined),
110         outline = ColorProvider(ColorNotDefined, ColorNotDefined),
111         inverseOnSurface = ColorProvider(ColorNotDefined, ColorNotDefined),
112         inverseSurface = ColorProvider(ColorNotDefined, ColorNotDefined),
113         inversePrimary = ColorProvider(ColorNotDefined, ColorNotDefined),
114         widgetBackground = background,
115     )
116 }
117 
118 private val ColorNotDefined = Color.Magenta
119