1 /* 2 * Copyright (c) 2021-2022 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_FRAMEWORKS_CORE_COMPONENTS_THEME_RESOURCE_ADAPTER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_RESOURCE_ADAPTER_H 18 19 #include "base/image/pixel_map.h" 20 #include "base/utils/resource_configuration.h" 21 #include "core/components/theme/theme_style.h" 22 namespace OHOS::Ace { 23 24 struct RawfileDescription { 25 // the rawfile fd 26 int fd = 0; 27 // the offset from where the rawfile starts in the hap 28 long offset = 0; 29 // the length of the rawfile in the hap 30 long length = 0; 31 }; 32 33 class ResourceAdapter : public virtual AceType { 34 DECLARE_ACE_TYPE(ResourceAdapter, AceType); 35 36 public: 37 ResourceAdapter() = default; 38 ~ResourceAdapter() override = default; 39 40 static RefPtr<ResourceAdapter> Create(); 41 Init(const ResourceInfo & resourceInfo)42 virtual void Init(const ResourceInfo& resourceInfo) {} 43 UpdateConfig(const ResourceConfiguration & config)44 virtual void UpdateConfig(const ResourceConfiguration& config) {} 45 GetTheme(int32_t themeId)46 virtual RefPtr<ThemeStyle> GetTheme(int32_t themeId) 47 { 48 return nullptr; 49 } 50 51 virtual Color GetColor(uint32_t resId) = 0; 52 GetColorByName(const std::string & resName)53 virtual Color GetColorByName(const std::string& resName) 54 { 55 return {}; 56 } 57 58 virtual Dimension GetDimension(uint32_t resId) = 0; 59 GetDimensionByName(const std::string & resName)60 virtual Dimension GetDimensionByName(const std::string& resName) 61 { 62 return {}; 63 } 64 65 virtual std::string GetString(uint32_t resId) = 0; 66 GetStringByName(const std::string & resName)67 virtual std::string GetStringByName(const std::string& resName) 68 { 69 return {}; 70 } 71 72 virtual std::vector<std::string> GetStringArray(uint32_t resId) const = 0; 73 GetStringArrayByName(const std::string & resName)74 virtual std::vector<std::string> GetStringArrayByName(const std::string& resName) const 75 { 76 return {}; 77 } 78 79 virtual double GetDouble(uint32_t resId) = 0; 80 GetDoubleByName(const std::string & resName)81 virtual double GetDoubleByName(const std::string& resName) 82 { 83 return 0.0; 84 } 85 86 virtual int32_t GetInt(uint32_t resId) = 0; 87 GetIntByName(const std::string & resName)88 virtual int32_t GetIntByName(const std::string& resName) 89 { 90 return 0; 91 } 92 GetPluralString(uint32_t resId,int quantity)93 virtual std::string GetPluralString(uint32_t resId, int quantity) 94 { 95 return {}; 96 } 97 GetPluralStringByName(const std::string & resName,int quantity)98 virtual std::string GetPluralStringByName(const std::string& resName, int quantity) 99 { 100 return {}; 101 } 102 GetPixelMap(uint32_t resId)103 virtual std::shared_ptr<Media::PixelMap> GetPixelMap(uint32_t resId) 104 { 105 return nullptr; 106 } 107 GetMediaPath(uint32_t resId)108 virtual std::string GetMediaPath(uint32_t resId) 109 { 110 return {}; 111 } 112 GetMediaPathByName(const std::string & resName)113 virtual std::string GetMediaPathByName(const std::string& resName) 114 { 115 return {}; 116 } 117 GetRawfile(const std::string & fileName)118 virtual std::string GetRawfile(const std::string& fileName) 119 { 120 return {}; 121 } 122 GetRawFileData(const std::string & rawFile,size_t & len,std::unique_ptr<uint8_t[]> & dest)123 virtual bool GetRawFileData(const std::string& rawFile, size_t& len, std::unique_ptr<uint8_t[]>& dest) 124 { 125 return false; 126 } 127 GetRawFileData(const std::string & rawFile,size_t & len,std::unique_ptr<uint8_t[]> & dest,const std::string & bundleName,const std::string & moduleName)128 virtual bool GetRawFileData(const std::string& rawFile, size_t& len, std::unique_ptr<uint8_t[]>& dest, 129 const std::string& bundleName, const std::string& moduleName) 130 { 131 return false; 132 } 133 GetMediaData(uint32_t resId,size_t & len,std::unique_ptr<uint8_t[]> & dest)134 virtual bool GetMediaData(uint32_t resId, size_t& len, std::unique_ptr<uint8_t[]>& dest) 135 { 136 return false; 137 } 138 GetMediaData(uint32_t resId,size_t & len,std::unique_ptr<uint8_t[]> & dest,const std::string & bundleName,const std::string & moduleName)139 virtual bool GetMediaData(uint32_t resId, size_t& len, std::unique_ptr<uint8_t[]>& dest, 140 const std::string& bundleName, const std::string& moduleName) 141 { 142 return false; 143 } 144 GetMediaData(const std::string & resName,size_t & len,std::unique_ptr<uint8_t[]> & dest)145 virtual bool GetMediaData(const std::string& resName, size_t& len, std::unique_ptr<uint8_t[]>& dest) 146 { 147 return false; 148 } 149 GetMediaData(const std::string & resName,size_t & len,std::unique_ptr<uint8_t[]> & dest,const std::string & bundleName,const std::string & moduleName)150 virtual bool GetMediaData(const std::string& resName, size_t& len, std::unique_ptr<uint8_t[]>& dest, 151 const std::string& bundleName, const std::string& moduleName) 152 { 153 return false; 154 } 155 GetBoolean(uint32_t resId)156 virtual bool GetBoolean(uint32_t resId) const 157 { 158 return false; 159 } 160 GetBooleanByName(const std::string & resName)161 virtual bool GetBooleanByName(const std::string& resName) const 162 { 163 return false; 164 } 165 GetIntArray(uint32_t resId)166 virtual std::vector<uint32_t> GetIntArray(uint32_t resId) const 167 { 168 return {}; 169 } 170 GetIntArrayByName(const std::string & resName)171 virtual std::vector<uint32_t> GetIntArrayByName(const std::string& resName) const 172 { 173 return {}; 174 } 175 GetResource(uint32_t resId,std::ostream & dest)176 virtual bool GetResource(uint32_t resId, std::ostream& dest) const 177 { 178 return false; 179 } 180 GetResource(const std::string & resId,std::ostream & dest)181 virtual bool GetResource(const std::string& resId, std::ostream& dest) const 182 { 183 return false; 184 } 185 GetIdByName(const std::string & resName,const std::string & resType,uint32_t & resId)186 virtual bool GetIdByName(const std::string& resName, const std::string& resType, uint32_t& resId) const 187 { 188 return false; 189 } 190 UpdateResourceManager(const std::string & bundleName,const std::string & moduleName)191 virtual void UpdateResourceManager(const std::string& bundleName, const std::string& moduleName) {} 192 GetRawFileDescription(const std::string & rawfileName,RawfileDescription & rawfileDescription)193 virtual bool GetRawFileDescription(const std::string& rawfileName, RawfileDescription& rawfileDescription) const 194 { 195 return false; 196 } 197 GetMediaById(const int32_t & resId,std::string & mediaPath)198 virtual bool GetMediaById(const int32_t& resId, std::string& mediaPath) const 199 { 200 return false; 201 } 202 }; 203 204 } // namespace OHOS::Ace 205 206 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_THEME_RESOURCE_ADAPTER_H 207