• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2022 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.scheme;
18 
19 import com.google.ux.material.libmonet.dislike.DislikeAnalyzer;
20 import com.google.ux.material.libmonet.hct.Hct;
21 import com.google.ux.material.libmonet.palettes.TonalPalette;
22 import com.google.ux.material.libmonet.temperature.TemperatureCache;
23 
24 /**
25  * A scheme that places the source color in Scheme.primaryContainer.
26  *
27  * <p>Primary Container is the source color, adjusted for color relativity. It maintains constant
28  * appearance in light mode and dark mode. This adds ~5 tone in light mode, and subtracts ~5 tone in
29  * dark mode.
30  *
31  * <p>Tertiary Container is the complement to the source color, using TemperatureCache. It also
32  * maintains constant appearance.
33  */
34 public class SchemeFidelity extends DynamicScheme {
SchemeFidelity(Hct sourceColorHct, boolean isDark, double contrastLevel)35   public SchemeFidelity(Hct sourceColorHct, boolean isDark, double contrastLevel) {
36     super(
37         sourceColorHct,
38         Variant.FIDELITY,
39         isDark,
40         contrastLevel,
41         TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), sourceColorHct.getChroma()),
42         TonalPalette.fromHueAndChroma(
43             sourceColorHct.getHue(),
44             Math.max(sourceColorHct.getChroma() - 32.0, sourceColorHct.getChroma() * 0.5)),
45         TonalPalette.fromHct(
46             DislikeAnalyzer.fixIfDisliked(new TemperatureCache(sourceColorHct).getComplement())),
47         TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), sourceColorHct.getChroma() / 8.0),
48         TonalPalette.fromHueAndChroma(
49             sourceColorHct.getHue(), (sourceColorHct.getChroma() / 8.0) + 4.0));
50   }
51 }
52