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_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 ReloadResource()34 void ReloadResource() override 35 { 36 themeConstants_->ReloadResource(); 37 } 38 UpdateConfig(const ResourceConfiguration & config)39 void UpdateConfig(const ResourceConfiguration& config) override 40 { 41 themeConstants_->UpdateConfig(config); 42 } 43 LoadSystemTheme(int32_t themeId)44 void LoadSystemTheme(int32_t themeId) override 45 { 46 currentThemeId_ = themeId; 47 themeConstants_->LoadTheme(themeId); 48 } 49 ParseSystemTheme()50 void ParseSystemTheme() override 51 { 52 themeConstants_->ParseTheme(); 53 } 54 LoadCustomTheme(const RefPtr<AssetManager> & assetManager)55 void LoadCustomTheme(const RefPtr<AssetManager>& assetManager) override 56 { 57 themeConstants_->LoadCustomStyle(assetManager); 58 } 59 60 /* 61 * Color scheme of the whole window, app bg color will be change in transparent scheme. 62 */ SetColorScheme(ColorScheme colorScheme)63 void SetColorScheme(ColorScheme colorScheme) override 64 { 65 themeConstants_->SetColorScheme(colorScheme); 66 } 67 68 /* 69 * Get color value from AppTheme (if exists) or system theme style. 70 * Prebuild background color will be returned if AppTheme and system theme style both not exists. 71 * @return App background color. 72 */ 73 Color GetBackgroundColor() const override; 74 75 RefPtr<ThemeConstants> GetThemeConstants( 76 const std::string& bundleName = "", const std::string& moduleName = "") const override 77 { 78 themeConstants_->UpdateThemeConstants(bundleName, moduleName); 79 return themeConstants_; 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