1 /* 2 * Copyright (C) 2024 The Android Open Source Project 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.android.systemui.monet; 18 19 import java.util.Arrays; 20 import java.util.List; 21 import java.util.Map; 22 import java.util.stream.Collectors; 23 24 public class TonalPalette { 25 private final com.google.ux.material.libmonet.palettes.TonalPalette mMaterialTonalPalette; 26 /** 27 * @deprecated Do not use. For color system only 28 */ 29 @Deprecated 30 public final List<Integer> allShades; 31 public final Map<Integer, Integer> allShadesMapped; 32 TonalPalette(com.google.ux.material.libmonet.palettes.TonalPalette materialTonalPalette)33 TonalPalette(com.google.ux.material.libmonet.palettes.TonalPalette materialTonalPalette) { 34 this.mMaterialTonalPalette = materialTonalPalette; 35 this.allShades = SHADE_KEYS.stream().map(key -> getAtTone(key.floatValue())).collect( 36 Collectors.toList()); 37 this.allShadesMapped = SHADE_KEYS.stream().collect( 38 Collectors.toMap(key -> key, key -> getAtTone(key.floatValue()))); 39 } 40 41 /** 42 * Dynamically computed tones across the full range from 0 to 1000 43 * @param shade expected shade from 0 (white) to 1000 (black) 44 * @return Int representing color at new shade / tone 45 */ getAtTone(float shade)46 public int getAtTone(float shade) { 47 return mMaterialTonalPalette.tone((int) ((1000.0f - shade) / 10f)); 48 } 49 50 // Predefined & precomputed tones getS0()51 public int getS0() { 52 return this.allShades.get(0); 53 } 54 getS10()55 public int getS10() { 56 return this.allShades.get(1); 57 } 58 getS50()59 public int getS50() { 60 return this.allShades.get(2); 61 } 62 getS100()63 public int getS100() { 64 return this.allShades.get(3); 65 } 66 getS200()67 public int getS200() { 68 return this.allShades.get(4); 69 } 70 getS300()71 public int getS300() { 72 return this.allShades.get(5); 73 } 74 getS400()75 public int getS400() { 76 return this.allShades.get(6); 77 } 78 getS500()79 public int getS500() { 80 return this.allShades.get(7); 81 } 82 getS600()83 public int getS600() { 84 return this.allShades.get(8); 85 } 86 getS700()87 public int getS700() { 88 return this.allShades.get(9); 89 } 90 getS800()91 public int getS800() { 92 return this.allShades.get(10); 93 } 94 getS900()95 public int getS900() { 96 return this.allShades.get(11); 97 } 98 getS1000()99 public int getS1000() { 100 return this.allShades.get(12); 101 } 102 103 public static final List<Integer> SHADE_KEYS = Arrays.asList(0, 10, 50, 100, 200, 300, 400, 500, 104 600, 700, 800, 900, 1000); 105 } 106