• 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             // Read style from system.
75             ParsePattern(themeConstants->GetThemeStyle(), theme);
76             return theme;
77         }
78 
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<ProgressTheme> & theme)79         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<ProgressTheme>& theme) const
80         {
81             if (!themeStyle) {
82                 LOGI("progress theme style is null");
83                 return;
84             }
85             theme->trackBgColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_COMPONENT_NORMAL, Color::RED);
86             theme->trackSelectedColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_EMPHASIZE, Color::RED);
87             theme->trackCachedColor_ =
88                 themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_EMPHASIZE, Color::RED).BlendOpacity(0.4);
89             theme->loadingColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_PROGRESS, Color::RED).BlendOpacity(0.6);
90             theme->progressColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_PROGRESS, Color::RED);
91             theme->moonFrontColor_ =
92                 themeStyle->GetAttr<Color>(TEXT_OVERLAY_HANDLE_COLOR, Color::RED)
93                     .BlendOpacity(themeStyle->GetAttr<double>(THEME_ATTR_HIGHLIGHT_BACKGROUND_ALPHA, 1.0));
94             theme->moonTrackBackgroundColor_ =
95                 themeStyle->GetAttr<Color>(TEXT_OVERLAY_HANDLE_COLOR, Color::RED)
96                     .BlendOpacity(themeStyle->GetAttr<double>(THEME_ATTR_HIGHLIGHT_BACKGROUND_ALPHA, 1.0))
97                     .BlendOpacity(themeStyle->GetAttr<double>(THEME_ATTR_DISABLED_ALPHA, 1.0));
98         }
99     };
100 
101     ~ProgressTheme() override = default;
102 
GetTrackThickness()103     const Dimension& GetTrackThickness() const
104     {
105         return trackThickness_;
106     }
107 
GetTrackWidth()108     const Dimension& GetTrackWidth() const
109     {
110         return trackWidth_;
111     }
112 
GetRingThickness()113     const Dimension& GetRingThickness() const
114     {
115         return ringThickness_;
116     }
117 
GetRingDiameter()118     const Dimension& GetRingDiameter() const
119     {
120         return ringDiameter_;
121     }
122 
GetTrackBgColor()123     const Color& GetTrackBgColor() const
124     {
125         return trackBgColor_;
126     }
127 
GetTrackSelectedColor()128     const Color& GetTrackSelectedColor() const
129     {
130         return trackSelectedColor_;
131     }
132 
GetTrackCachedColor()133     Color GetTrackCachedColor() const
134     {
135         return trackCachedColor_;
136     }
137 
GetLoadingDiameter()138     const Dimension& GetLoadingDiameter() const
139     {
140         return loadingDiameter_;
141     }
142 
GetLoadingColor()143     const Color& GetLoadingColor() const
144     {
145         return loadingColor_;
146     }
147 
GetScaleWidth()148     const Dimension& GetScaleWidth() const
149     {
150         return scaleWidth_;
151     }
152 
GetScaleNumber()153     int32_t GetScaleNumber() const
154     {
155         return scaleNumber_;
156     }
157 
GetScaleLength()158     const Dimension& GetScaleLength() const
159     {
160         return scaleLength_;
161     }
162 
GetProgressColor()163     const Color& GetProgressColor() const
164     {
165         return progressColor_;
166     }
167 
GetMoveRatio()168     double GetMoveRatio() const
169     {
170         return moveRatio_;
171     }
172 
GetRingRadius()173     const Dimension& GetRingRadius() const
174     {
175         return ringRadius_;
176     }
177 
GetOrbitRadius()178     const Dimension& GetOrbitRadius() const
179     {
180         return orbitRadius_;
181     }
182 
GetCometTailLen()183     double GetCometTailLen() const
184     {
185         return cometTailLen_;
186     }
187 
GetScaleRingDiameter()188     const Dimension& GetScaleRingDiameter() const
189     {
190         return scaleRingDiameter_;
191     }
192 
GetMoonDiameter()193     const Dimension& GetMoonDiameter() const
194     {
195         return moonDiameter_;
196     }
197 
GetMoonBackgroundColor()198     const Color& GetMoonBackgroundColor() const
199     {
200         return moonTrackBackgroundColor_;
201     }
202 
GetMoonFrontColor()203     const Color& GetMoonFrontColor() const
204     {
205         return moonFrontColor_;
206     }
207 
GetBubbleDiameter()208     const Dimension& GetBubbleDiameter() const
209     {
210         return bubbleDiameter_;
211     }
212 
GetBubbleRadius()213     const Dimension& GetBubbleRadius() const
214     {
215         return bubbleRadius_;
216     }
217 
218 protected:
219     ProgressTheme() = default;
220 
221 private:
222     Dimension trackThickness_;
223     Dimension trackWidth_;
224     Color trackBgColor_;
225     Color trackSelectedColor_;
226     Color trackCachedColor_;
227 
228     Dimension ringThickness_;
229     Dimension ringDiameter_;
230     Dimension bubbleDiameter_;
231     Dimension bubbleRadius_;
232 
233     Dimension loadingDiameter_;
234     Color loadingColor_;
235 
236     Dimension scaleWidth_;
237     int32_t scaleNumber_ = 0;
238     Dimension scaleLength_;
239     Dimension scaleRingDiameter_;
240 
241     Dimension moonDiameter_;
242     Color moonTrackBackgroundColor_;
243     Color moonFrontColor_;
244 
245     // For loading progress in cycle type.
246     Color progressColor_;
247     double moveRatio_ = 0.0;
248     Dimension ringRadius_;
249     Dimension orbitRadius_;
250     double cometTailLen_ = 0.0;
251 };
252 
253 } // namespace OHOS::Ace
254 
255 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_PROGRESS_PROGRESS_THEME_H
256