1 /*
2  * Copyright (c) 2021 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DATA_PANEL_DATA_PANEL_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DATA_PANEL_DATA_PANEL_THEME_H
18 
19 #include "core/components/theme/theme.h"
20 #include "core/components/theme/theme_constants.h"
21 #include "core/components/theme/theme_constants_defines.h"
22 #include "core/components/theme/theme_manager.h"
23 
24 namespace OHOS::Ace {
25 
26 class DataPanelTheme : public virtual Theme {
27     DECLARE_ACE_TYPE(DataPanelTheme, Theme);
28 
29 public:
30     class Builder {
31     public:
32         Builder() = default;
33         ~Builder() = default;
34 
Build(const RefPtr<ThemeConstants> & themeConstants)35         RefPtr<DataPanelTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
36         {
37             RefPtr<DataPanelTheme> theme = AceType::Claim(new DataPanelTheme());
38             if (!themeConstants) {
39                 return theme;
40             }
41             ParsePattern(themeConstants, theme);
42             return theme;
43         }
44 
45     private:
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<DataPanelTheme> & theme)46         void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<DataPanelTheme>& theme) const
47         {
48             RefPtr<ThemeStyle> dataPanelPattern = themeConstants->GetPatternByName(THEME_PATTERN_DATA_PANEL);
49             if (!dataPanelPattern) {
50                 LOGW("find pattern of datapanel fail");
51                 return;
52             }
53             theme->thickness_ = dataPanelPattern->GetAttr<Dimension>("datapanel_thickness", 0.0_vp);
54             theme->defaultHeight_ = dataPanelPattern->GetAttr<Dimension>("datapanel_height", 0.0_vp);
55             theme->defaultWidth_ = dataPanelPattern->GetAttr<Dimension>("datapanel_width", 0.0_vp);
56             theme->defaultBorderRadius_ = dataPanelPattern->GetAttr<Dimension>("datapanel_corner_radius", 8.0_vp);
57             theme->trackShadowOffsetX_ = dataPanelPattern->GetAttr<Dimension>("datapanel_trackshadow_offsetx", 0.0_vp);
58             theme->trackShadowOffsetY_ = dataPanelPattern->GetAttr<Dimension>("datapanel_trackshadow_offsety", 0.0_vp);
59             theme->backgroundColor_ = dataPanelPattern->GetAttr<Color>(PATTERN_BG_COLOR, Color::BLACK);
60             theme->trackShadowRadius_ = dataPanelPattern->GetAttr<Dimension>(DATA_PANEL_TRACK_SHADOW_RADIU, 0.0_vp);
61             theme->loadingColors_.first = dataPanelPattern->GetAttr<Color>(DATA_PANEL_LOADING_COLOR_END, Color::BLACK);
62             theme->loadingColors_.second =
63                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_LOADING_COLOR_START, Color::BLACK);
64             theme->progressColors_.first =
65                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_PROGRESS_COLOR_END, Color::BLACK);
66             theme->progressColors_.second =
67                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_PROGRESS_COLOR_START, Color::BLACK);
68             theme->percentageColors_.clear();
69             theme->percentageColors_.emplace_back(
70                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_1_START, Color::BLACK),
71                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_1_END, Color::BLACK));
72             theme->percentageColors_.emplace_back(
73                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_2_START, Color::BLACK),
74                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_2_END, Color::BLACK));
75             theme->percentageColors_.emplace_back(
76                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_3_START, Color::BLACK),
77                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_3_END, Color::BLACK));
78             theme->percentageColors_.emplace_back(
79                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_4_START, Color::BLACK),
80                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_4_END, Color::BLACK));
81             theme->percentageColors_.emplace_back(
82                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_5_START, Color::BLACK),
83                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_5_END, Color::BLACK));
84             theme->percentageColors_.emplace_back(
85                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_6_START, Color::BLACK),
86                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_6_END, Color::BLACK));
87             theme->percentageColors_.emplace_back(
88                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_7_START, Color::BLACK),
89                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_7_END, Color::BLACK));
90             theme->percentageColors_.emplace_back(
91                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_8_START, Color::BLACK),
92                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_8_END, Color::BLACK));
93             theme->percentageColors_.emplace_back(
94                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_9_START, Color::BLACK),
95                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_9_END, Color::BLACK));
96         }
97     };
98 
GetLoadingColor()99     const std::pair<Color, Color>& GetLoadingColor() const
100     {
101         return loadingColors_;
102     }
103 
GetProgressColor()104     const std::pair<Color, Color>& GetProgressColor() const
105     {
106         return progressColors_;
107     }
108 
GetBackgroundColor()109     const Color& GetBackgroundColor() const
110     {
111         return backgroundColor_;
112     }
113 
GetDefaultHeight()114     const Dimension& GetDefaultHeight() const
115     {
116         return defaultHeight_;
117     }
118 
GetDefaultWidth()119     const Dimension& GetDefaultWidth() const
120     {
121         return defaultWidth_;
122     }
123 
GetDefaultBorderRadius()124     const Dimension& GetDefaultBorderRadius() const
125     {
126         return defaultBorderRadius_;
127     }
128 
GetThickness()129     const Dimension& GetThickness() const
130     {
131         return thickness_;
132     }
133 
GetColorsArray()134     const std::vector<std::pair<Color, Color>> GetColorsArray() const
135     {
136         return percentageColors_;
137     }
138 
GetTrackShadowRadius()139     const Dimension& GetTrackShadowRadius() const
140     {
141         return trackShadowRadius_;
142     }
143 
GetTrackShadowOffsetX()144     const Dimension& GetTrackShadowOffsetX() const
145     {
146         return trackShadowOffsetX_;
147     }
148 
GetTrackShadowOffsetY()149     const Dimension& GetTrackShadowOffsetY() const
150     {
151         return trackShadowOffsetY_;
152     }
153 
154 protected:
155 private:
156     std::vector<std::pair<Color, Color>> percentageColors_;
157     std::pair<Color, Color> loadingColors_;
158     std::pair<Color, Color> progressColors_;
159     Color backgroundColor_;
160     Dimension defaultHeight_;
161     Dimension defaultWidth_;
162     Dimension defaultBorderRadius_;
163     Dimension thickness_;
164     Dimension trackShadowRadius_;
165     Dimension trackShadowOffsetX_;
166     Dimension trackShadowOffsetY_;
167 };
168 
169 } // namespace OHOS::Ace
170 
171 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DATA_PANEL_DATA_PANEL_THEME_H
172