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 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_REFRESH, nullptr); 64 if (!pattern) { 65 LOGW("find pattern of search fail"); 66 return; 67 } 68 theme->textStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 0.0_vp)); 69 theme->textStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::BLACK)); 70 theme->progressColor_ = pattern->GetAttr<Color>("progress_color", Color::BLACK); 71 theme->backgroundColor_ = pattern->GetAttr<Color>("progress_bg_color", Color::WHITE); 72 } 73 }; 74 75 ~RefreshTheme() override = default; 76 GetLoadingDistance()77 const Dimension& GetLoadingDistance() const 78 { 79 return loadingDistance_; 80 } 81 GetRefreshDistance()82 const Dimension& GetRefreshDistance() const 83 { 84 return refreshDistance_; 85 } 86 GetProgressDistance()87 const Dimension& GetProgressDistance() const 88 { 89 return progressDistance_; 90 } 91 GetShowTimeDistance()92 const Dimension& GetShowTimeDistance() const 93 { 94 return showTimeDistance_; 95 } 96 GetMaxDistance()97 const Dimension& GetMaxDistance() const 98 { 99 return maxDistance_; 100 } 101 GetProgressDiameter()102 const Dimension& GetProgressDiameter() const 103 { 104 return progressDiameter_; 105 } 106 GetTextStyle()107 const TextStyle& GetTextStyle() const 108 { 109 return textStyle_; 110 } 111 GetProgressColor()112 const Color& GetProgressColor() const 113 { 114 return progressColor_; 115 } 116 GetBackgroundColor()117 const Color& GetBackgroundColor() const 118 { 119 return backgroundColor_; 120 } 121 122 protected: 123 RefreshTheme() = default; 124 125 private: 126 Dimension loadingDistance_; 127 Dimension progressDistance_; 128 Dimension refreshDistance_; 129 Dimension maxDistance_; 130 Dimension progressDiameter_; 131 Dimension showTimeDistance_; 132 TextStyle textStyle_; 133 Color progressColor_; 134 Color backgroundColor_; 135 }; 136 137 } // namespace OHOS::Ace 138 139 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_REFRESH_REFRESH_THEME_H 140