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_DATA_PANEL_DATA_PANEL_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DATA_PANEL_DATA_PANEL_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 #include "core/components/theme/theme_manager.h" 23 24 namespace OHOS::Ace { 25 26 class DataPanelTheme : public virtual Theme { 27 DECLARE_ACE_TYPE(DataPanelTheme, Theme); 28 29 public: 30 class Builder { 31 public: 32 Builder() = default; 33 ~Builder() = default; 34 Build(const RefPtr<ThemeConstants> & themeConstants)35 RefPtr<DataPanelTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 36 { 37 RefPtr<DataPanelTheme> theme = AceType::Claim(new DataPanelTheme()); 38 if (!themeConstants) { 39 return theme; 40 } 41 theme->backgroundColor_ = themeConstants->GetColor(THEME_DATA_PANEL_BACKGROUND_COLOR); 42 theme->thickness_ = themeConstants->GetDimension(THEME_DATA_PANEL_THICKNESS); 43 theme->defaultHeight_ = themeConstants->GetDimension(THEME_DATA_PANEL_HEIGHT); 44 theme->defaultWidth_ = themeConstants->GetDimension(THEME_DATA_PANEL_WIDTH); 45 theme->loadingColors_.first = themeConstants->GetColor(THEME_DATA_PANEL_LOADING_START_COLOR); 46 theme->loadingColors_.second = themeConstants->GetColor(THEME_DATA_PANEL_LOADING_END_COLOR); 47 theme->progressColors_.first = themeConstants->GetColor(THEME_DATA_PANEL_PROGRESS_START_COLOR); 48 theme->progressColors_.second = themeConstants->GetColor(THEME_DATA_PANEL_PROGRESS_END_COLOR); 49 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_1_START), 50 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_1_END)); 51 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_2_START), 52 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_2_END)); 53 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_3_START), 54 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_3_END)); 55 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_4_START), 56 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_4_END)); 57 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_5_START), 58 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_5_END)); 59 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_6_START), 60 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_6_END)); 61 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_7_START), 62 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_7_END)); 63 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_8_START), 64 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_8_END)); 65 theme->percentageColors_.emplace_back(themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_9_START), 66 themeConstants->GetColor(THEME_DATA_PANEL_CONFIG_COLOR_9_END)); 67 ParsePattern(themeConstants->GetThemeStyle(), theme); 68 return theme; 69 } 70 71 private: ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<DataPanelTheme> & theme)72 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<DataPanelTheme>& theme) const 73 { 74 if (!themeStyle) { 75 return; 76 } 77 auto dataPanelPattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_DATA_PANEL, nullptr); 78 if (!dataPanelPattern) { 79 LOGW("find pattern of datapanel fail"); 80 return; 81 } 82 theme->backgroundColor_ = dataPanelPattern->GetAttr<Color>(PATTERN_BG_COLOR, Color::BLACK); 83 theme->loadingColors_.first = dataPanelPattern->GetAttr<Color>(DATA_PANEL_LOADING_COLOR_END, Color::BLACK); 84 theme->loadingColors_.second = 85 dataPanelPattern->GetAttr<Color>(DATA_PANEL_LOADING_COLOR_START, Color::BLACK); 86 theme->progressColors_.first = 87 dataPanelPattern->GetAttr<Color>(DATA_PANEL_PROGRESS_COLOR_END, Color::BLACK); 88 theme->progressColors_.second = 89 dataPanelPattern->GetAttr<Color>(DATA_PANEL_PROGRESS_COLOR_START, Color::BLACK); 90 theme->percentageColors_.clear(); 91 theme->percentageColors_.emplace_back( 92 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_1_START, Color::BLACK), 93 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_1_END, Color::BLACK)); 94 theme->percentageColors_.emplace_back( 95 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_2_START, Color::BLACK), 96 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_2_END, Color::BLACK)); 97 theme->percentageColors_.emplace_back( 98 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_3_START, Color::BLACK), 99 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_3_END, Color::BLACK)); 100 theme->percentageColors_.emplace_back( 101 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_4_START, Color::BLACK), 102 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_4_END, Color::BLACK)); 103 theme->percentageColors_.emplace_back( 104 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_5_START, Color::BLACK), 105 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_5_END, Color::BLACK)); 106 theme->percentageColors_.emplace_back( 107 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_6_START, Color::BLACK), 108 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_6_END, Color::BLACK)); 109 theme->percentageColors_.emplace_back( 110 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_7_START, Color::BLACK), 111 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_7_END, Color::BLACK)); 112 theme->percentageColors_.emplace_back( 113 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_8_START, Color::BLACK), 114 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_8_END, Color::BLACK)); 115 theme->percentageColors_.emplace_back( 116 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_9_START, Color::BLACK), 117 dataPanelPattern->GetAttr<Color>(DATA_PANEL_COLOR_9_END, Color::BLACK)); 118 } 119 }; 120 GetLoadingColor()121 const std::pair<Color, Color>& GetLoadingColor() const 122 { 123 return loadingColors_; 124 } 125 GetProgressColor()126 const std::pair<Color, Color>& GetProgressColor() const 127 { 128 return progressColors_; 129 } 130 GetBackgroundColor()131 const Color& GetBackgroundColor() const 132 { 133 return backgroundColor_; 134 } 135 GetDefaultHeight()136 const Dimension& GetDefaultHeight() const 137 { 138 return defaultHeight_; 139 } 140 GetDefaultWidth()141 const Dimension& GetDefaultWidth() const 142 { 143 return defaultWidth_; 144 } 145 GetThickness()146 const Dimension& GetThickness() const 147 { 148 return thickness_; 149 } 150 GetColorsArray()151 const std::vector<std::pair<Color, Color>> GetColorsArray() const 152 { 153 return percentageColors_; 154 } 155 156 protected: 157 private: 158 std::vector<std::pair<Color, Color>> percentageColors_; 159 std::pair<Color, Color> loadingColors_; 160 std::pair<Color, Color> progressColors_; 161 Color backgroundColor_; 162 Dimension defaultHeight_; 163 Dimension defaultWidth_; 164 Dimension thickness_; 165 }; 166 167 } // namespace OHOS::Ace 168 169 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DATA_PANEL_DATA_PANEL_THEME_H 170