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