• 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_PROGRESS_PROGRESS_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_PROGRESS_THEME_H
18 
19 #include "base/geometry/dimension.h"
20 #include "core/components/common/properties/color.h"
21 #include "core/components/theme/theme.h"
22 #include "core/components/theme/theme_constants.h"
23 #include "core/components/theme/theme_constants_defines.h"
24 
25 namespace OHOS::Ace {
26 
27 /**
28  * ProgressTheme defines color and styles of ProgressComponent. ProgressTheme should be built
29  * using ProgressTheme::Builder.
30  */
31 class ProgressTheme : public virtual Theme {
32     DECLARE_ACE_TYPE(ProgressTheme, Theme);
33 
34 public:
35     class Builder {
36     public:
37         Builder() = default;
38         ~Builder() = default;
39 
Build(const RefPtr<ThemeConstants> & themeConstants)40         RefPtr<ProgressTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
41         {
42             RefPtr<ProgressTheme> theme = AceType::Claim(new ProgressTheme());
43             if (!themeConstants) {
44                 return theme;
45             }
46             theme->trackThickness_ = themeConstants->GetDimension(THEME_PROGRERSS_THICKNESS);
47             theme->trackWidth_ = themeConstants->GetDimension(THEME_PROGRESS_DEFAULT_WIDTH);
48             theme->ringThickness_ = themeConstants->GetDimension(THEME_PROGRESS_RING_THICKNESS);
49             theme->ringDiameter_ = themeConstants->GetDimension(THEME_PROGRESS_DEFAULT_DIAMETER);
50             theme->trackBgColor_ = themeConstants->GetColor(THEME_PROGRESS_BG_COLOR);
51             theme->trackSelectedColor_ = themeConstants->GetColor(THEME_PROGRESS_COLOR);
52             theme->trackCachedColor_ = themeConstants->GetColor(THEME_PROGRESS_CACHED_COLOR);
53             theme->loadingColor_ = themeConstants->GetColor(THEME_LOADING_COLOR);
54             theme->loadingDiameter_ = themeConstants->GetDimension(THEME_PROGRESS_DEFAULT_DIAMETER);
55             theme->scaleNumber_ = themeConstants->GetInt(THEME_PROGRESS_SCALE_NUMBER);
56             theme->scaleWidth_ = themeConstants->GetDimension(THEME_PROGRESS_SCALE_WIDTH);
57             theme->scaleLength_ = themeConstants->GetDimension(THEME_PROGRESS_STROKE_WIDTH);
58             theme->scaleRingDiameter_ = themeConstants->GetDimension(THEME_SCALE_PROGRESS_DEFAULT_DIAMETER);
59 
60             // For moon progress
61             theme->moonDiameter_ = themeConstants->GetDimension(THEME_MOON_PROGRESS_DIAMETER);
62             theme->moonTrackBackgroundColor_ = themeConstants->GetColor(THEME_MOON_BACKGROUDN_COLOR);
63             theme->moonFrontColor_ = themeConstants->GetColor(THEME_MOON_FRONT_COLOR);
64 
65             // For loading progress in cycle type.
66             theme->progressColor_ = themeConstants->GetColor(THEME_LOADING_PROGRESS_COLOR);
67             theme->moveRatio_ = themeConstants->GetDouble(THEME_LOADING_PROGRESS_MOVE_RATIO);
68             theme->ringRadius_ = themeConstants->GetDimension(THEME_LOADING_PROGRESS_RING_RADIUS);
69             theme->orbitRadius_ = themeConstants->GetDimension(THEME_LOADING_PROGRESS_ORBIT_RADIUS);
70             theme->cometTailLen_ = themeConstants->GetDouble(THEME_LOADING_PROGRESS_COMET_TAIL_LEN);
71 
72             theme->bubbleRadius_ = themeConstants->GetDimension(THEME_BUBBLE_PROGRESS_RADIUS);
73             theme->bubbleDiameter_ = themeConstants->GetDimension(THEME_BUBBLE_PROGRESS_DIAMETER);
74             theme->progressHeight_ = themeConstants->GetDimension(THEME_BUTTON_DOWNLOAD_HEIGHT);
75 
76             // Read style from system.
77             ParsePattern(themeConstants->GetThemeStyle(), theme);
78             return theme;
79         }
80 
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<ProgressTheme> & theme)81         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<ProgressTheme>& theme) const
82         {
83             if (!themeStyle) {
84                 LOGI("progress theme style is null");
85                 return;
86             }
87             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>("progress_pattern", nullptr);
88             if (!pattern) {
89                 LOGE("Pattern of progress is null, please check!");
90                 return;
91             }
92             const double defaultCachedAlpha = 0.4;
93             const double defaultLoadBGAlpha = 0.6;
94             const double defaultRingBackgroundOpacity = 0.03;
95             Color defaultColor = Color::FromRGBO(18, 24, 31, 1.0);
96             theme->trackBgColor_ = pattern->GetAttr<Color>(PATTERN_BG_COLOR, Color::RED);
97             theme->trackSelectedColor_ = pattern->GetAttr<Color>(PATTERN_FG_COLOR, Color::RED);
98             theme->trackCachedColor_ = theme->trackSelectedColor_
99                 .BlendOpacity(pattern->GetAttr<double>("fg_color_cached_alpha", defaultCachedAlpha));
100             theme->progressColor_ = pattern->GetAttr<Color>("fg_progress_color", Color::RED);
101             theme->loadingColor_ = theme->progressColor_
102                 .BlendOpacity(pattern->GetAttr<double>("loading_progress_bg_color_alpha", defaultLoadBGAlpha));
103             theme->moonFrontColor_ = pattern->GetAttr<Color>("moon_progress_fg_color", Color::RED)
104                 .BlendOpacity(pattern->GetAttr<double>("moon_progress_fg_color_alpha", 1.0));
105             theme->moonTrackBackgroundColor_ = pattern->GetAttr<Color>("moon_progress_bg_color", Color::RED)
106                 .BlendOpacity(pattern->GetAttr<double>("moon_progress_bg_color_alpha", 1.0))
107                 .BlendOpacity(pattern->GetAttr<double>("moon_progress_bg_color_alpha_ex", 1.0));
108             theme->borderColor_ = pattern->GetAttr<Color>("progress_border_color", Color::RED);
109             theme->maskColor_ = pattern->GetAttr<Color>("progress_mask_color", Color::RED);
110             theme->borderWidth_ = pattern->GetAttr<Dimension>("progress_border_width", 1.0_vp);
111 
112             theme->textColor_ = pattern->GetAttr<Color>("progress_text_color", defaultColor);
113             theme->textSize_ = pattern->GetAttr<Dimension>("progress_text_size", 12.0_fp);
114             theme->capsuleSelectColor_ = pattern->GetAttr<Color>("capsule_progress_select_color", Color::RED);
115             theme->selectColorAlpha_ = pattern->GetAttr<double>("capsule_progress_default_alpha", 1.0);
116             theme->capsuleSelectColor_ = theme->capsuleSelectColor_.BlendOpacity(theme->selectColorAlpha_);
117             theme->borderColor_ = theme->capsuleSelectColor_;
118             theme->progressDisable_ = pattern->GetAttr<double>("progress_disabled_alpha", 1.0);
119             theme->clickEffect_ = pattern->GetAttr<Color>("progress_click_effect", Color::RED);
120             theme->capsuleBgColor_ = pattern->GetAttr<Color>("capsule_progress_bg_color", Color::RED)
121                 .BlendOpacity(pattern->GetAttr<double>("capsule_progress_bg_alpha", 1.0));
122             theme->ringProgressEndSideColor_ =
123                 pattern->GetAttr<Color>("ring_progress_fg_color_end", theme->trackSelectedColor_);
124             theme->ringProgressBeginSideColor_ =
125                 pattern->GetAttr<Color>("ring_progress_fg_color_begin", theme->trackSelectedColor_);
126             theme->ringProgressBackgroundColor_ =
127                 theme->trackBgColor_.ChangeOpacity(defaultRingBackgroundOpacity);
128         }
129     };
130 
131     ~ProgressTheme() override = default;
132 
GetTrackThickness()133     const Dimension& GetTrackThickness() const
134     {
135         return trackThickness_;
136     }
137 
GetTrackWidth()138     const Dimension& GetTrackWidth() const
139     {
140         return trackWidth_;
141     }
142 
GetRingThickness()143     const Dimension& GetRingThickness() const
144     {
145         return ringThickness_;
146     }
147 
GetRingDiameter()148     const Dimension& GetRingDiameter() const
149     {
150         return ringDiameter_;
151     }
152 
GetTrackBgColor()153     const Color& GetTrackBgColor() const
154     {
155         return trackBgColor_;
156     }
157 
GetTrackSelectedColor()158     const Color& GetTrackSelectedColor() const
159     {
160         return trackSelectedColor_;
161     }
162 
GetTrackCachedColor()163     Color GetTrackCachedColor() const
164     {
165         return trackCachedColor_;
166     }
167 
GetLoadingDiameter()168     const Dimension& GetLoadingDiameter() const
169     {
170         return loadingDiameter_;
171     }
172 
GetLoadingColor()173     const Color& GetLoadingColor() const
174     {
175         return loadingColor_;
176     }
177 
GetScaleWidth()178     const Dimension& GetScaleWidth() const
179     {
180         return scaleWidth_;
181     }
182 
GetScaleNumber()183     int32_t GetScaleNumber() const
184     {
185         return scaleNumber_;
186     }
187 
GetScaleLength()188     const Dimension& GetScaleLength() const
189     {
190         return scaleLength_;
191     }
192 
GetProgressColor()193     const Color& GetProgressColor() const
194     {
195         return progressColor_;
196     }
197 
GetMoveRatio()198     double GetMoveRatio() const
199     {
200         return moveRatio_;
201     }
202 
GetRingRadius()203     const Dimension& GetRingRadius() const
204     {
205         return ringRadius_;
206     }
207 
GetOrbitRadius()208     const Dimension& GetOrbitRadius() const
209     {
210         return orbitRadius_;
211     }
212 
GetCometTailLen()213     double GetCometTailLen() const
214     {
215         return cometTailLen_;
216     }
217 
GetScaleRingDiameter()218     const Dimension& GetScaleRingDiameter() const
219     {
220         return scaleRingDiameter_;
221     }
222 
GetMoonDiameter()223     const Dimension& GetMoonDiameter() const
224     {
225         return moonDiameter_;
226     }
227 
GetMoonBackgroundColor()228     const Color& GetMoonBackgroundColor() const
229     {
230         return moonTrackBackgroundColor_;
231     }
232 
GetMoonFrontColor()233     const Color& GetMoonFrontColor() const
234     {
235         return moonFrontColor_;
236     }
237 
GetBubbleDiameter()238     const Dimension& GetBubbleDiameter() const
239     {
240         return bubbleDiameter_;
241     }
242 
GetBubbleRadius()243     const Dimension& GetBubbleRadius() const
244     {
245         return bubbleRadius_;
246     }
247 
GetBorderColor()248     const Color& GetBorderColor() const
249     {
250         return borderColor_;
251     }
252 
GetBorderWidth()253     const Dimension& GetBorderWidth() const
254     {
255         return borderWidth_;
256     }
257 
GetMaskColor()258     const Color& GetMaskColor() const
259     {
260         return maskColor_;
261     }
262 
GetTextColor()263     const Color& GetTextColor() const
264     {
265         return textColor_;
266     }
267 
GetTextSize()268     const Dimension& GetTextSize() const
269     {
270         return textSize_;
271     }
272 
GetProgressHeight()273     const Dimension& GetProgressHeight() const
274     {
275         return progressHeight_;
276     }
277 
GetCapsuleSelectColor()278     const Color& GetCapsuleSelectColor() const
279     {
280         return capsuleSelectColor_;
281     }
282 
GetProgressDisable()283     const float& GetProgressDisable() const
284     {
285         return progressDisable_;
286     }
287 
GetClickEffect()288     const Color& GetClickEffect() const
289     {
290         return clickEffect_;
291     }
292 
GetSelectColorAlpha()293     const float& GetSelectColorAlpha() const
294     {
295         return selectColorAlpha_;
296     }
297 
GetTextMargin()298     const Dimension& GetTextMargin() const
299     {
300         return textMargin_;
301     }
302 
GetCapsuleBgColor()303     const Color& GetCapsuleBgColor() const
304     {
305         return capsuleBgColor_;
306     }
307 
GetRingProgressEndSideColor()308     const Color& GetRingProgressEndSideColor() const
309     {
310         return ringProgressEndSideColor_;
311     }
312 
GetRingProgressBeginSideColor()313     const Color& GetRingProgressBeginSideColor() const
314     {
315         return ringProgressBeginSideColor_;
316     }
317 
GetRingProgressBgColor()318     const Color& GetRingProgressBgColor() const
319     {
320         return ringProgressBackgroundColor_;
321     }
322 
323 protected:
324     ProgressTheme() = default;
325 
326 private:
327     Dimension trackThickness_;
328     Dimension trackWidth_;
329     Color trackBgColor_;
330     Color trackSelectedColor_;
331     Color trackCachedColor_;
332 
333     Dimension ringThickness_;
334     Dimension ringDiameter_;
335     Dimension bubbleDiameter_;
336     Dimension bubbleRadius_;
337 
338     Dimension loadingDiameter_;
339     Color loadingColor_;
340 
341     Dimension scaleWidth_;
342     int32_t scaleNumber_ = 0;
343     Dimension scaleLength_;
344     Dimension scaleRingDiameter_;
345 
346     Dimension moonDiameter_;
347     Color moonTrackBackgroundColor_;
348     Color moonFrontColor_;
349 
350     // For loading progress in cycle type.
351     Color progressColor_;
352     double moveRatio_ = 0.0;
353     Dimension ringRadius_;
354     Dimension orbitRadius_;
355     double cometTailLen_ = 0.0;
356 
357     Color borderColor_;
358     Dimension borderWidth_;
359     Color maskColor_;
360 
361     // For capsule progress.
362     Color textColor_;
363     Dimension textSize_;
364     Dimension progressHeight_;
365     Color capsuleSelectColor_;
366     float progressDisable_ = 0.4;
367     Color clickEffect_;
368     float selectColorAlpha_ = 1.0f;
369     const Dimension textMargin_ = 8.0_vp;
370     Color capsuleBgColor_;
371 
372     // For ring progress.
373     Color ringProgressEndSideColor_;
374     Color ringProgressBeginSideColor_;
375     Color ringProgressBackgroundColor_;
376 };
377 
378 } // namespace OHOS::Ace
379 
380 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_PROGRESS_THEME_H
381