From 4bed718195857d6e5a04523bb4b7df07e320da00 Mon Sep 17 00:00:00 2001 From: LiPing Date: Mon, 21 Oct 2024 11:25:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=87=E6=8D=A2=E5=9B=BE=E6=A0=87=E6=97=B6?= =?UTF-8?q?=E5=8F=AA=E6=9B=B4=E6=96=B0=E5=9B=BE=E6=A0=87=E8=B5=84=E6=BA=90?= =?UTF-8?q?=EF=BC=8C=E4=B8=8D=E8=BF=9B=E8=A1=8C=E5=85=A8=E9=87=8F=E7=9A=84?= =?UTF-8?q?=E4=B8=BB=E9=A2=98=E5=88=B7=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: LiPing --- frameworks/resmgr/include/res_config_impl.h | 9 +++++++ .../resmgr/include/theme_pack_manager.h | 2 ++ frameworks/resmgr/src/res_config_impl.cpp | 13 +++++++++- .../resmgr/src/resource_manager_impl.cpp | 9 +++++-- frameworks/resmgr/src/theme_pack_manager.cpp | 25 ++++++++++++++++++- interfaces/inner_api/include/res_config.h | 4 +++ 6 files changed, 58 insertions(+), 4 deletions(-) diff --git a/frameworks/resmgr/include/res_config_impl.h b/frameworks/resmgr/include/res_config_impl.h index f269d31..36c710a 100644 --- a/frameworks/resmgr/include/res_config_impl.h +++ b/frameworks/resmgr/include/res_config_impl.h @@ -109,6 +109,12 @@ public: */ void SetThemeId(uint32_t themeId); + /** + * Set resConfig themeIcon + * @param isIcon the resConfig themeIcon flag + */ + void SetThemeIcon(bool isIcon); + #ifdef SUPPORT_GRAPHICS const ResLocale *GetResPreferredLocale() const; @@ -137,6 +143,8 @@ public: uint32_t GetThemeId() const; + bool GetThemeIcon() const; + DeviceType GetDeviceType() const; /** @@ -264,6 +272,7 @@ private: bool isAppColorMode_; bool isAppDarkRes_; uint32_t themeId_; + bool isThemeIcon_; }; } // namespace Resource } // namespace Global diff --git a/frameworks/resmgr/include/theme_pack_manager.h b/frameworks/resmgr/include/theme_pack_manager.h index 94ac435..0a009b6 100644 --- a/frameworks/resmgr/include/theme_pack_manager.h +++ b/frameworks/resmgr/include/theme_pack_manager.h @@ -156,6 +156,8 @@ public: * @return true if update theme by the user id, else not update */ bool IsUpdateByUserId(int32_t userId); + + void LoadThemeIconRes(const std::string &bundleName, const std::string &moduleName, int32_t userId); private: ThemePackManager(); std::string themeMask; diff --git a/frameworks/resmgr/src/res_config_impl.cpp b/frameworks/resmgr/src/res_config_impl.cpp index 061c44b..d8d8cb3 100644 --- a/frameworks/resmgr/src/res_config_impl.cpp +++ b/frameworks/resmgr/src/res_config_impl.cpp @@ -57,7 +57,8 @@ ResConfigImpl::ResConfigImpl() isCompletedScript_(false), isAppColorMode_(false), isAppDarkRes_(false), - themeId_(0) + themeId_(0), + isThemeIcon_(false) {} #ifdef SUPPORT_GRAPHICS @@ -192,6 +193,11 @@ void ResConfigImpl::SetThemeId(uint32_t themeId) this->themeId_ = themeId; } +void ResConfigImpl::SetThemeIcon(bool isIcon) +{ + this->isThemeIcon_ = isIcon; +} + ScreenDensity ResConfigImpl::ConvertDensity(float density) { float deviceDpi = density * Utils::DPI_BASE; @@ -279,6 +285,11 @@ uint32_t ResConfigImpl::GetThemeId() const return this->themeId_; } +bool ResConfigImpl::GetThemeIcon() const +{ + return this->isThemeIcon_; +} + DeviceType ResConfigImpl::GetDeviceType() const { return this->deviceType_; diff --git a/frameworks/resmgr/src/resource_manager_impl.cpp b/frameworks/resmgr/src/resource_manager_impl.cpp index c1d4f07..4d20d2f 100644 --- a/frameworks/resmgr/src/resource_manager_impl.cpp +++ b/frameworks/resmgr/src/resource_manager_impl.cpp @@ -1150,8 +1150,13 @@ RState ResourceManagerImpl::UpdateResConfig(ResConfig &resConfig, bool isUpdateT { auto themePackManager = ThemePackManager::GetThemePackManager(); if (themePackManager->UpdateThemeId(resConfig.GetThemeId())) { - RESMGR_HILOGD(RESMGR_TAG, "The theme enabled"); - themePackManager->LoadThemeRes(bundleInfo.first, bundleInfo.second, userId); + if (resConfig.GetThemeIcon()) { + RESMGR_HILOGD(RESMGR_TAG, "The themeIcon enabled"); + themePackManager->LoadThemeIconRes(bundleInfo.first, bundleInfo.second, userId); + } else { + RESMGR_HILOGD(RESMGR_TAG, "The theme enabled"); + themePackManager->LoadThemeRes(bundleInfo.first, bundleInfo.second, userId); + } } #if !defined(__WINNT__) && !defined(__IDE_PREVIEW__) && !defined(__ARKUI_CROSS__) HITRACE_METER_NAME(HITRACE_TAG_APP, __PRETTY_FUNCTION__); diff --git a/frameworks/resmgr/src/theme_pack_manager.cpp b/frameworks/resmgr/src/theme_pack_manager.cpp index da9d144..4c4b013 100644 --- a/frameworks/resmgr/src/theme_pack_manager.cpp +++ b/frameworks/resmgr/src/theme_pack_manager.cpp @@ -157,6 +157,27 @@ void ThemePackManager::LoadThemeRes(const std::string &bundleName, const std::st return; } +void ThemePackManager::LoadThemeIconRes(const std::string &bundleName, const std::string &moduleName, int32_t userId) +{ + UpdateUserId(userId); + std::vector iconDirs; + if (Utils::IsFileExist(themeFlagA)) { + iconDirs = GetRootDir(themeIconsA); + } else if (Utils::IsFileExist(themeFlagB)) { + iconDirs = GetRootDir(themeIconsB); + } else { + if (Utils::IsFileExist(ReplaceUserIdInPath(absoluteThemeFlagA, userId))) { + iconDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeIconsA, userId)); + } else if (Utils::IsFileExist(ReplaceUserIdInPath(absoluteThemeFlagB, userId))) { + iconDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeIconsB, userId)); + } else { + RESMGR_HILOGE(RESMGR_TAG, "LoadThemesRes failed, userId = %{public}d, bundleName = %{public}s", + userId, bundleName.c_str()); + } + } + LoadThemeIconsResource(bundleName, moduleName, iconDirs, userId); +} + void ThemePackManager::LoadSAThemeRes(const std::string &bundleName, const std::string &moduleName, int32_t userId, std::vector &rootDirs, std::vector &iconDirs) { @@ -166,8 +187,10 @@ void ThemePackManager::LoadSAThemeRes(const std::string &bundleName, const std:: } else if (Utils::IsFileExist(ReplaceUserIdInPath(absoluteThemeFlagB, userId))) { rootDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeSkinB, userId)); iconDirs = GetRootDir(ReplaceUserIdInPath(absoluteThemeIconsB, userId)); + } else { + RESMGR_HILOGE(RESMGR_TAG, "LoadThemesRes failed, userId = %{public}d, bundleName = %{public}s", + userId, bundleName.c_str()); } - return; } const std::string ThemePackManager::ReplaceUserIdInPath(const std::string &originalPath, int32_t userId) diff --git a/interfaces/inner_api/include/res_config.h b/interfaces/inner_api/include/res_config.h index 3eb17bd..d8c0af9 100644 --- a/interfaces/inner_api/include/res_config.h +++ b/interfaces/inner_api/include/res_config.h @@ -49,6 +49,8 @@ public: virtual void SetThemeId(uint32_t themeId) = 0; + virtual void SetThemeIcon(bool isIcon) = 0; + #ifdef SUPPORT_GRAPHICS virtual const Locale *GetLocaleInfo() const = 0; #endif @@ -67,6 +69,8 @@ public: virtual uint32_t GetThemeId() const = 0; + virtual bool GetThemeIcon() const = 0; + virtual bool Copy(ResConfig &other, bool isRead = false) = 0; virtual void SetInputDevice(InputDevice inputDevice) = 0; -- Gitee