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_ADAPTER_OHOS_OSAL_RESOURCE_ADAPTER_IMPL_H 17 #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_RESOURCE_ADAPTER_IMPL_H 18 19 #include "resource_manager.h" 20 21 #include <mutex> 22 #include <shared_mutex> 23 24 #include "core/components/theme/resource_adapter.h" 25 26 namespace OHOS::Ace { 27 28 class ResourceAdapterImpl : public ResourceAdapter { 29 DECLARE_ACE_TYPE(ResourceAdapterImpl, ResourceAdapter); 30 public: 31 ResourceAdapterImpl() = default; 32 ~ResourceAdapterImpl() override = default; 33 34 void Init(const ResourceInfo& resourceInfo) override; 35 void Reload() override; 36 void UpdateConfig(const ResourceConfiguration& config) override; 37 38 RefPtr<ThemeStyle> GetTheme(int32_t themeId) override; 39 40 Color GetColor(uint32_t resId) override; 41 Color GetColorByName(const std::string& resName) override; 42 Dimension GetDimension(uint32_t resId) override; 43 Dimension GetDimensionByName(const std::string& resName) override; 44 std::string GetString(uint32_t resId) override; 45 std::string GetStringByName(const std::string& resName) override; 46 std::string GetPluralString(uint32_t resId, int quantity) override; 47 std::string GetPluralStringByName(const std::string& resName, int quantity) override; 48 std::vector<std::string> GetStringArray(uint32_t resId) const override; 49 std::vector<std::string> GetStringArrayByName(const std::string& resName) const override; 50 double GetDouble(uint32_t resId) override; 51 double GetDoubleByName(const std::string& resName) override; 52 int32_t GetInt(uint32_t resId) override; 53 int32_t GetIntByName(const std::string& resName) override; 54 std::vector<uint32_t> GetIntArray(uint32_t resId) const override; 55 std::vector<uint32_t> GetIntArrayByName(const std::string& resName) const override; 56 bool GetBoolean(uint32_t resId) const override; 57 bool GetBooleanByName(const std::string& resName) const override; 58 std::string GetMediaPath(uint32_t resId) override; 59 std::string GetMediaPathByName(const std::string& resName) override; 60 std::string GetRawfile(const std::string& fileName) override; 61 bool GetRawFileData(const std::string& rawFile, size_t& len, std::unique_ptr<uint8_t[]> &dest) override; 62 bool GetMediaData(uint32_t resId, size_t& len, std::unique_ptr<uint8_t[]> &dest) override; 63 bool GetMediaData(const std::string& resName, size_t& len, std::unique_ptr<uint8_t[]> &dest) override; 64 void UpdateResourceManager(const std::string& bundleName, const std::string& moduleName) override; 65 66 private: 67 std::string GetActualResourceName(const std::string& resName) const; 68 69 std::shared_ptr<Global::Resource::ResourceManager> resourceManager_; 70 std::shared_ptr<Global::Resource::ResourceManager> sysResourceManager_; 71 std::map<std::pair<std::string, std::string>, std::shared_ptr<Global::Resource::ResourceManager>> resourceManagers_; 72 std::string packagePathStr_; 73 mutable std::shared_mutex resourceMutex_; 74 std::shared_ptr<Global::Resource::ResConfig> resConfig_; 75 ACE_DISALLOW_COPY_AND_MOVE(ResourceAdapterImpl); 76 }; 77 } // namespace OHOS::Ace 78 79 #endif // FOUNDATION_ACE_ADAPTER_OHOS_OSAL_RESOURCE_ADAPTER_IMPL_H 80