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