• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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             theme->backgroundColor_ = themeConstants->GetColor(THEME_DATA_PANEL_BACKGROUND_COLOR);
42             theme->thickness_ = themeConstants->GetDimension(THEME_DATA_PANEL_THICKNESS);
43             theme->defaultHeight_ = themeConstants->GetDimension(THEME_DATA_PANEL_HEIGHT);
44             theme->defaultWidth_ = themeConstants->GetDimension(THEME_DATA_PANEL_WIDTH);
45             theme->loadingColors_.first = themeConstants->GetColor(THEME_DATA_PANEL_LOADING_START_COLOR);
46             theme->loadingColors_.second = themeConstants->GetColor(THEME_DATA_PANEL_LOADING_END_COLOR);
47             theme->progressColors_.first = themeConstants->GetColor(THEME_DATA_PANEL_PROGRESS_START_COLOR);
48             theme->progressColors_.second = themeConstants->GetColor(THEME_DATA_PANEL_PROGRESS_END_COLOR);
49             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_1_START),
50                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_1_END));
51             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_2_START),
52                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_2_END));
53             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_3_START),
54                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_3_END));
55             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_4_START),
56                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_4_END));
57             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_5_START),
58                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_5_END));
59             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_6_START),
60                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_6_END));
61             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_7_START),
62                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_7_END));
63             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_8_START),
64                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_8_END));
65             theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_9_START),
66                 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_9_END));
67             theme->trackShadowRadius_ = themeConstants->GetDimension(THEME_DATA_PANEL_TRACKSHADOW_RADIU);
68             theme->trackShadowOffsetX_ = themeConstants->GetDimension(THEME_DATA_PANEL_TRACKSHADOW_OFFSETX);
69             theme->trackShadowOffsetY_ = themeConstants->GetDimension(THEME_DATA_PANEL_TRACKSHADOW_OFFSETY);
70             ParsePattern(themeConstants->GetThemeStyle(), theme);
71             return theme;
72         }
73 
74     private:
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<DataPanelTheme> & theme)75         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<DataPanelTheme>& theme) const
76         {
77             if (!themeStyle) {
78                 return;
79             }
80             auto dataPanelPattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_DATA_PANEL, nullptr);
81             if (!dataPanelPattern) {
82                 LOGW("find pattern of datapanel fail");
83                 return;
84             }
85             theme->backgroundColor_ = dataPanelPattern->GetAttr<Color>(PATTERN_BG_COLOR, Color::BLACK);
86             theme->trackShadowRadius_ = dataPanelPattern->GetAttr<Dimension>(DATA_PANEL_TRACK_SHADOW_RADIU, 0.0_vp);
87             theme->loadingColors_.first = dataPanelPattern->GetAttr<Color>(DATA_PANEL_LOADING_COLOR_END, Color::BLACK);
88             theme->loadingColors_.second =
89                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_LOADING_COLOR_START, Color::BLACK);
90             theme->progressColors_.first =
91                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_PROGRESS_COLOR_END, Color::BLACK);
92             theme->progressColors_.second =
93                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_PROGRESS_COLOR_START, Color::BLACK);
94             theme->percentageColors_.clear();
95             theme->percentageColors_.emplace_back(
96                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_1_START, Color::BLACK),
97                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_1_END, Color::BLACK));
98             theme->percentageColors_.emplace_back(
99                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_2_START, Color::BLACK),
100                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_2_END, Color::BLACK));
101             theme->percentageColors_.emplace_back(
102                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_3_START, Color::BLACK),
103                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_3_END, Color::BLACK));
104             theme->percentageColors_.emplace_back(
105                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_4_START, Color::BLACK),
106                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_4_END, Color::BLACK));
107             theme->percentageColors_.emplace_back(
108                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_5_START, Color::BLACK),
109                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_5_END, Color::BLACK));
110             theme->percentageColors_.emplace_back(
111                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_6_START, Color::BLACK),
112                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_6_END, Color::BLACK));
113             theme->percentageColors_.emplace_back(
114                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_7_START, Color::BLACK),
115                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_7_END, Color::BLACK));
116             theme->percentageColors_.emplace_back(
117                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_8_START, Color::BLACK),
118                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_8_END, Color::BLACK));
119             theme->percentageColors_.emplace_back(
120                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_9_START, Color::BLACK),
121                 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_9_END, Color::BLACK));
122         }
123     };
124 
GetLoadingColor()125     const std::pair<Color, Color>& GetLoadingColor() const
126     {
127         return loadingColors_;
128     }
129 
GetProgressColor()130     const std::pair<Color, Color>& GetProgressColor() const
131     {
132         return progressColors_;
133     }
134 
GetBackgroundColor()135     const Color& GetBackgroundColor() const
136     {
137         return backgroundColor_;
138     }
139 
GetDefaultHeight()140     const Dimension& GetDefaultHeight() const
141     {
142         return defaultHeight_;
143     }
144 
GetDefaultWidth()145     const Dimension& GetDefaultWidth() const
146     {
147         return defaultWidth_;
148     }
149 
GetThickness()150     const Dimension& GetThickness() const
151     {
152         return thickness_;
153     }
154 
GetColorsArray()155     const std::vector<std::pair<Color, Color>> GetColorsArray() const
156     {
157         return percentageColors_;
158     }
159 
GetTrackShadowRadius()160     const Dimension& GetTrackShadowRadius() const
161     {
162         return trackShadowRadius_;
163     }
164 
GetTrackShadowOffsetX()165     const Dimension& GetTrackShadowOffsetX() const
166     {
167         return trackShadowOffsetX_;
168     }
169 
GetTrackShadowOffsetY()170     const Dimension& GetTrackShadowOffsetY() const
171     {
172         return trackShadowOffsetY_;
173     }
174 
175 protected:
176 private:
177     std::vector<std::pair<Color, Color>> percentageColors_;
178     std::pair<Color, Color> loadingColors_;
179     std::pair<Color, Color> progressColors_;
180     Color backgroundColor_;
181     Dimension defaultHeight_;
182     Dimension defaultWidth_;
183     Dimension thickness_;
184     Dimension trackShadowRadius_;
185     Dimension trackShadowOffsetX_;
186     Dimension trackShadowOffsetY_;
187 };
188 
189 } // namespace OHOS::Ace
190 
191 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DATA_PANEL_DATA_PANEL_THEME_H
192