• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_CONFIG_H
17 #define FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ACE_RES_CONFIG_H
18 
19 #include <cstdint>
20 #include <set>
21 #include <string>
22 #include <vector>
23 
24 #include "base/utils/device_config.h"
25 #include "base/utils/device_type.h"
26 #include "base/utils/system_properties.h"
27 
28 namespace OHOS::Ace {
29 struct KeyParam;
30 
31 class AceResConfig {
32 public:
33     AceResConfig() = default;
34     ~AceResConfig() = default;
35     AceResConfig(const AceResConfig& config) = default;
36     AceResConfig& operator=(const AceResConfig& config) = default;
AceResConfig(const std::string & language,const std::string & script,const std::string & region)37     AceResConfig(const std::string& language, const std::string& script, const std::string& region)
38         : language_(language), script_(script), region_(region)
39     {}
40 
AceResConfig(int32_t mcc,int32_t mnc,DeviceOrientation orientation,ColorMode colorMode,DeviceType deviceType,ResolutionType resolution)41     AceResConfig(int32_t mcc, int32_t mnc, DeviceOrientation orientation, ColorMode colorMode, DeviceType deviceType,
42         ResolutionType resolution)
43         : mcc_(mcc), mnc_(mnc), orientation_(orientation), colorMode_(colorMode), deviceType_(deviceType),
44           resolution_(resolution)
45     {}
46 
AceResConfig(const std::string & language,const std::string & script,const std::string & region,LongScreenType screenLong,ScreenShape screenShape,DeviceOrientation orientation,ColorMode colorMode,DeviceType deviceType,ResolutionType resolution)47     AceResConfig(const std::string& language, const std::string& script, const std::string& region,
48         LongScreenType screenLong, ScreenShape screenShape, DeviceOrientation orientation, ColorMode colorMode,
49         DeviceType deviceType, ResolutionType resolution)
50         : language_(language), script_(script), region_(region), screenLong_(screenLong), screenShape_(screenShape),
51           orientation_(orientation), colorMode_(colorMode), deviceType_(deviceType), resolution_(resolution)
52     {}
53 
54     bool operator==(const AceResConfig& other) const;
55 
56     static std::vector<std::string> GetLocaleFallback(
57         const std::string& localeTag, const std::vector<std::string>& localeList);
58     static std::vector<std::string> GetResourceFallback(const std::vector<std::string>& resourceList);
59     static std::vector<std::string> GetStyleResourceFallback(const std::vector<std::string>& resourceList);
60     static std::vector<std::string> GetDeclarativeResourceFallback(const std::set<std::string>& resourceList);
61     static std::string GetCurrentDeviceResTag();
62     static std::string GetCurrentDeviceDeclarativeResTag();
63     static double GetTargetMediaScaleRatio(const std::string& targetResTag);
64 
65     static void MatchAndSortI18nConfigs(const std::vector<std::string>& candidatesFiles,
66         const std::string& devicesLocaleTag, std::vector<std::string>& fileList);
67     static void MatchAndSortResConfigs(const std::vector<std::string>& candidateFiles,
68         const std::string& deviceConfigTag, std::vector<std::string>& viableFileList, bool styleRes = false);
69     static void MatchAndSortStyleResConfigs(const std::vector<std::string>& candidateFiles,
70         const std::string& deviceConfigTag, std::vector<std::string>& viableFileList);
71     static void MatchAndSortDeclarativeResConfigs(const std::set<std::string>& candidateFolders,
72         const std::string& deviceConfigTag, std::vector<std::string>& viableFileList);
73     bool ParseConfig(const std::vector<KeyParam>& keyParams);
74     static ResolutionType GetResolutionType(double resolution);
75     static LongScreenType GetLongScreenType(double resolution);
76     static AceResConfig ConvertResTagToConfig(const std::string& deviceResConfigTag, bool styleRes);
77     static AceResConfig ConvertDeclarativeResTagToConfig(const std::string& deviceResConfigTag);
78     static std::string ConvertResConfigToTag(const AceResConfig& resConfig, bool styleRes);
79     static std::string ConvertDeclarativeResConfigToTag(const AceResConfig& resConfig);
80 
81     std::string language_;
82     std::string script_;
83     std::string region_;
84     int32_t mcc_ = MCC_UNDEFINED;
85     int32_t mnc_ = MNC_UNDEFINED;
86     bool mncShortLen_ = false;
87     LongScreenType screenLong_ = LongScreenType::LONG_SCREEN_UNDEFINED;
88     ScreenShape screenShape_ = ScreenShape::SCREEN_SHAPE_UNDEFINED;
89     DeviceOrientation orientation_ = DeviceOrientation::ORIENTATION_UNDEFINED;
90     ColorMode colorMode_ = ColorMode::COLOR_MODE_UNDEFINED;
91     DeviceType deviceType_ = DeviceType::UNKNOWN;
92     ResolutionType resolution_ = ResolutionType::RESOLUTION_NONE;
93 };
94 
95 } // namespace OHOS::Ace
96 
97 #endif // FOUNDATION_ACE_FRAMEWORKS_BASE_RESOURCE_ACE_RES_CONFIG_H