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 static java.lang.Math.max; 20 21 import com.google.ux.material.libmonet.dislike.DislikeAnalyzer; 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 an analogous color, specifically, the analog of a color wheel divided 34 * into 6, and the precise analog is the one found by increasing hue. This is a scientifically 35 * grounded equivalent to rotating hue clockwise by 60 degrees. It also maintains constant 36 * appearance. 37 */ 38 public class SchemeContent extends DynamicScheme { SchemeContent(Hct sourceColorHct, boolean isDark, double contrastLevel)39 public SchemeContent(Hct sourceColorHct, boolean isDark, double contrastLevel) { 40 super( 41 sourceColorHct, 42 Variant.CONTENT, 43 isDark, 44 contrastLevel, 45 TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), sourceColorHct.getChroma()), 46 TonalPalette.fromHueAndChroma( 47 sourceColorHct.getHue(), 48 max(sourceColorHct.getChroma() - 32.0, sourceColorHct.getChroma() * 0.5)), 49 TonalPalette.fromHct( 50 DislikeAnalyzer.fixIfDisliked( 51 new TemperatureCache(sourceColorHct) 52 .getAnalogousColors(/* count= */ 3, /* divisions= */ 6) 53 .get(2))), 54 TonalPalette.fromHueAndChroma(sourceColorHct.getHue(), sourceColorHct.getChroma() / 8.0), 55 TonalPalette.fromHueAndChroma( 56 sourceColorHct.getHue(), (sourceColorHct.getChroma() / 8.0) + 4.0)); 57 } 58 } 59