• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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_ADAPTER_OHOS_OSAL_RESOURCE_ADAPTER_IMPL_V2_H
17 #define FOUNDATION_ACE_ADAPTER_OHOS_OSAL_RESOURCE_ADAPTER_IMPL_V2_H
18 
19 #include <mutex>
20 #include <shared_mutex>
21 
22 #include "resource_manager.h"
23 
24 #include "base/image/pixel_map.h"
25 #include "core/components/theme/resource_adapter.h"
26 
27 namespace OHOS::Ace {
28 class ResourceAdapterImplV2 : public ResourceAdapter {
29     DECLARE_ACE_TYPE(ResourceAdapterImplV2, ResourceAdapter);
30 
31 public:
32     ResourceAdapterImplV2() = default;
33     explicit ResourceAdapterImplV2(std::shared_ptr<Global::Resource::ResourceManager> resourceManager);
34     ResourceAdapterImplV2(
35         std::shared_ptr<Global::Resource::ResourceManager> resourceManager, const ResourceInfo& resourceInfo);
36     ~ResourceAdapterImplV2() override = default;
37 
38     void Init(const ResourceInfo& resourceInfo) override;
39     void UpdateConfig(const ResourceConfiguration& config, bool themeFlag = false) override;
40 
41     RefPtr<ThemeStyle> GetTheme(int32_t themeId) override;
42 
43     Color GetColor(uint32_t resId) override;
44     Color GetColorByName(const std::string& resName) override;
45     Dimension GetDimension(uint32_t resId) override;
46     Dimension GetDimensionByName(const std::string& resName) override;
47     std::string GetString(uint32_t resId) override;
48     std::string GetStringByName(const std::string& resName) override;
49     std::string GetPluralString(uint32_t resId, int quantity) override;
50     std::string GetPluralStringByName(const std::string& resName, int quantity) override;
51     std::vector<std::string> GetStringArray(uint32_t resId) const override;
52     std::vector<std::string> GetStringArrayByName(const std::string& resName) const override;
53     double GetDouble(uint32_t resId) override;
54     double GetDoubleByName(const std::string& resName) override;
55     int32_t GetInt(uint32_t resId) override;
56     int32_t GetIntByName(const std::string& resName) override;
57     std::vector<uint32_t> GetIntArray(uint32_t resId) const override;
58     std::vector<uint32_t> GetIntArrayByName(const std::string& resName) const override;
59     bool GetBoolean(uint32_t resId) const override;
60     bool GetBooleanByName(const std::string& resName) const override;
61     std::shared_ptr<Media::PixelMap> GetPixelMap(uint32_t resId) override;
62     std::string GetMediaPath(uint32_t resId) override;
63     std::string GetMediaPathByName(const std::string& resName) override;
64     std::string GetRawfile(const std::string& fileName) override;
65     bool GetRawFileData(const std::string& rawFile, size_t& len, std::unique_ptr<uint8_t[]>& dest) override;
66     bool GetRawFileData(const std::string& rawFile, size_t& len, std::unique_ptr<uint8_t[]>& dest,
67         const std::string& bundleName, const std::string& moduleName) override;
68     bool GetMediaData(uint32_t resId, size_t& len, std::unique_ptr<uint8_t[]>& dest) override;
69     bool GetMediaData(uint32_t resId, size_t& len, std::unique_ptr<uint8_t[]>& dest, const std::string& bundleName,
70         const std::string& moduleName) override;
71     bool GetMediaData(const std::string& resName, size_t& len, std::unique_ptr<uint8_t[]>& dest) override;
72     bool GetMediaData(const std::string& resName, size_t& len, std::unique_ptr<uint8_t[]>& dest,
73         const std::string& bundleName, const std::string& moduleName) override;
UpdateResourceManager(const std::string & bundleName,const std::string & moduleName)74     void UpdateResourceManager(const std::string& bundleName, const std::string& moduleName) override {};
75     bool GetRawFileDescription(const std::string& rawfileName, RawfileDescription& rawfileDescription) const override;
76     bool GetMediaById(const int32_t& resId, std::string& mediaPath) const override;
77     uint32_t GetResourceLimitKeys() const override;
78     uint32_t GetSymbolByName(const char* resName) const override;
79     uint32_t GetSymbolById(uint32_t resId) const override;
80     RefPtr<ThemeStyle> GetPatternByName(const std::string& patternName) override;
81 
82 private:
83     std::string GetActualResourceName(const std::string& resName) const;
84     bool NeedUpdateResConfig(const std::shared_ptr<Global::Resource::ResConfig>& oldResConfig,
85         const std::shared_ptr<Global::Resource::ResConfig>& newResConfig);
86 
GetResourceManager()87     inline std::shared_ptr<Global::Resource::ResourceManager> GetResourceManager() const
88     {
89         return sysResourceManager_;
90     }
91 
92     std::shared_ptr<Global::Resource::ResourceManager> sysResourceManager_;
93     std::string packagePathStr_;
94     std::shared_ptr<Global::Resource::ResConfig> resConfig_;
95     ACE_DISALLOW_COPY_AND_MOVE(ResourceAdapterImplV2);
96 };
97 } // namespace OHOS::Ace
98 
99 #endif
100