1 /* 2 * Copyright (c) 2023 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_APP_BAR_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_APP_BAR_THEME_H 18 19 #include "base/geometry/dimension.h" 20 #include "base/memory/ace_type.h" 21 #include "base/memory/referenced.h" 22 #include "core/components/common/properties/color.h" 23 #include "core/components/theme/theme.h" 24 #include "core/components/theme/theme_attributes.h" 25 #include "core/components/theme/theme_constants.h" 26 #include "core/components/theme/theme_style.h" 27 28 namespace OHOS::Ace::NG { 29 30 class AppBarTheme : public virtual Theme { 31 DECLARE_ACE_TYPE(AppBarTheme, Theme); 32 33 public: 34 ~AppBarTheme() = default; 35 36 class Builder { 37 public: 38 Builder() = default; 39 ~Builder() = default; Build(const RefPtr<ThemeConstants> & themeConstants)40 RefPtr<AppBarTheme> Build(const RefPtr<ThemeConstants>& themeConstants) 41 { 42 RefPtr<AppBarTheme> theme = AceType::Claim(new AppBarTheme()); 43 if (!themeConstants) { 44 LOGE("Build AppBarTheme error, themeConstants is null!"); 45 return theme; 46 } 47 ParsePattern(themeConstants->GetThemeStyle(), theme); 48 return theme; 49 } 50 }; 51 GetAppBarHeight()52 const Dimension& GetAppBarHeight() const 53 { 54 return appBarHeight_; 55 } 56 GetIconSize()57 const Dimension& GetIconSize() const 58 { 59 return iconSize_; 60 } 61 GetIconCornerRadius()62 const Dimension& GetIconCornerRadius() const 63 { 64 return iconCornerRadius_; 65 } 66 GetFontSize()67 const Dimension& GetFontSize() const 68 { 69 return appBarFontSize_; 70 } 71 GetTextColor()72 const Color& GetTextColor() const 73 { 74 return textColorPrimary_; 75 } 76 GetClickEffectColor()77 const Color& GetClickEffectColor() const 78 { 79 return clickEffectColor_; 80 } 81 GetBgColor()82 const Color& GetBgColor() const 83 { 84 return appBarBgColor_; 85 } 86 GetBundleName()87 const std::string& GetBundleName() const 88 { 89 return bundleName_; 90 } 91 GetAbilityName()92 const std::string& GetAbilityName() const 93 { 94 return abilityName_; 95 } 96 97 private: 98 AppBarTheme() = default; ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<AppBarTheme> & theme)99 static void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<AppBarTheme>& theme) 100 { 101 if (!themeStyle) { 102 return; 103 } 104 auto appBarPattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_APP_BAR, nullptr); 105 if (!appBarPattern) { 106 LOGE("Pattern of app bar is null, please check!"); 107 return; 108 } 109 theme->appBarHeight_ = appBarPattern->GetAttr<Dimension>("app_bar_height", 0.0_vp); 110 theme->iconSize_ = appBarPattern->GetAttr<Dimension>("icon_size", 0.0_vp); 111 theme->iconCornerRadius_ = appBarPattern->GetAttr<Dimension>("icon_corner_radius", 0.0_vp); 112 theme->appBarFontSize_ = appBarPattern->GetAttr<Dimension>("app_bar_font_size", 0.0_vp); 113 theme->textColorPrimary_ = appBarPattern->GetAttr<Color>("text_color_primary", Color()); 114 theme->clickEffectColor_ = appBarPattern->GetAttr<Color>("click_effect_color", Color()); 115 theme->appBarBgColor_ = appBarPattern->GetAttr<Color>("app_bar_bg_color", Color()); 116 theme->bundleName_ = appBarPattern->GetAttr<std::string>("app_bar_bundle_name", "com.ohos.hag.famanager"); 117 theme->abilityName_ = appBarPattern->GetAttr<std::string>("app_bar_ability_name", "FaPanelAbility"); 118 } 119 120 Dimension appBarHeight_; 121 Dimension iconSize_; 122 Dimension iconCornerRadius_; 123 Dimension appBarFontSize_; 124 Color textColorPrimary_; 125 Color clickEffectColor_; 126 Color appBarBgColor_; 127 std::string bundleName_; 128 std::string abilityName_; 129 }; 130 } // namespace OHOS::Ace::NG 131 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_APP_BAR_THEME_H