• 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_REFRESH_REFRESH_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_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 
23 namespace OHOS::Ace {
24 
25 /**
26  * RefreshTheme should be built using RefreshTheme::Builder.
27  */
28 class RefreshTheme : public virtual Theme {
29     DECLARE_ACE_TYPE(RefreshTheme, Theme);
30 
31 public:
32     class Builder {
33     public:
34         Builder() = default;
35         ~Builder() = default;
36 
Build(const RefPtr<ThemeConstants> & themeConstants)37         RefPtr<RefreshTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
38         {
39             RefPtr<RefreshTheme> theme = AceType::Claim(new RefreshTheme());
40             if (!themeConstants) {
41                 return theme;
42             }
43             theme->loadingDistance_ = themeConstants->GetDimension(THEME_REFRESH_DEFAULT_LOADING_DISTANCE);
44             theme->refreshDistance_ = themeConstants->GetDimension(THEME_REFRESH_DEFAULT_REFRESHING_DISTANCE);
45             theme->maxDistance_ = themeConstants->GetDimension(THEME_REFRESH_DEFAULT_MAX_DISTANCE);
46             theme->progressDistance_ = themeConstants->GetDimension(THEME_REFRESH_DEFAULT_PROGRESS_DISTANCE);
47             theme->progressDiameter_ = themeConstants->GetDimension(THEME_REFRESH_DEFAULT_PROGRESS_DIAMETER);
48             theme->showTimeDistance_ = themeConstants->GetDimension(THEME_REFRESH_DEFAULT_SHOWTIME_DISTANCE);
49             theme->textStyle_.SetFontSize(themeConstants->GetDimension(THEME_REFRESH_DEFAULT_FONTSIZE));
50             theme->textStyle_.SetTextColor(themeConstants->GetColor(THEME_REFRESH_DEFAULT_TEXT_COLOR));
51             theme->textStyle_.SetFontWeight(FontWeight(themeConstants->GetInt(THEME_TEXTFIELD_FONT_WEIGHT)));
52             theme->progressColor_ = themeConstants->GetColor(THEME_REFRESH_DEFAULT_PROGRESS_COLOR);
53             theme->backgroundColor_ = themeConstants->GetColor(THEME_REFRESH_DEFAULT_BACKGROUND_COLOR);
54             ParsePattern(themeConstants->GetThemeStyle(), theme);
55             return theme;
56         }
57     private:
ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<RefreshTheme> & theme)58         void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<RefreshTheme>& theme) const
59         {
60             if (!themeStyle) {
61                 return;
62             }
63             theme->textStyle_.SetFontSize(themeStyle->GetAttr<Dimension>(THEME_ATTR_TEXT_SIZE_BODY2, 0.0_vp));
64             theme->textStyle_.SetTextColor(themeStyle->GetAttr<Color>(THEME_ATTR_TEXT_COLOR_SECONDARY, Color::BLACK));
65             theme->progressColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_COLOR_PROGRESS, Color::BLACK);
66             theme->backgroundColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_BG_COLOR, Color::WHITE);
67         }
68     };
69 
70     ~RefreshTheme() override = default;
71 
GetLoadingDistance()72     const Dimension& GetLoadingDistance() const
73     {
74         return loadingDistance_;
75     }
76 
GetRefreshDistance()77     const Dimension& GetRefreshDistance() const
78     {
79         return refreshDistance_;
80     }
81 
GetProgressDistance()82     const Dimension& GetProgressDistance() const
83     {
84         return progressDistance_;
85     }
86 
GetShowTimeDistance()87     const Dimension& GetShowTimeDistance() const
88     {
89         return showTimeDistance_;
90     }
91 
GetMaxDistance()92     const Dimension& GetMaxDistance() const
93     {
94         return maxDistance_;
95     }
96 
GetProgressDiameter()97     const Dimension& GetProgressDiameter() const
98     {
99         return progressDiameter_;
100     }
101 
GetTextStyle()102     const TextStyle& GetTextStyle() const
103     {
104         return textStyle_;
105     }
106 
GetProgressColor()107     const Color& GetProgressColor() const
108     {
109         return progressColor_;
110     }
111 
GetBackgroundColor()112     const Color& GetBackgroundColor() const
113     {
114         return backgroundColor_;
115     }
116 
117 protected:
118     RefreshTheme() = default;
119 
120 private:
121     Dimension loadingDistance_;
122     Dimension progressDistance_;
123     Dimension refreshDistance_;
124     Dimension maxDistance_;
125     Dimension progressDiameter_;
126     Dimension showTimeDistance_;
127     TextStyle textStyle_;
128     Color progressColor_;
129     Color backgroundColor_;
130 };
131 
132 } // namespace OHOS::Ace
133 
134 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_THEME_H
135