1 /* 2 * Copyright (c) 2025 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_NG_REFRESH_REFRESH_THEME_NG_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_REFRESH_REFRESH_THEME_NG_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::NG { 24 25 /** 26 * RefreshThemeNG should be built using RefreshThemeNG::Builder. 27 */ 28 class RefreshThemeNG : public virtual Theme { 29 DECLARE_ACE_TYPE(RefreshThemeNG, Theme); 30 31 public: 32 class Builder { 33 public: 34 Builder() = default; 35 ~Builder() = default; 36 Build(const RefPtr<ThemeConstants> & themeConstants)37 RefPtr<RefreshThemeNG> Build(const RefPtr<ThemeConstants>& themeConstants) const 38 { 39 RefPtr<RefreshThemeNG> theme = AceType::MakeRefPtr<RefreshThemeNG>(); 40 if (!themeConstants) { 41 return theme; 42 } 43 ParsePattern(themeConstants, theme); 44 return theme; 45 } 46 47 private: ParsePattern(const RefPtr<ThemeConstants> & themeConstants,const RefPtr<RefreshThemeNG> & theme)48 void ParsePattern(const RefPtr<ThemeConstants>& themeConstants, const RefPtr<RefreshThemeNG>& theme) const 49 { 50 RefPtr<ThemeStyle> pattern = themeConstants->GetPatternByName(THEME_PATTERN_REFRESH); 51 if (!pattern) { 52 LOGW("find pattern of refresh fail"); 53 return; 54 } 55 theme->textStyle_.SetFontSize(pattern->GetAttr<Dimension>(PATTERN_TEXT_SIZE, 14.0_fp)); 56 theme->textStyle_.SetTextColor(pattern->GetAttr<Color>(PATTERN_TEXT_COLOR, Color::BLACK)); 57 theme->progressColor_ = pattern->GetAttr<Color>("progress_color", Color::BLACK); 58 theme->loadingDistance_ = pattern->GetAttr<Dimension>("default_loading_distance", 16.0_vp); 59 theme->progressDiameter_ = pattern->GetAttr<Dimension>("default_progress_diameter", 32.0_vp); 60 theme->ratio_ = pattern->GetAttr<double>("refresh_over_edge_following_ratio_api_twenty", 5.0f); 61 } 62 }; 63 64 ~RefreshThemeNG() override = default; 65 GetLoadingDistance()66 const Dimension& GetLoadingDistance() const 67 { 68 return loadingDistance_; 69 } 70 GetProgressDiameter()71 const Dimension& GetProgressDiameter() const 72 { 73 return progressDiameter_; 74 } 75 GetTextStyle()76 const TextStyle& GetTextStyle() const 77 { 78 return textStyle_; 79 } 80 GetProgressColor()81 const Color& GetProgressColor() const 82 { 83 return progressColor_; 84 } 85 GetRatio()86 float GetRatio() const 87 { 88 return ratio_; 89 } 90 91 protected: 92 RefreshThemeNG() = default; 93 94 private: 95 Dimension loadingDistance_; 96 Dimension progressDiameter_; 97 TextStyle textStyle_; 98 Color progressColor_; 99 float ratio_ = 5.0f; 100 }; 101 102 } // namespace OHOS::Ace::NG 103 104 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_REFRESH_REFRESH_THEME_NG_H 105