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 #ifndef OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H 16 #define OHOS_RESOURCE_MANAGER_RESCONFIG_IMPL_H 17 18 #include <stdint.h> 19 #include "res_locale.h" 20 #include "res_common.h" 21 #include "res_config.h" 22 23 #ifdef SUPPORT_GRAPHICS 24 using icu::Locale; 25 #endif 26 namespace OHOS { 27 namespace Global { 28 namespace Resource { 29 class ResConfigImpl : public ResConfig { 30 public: 31 ResConfigImpl(); 32 33 /** 34 * Whether this resConfig more match request resConfig 35 * @param other the other resConfig 36 * @param request the request resConfig 37 * @param density the input screen density 38 * @return true if this resConfig more match request resConfig than other resConfig, else false 39 */ 40 bool IsMoreSuitable(const ResConfigImpl *other, const ResConfigImpl *request, uint32_t density = 0) const; 41 42 /** 43 * Set locale information 44 * @param language the locale language 45 * @param script the locale script 46 * @param region the locale region 47 * @return SUCCESS if set locale information success, else false 48 */ 49 RState SetLocaleInfo(const char *language, const char *script, const char *region); 50 51 #ifdef SUPPORT_GRAPHICS 52 RState SetLocaleInfo(Locale &localeInfo); 53 #endif 54 /** 55 * Set resConfig device type 56 * @param deviceType the device type 57 */ 58 void SetDeviceType(DeviceType deviceType); 59 60 /** 61 * Set resConfig direction 62 * @param direction the resConfig direction 63 */ 64 void SetDirection(Direction direction); 65 66 /** 67 * Set resConfig colorMode 68 * @param colorMode the resConfig colorMode 69 */ 70 void SetColorMode(ColorMode colorMode); 71 72 /** 73 * Set resConfig mcc 74 * @param mcc the resConfig mcc 75 */ 76 void SetMcc(uint32_t mcc); 77 78 /** 79 * Set resConfig mnc 80 * @param mnc the resConfig mnc 81 */ 82 void SetMnc(uint32_t mnc); 83 84 /** 85 * Set resConfig screenDensity 86 * @param screenDensity the resConfig screenDensity 87 */ 88 void SetScreenDensity(float screenDensity); 89 90 #ifdef SUPPORT_GRAPHICS 91 const Locale *GetLocaleInfo() const; 92 #endif 93 94 const ResLocale *GetResLocale() const; 95 96 Direction GetDirection() const; 97 98 float GetScreenDensity() const; 99 100 ColorMode GetColorMode() const; 101 102 uint32_t GetMcc() const; 103 104 uint32_t GetMnc() const; 105 106 DeviceType GetDeviceType() const; 107 108 /** 109 * Whether this resConfig match other resConfig 110 * @param other the other resConfig 111 * @return true if this resConfig match other resConfig, else false 112 */ 113 bool Match(const ResConfigImpl *other) const; 114 115 /** 116 * Copy other resConfig to this resConfig 117 * @param other the other resConfig 118 * @return true if copy other resConfig to this resConfig success, else false 119 */ 120 bool Copy(ResConfig &other); 121 122 /** 123 * Complete the local script 124 */ 125 void CompleteScript(); 126 127 /** 128 * Whether this resLocal script completed 129 * @return true if resLocal script completed, else false 130 */ 131 bool IsCompletedScript() const; 132 133 /** 134 * Set resConfig input device 135 * @param inputDevice the resConfig input device 136 */ 137 void SetInputDevice(InputDevice inputDevice); 138 139 /** 140 * Get resConfig input device 141 * @return the resConfig input device 142 */ 143 InputDevice GetInputDevice() const; 144 145 /** 146 * Matching screen density by screen density ratio 147 * @return ScreenDensity 148 */ 149 ScreenDensity ConvertDensity(float density); 150 151 virtual ~ResConfigImpl(); 152 153 private: 154 bool IsMoreSpecificThan(const ResConfigImpl *other, uint32_t density = 0) const; 155 156 bool CopyLocale(ResConfig &other); 157 158 bool IsMccMncMatch(uint32_t mcc, uint32_t mnc) const; 159 160 bool IsDirectionMatch(Direction direction) const; 161 162 bool IsDeviceTypeMatch(DeviceType deviceType) const; 163 164 bool IsColorModeMatch(ColorMode colorMode) const; 165 166 bool IsInputDeviceMatch(InputDevice inputDevice) const; 167 168 int IsMccMncMoreSuitable(uint32_t otherMcc, uint32_t otherMnc, uint32_t requestMcc, uint32_t requestMnc) const; 169 170 int IsDensityMoreSuitable(ScreenDensity otherDensity, ScreenDensity requestDensity, uint32_t density = 0) const; 171 172 bool IsDensityMoreSuitable(int thisDistance, int otherDistance) const; 173 174 int IsDensityMoreSpecificThan(ScreenDensity otherDensity, uint32_t density = 0) const; 175 private: 176 ResLocale *resLocale_; 177 Direction direction_; 178 float density_; 179 ScreenDensity screenDensityDpi_; 180 ColorMode colorMode_; 181 uint32_t mcc_; 182 uint32_t mnc_; 183 DeviceType deviceType_; 184 InputDevice inputDevice_; 185 #ifdef SUPPORT_GRAPHICS 186 Locale *localeInfo_; 187 #endif 188 bool isCompletedScript_; 189 }; 190 } // namespace Resource 191 } // namespace Global 192 } // namespace OHOS 193 #endif