• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.statusbar.chips.ui.model
18 
19 import android.content.Context
20 import android.content.res.ColorStateList
21 import androidx.annotation.ColorInt
22 import com.android.systemui.res.R
23 
24 /** Model representing how the chip in the status bar should be colored. */
25 sealed interface ColorsModel {
26     /** The color for the background of the chip. */
backgroundnull27     fun background(context: Context): ColorStateList
28 
29     /** The color for the text (and icon) on the chip. */
30     @ColorInt fun text(context: Context): Int
31 
32     /** The color to use for the chip outline, or null if the chip shouldn't have an outline. */
33     @ColorInt fun outline(context: Context): Int?
34 
35     /** The chip should match the theme's primary accent color. */
36     data object AccentThemed : ColorsModel {
37         override fun background(context: Context): ColorStateList =
38             ColorStateList.valueOf(
39                 context.getColor(com.android.internal.R.color.materialColorPrimaryFixedDim)
40             )
41 
42         override fun text(context: Context) =
43             context.getColor(com.android.internal.R.color.materialColorOnPrimaryFixed)
44 
45         override fun outline(context: Context) = null
46     }
47 
48     /** The chip should match the system theme main color. */
49     // Note: When StatusBarChipsModernization is disabled, the chip's color doesn't get
50     // updated when the user switches theme. It only gets updated when a different
51     // configuration change happens, like a rotation.
52     data object SystemThemed : ColorsModel {
backgroundnull53         override fun background(context: Context): ColorStateList =
54             ColorStateList.valueOf(
55                 context.getColor(com.android.internal.R.color.materialColorSurfaceDim)
56             )
57 
58         override fun text(context: Context) =
59             context.getColor(com.android.internal.R.color.materialColorOnSurface)
60 
61         override fun outline(context: Context) =
62             // Outline is required on the SystemThemed chip to guarantee the chip doesn't completely
63             // blend in with the background.
64             context.getColor(com.android.internal.R.color.materialColorOutlineVariant)
65     }
66 
67     /** The chip should have the given background color and primary text color. */
68     data class Custom(val backgroundColorInt: Int, val primaryTextColorInt: Int) : ColorsModel {
69         override fun background(context: Context): ColorStateList =
70             ColorStateList.valueOf(backgroundColorInt)
71 
72         override fun text(context: Context): Int = primaryTextColorInt
73 
74         override fun outline(context: Context) = null
75     }
76 
77     /** The chip should have a red background with white text. */
78     data object Red : ColorsModel {
backgroundnull79         override fun background(context: Context): ColorStateList {
80             return ColorStateList.valueOf(context.getColor(R.color.GM2_red_700))
81         }
82 
textnull83         override fun text(context: Context) = context.getColor(android.R.color.white)
84 
85         override fun outline(context: Context) = null
86     }
87 }
88