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 
17 package com.android.systemui.monet;
18 
19 import com.google.ux.material.libmonet.dynamiccolor.ContrastCurve;
20 import com.google.ux.material.libmonet.dynamiccolor.DynamicColor;
21 import com.google.ux.material.libmonet.dynamiccolor.MaterialDynamicColors;
22 import com.google.ux.material.libmonet.dynamiccolor.ToneDeltaPair;
23 import com.google.ux.material.libmonet.dynamiccolor.TonePolarity;
24 
25 class CustomDynamicColors {
26     private final MaterialDynamicColors mMdc;
27 
CustomDynamicColors(boolean isExtendedFidelity)28     CustomDynamicColors(boolean isExtendedFidelity) {
29         this.mMdc = new MaterialDynamicColors(isExtendedFidelity);
30     }
31 
32     // CLOCK COLORS
33 
widgetBackground()34     public DynamicColor widgetBackground() {
35         return new DynamicColor(
36                 /* name= */ "widget_background",
37                 /* palette= */ (s) -> s.primaryPalette,
38                 /* tone= */ (s) -> s.isDark ? 20.0 : 95.0,
39                 /* isBackground= */ true,
40                 /* background= */ null,
41                 /* secondBackground= */ null,
42                 /* contrastCurve= */ null,
43                 /* toneDeltaPair= */ null);
44     }
45 
clockHour()46     public DynamicColor clockHour() {
47         return new DynamicColor(
48                 /* name= */ "clock_hour",
49                 /* palette= */ (s) -> s.secondaryPalette,
50                 /* tone= */ (s) -> s.isDark ? 30.0 : 60.0,
51                 /* isBackground= */ false,
52                 /* background= */ (s) -> widgetBackground(),
53                 /* secondBackground= */ null,
54                 /* contrastCurve= */ new ContrastCurve(1.0, 4.0, 5.0, 15.0),
55                 /* toneDeltaPair= */
56                 (s) -> new ToneDeltaPair(clockHour(), clockMinute(), 10.0, TonePolarity.DARKER,
57                         false));
58     }
59 
clockMinute()60     public DynamicColor clockMinute() {
61         return new DynamicColor(
62                 /* name= */ "clock_minute",
63                 /* palette= */ (s) -> s.primaryPalette,
64                 /* tone= */ (s) -> s.isDark ? 40.0 : 90.0,
65                 /* isBackground= */ false,
66                 /* background= */ (s) -> widgetBackground(),
67                 /* secondBackground= */ null,
68                 /* contrastCurve= */ new ContrastCurve(1.0, 6.5, 10.0, 15.0),
69                 /* toneDeltaPair= */ null);
70     }
71 
clockSecond()72     public DynamicColor clockSecond() {
73         return new DynamicColor(
74                 /* name= */ "clock_second",
75                 /* palette= */ (s) -> s.tertiaryPalette,
76                 /* tone= */ (s) -> s.isDark ? 40.0 : 90.0,
77                 /* isBackground= */ false,
78                 /* background= */ (s) -> widgetBackground(),
79                 /* secondBackground= */ null,
80                 /* contrastCurve= */ new ContrastCurve(1.0, 5.0, 70.0, 11.0),
81                 /* toneDeltaPair= */ null);
82     }
83 
weatherTemp()84     public DynamicColor weatherTemp() {
85         return new DynamicColor(
86                 /* name= */ "clock_second",
87                 /* palette= */ (s) -> s.primaryPalette,
88                 /* tone= */ (s) -> s.isDark ? 55.0 : 80.0,
89                 /* isBackground= */ false,
90                 /* background= */ (s) -> widgetBackground(),
91                 /* secondBackground= */ null,
92                 /* contrastCurve= */ new ContrastCurve(1.0, 5.0, 70.0, 11.0),
93                 /* toneDeltaPair= */ null);
94     }
95 
96     // THEME APP ICONS
97 
themeApp()98     public DynamicColor themeApp() {
99         return new DynamicColor(
100                 /* name= */ "theme_app",
101                 /* palette= */ (s) -> s.primaryPalette,
102                 /* tone= */ (s) -> s.isDark ? 90.0 : 30.0, // Adjusted values
103                 /* isBackground= */ true,
104                 /* background= */ null,
105                 /* secondBackground= */ null,
106                 /* contrastCurve= */ null,
107                 /* toneDeltaPair= */ null);
108     }
109 
onThemeApp()110     public DynamicColor onThemeApp() {
111         return new DynamicColor(
112                 /* name= */ "on_theme_app",
113                 /* palette= */ (s) -> s.primaryPalette,
114                 /* tone= */ (s) -> s.isDark ? 40.0 : 80.0, // Adjusted values
115                 /* isBackground= */ false,
116                 /* background= */ (s) -> themeApp(),
117                 /* secondBackground= */ null,
118                 /* contrastCurve= */ new ContrastCurve(1.0, 3.0, 7.0, 10.0),
119                 /* toneDeltaPair= */ null);
120     }
121 
themeAppRing()122     public DynamicColor themeAppRing() {
123         return new DynamicColor(
124                 /* name= */ "theme_app_ring",
125                 /* palette= */ (s) -> s.primaryPalette,
126                 /* tone= */ (s) -> 70.0,
127                 /* isBackground= */ true,
128                 /* background= */ null,
129                 /* secondBackground= */ null,
130                 /* contrastCurve= */ new ContrastCurve(1.0, 1.0, 1.0, 1.0),
131                 /* toneDeltaPair= */ null);
132     }
133 
themeNotif()134     public DynamicColor themeNotif() {
135         return new DynamicColor(
136                 /* name= */ "theme_notif",
137                 /* palette= */ (s) -> s.tertiaryPalette,
138                 /* tone= */ (s) -> s.isDark ? 80.0 : 90.0,
139                 /* isBackground= */ false,
140                 /* background= */ (s) -> themeAppRing(),
141                 /* secondBackground= */ null,
142                 /* contrastCurve= */ new ContrastCurve(1.0, 1.0, 1.0, 1.0),
143                 /* toneDeltaPair= */
144                 (s) -> new ToneDeltaPair(themeNotif(), themeAppRing(), 10.0, TonePolarity.NEARER,
145                         false));
146     }
147 
148     // SUPER G COLORS
149 
brandA()150     public DynamicColor brandA() {
151         return new DynamicColor(
152                 /* name= */ "brand_a",
153                 /* palette= */ (s) -> s.primaryPalette,
154                 /* tone= */ (s) -> s.isDark ? 40.0 : 80.0,
155                 /* isBackground= */ true,
156                 /* background= */ (s) -> mMdc.surfaceContainerLow(),
157                 /* secondBackground= */ null,
158                 /* contrastCurve= */ new ContrastCurve(1.0, 3.0, 7.0, 17.0),
159                 /* toneDeltaPair= */
160                 (s) -> new ToneDeltaPair(brandA(), brandB(), 10.0, TonePolarity.NEARER, false));
161     }
162 
brandB()163     public DynamicColor brandB() {
164         return new DynamicColor(
165                 /* name= */ "brand_b",
166                 /* palette= */ (s) -> s.secondaryPalette,
167                 /* tone= */ (s) -> s.isDark ? 70.0 : 98.0,
168                 /* isBackground= */ true,
169                 /* background= */ (s) -> mMdc.surfaceContainerLow(),
170                 /* secondBackground= */ null,
171                 /* contrastCurve= */ new ContrastCurve(1.0, 3.0, 3.0, 6.0),
172                 /* toneDeltaPair= */
173                 (s) -> new ToneDeltaPair(brandB(), brandC(), 10.0, TonePolarity.NEARER, false));
174     }
175 
brandC()176     public DynamicColor brandC() {
177         return new DynamicColor(
178                 /* name= */ "brand_c",
179                 /* palette= */ (s) -> s.primaryPalette,
180                 /* tone= */ (s) -> s.isDark ? 50.0 : 60.0,
181                 /* isBackground= */ false,
182                 /* background= */ (s) -> mMdc.surfaceContainerLow(),
183                 /* secondBackground= */ null,
184                 /* contrastCurve= */ new ContrastCurve(1.0, 3.0, 4.0, 9.0),
185                 /* toneDeltaPair= */
186                 (s) -> new ToneDeltaPair(brandC(), brandD(), 10.0, TonePolarity.NEARER, false));
187     }
188 
brandD()189     public DynamicColor brandD() {
190         return new DynamicColor(
191                 /* name= */ "brand_d",
192                 /* palette= */ (s) -> s.tertiaryPalette,
193                 /* tone= */ (s) -> s.isDark ? 59.0 : 90.0,
194                 /* isBackground= */ false,
195                 /* background= */ (s) -> mMdc.surfaceContainerLow(),
196                 /* secondBackground= */ null,
197                 /* contrastCurve= */ new ContrastCurve(1.0, 3.0, 4.0, 13.0),
198                 /* toneDeltaPair= */
199                 (s) -> new ToneDeltaPair(brandD(), brandA(), 10.0, TonePolarity.NEARER, false));
200     }
201 
202     // QUICK SETTING TIILES
203 
underSurface()204     public DynamicColor underSurface() {
205         return new DynamicColor(
206                 /* name= */ "under_surface",
207                 /* palette= */ (s) -> s.primaryPalette,
208                 /* tone= */ (s) -> 0.0,
209                 /* isBackground= */ true,
210                 /* background= */ null,
211                 /* secondBackground= */ null,
212                 /* contrastCurve= */ null,
213                 /* toneDeltaPair= */ null);
214     }
215 
shadeActive()216     public DynamicColor shadeActive() {
217         return new DynamicColor(
218                 /* name= */ "shade_active",
219                 /* palette= */ (s) -> s.primaryPalette,
220                 /* tone= */ (s) -> 90.0,
221                 /* isBackground= */ false,
222                 /* background= */ (s) -> underSurface(),
223                 /* secondBackground= */ null,
224                 /* contrastCurve= */ new ContrastCurve(1.0, 3.0, 4.5, 7.0),
225                 /* toneDeltaPair= */
226                 (s) -> new ToneDeltaPair(shadeActive(), shadeInactive(), 30.0, TonePolarity.LIGHTER,
227                         false));
228     }
229 
onShadeActive()230     public DynamicColor onShadeActive() {
231         return new DynamicColor(
232                 /* name= */ "on_shade_active",
233                 /* palette= */ (s) -> s.primaryPalette,
234                 /* tone= */ (s) -> 10.0,
235                 /* isBackground= */ false,
236                 /* background= */ (s) -> shadeActive(),
237                 /* secondBackground= */ null,
238                 /* contrastCurve= */ new ContrastCurve(1.0, 4.5, 7.0, 11.0),
239                 /* toneDeltaPair= */
240                 (s) -> new ToneDeltaPair(onShadeActive(), onShadeActiveVariant(), 20.0,
241                         TonePolarity.NEARER, false));
242     }
243 
onShadeActiveVariant()244     public DynamicColor onShadeActiveVariant() {
245         return new DynamicColor(
246                 /* name= */ "on_shade_active_variant",
247                 /* palette= */ (s) -> s.primaryPalette,
248                 /* tone= */ (s) -> 30.0,
249                 /* isBackground= */ false,
250                 /* background= */ (s) -> shadeActive(),
251                 /* secondBackground= */ null,
252                 /* contrastCurve= */ new ContrastCurve(1.0, 4.5, 7.0, 11.0),
253                 /* toneDeltaPair= */
254                 (s) -> new ToneDeltaPair(onShadeActiveVariant(), onShadeActive(), 20.0,
255                         TonePolarity.NEARER, false));
256     }
257 
shadeInactive()258     public DynamicColor shadeInactive() {
259         return new DynamicColor(
260                 /* name= */ "shade_inactive",
261                 /* palette= */ (s) -> s.neutralPalette,
262                 /* tone= */ (s) -> 20.0,
263                 /* isBackground= */ true,
264                 /* background= */ (s) -> underSurface(),
265                 /* secondBackground= */ null,
266                 /* contrastCurve= */ new ContrastCurve(1.0, 1.0, 1.0, 1.0),
267                 /* toneDeltaPair= */(s) -> new ToneDeltaPair(shadeInactive(), shadeDisabled(), 15.0,
268                 TonePolarity.LIGHTER, false));
269     }
270 
onShadeInactive()271     public DynamicColor onShadeInactive() {
272         return new DynamicColor(
273                 /* name= */ "on_shade_inactive",
274                 /* palette= */ (s) -> s.neutralVariantPalette,
275                 /* tone= */ (s) -> 90.0,
276                 /* isBackground= */ true,
277                 /* background= */ (s) -> shadeInactive(),
278                 /* secondBackground= */ null,
279                 /* contrastCurve= */ new ContrastCurve(1.0, 4.5, 7.0, 11.0),
280                 /* toneDeltaPair= */
281                 (s) -> new ToneDeltaPair(onShadeInactive(), onShadeInactiveVariant(), 10.0,
282                         TonePolarity.NEARER, false));
283     }
284 
onShadeInactiveVariant()285     public DynamicColor onShadeInactiveVariant() {
286         return new DynamicColor(
287                 /* name= */ "on_shade_inactive_variant",
288                 /* palette= */ (s) -> s.neutralVariantPalette,
289                 /* tone= */ (s) -> 80.0,
290                 /* isBackground= */ false,
291                 /* background= */ (s) -> shadeInactive(),
292                 /* secondBackground= */ null,
293                 /* contrastCurve= */ new ContrastCurve(1.0, 4.5, 7.0, 11.0),
294                 /* toneDeltaPair= */
295                 (s) -> new ToneDeltaPair(onShadeInactiveVariant(), onShadeInactive(), 10.0,
296                         TonePolarity.NEARER, false));
297     }
298 
shadeDisabled()299     public DynamicColor shadeDisabled() {
300         return new DynamicColor(
301                 /* name= */ "shade_disabled",
302                 /* palette= */ (s) -> s.neutralPalette,
303                 /* tone= */ (s) -> 4.0,
304                 /* isBackground= */ false,
305                 /* background= */ (s) -> underSurface(),
306                 /* secondBackground= */ null,
307                 /* contrastCurve= */ new ContrastCurve(1.0, 1.0, 1.0, 1.0),
308                 /* toneDeltaPair= */ null);
309     }
310 
overviewBackground()311     public DynamicColor overviewBackground() {
312         return new DynamicColor(
313                 /* name= */ "overview_background",
314                 /* palette= */ (s) -> s.neutralVariantPalette,
315                 /* tone= */ (s) -> s.isDark ? 80.0 : 35.0,
316                 /* isBackground= */ true,
317                 /* background= */ null,
318                 /* secondBackground= */ null,
319                 /* contrastCurve= */null,
320                 /* toneDeltaPair= */ null);
321     }
322 }
323