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::MakeRefPtr<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 theme->ratio_ = pattern->GetAttr<double>("refresh_over_edge_following_ratio_api_twenty", 5.0f); 70 } 71 }; 72 73 ~RefreshTheme() override = default; 74 GetLoadingDistance()75 const Dimension& GetLoadingDistance() const 76 { 77 return loadingDistance_; 78 } 79 GetRefreshDistance()80 const Dimension& GetRefreshDistance() const 81 { 82 return refreshDistance_; 83 } 84 GetProgressDistance()85 const Dimension& GetProgressDistance() const 86 { 87 return progressDistance_; 88 } 89 GetShowTimeDistance()90 const Dimension& GetShowTimeDistance() const 91 { 92 return showTimeDistance_; 93 } 94 GetMaxDistance()95 const Dimension& GetMaxDistance() const 96 { 97 return maxDistance_; 98 } 99 GetProgressDiameter()100 const Dimension& GetProgressDiameter() const 101 { 102 return progressDiameter_; 103 } 104 GetTextStyle()105 const TextStyle& GetTextStyle() const 106 { 107 return textStyle_; 108 } 109 GetProgressColor()110 const Color& GetProgressColor() const 111 { 112 return progressColor_; 113 } 114 GetBackgroundColor()115 const Color& GetBackgroundColor() const 116 { 117 return backgroundColor_; 118 } 119 GetRatio()120 float GetRatio() const 121 { 122 return ratio_; 123 } 124 125 protected: 126 RefreshTheme() = default; 127 128 private: 129 Dimension loadingDistance_; 130 Dimension progressDistance_; 131 Dimension refreshDistance_; 132 Dimension maxDistance_; 133 Dimension progressDiameter_; 134 Dimension showTimeDistance_; 135 TextStyle textStyle_; 136 Color progressColor_; 137 Color backgroundColor_; 138 float ratio_ = 5.0f; 139 }; 140 141 } // namespace OHOS::Ace 142 143 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_THEME_H 144