• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2021 Google LLC
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.google.ux.material.libmonet.palettes;
18 
19 import static java.lang.Math.max;
20 import static java.lang.Math.min;
21 
22 import com.google.ux.material.libmonet.hct.Hct;
23 
24 /**
25  * An intermediate concept between the key color for a UI theme, and a full color scheme. 5 sets of
26  * tones are generated, all except one use the same hue as the key color, and all vary in chroma.
27  *
28  * @deprecated Use {@link com.google.ux.material.libmonet.dynamiccolor.DynamicScheme} for color
29  *     scheme generation. Use {@link com.google.ux.material.libmonet.palettes.CorePalettes} for core
30  *     palettes container class.
31  */
32 @Deprecated
33 public final class CorePalette {
34   public TonalPalette a1;
35   public TonalPalette a2;
36   public TonalPalette a3;
37   public TonalPalette n1;
38   public TonalPalette n2;
39   public TonalPalette error;
40 
41   /**
42    * Create key tones from a color.
43    *
44    * @param argb ARGB representation of a color
45    * @deprecated Use {@link com.google.ux.material.libmonet.dynamiccolor.DynamicScheme} for color
46    *     scheme generation. Use {@link com.google.ux.material.libmonet.palettes.CorePalettes} for
47    *     core palettes container class.
48    */
49   @Deprecated
of(int argb)50   public static CorePalette of(int argb) {
51     return new CorePalette(argb, false);
52   }
53 
54   /**
55    * Create content key tones from a color.
56    *
57    * @param argb ARGB representation of a color
58    * @deprecated Use {@link com.google.ux.material.libmonet.dynamiccolor.DynamicScheme} for color
59    *     scheme generation. Use {@link com.google.ux.material.libmonet.palettes.CorePalettes} for
60    *     core palettes container class.
61    */
62   @Deprecated
contentOf(int argb)63   public static CorePalette contentOf(int argb) {
64     return new CorePalette(argb, true);
65   }
66 
CorePalette(int argb, boolean isContent)67   private CorePalette(int argb, boolean isContent) {
68     Hct hct = Hct.fromInt(argb);
69     double hue = hct.getHue();
70     double chroma = hct.getChroma();
71     if (isContent) {
72       this.a1 = TonalPalette.fromHueAndChroma(hue, chroma);
73       this.a2 = TonalPalette.fromHueAndChroma(hue, chroma / 3.);
74       this.a3 = TonalPalette.fromHueAndChroma(hue + 60., chroma / 2.);
75       this.n1 = TonalPalette.fromHueAndChroma(hue, min(chroma / 12., 4.));
76       this.n2 = TonalPalette.fromHueAndChroma(hue, min(chroma / 6., 8.));
77     } else {
78       this.a1 = TonalPalette.fromHueAndChroma(hue, max(48., chroma));
79       this.a2 = TonalPalette.fromHueAndChroma(hue, 16.);
80       this.a3 = TonalPalette.fromHueAndChroma(hue + 60., 24.);
81       this.n1 = TonalPalette.fromHueAndChroma(hue, 4.);
82       this.n2 = TonalPalette.fromHueAndChroma(hue, 8.);
83     }
84     this.error = TonalPalette.fromHueAndChroma(25, 84.);
85   }
86 }
87