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 "ResourceManager.h"
20 #include "TypeAttribute.h"
21 
22 #include "core/components/theme/resource_adapter.h"
23 
24 namespace OHOS::Ace {
25 
26 class ResourceAdapterImpl : public ResourceAdapter {
27     DECLARE_ACE_TYPE(ResourceAdapterImpl, ResourceAdapter);
28 
29 public:
30     ResourceAdapterImpl() = default;
31     explicit ResourceAdapterImpl(std::shared_ptr<Global::Resource::ResourceManager> resourceManager);
32     ~ResourceAdapterImpl() override = default;
33 
34     void Init(const ResourceInfo& resourceInfo) override;
35     void UpdateConfig(const ResourceConfiguration& config, bool themeFlag = false) override;
36 
37     RefPtr<ThemeStyle> GetTheme(int32_t themeId) override;
38 
39     Color GetColor(uint32_t resId) override;
40     Dimension GetDimension(uint32_t resId) override;
41     std::string GetString(uint32_t resId) override;
42     std::string GetPluralString(uint32_t resId, int quantity) override;
43     std::vector<std::string> GetStringArray(uint32_t resId) const override;
44     double GetDouble(uint32_t resId) override;
45     int32_t GetInt(uint32_t resId) override;
46     bool GetResource(uint32_t resId, std::ostream& dest) const override;
47     bool GetResource(const std::string& path, std::ostream& dest) const override;
48     bool GetIdByName(const std::string& resName, const std::string& resType, uint32_t& resId) const override;
49     std::string GetMediaPath(uint32_t resId) override;
50     std::string GetRawfile(const std::string& fileName) override;
51     uint32_t GetSymbolById(uint32_t resId) const override;
52 
53 private:
54     bool ConvertToGlobalResourceType(const std::string& resTypeName, Global::Resource::ResourceType& resType) const;
55     Global::Resource::ResourceManager resourceManger_;
56 
57     ACE_DISALLOW_COPY_AND_MOVE(ResourceAdapterImpl);
58 };
59 
60 } // namespace OHOS::Ace
61 
62 #endif // FOUNDATION_ACE_ADAPTER_PREVIEW_OSAL_RESOURCE_ADAPTER_IMPL_H
63