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.settingslib.spa.framework.theme
18
19 import android.R
20 import android.content.Context
21 import androidx.annotation.ColorRes
22 import androidx.annotation.DoNotInline
23 import androidx.compose.ui.graphics.Color
24
25 /**
26 * Tonal Palette structure in Material.
27 *
28 * A tonal palette is comprised of 5 tonal ranges. Each tonal range includes the 13 stops, or
29 * tonal swatches.
30 *
31 * Tonal range names are:
32 * - Neutral (N)
33 * - Neutral variant (NV)
34 * - Primary (P)
35 * - Secondary (S)
36 * - Tertiary (T)
37 */
38 internal class SettingsTonalPalette(
39 // The neutral tonal range from the generated dynamic color palette.
40 // Ordered from the lightest shade [neutral100] to the darkest shade [neutral0].
41 val neutral100: Color,
42 val neutral99: Color,
43 val neutral95: Color,
44 val neutral90: Color,
45 val neutral80: Color,
46 val neutral70: Color,
47 val neutral60: Color,
48 val neutral50: Color,
49 val neutral40: Color,
50 val neutral30: Color,
51 val neutral20: Color,
52 val neutral10: Color,
53 val neutral0: Color,
54
55 // The neutral variant tonal range, sometimes called "neutral 2", from the
56 // generated dynamic color palette.
57 // Ordered from the lightest shade [neutralVariant100] to the darkest shade [neutralVariant0].
58 val neutralVariant100: Color,
59 val neutralVariant99: Color,
60 val neutralVariant95: Color,
61 val neutralVariant90: Color,
62 val neutralVariant80: Color,
63 val neutralVariant70: Color,
64 val neutralVariant60: Color,
65 val neutralVariant50: Color,
66 val neutralVariant40: Color,
67 val neutralVariant30: Color,
68 val neutralVariant20: Color,
69 val neutralVariant10: Color,
70 val neutralVariant0: Color,
71
72 // The primary tonal range from the generated dynamic color palette.
73 // Ordered from the lightest shade [primary100] to the darkest shade [primary0].
74 val primary100: Color,
75 val primary99: Color,
76 val primary95: Color,
77 val primary90: Color,
78 val primary80: Color,
79 val primary70: Color,
80 val primary60: Color,
81 val primary50: Color,
82 val primary40: Color,
83 val primary30: Color,
84 val primary20: Color,
85 val primary10: Color,
86 val primary0: Color,
87
88 // The secondary tonal range from the generated dynamic color palette.
89 // Ordered from the lightest shade [secondary100] to the darkest shade [secondary0].
90 val secondary100: Color,
91 val secondary99: Color,
92 val secondary95: Color,
93 val secondary90: Color,
94 val secondary80: Color,
95 val secondary70: Color,
96 val secondary60: Color,
97 val secondary50: Color,
98 val secondary40: Color,
99 val secondary30: Color,
100 val secondary20: Color,
101 val secondary10: Color,
102 val secondary0: Color,
103
104 // The tertiary tonal range from the generated dynamic color palette.
105 // Ordered from the lightest shade [tertiary100] to the darkest shade [tertiary0].
106 val tertiary100: Color,
107 val tertiary99: Color,
108 val tertiary95: Color,
109 val tertiary90: Color,
110 val tertiary80: Color,
111 val tertiary70: Color,
112 val tertiary60: Color,
113 val tertiary50: Color,
114 val tertiary40: Color,
115 val tertiary30: Color,
116 val tertiary20: Color,
117 val tertiary10: Color,
118 val tertiary0: Color,
119 )
120
121 /** Static colors in Material. */
tonalPalettenull122 internal fun tonalPalette() = SettingsTonalPalette(
123 // The neutral static tonal range.
124 neutral100 = Color(red = 255, green = 255, blue = 255),
125 neutral99 = Color(red = 255, green = 251, blue = 254),
126 neutral95 = Color(red = 244, green = 239, blue = 244),
127 neutral90 = Color(red = 230, green = 225, blue = 229),
128 neutral80 = Color(red = 201, green = 197, blue = 202),
129 neutral70 = Color(red = 174, green = 170, blue = 174),
130 neutral60 = Color(red = 147, green = 144, blue = 148),
131 neutral50 = Color(red = 120, green = 117, blue = 121),
132 neutral40 = Color(red = 96, green = 93, blue = 98),
133 neutral30 = Color(red = 72, green = 70, blue = 73),
134 neutral20 = Color(red = 49, green = 48, blue = 51),
135 neutral10 = Color(red = 28, green = 27, blue = 31),
136 neutral0 = Color(red = 0, green = 0, blue = 0),
137
138 // The neutral variant static tonal range, sometimes called "neutral 2".
139 neutralVariant100 = Color(red = 255, green = 255, blue = 255),
140 neutralVariant99 = Color(red = 255, green = 251, blue = 254),
141 neutralVariant95 = Color(red = 245, green = 238, blue = 250),
142 neutralVariant90 = Color(red = 231, green = 224, blue = 236),
143 neutralVariant80 = Color(red = 202, green = 196, blue = 208),
144 neutralVariant70 = Color(red = 174, green = 169, blue = 180),
145 neutralVariant60 = Color(red = 147, green = 143, blue = 153),
146 neutralVariant50 = Color(red = 121, green = 116, blue = 126),
147 neutralVariant40 = Color(red = 96, green = 93, blue = 102),
148 neutralVariant30 = Color(red = 73, green = 69, blue = 79),
149 neutralVariant20 = Color(red = 50, green = 47, blue = 55),
150 neutralVariant10 = Color(red = 29, green = 26, blue = 34),
151 neutralVariant0 = Color(red = 0, green = 0, blue = 0),
152
153 // The primary static tonal range.
154 primary100 = Color(red = 255, green = 255, blue = 255),
155 primary99 = Color(red = 255, green = 251, blue = 254),
156 primary95 = Color(red = 246, green = 237, blue = 255),
157 primary90 = Color(red = 234, green = 221, blue = 255),
158 primary80 = Color(red = 208, green = 188, blue = 255),
159 primary70 = Color(red = 182, green = 157, blue = 248),
160 primary60 = Color(red = 154, green = 130, blue = 219),
161 primary50 = Color(red = 127, green = 103, blue = 190),
162 primary40 = Color(red = 103, green = 80, blue = 164),
163 primary30 = Color(red = 79, green = 55, blue = 139),
164 primary20 = Color(red = 56, green = 30, blue = 114),
165 primary10 = Color(red = 33, green = 0, blue = 93),
166 primary0 = Color(red = 33, green = 0, blue = 93),
167
168 // The secondary static tonal range.
169 secondary100 = Color(red = 255, green = 255, blue = 255),
170 secondary99 = Color(red = 255, green = 251, blue = 254),
171 secondary95 = Color(red = 246, green = 237, blue = 255),
172 secondary90 = Color(red = 232, green = 222, blue = 248),
173 secondary80 = Color(red = 204, green = 194, blue = 220),
174 secondary70 = Color(red = 176, green = 167, blue = 192),
175 secondary60 = Color(red = 149, green = 141, blue = 165),
176 secondary50 = Color(red = 122, green = 114, blue = 137),
177 secondary40 = Color(red = 98, green = 91, blue = 113),
178 secondary30 = Color(red = 74, green = 68, blue = 88),
179 secondary20 = Color(red = 51, green = 45, blue = 65),
180 secondary10 = Color(red = 29, green = 25, blue = 43),
181 secondary0 = Color(red = 0, green = 0, blue = 0),
182
183 // The tertiary static tonal range.
184 tertiary100 = Color(red = 255, green = 255, blue = 255),
185 tertiary99 = Color(red = 255, green = 251, blue = 250),
186 tertiary95 = Color(red = 255, green = 236, blue = 241),
187 tertiary90 = Color(red = 255, green = 216, blue = 228),
188 tertiary80 = Color(red = 239, green = 184, blue = 200),
189 tertiary70 = Color(red = 210, green = 157, blue = 172),
190 tertiary60 = Color(red = 181, green = 131, blue = 146),
191 tertiary50 = Color(red = 152, green = 105, blue = 119),
192 tertiary40 = Color(red = 125, green = 82, blue = 96),
193 tertiary30 = Color(red = 99, green = 59, blue = 72),
194 tertiary20 = Color(red = 73, green = 37, blue = 50),
195 tertiary10 = Color(red = 49, green = 17, blue = 29),
196 tertiary0 = Color(red = 0, green = 0, blue = 0),
197 )
198
199 /** Dynamic colors in Material. */
200 internal fun dynamicTonalPalette(context: Context) = SettingsTonalPalette(
201 // The neutral tonal range from the generated dynamic color palette.
202 neutral100 = ColorResourceHelper.getColor(context, R.color.system_neutral1_0),
203 neutral99 = ColorResourceHelper.getColor(context, R.color.system_neutral1_10),
204 neutral95 = ColorResourceHelper.getColor(context, R.color.system_neutral1_50),
205 neutral90 = ColorResourceHelper.getColor(context, R.color.system_neutral1_100),
206 neutral80 = ColorResourceHelper.getColor(context, R.color.system_neutral1_200),
207 neutral70 = ColorResourceHelper.getColor(context, R.color.system_neutral1_300),
208 neutral60 = ColorResourceHelper.getColor(context, R.color.system_neutral1_400),
209 neutral50 = ColorResourceHelper.getColor(context, R.color.system_neutral1_500),
210 neutral40 = ColorResourceHelper.getColor(context, R.color.system_neutral1_600),
211 neutral30 = ColorResourceHelper.getColor(context, R.color.system_neutral1_700),
212 neutral20 = ColorResourceHelper.getColor(context, R.color.system_neutral1_800),
213 neutral10 = ColorResourceHelper.getColor(context, R.color.system_neutral1_900),
214 neutral0 = ColorResourceHelper.getColor(context, R.color.system_neutral1_1000),
215
216 // The neutral variant tonal range, sometimes called "neutral 2", from the
217 // generated dynamic color palette.
218 neutralVariant100 = ColorResourceHelper.getColor(context, R.color.system_neutral2_0),
219 neutralVariant99 = ColorResourceHelper.getColor(context, R.color.system_neutral2_10),
220 neutralVariant95 = ColorResourceHelper.getColor(context, R.color.system_neutral2_50),
221 neutralVariant90 = ColorResourceHelper.getColor(context, R.color.system_neutral2_100),
222 neutralVariant80 = ColorResourceHelper.getColor(context, R.color.system_neutral2_200),
223 neutralVariant70 = ColorResourceHelper.getColor(context, R.color.system_neutral2_300),
224 neutralVariant60 = ColorResourceHelper.getColor(context, R.color.system_neutral2_400),
225 neutralVariant50 = ColorResourceHelper.getColor(context, R.color.system_neutral2_500),
226 neutralVariant40 = ColorResourceHelper.getColor(context, R.color.system_neutral2_600),
227 neutralVariant30 = ColorResourceHelper.getColor(context, R.color.system_neutral2_700),
228 neutralVariant20 = ColorResourceHelper.getColor(context, R.color.system_neutral2_800),
229 neutralVariant10 = ColorResourceHelper.getColor(context, R.color.system_neutral2_900),
230 neutralVariant0 = ColorResourceHelper.getColor(context, R.color.system_neutral2_1000),
231
232 // The primary tonal range from the generated dynamic color palette.
233 primary100 = ColorResourceHelper.getColor(context, R.color.system_accent1_0),
234 primary99 = ColorResourceHelper.getColor(context, R.color.system_accent1_10),
235 primary95 = ColorResourceHelper.getColor(context, R.color.system_accent1_50),
236 primary90 = ColorResourceHelper.getColor(context, R.color.system_accent1_100),
237 primary80 = ColorResourceHelper.getColor(context, R.color.system_accent1_200),
238 primary70 = ColorResourceHelper.getColor(context, R.color.system_accent1_300),
239 primary60 = ColorResourceHelper.getColor(context, R.color.system_accent1_400),
240 primary50 = ColorResourceHelper.getColor(context, R.color.system_accent1_500),
241 primary40 = ColorResourceHelper.getColor(context, R.color.system_accent1_600),
242 primary30 = ColorResourceHelper.getColor(context, R.color.system_accent1_700),
243 primary20 = ColorResourceHelper.getColor(context, R.color.system_accent1_800),
244 primary10 = ColorResourceHelper.getColor(context, R.color.system_accent1_900),
245 primary0 = ColorResourceHelper.getColor(context, R.color.system_accent1_1000),
246
247 // The secondary tonal range from the generated dynamic color palette.
248 secondary100 = ColorResourceHelper.getColor(context, R.color.system_accent2_0),
249 secondary99 = ColorResourceHelper.getColor(context, R.color.system_accent2_10),
250 secondary95 = ColorResourceHelper.getColor(context, R.color.system_accent2_50),
251 secondary90 = ColorResourceHelper.getColor(context, R.color.system_accent2_100),
252 secondary80 = ColorResourceHelper.getColor(context, R.color.system_accent2_200),
253 secondary70 = ColorResourceHelper.getColor(context, R.color.system_accent2_300),
254 secondary60 = ColorResourceHelper.getColor(context, R.color.system_accent2_400),
255 secondary50 = ColorResourceHelper.getColor(context, R.color.system_accent2_500),
256 secondary40 = ColorResourceHelper.getColor(context, R.color.system_accent2_600),
257 secondary30 = ColorResourceHelper.getColor(context, R.color.system_accent2_700),
258 secondary20 = ColorResourceHelper.getColor(context, R.color.system_accent2_800),
259 secondary10 = ColorResourceHelper.getColor(context, R.color.system_accent2_900),
260 secondary0 = ColorResourceHelper.getColor(context, R.color.system_accent2_1000),
261
262 // The tertiary tonal range from the generated dynamic color palette.
263 tertiary100 = ColorResourceHelper.getColor(context, R.color.system_accent3_0),
264 tertiary99 = ColorResourceHelper.getColor(context, R.color.system_accent3_10),
265 tertiary95 = ColorResourceHelper.getColor(context, R.color.system_accent3_50),
266 tertiary90 = ColorResourceHelper.getColor(context, R.color.system_accent3_100),
267 tertiary80 = ColorResourceHelper.getColor(context, R.color.system_accent3_200),
268 tertiary70 = ColorResourceHelper.getColor(context, R.color.system_accent3_300),
269 tertiary60 = ColorResourceHelper.getColor(context, R.color.system_accent3_400),
270 tertiary50 = ColorResourceHelper.getColor(context, R.color.system_accent3_500),
271 tertiary40 = ColorResourceHelper.getColor(context, R.color.system_accent3_600),
272 tertiary30 = ColorResourceHelper.getColor(context, R.color.system_accent3_700),
273 tertiary20 = ColorResourceHelper.getColor(context, R.color.system_accent3_800),
274 tertiary10 = ColorResourceHelper.getColor(context, R.color.system_accent3_900),
275 tertiary0 = ColorResourceHelper.getColor(context, R.color.system_accent3_1000),
276 )
277
278 private object ColorResourceHelper {
279 @DoNotInline
280 fun getColor(context: Context, @ColorRes id: Int): Color {
281 return Color(context.resources.getColor(id, context.theme))
282 }
283 }
284