1 /*
2 * Copyright (c) 2023 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 #include "theme_pack_config.h"
16
17 #include "hap_manager.h"
18 #include "hilog_wrapper.h"
19 namespace OHOS {
20 namespace Global {
21 namespace Resource {
ThemeConfig()22 ThemeConfig::ThemeConfig() : themeDirection_(DIRECTION_NOT_SET), themeColorMode_(COLOR_MODE_NOT_SET) {}
23
SetThemeDirection(Direction direction)24 void ThemeConfig::SetThemeDirection(Direction direction)
25 {
26 this->themeDirection_ = direction;
27 }
28
SetThemeColorMode(ColorMode colorMode)29 void ThemeConfig::SetThemeColorMode(ColorMode colorMode)
30 {
31 this->themeColorMode_ = colorMode;
32 }
33
Match(const std::shared_ptr<ThemeConfig> & themeConfig,const ResConfigImpl & resConfig)34 bool ThemeConfig::Match(const std::shared_ptr<ThemeConfig> &themeConfig, const ResConfigImpl &resConfig)
35 {
36 ColorMode colorMode = resConfig.GetColorMode();
37 Direction direction = resConfig.GetDirection();
38 ColorMode themeColorMode_ = themeConfig->GetThemeColorMode();
39 Direction themeDirection_ = themeConfig->GetThemeDirection();
40 if (direction != DIRECTION_NOT_SET && themeDirection_ != DIRECTION_NOT_SET) {
41 if (direction != themeDirection_) {
42 return false;
43 }
44 }
45
46 if (colorMode != COLOR_MODE_NOT_SET && themeColorMode_ != COLOR_MODE_NOT_SET) {
47 if (colorMode != themeColorMode_) {
48 return false;
49 }
50 }
51 return true;
52 }
53
BestMatch(const std::shared_ptr<ThemeConfig> & themeConfig,const ResConfigImpl & resConfig) const54 bool ThemeConfig::BestMatch(const std::shared_ptr<ThemeConfig> &themeConfig, const ResConfigImpl &resConfig) const
55 {
56 ColorMode colorMode = resConfig.GetColorMode();
57 Direction direction = resConfig.GetDirection();
58 ColorMode themeColorMode_ = themeConfig->GetThemeColorMode();
59 Direction themeDirection_ = themeConfig->GetThemeDirection();
60 if (this->themeDirection_ != themeDirection_ && direction != DIRECTION_NOT_SET) {
61 return this->themeDirection_ != DIRECTION_NOT_SET;
62 }
63
64 if (this->themeColorMode_ != themeColorMode_ && colorMode != COLOR_MODE_NOT_SET) {
65 return this->themeColorMode_ != COLOR_MODE_NOT_SET;
66 }
67 return this->IsMoreMatchThan(themeConfig);
68 }
69
IsMoreMatchThan(const std::shared_ptr<ThemeConfig> & themeConfig) const70 bool ThemeConfig::IsMoreMatchThan(const std::shared_ptr<ThemeConfig> &themeConfig) const
71 {
72 if (this->themeDirection_ != themeConfig->themeDirection_) {
73 return this->themeDirection_ != DIRECTION_NOT_SET;
74 }
75
76 if (this->themeColorMode_ != themeConfig->themeColorMode_) {
77 return this->themeColorMode_ != COLOR_MODE_NOT_SET;
78 }
79
80 return true;
81 }
82 } // namespace Resource
83 } // namespace Global
84 } // namespace OHOS
85