• 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 namespace {
25 constexpr int TEXT_FIELD_FONT_WEIGHT = 3;
26 } // namespace
27 
28 /**
29  * RefreshTheme should be built using RefreshTheme::Builder.
30  */
31 class RefreshTheme : public virtual Theme {
32     DECLARE_ACE_TYPE(RefreshTheme, Theme);
33 
34 public:
35     class Builder {
36     public:
37         Builder() = default;
38         ~Builder() = default;
39 
Build(const RefPtr<ThemeConstants> & themeConstants)40         RefPtr<RefreshTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
41         {
42             RefPtr<RefreshTheme> theme = AceType::Claim(new RefreshTheme());
43             if (!themeConstants) {
44                 return theme;
45             }
46             ParsePattern(themeConstants, theme);
47             return theme;
48         }
49     private:
ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<RefreshTheme> & theme)50         void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<RefreshTheme>& theme) const
51         {
52             RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_REFRESH);
53             if (!pattern) {
54                 LOGW("find pattern of refresh fail");
55                 return;
56             }
57             theme->textStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_vp));
58             theme->textStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::BLACK));
59             theme->progressColor_ = pattern->GetAttr<Color>("progress_color", Color::BLACK);
60             theme->backgroundColor_ = pattern->GetAttr<Color>("progress_bg_color", Color::WHITE);
61             theme->loadingDistance_ = pattern->GetAttr<Dimension>("default_loading_distance", 16.0_vp);
62             theme->refreshDistance_ = pattern->GetAttr<Dimension>("default_refreshing_distance", 64.0_vp);
63             theme->maxDistance_ = pattern->GetAttr<Dimension>("default_max_distance", 128.0_vp);
64             theme->progressDistance_ = pattern->GetAttr<Dimension>("default_progress_distance", 16.0_vp);
65             theme->progressDiameter_ = pattern->GetAttr<Dimension>("default_progress_diameter", 32.0_vp);
66             theme->showTimeDistance_ = pattern->GetAttr<Dimension>("default_showtime_distance", 96.0_vp);
67             theme->textStyle_.SetFontWeight(FontWeight(pattern->GetAttr<int>("textfield_font_weight",
68                 TEXT_FIELD_FONT_WEIGHT)));
69             if (Container::GreatOrEqualAPITargetVersion(PlatformVersion::VERSION_EIGHTEEN)) {
70                 theme->ratio_ = pattern->GetAttr<double>("refresh_over_edge_following_ratio_api_eighteen", 5.0f);
71             } else {
72                 theme->ratio_ = pattern->GetAttr<double>("refresh_over_edge_following_ratio", 1.848f);
73             }
74         }
75     };
76 
77     ~RefreshTheme() override = default;
78 
GetLoadingDistance()79     const Dimension& GetLoadingDistance() const
80     {
81         return loadingDistance_;
82     }
83 
GetRefreshDistance()84     const Dimension& GetRefreshDistance() const
85     {
86         return refreshDistance_;
87     }
88 
GetProgressDistance()89     const Dimension& GetProgressDistance() const
90     {
91         return progressDistance_;
92     }
93 
GetShowTimeDistance()94     const Dimension& GetShowTimeDistance() const
95     {
96         return showTimeDistance_;
97     }
98 
GetMaxDistance()99     const Dimension& GetMaxDistance() const
100     {
101         return maxDistance_;
102     }
103 
GetProgressDiameter()104     const Dimension& GetProgressDiameter() const
105     {
106         return progressDiameter_;
107     }
108 
GetTextStyle()109     const TextStyle& GetTextStyle() const
110     {
111         return textStyle_;
112     }
113 
GetProgressColor()114     const Color& GetProgressColor() const
115     {
116         return progressColor_;
117     }
118 
GetBackgroundColor()119     const Color& GetBackgroundColor() const
120     {
121         return backgroundColor_;
122     }
123 
GetRatio()124     float GetRatio() const
125     {
126         return ratio_;
127     }
128 
129 protected:
130     RefreshTheme() = default;
131 
132 private:
133     Dimension loadingDistance_;
134     Dimension progressDistance_;
135     Dimension refreshDistance_;
136     Dimension maxDistance_;
137     Dimension progressDiameter_;
138     Dimension showTimeDistance_;
139     TextStyle textStyle_;
140     Color progressColor_;
141     Color backgroundColor_;
142     float ratio_ = 1.848f;
143 };
144 
145 } // namespace OHOS::Ace
146 
147 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_THEME_H
148