• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2023 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.dynamiccolor;
18 
19 import androidx.annotation.NonNull;
20 
21 /**
22  * Documents a constraint between two DynamicColors, in which their tones must have a certain
23  * distance from each other.
24  *
25  * <p>Prefer a DynamicColor with a background, this is for special cases when designers want tonal
26  * distance, literally contrast, between two colors that don't have a background / foreground
27  * relationship or a contrast guarantee.
28  */
29 public final class ToneDeltaPair {
30   /** The first role in a pair. */
31   private final DynamicColor roleA;
32 
33   /** The second role in a pair. */
34   private final DynamicColor roleB;
35 
36   /** Required difference between tones. Absolute value, negative values have undefined behavior. */
37   private final double delta;
38 
39   /** The relative relation between tones of roleA and roleB, as described above. */
40   private final TonePolarity polarity;
41 
42   /**
43    * Whether these two roles should stay on the same side of the "awkward zone" (T50-59). This is
44    * necessary for certain cases where one role has two backgrounds.
45    */
46   private final boolean stayTogether;
47 
48   /**
49    * Documents a constraint in tone distance between two DynamicColors.
50    *
51    * <p>The polarity is an adjective that describes "A", compared to "B".
52    *
53    * <p>For instance, ToneDeltaPair(A, B, 15, 'darker', stayTogether) states that A's tone should be
54    * at least 15 darker than B's.
55    *
56    * <p>'nearer' and 'farther' describes closeness to the surface roles. For instance,
57    * ToneDeltaPair(A, B, 10, 'nearer', stayTogether) states that A should be 10 lighter than B in
58    * light mode, and 10 darker than B in dark mode.
59    *
60    * @param roleA The first role in a pair.
61    * @param roleB The second role in a pair.
62    * @param delta Required difference between tones. Absolute value, negative values have undefined
63    *     behavior.
64    * @param polarity The relative relation between tones of roleA and roleB, as described above.
65    * @param stayTogether Whether these two roles should stay on the same side of the "awkward zone"
66    *     (T50-59). This is necessary for certain cases where one role has two backgrounds.
67    */
ToneDeltaPair( DynamicColor roleA, DynamicColor roleB, double delta, TonePolarity polarity, boolean stayTogether)68   public ToneDeltaPair(
69       DynamicColor roleA,
70       DynamicColor roleB,
71       double delta,
72       TonePolarity polarity,
73       boolean stayTogether) {
74     this.roleA = roleA;
75     this.roleB = roleB;
76     this.delta = delta;
77     this.polarity = polarity;
78     this.stayTogether = stayTogether;
79   }
80 
81   @NonNull
getRoleA()82   public DynamicColor getRoleA() {
83     return roleA;
84   }
85 
86   @NonNull
getRoleB()87   public DynamicColor getRoleB() {
88     return roleB;
89   }
90 
91   @NonNull
getDelta()92   public double getDelta() {
93     return delta;
94   }
95 
96   @NonNull
getPolarity()97   public TonePolarity getPolarity() {
98     return polarity;
99   }
100 
101   @NonNull
getStayTogether()102   public boolean getStayTogether() {
103     return stayTogether;
104   }
105 }
106