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 #ifndef OHOS_RESOURCE_MANAGER_RESCONFIG_H
16 #define OHOS_RESOURCE_MANAGER_RESCONFIG_H
17 
18 #ifdef SUPPORT_GRAPHICS
19 #include <unicode/locid.h>
20 #endif
21 #include <vector>
22 #include "res_common.h"
23 #include "rstate.h"
24 #ifdef SUPPORT_GRAPHICS
25 using icu::Locale;
26 #endif
27 namespace OHOS {
28 namespace Global {
29 namespace Resource {
30 class ResConfig {
31 public:
32     virtual RState SetLocaleInfo(const char *language, const char *script, const char *region) = 0;
33 
34 #ifdef SUPPORT_GRAPHICS
35     virtual RState SetLocaleInfo(Locale &localeInfo) = 0;
36 #endif
37 
38     virtual void SetDeviceType(DeviceType deviceType) = 0;
39 
40     virtual void SetDirection(Direction direction) = 0;
41 
42     virtual void SetScreenDensity(float screenDensity) = 0;
43 
44     virtual void SetColorMode(ColorMode colorMode) = 0;
45 
46     virtual void SetMcc(uint32_t mcc) = 0;
47 
48     virtual void SetMnc(uint32_t mnc) = 0;
49 
50     virtual void SetThemeId(uint32_t themeId) = 0;
51 
52 #ifdef SUPPORT_GRAPHICS
53     virtual const Locale *GetLocaleInfo() const = 0;
54 #endif
55 
56     virtual Direction GetDirection() const = 0;
57 
58     virtual float GetScreenDensity() const = 0;
59 
60     virtual DeviceType GetDeviceType() const = 0;
61 
62     virtual ColorMode GetColorMode() const = 0;
63 
64     virtual uint32_t GetMcc() const = 0;
65 
66     virtual uint32_t GetMnc() const = 0;
67 
68     virtual uint32_t GetThemeId() const = 0;
69 
70     virtual bool Copy(ResConfig &other, bool isRead = false) = 0;
71 
72     virtual void SetInputDevice(InputDevice inputDevice) = 0;
73 
74     virtual InputDevice GetInputDevice() const = 0;
75 
76     virtual ScreenDensity ConvertDensity(float density) = 0;
77 
~ResConfig()78     virtual ~ResConfig() {}
79 
80 #ifdef SUPPORT_GRAPHICS
81     virtual const Locale *GetPreferredLocaleInfo() const = 0;
82 
83     virtual RState SetPreferredLocaleInfo(Locale &preferredLocaleInfo) = 0;
84 #endif
85 
86     virtual void SetScreenDensityDpi(ScreenDensity screenDensityDpi) = 0;
87 
88     virtual RState SetLocaleInfo(const char *localeStr) = 0;
89 
90     virtual ScreenDensity GetScreenDensityDpi() const = 0;
91 
92     virtual void SetAppColorMode(bool isAppColorMode) = 0;
93 
94     virtual bool GetAppColorMode() const = 0;
95 
96     virtual bool GetAppDarkRes() const = 0;
97 };
98 
99 EXPORT_FUNC ResConfig *CreateResConfig();
100 
101 EXPORT_FUNC ResConfig *CreateDefaultResConfig();
102 
103 #ifdef SUPPORT_GRAPHICS
104 EXPORT_FUNC const Locale *GetSysDefault();
105 
106 EXPORT_FUNC void UpdateSysDefault(const Locale &localeInfo, bool needNotify);
107 
108 EXPORT_FUNC Locale *BuildFromString(const char *str, char sep, RState &rState);
109 
110 EXPORT_FUNC Locale *BuildFromParts(const char *language, const char *script, const char *region, RState &rState);
111 #endif
112 
113 void FindAndSort(const std::string localeStr, std::vector<std::string> &candidateLocale,
114     std::vector<std::string> &outValue);
115 } // namespace Resource
116 } // namespace Global
117 } // namespace OHOS
118 #endif