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_FRAMEWORKS_BASE_RESOURCE_ACE_RES_KEY_PARSER_H 17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ACE_RES_KEY_PARSER_H 18 19 #include <cstdint> 20 #include <functional> 21 #include <string> 22 #include <vector> 23 24 #include "base/resource/ace_res_data_struct.h" 25 #include "base/utils/device_config.h" 26 #include "base/utils/device_type.h" 27 #include "base/utils/noncopyable.h" 28 #include "base/utils/singleton.h" 29 #include "base/utils/system_properties.h" 30 31 namespace OHOS::Ace { 32 using parse_key_function = std::function<bool(const std::string&, std::vector<KeyParam>&)>; 33 34 class AceResKeyParser final : public Singleton<AceResKeyParser> { 35 DECLARE_SINGLETON(AceResKeyParser); 36 ACE_DISALLOW_MOVE(AceResKeyParser); 37 38 public: 39 bool Parse(const std::string& deviceResConfigTag, std::vector<KeyParam>& keyParams, bool styleRes); 40 bool DeclarativeParse(const std::string& deviceResConfigTag, std::vector<KeyParam>& keyParams); 41 std::string GetMccByValue(uint32_t value) const; 42 std::string GetMncByValue(uint32_t value) const; 43 std::string GetMncShortLenByValue(uint32_t value) const; 44 std::string GetOrientationByType(DeviceOrientation type) const; 45 std::string GetColorModeByType(ColorMode type) const; 46 std::string GetDeviceByType(DeviceType type) const; 47 std::string GetResolutionByType(ResolutionType type) const; 48 std::string GetScreenShapeByType(ScreenShape type) const; 49 std::string GetScreenLongByType(LongScreenType type) const; 50 std::string GetDeclarativeColorModeByType(ColorMode type) const; 51 52 private: 53 bool ParseMatch(const std::vector<std::string>& keys, std::vector<KeyParam>& keyParams, 54 parse_key_function functions[], int32_t funcLen, bool styleRes) const; 55 static bool ParseMcc(const std::string& key, std::vector<KeyParam>& keyParams); 56 static bool ParseMnc(const std::string& key, std::vector<KeyParam>& keyParams); 57 static bool ParseOrientation(const std::string& key, std::vector<KeyParam>& keyParams); 58 static bool ParseColorMode(const std::string& key, std::vector<KeyParam>& keyParams); 59 static bool ParseDeviceType(const std::string& key, std::vector<KeyParam>& keyParams); 60 static bool ParseResolution(const std::string& key, std::vector<KeyParam>& keyParams); 61 static bool ParseDefaults(const std::string& key, std::vector<KeyParam>& keyParams); 62 static bool ParseScreenShape(const std::string& key, std::vector<KeyParam>& keyParams); 63 static bool ParseLongScreen(const std::string& key, std::vector<KeyParam>& keyParams); 64 static bool ParseDeclarativeColorMode(const std::string& key, std::vector<KeyParam>& keyParams); 65 }; 66 67 } // namespace OHOS::Ace 68 69 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ACE_RES_KEY_PARSER_H