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.battery.unified 18 19 import android.graphics.Color 20 import android.graphics.drawable.Drawable 21 22 /** 23 * States that might set a color profile (e.g., red for low battery) and are mutually exclusive. 24 * This enum allows us to address which colors we want to use based on their function. 25 */ 26 enum class ColorProfile { 27 // Grayscale is the default color 28 None, 29 // Green for e.g., charging 30 Active, 31 // Yellow for e.g., battery saver 32 Warning, 33 // Red for e.g., low battery 34 Error, 35 } 36 37 /** 38 * Encapsulates all drawing information needed by BatteryMeterDrawable to render properly. Rendered 39 * state will be equivalent to the most recent state passed in. 40 */ 41 data class BatteryDrawableState( 42 /** [0-100] description of the battery level */ 43 val level: Int, 44 /** Whether or not to render the percent as a foreground text layer */ 45 val showPercent: Boolean, 46 47 /** Set the [ColorProfile] to get the appropriate fill colors */ 48 val color: ColorProfile = ColorProfile.None, 49 50 /** 51 * An attribution is a drawable that shows either alongside the percent, or centered in the 52 * foreground of the overall drawable. 53 * 54 * When space sharing with the percent text, the default rect is 6x6, positioned directly next 55 * to the percent and left-aligned. 56 * 57 * When the attribution is the only foreground layer, then we use a 16x8 canvas and center this 58 * drawable. 59 * 60 * In both cases, we use a FIT_CENTER style scaling. Note that for now the attributions will 61 * have to configure their own padding inside of their vector definitions. Future versions 62 * should abstract the side- and center- canvases and allow attributions to be defined with 63 * separate designs for each case. 64 */ 65 val attribution: Drawable? 66 ) { hasForegroundContentnull67 fun hasForegroundContent() = showPercent || attribution != null 68 69 companion object { 70 val DefaultInitialState = 71 BatteryDrawableState( 72 level = 50, 73 showPercent = false, 74 attribution = null, 75 ) 76 } 77 } 78 79 sealed interface BatteryColors { 80 /** The color for the frame and any foreground attributions for the battery */ 81 val fg: Int 82 /** 83 * Default color for the frame background. Configured to be a transparent white or black that 84 * matches the current mode (white for light theme, black for dark theme) and provides extra 85 * contrast for the drawable 86 */ 87 val bg: Int 88 89 /** Color for the level fill when there is an attribution on top */ 90 val fill: Int 91 /** 92 * When there is no attribution, [fillOnlyColor] describes an opaque color with more contrast 93 */ 94 val fillOnly: Int 95 96 /** Used when charging */ 97 val activeFill: Int 98 99 /** Warning color is used for battery saver mode */ 100 val warnFill: Int 101 102 /** Error colors are used for low battery states typically */ 103 val errorFill: Int 104 105 /** Color scheme appropriate for light mode (dark icons) */ 106 data object LightThemeColors : BatteryColors { 107 override val fg = Color.BLACK 108 // 22% alpha white 109 override val bg: Int = Color.valueOf(1f, 1f, 1f, 0.22f).toArgb() 110 111 // GM Gray 500 112 override val fill = Color.parseColor("#9AA0A6") 113 // GM Gray 600 114 override val fillOnly = Color.parseColor("#80868B") 115 116 // GM Green 500 117 override val activeFill = Color.parseColor("#34A853") 118 // GM Yellow 500 119 override val warnFill = Color.parseColor("#FBBC04") 120 // GM Red 500 121 override val errorFill = Color.parseColor("#EA4335") 122 } 123 124 /** Color scheme appropriate for dark mode (light icons) */ 125 data object DarkThemeColors : BatteryColors { 126 override val fg = Color.WHITE 127 // 18% alpha black 128 override val bg: Int = Color.valueOf(0f, 0f, 0f, 0.18f).toArgb() 129 130 // GM Gray 700 131 override val fill = Color.parseColor("#5F6368") 132 // GM Gray 400 133 override val fillOnly = Color.parseColor("#BDC1C6") 134 135 // GM Green 700 136 override val activeFill = Color.parseColor("#188038") 137 // GM Yellow 700 138 override val warnFill = Color.parseColor("#F29900") 139 // GM Red 700 140 override val errorFill = Color.parseColor("#C5221F") 141 } 142 143 companion object { 144 /** For use from java */ 145 @JvmField val LIGHT_THEME_COLORS = LightThemeColors 146 147 @JvmField val DARK_THEME_COLORS = DarkThemeColors 148 } 149 } 150