1 /* 2 * Copyright (c) 2022-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_THEME_THEME_MANAGER_IMPL_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_THEME_MANAGER_IMPL_H 18 19 #include "core/components/theme/theme_manager.h" 20 21 namespace OHOS::Ace { 22 class ACE_EXPORT ThemeManagerImpl : public ThemeManager { 23 DECLARE_ACE_TYPE(ThemeManagerImpl, ThemeManager); 24 25 public: 26 ThemeManagerImpl(); 27 ~ThemeManagerImpl() override = default; 28 InitResource(const ResourceInfo & resourceInfo)29 void InitResource(const ResourceInfo& resourceInfo) override 30 { 31 themeConstants_->InitResource(resourceInfo); 32 } 33 UpdateConfig(const ResourceConfiguration & config)34 void UpdateConfig(const ResourceConfiguration& config) override 35 { 36 themeConstants_->UpdateConfig(config); 37 } 38 LoadSystemTheme(int32_t themeId)39 void LoadSystemTheme(int32_t themeId) override 40 { 41 currentThemeId_ = themeId; 42 themeConstants_->LoadTheme(themeId); 43 } 44 ParseSystemTheme()45 void ParseSystemTheme() override 46 { 47 themeConstants_->ParseTheme(); 48 } 49 LoadCustomTheme(const RefPtr<AssetManager> & assetManager)50 void LoadCustomTheme(const RefPtr<AssetManager>& assetManager) override 51 { 52 themeConstants_->LoadCustomStyle(assetManager); 53 } 54 55 /* 56 * Color scheme of the whole window, app bg color will be change in transparent scheme. 57 */ SetColorScheme(ColorScheme colorScheme)58 void SetColorScheme(ColorScheme colorScheme) override 59 { 60 themeConstants_->SetColorScheme(colorScheme); 61 } 62 63 /* 64 * Get color value from AppTheme (if exists) or system theme style. 65 * Prebuilt background color will be returned if AppTheme and system theme style both not exists. 66 * @return App background color. 67 */ 68 Color GetBackgroundColor() const override; 69 GetThemeConstants(const std::string & bundleName,const std::string & moduleName)70 RefPtr<ThemeConstants> GetThemeConstants( 71 const std::string& bundleName, const std::string& moduleName) const override 72 { 73 themeConstants_->UpdateThemeConstants(bundleName, moduleName); 74 return themeConstants_; 75 } 76 GetThemeConstants()77 RefPtr<ThemeConstants> GetThemeConstants() const override 78 { 79 return GetThemeConstants("", ""); 80 } 81 82 /* 83 * Get target theme, this function will cause construction of the theme if it not exists. 84 * @return Target component theme. 85 */ 86 RefPtr<Theme> GetTheme(ThemeType type) override; 87 88 template<typename T> GetTheme()89 RefPtr<T> GetTheme() 90 { 91 return AceType::DynamicCast<T>(GetTheme(T::TypeId())); 92 } 93 94 void LoadResourceThemes() override; 95 96 private: 97 std::unordered_map<ThemeType, RefPtr<Theme>> themes_; 98 RefPtr<ThemeConstants> themeConstants_; 99 int32_t currentThemeId_ = -1; 100 101 ACE_DISALLOW_COPY_AND_MOVE(ThemeManagerImpl); 102 }; 103 } // namespace OHOS::Ace 104 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_THEME_MANAGER_H 105