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.launcher3.views
18 
19 import android.content.Context
20 import android.util.AttributeSet
21 import com.android.launcher3.R
22 
23 /**
24  * Launcher data holder for classes such as [DoubleShadowBubbleTextView] to model shadows for
25  * "double shadow" effect.
26  */
27 data class ShadowInfo(
28     val ambientShadowBlur: Float,
29     val ambientShadowColor: Int,
30     val keyShadowBlur: Float,
31     val keyShadowOffsetX: Float,
32     val keyShadowOffsetY: Float,
33     val keyShadowColor: Int
34 ) {
35 
36     companion object {
37         /** Constructs instance of ShadowInfo from Context and given attribute set. */
38         @JvmStatic
fromContextnull39         fun fromContext(context: Context, attrs: AttributeSet?, defStyle: Int): ShadowInfo {
40             val styledAttrs =
41                 context.obtainStyledAttributes(attrs, R.styleable.ShadowInfo, defStyle, 0)
42             val shadowInfo =
43                 ShadowInfo(
44                     ambientShadowBlur =
45                         styledAttrs
46                             .getDimensionPixelSize(R.styleable.ShadowInfo_ambientShadowBlur, 0)
47                             .toFloat(),
48                     ambientShadowColor =
49                         styledAttrs.getColor(R.styleable.ShadowInfo_ambientShadowColor, 0),
50                     keyShadowBlur =
51                         styledAttrs
52                             .getDimensionPixelSize(R.styleable.ShadowInfo_keyShadowBlur, 0)
53                             .toFloat(),
54                     keyShadowOffsetX =
55                         styledAttrs
56                             .getDimensionPixelSize(R.styleable.ShadowInfo_keyShadowOffsetX, 0)
57                             .toFloat(),
58                     keyShadowOffsetY =
59                         styledAttrs
60                             .getDimensionPixelSize(R.styleable.ShadowInfo_keyShadowOffsetY, 0)
61                             .toFloat(),
62                     keyShadowColor = styledAttrs.getColor(R.styleable.ShadowInfo_keyShadowColor, 0)
63                 )
64             styledAttrs.recycle()
65             return shadowInfo
66         }
67     }
68 }
69