1 /*
2  * Copyright (C) 2023 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.car.docklib.data
18 
19 import android.content.ComponentName
20 import android.graphics.Color
21 import android.graphics.drawable.Drawable
22 import androidx.annotation.ColorInt
23 import com.android.internal.graphics.ColorUtils
24 import com.android.launcher3.icons.FastBitmapDrawable
25 import com.android.launcher3.icons.GraphicsUtils
26 import java.util.UUID
27 
28 /**
29  * Data class that describes an app being showed on Dock.
30  *
31  * @param iconColor dominant color to be used with the [icon].
32  * @param iconColorScrim color to be used to create a slightly dull/bright color variation of
33  * [iconColor]. Uses the default scrim if not provided.
34  */
35 data class DockAppItem(
36         val id: @DockItemId UUID = UUID.randomUUID(),
37         val type: Type,
38         val component: ComponentName,
39         val name: String,
40         val icon: Drawable,
41         @ColorInt val iconColor: Int,
42         @ColorInt private val iconColorScrim: Int = defaultIconColorScrim,
43         val isDistractionOptimized: Boolean,
44         val isMediaApp: Boolean,
45 ) {
46     companion object{
47         private val defaultIconColorScrim = GraphicsUtils.setColorAlphaBound(
48                 Color.WHITE,
49                 FastBitmapDrawable.WHITE_SCRIM_ALPHA
50         )
51 
52         /**
53          * Composes the [iconColor] with the [iconColorScrim].
54          *
55          * @param iconColorScrim color to be used to create a slightly dull/bright color variation
56          * of [iconColor]. Uses the default scrim if not provided.
57          */
getIconColorWithScrimnull58         fun getIconColorWithScrim(
59                 iconColor: Int,
60                 iconColorScrim: Int = defaultIconColorScrim
61         ): Int {
62             return ColorUtils.compositeColors(iconColorScrim, iconColor)
63         }
64     }
65 
66     @ColorInt val iconColorWithScrim = getIconColorWithScrim(iconColor, iconColorScrim)
67 
68     enum class Type(val value: String) {
69         DYNAMIC("DYNAMIC"),
70         STATIC("STATIC");
71 
toStringnull72         override fun toString(): String {
73             return value
74         }
75     }
76 
equalsnull77     override fun equals(other: Any?): Boolean {
78         return (this === other) ||
79                 (other is DockAppItem &&
80                         this.id == other.id &&
81                         this.name == other.name &&
82                         this.type == other.type &&
83                         this.component == other.component &&
84                         this.icon.constantState == other.icon.constantState &&
85                         this.iconColor == other.iconColor &&
86                         this.iconColorWithScrim == other.iconColorWithScrim &&
87                         this.isDistractionOptimized == other.isDistractionOptimized &&
88                         this.isMediaApp == other.isMediaApp)
89     }
90 
toStringnull91     override fun toString(): String {
92         return ("DockAppItem#${hashCode()}{id: $id, name: $name, component: $component, " +
93                 "type: $type, isDistractionOptimized: $isDistractionOptimized, icon: $icon, " +
94                 "iconColor: $iconColor, iconColorScrim: $iconColorScrim, " +
95                 "iconColorWithScrim: $iconColorWithScrim}")
96     }
97 }
98