1 /*
2  * Copyright (c) 2024 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_CORE_COMMON_AGINGADAPATIONDIALOGTHEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMMON_AGINGADAPATIONDIALOGTHEME_H
18 
19 #include "base/utils/system_properties.h"
20 #include "core/common/container.h"
21 #include "core/components/common/layout/constants.h"
22 #include "core/components/common/layout/layout_param.h"
23 #include "core/components/common/properties/color.h"
24 #include "core/components/common/properties/edge.h"
25 #include "core/components/common/properties/radius.h"
26 #include "core/components/common/properties/text_style.h"
27 #include "core/components/theme/theme.h"
28 #include "core/components/theme/theme_constants.h"
29 #include "core/components/theme/theme_constants_defines.h"
30 
31 namespace OHOS::Ace {
32 
33 namespace {
34 constexpr int32_t GRID_COUNT = 2;
35 constexpr int32_t MAX_LINES = 6;
36 }
37 
38 class AgingAdapationDialogTheme : public virtual Theme {
39     DECLARE_ACE_TYPE(AgingAdapationDialogTheme, Theme);
40 
41 public:
42     class Builder {
43     public:
44         Builder() = default;
45         ~Builder() = default;
46 
Build(const RefPtr<ThemeConstants> & themeConstants)47         RefPtr<AgingAdapationDialogTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
48         {
49             RefPtr<AgingAdapationDialogTheme> theme = AceType::Claim(new AgingAdapationDialogTheme());
50             if (!themeConstants) {
51                 return theme;
52             }
53             // init theme from global data
54             auto themeStyle = themeConstants->GetThemeStyle();
55             if (!themeStyle) {
56                 return theme;
57             }
58             RefPtr<ThemeStyle> dialogPattern = themeConstants->GetPatternByName(THEME_PATTERN_AGING_ADAPATION_DIALOG);
59             if (!dialogPattern) {
60                 return theme;
61             }
62             theme->dialogIconColor_ = dialogPattern->GetAttr<Color>("aging_dialog_icon_primary", Color(0xff182431));
63             theme->dialogFontColor_ = dialogPattern->GetAttr<Color>("aging_dialog_font_primary", Color(0xff182431));
64             theme->bigFontSizeScale_ = dialogPattern->GetAttr<double>("big_font_size_scale", 0.0);
65             theme->largeFontSizeScale_ = dialogPattern->GetAttr<double>("large_font_size_scale", 0.0);
66             theme->maxFontSizeScale_ = dialogPattern->GetAttr<double>("max_font_size_scale", 0.0);
67             theme->bigDialogWidth_ = dialogPattern->GetAttr<double>("big_dialog_width", 0.0);
68             theme->maxDialogWidth_ = dialogPattern->GetAttr<double>("max_dialog_width", 0.0);
69             theme->idealSize_ = dialogPattern->GetAttr<Dimension>("ideal_size", 0.0_vp);
70             theme->dialogPropertyTop_ = dialogPattern->GetAttr<Dimension>("dialog_property_top", 0.0_vp);
71             theme->dialogPropertyBottom_ = dialogPattern->GetAttr<Dimension>("dialog_property_bottom", 0.0_vp);
72             theme->textPropertyLeft_ = dialogPattern->GetAttr<Dimension>("text_property_left", 0.0_vp);
73             theme->textPropertyBottom_ = dialogPattern->GetAttr<Dimension>("text_property_bottom", 0.0_vp);
74             theme->textPropertyRight_ = dialogPattern->GetAttr<Dimension>("text_property_right", 0.0_vp);
75             theme->dialogFontSize_ = dialogPattern->GetAttr<Dimension>("dialog_font_size", 0.0_fp);
76             theme->gridCount_ = GRID_COUNT;
77             theme->maxLines_ = MAX_LINES;
78             theme->dialogCornerRadius_ = dialogPattern->GetAttr<Dimension>("dialog_corner_radius_level10", 0.0_vp);
79             return theme;
80         }
81     };
82 
83     ~AgingAdapationDialogTheme() override = default;
84 
GetBigFontSizeScale()85     const double& GetBigFontSizeScale() const
86     {
87         return bigFontSizeScale_;
88     }
89 
GetLargeFontSizeScale()90     const double& GetLargeFontSizeScale() const
91     {
92         return largeFontSizeScale_;
93     }
94 
GetMaxFontSizeScale()95     const double& GetMaxFontSizeScale() const
96     {
97         return maxFontSizeScale_;
98     }
99 
GetBigDialogWidth()100     const double& GetBigDialogWidth() const
101     {
102         return bigDialogWidth_;
103     }
104 
GetMaxDialogWidth()105     const double& GetMaxDialogWidth() const
106     {
107         return maxDialogWidth_;
108     }
109 
GetIdealSize()110     const Dimension& GetIdealSize() const
111     {
112         return idealSize_;
113     }
114 
GetDialogPropertyTop()115     const Dimension& GetDialogPropertyTop() const
116     {
117         return dialogPropertyTop_;
118     }
119 
GetDialogPropertyBottom()120     const Dimension& GetDialogPropertyBottom() const
121     {
122         return dialogPropertyBottom_;
123     }
124 
GetTextPropertyLeft()125     const Dimension& GetTextPropertyLeft() const
126     {
127         return textPropertyLeft_;
128     }
129 
GetTextPropertyBottom()130     const Dimension& GetTextPropertyBottom() const
131     {
132         return textPropertyBottom_;
133     }
134 
GetTextPropertyRight()135     const Dimension& GetTextPropertyRight() const
136     {
137         return textPropertyRight_;
138     }
139 
GetDialogFontSize()140     const Dimension& GetDialogFontSize() const
141     {
142         return dialogFontSize_;
143     }
144 
GetDialogIconColor()145     const Color& GetDialogIconColor() const
146     {
147         return dialogIconColor_;
148     }
149 
GetDialogFontColor()150     const Color& GetDialogFontColor() const
151     {
152         return dialogFontColor_;
153     }
154 
GetGridCount()155     const int32_t& GetGridCount() const
156     {
157         return gridCount_;
158     }
159 
GetMaxLines()160     const int32_t& GetMaxLines() const
161     {
162         return maxLines_;
163     }
164 
GetDialogCornerRadius()165     const Dimension& GetDialogCornerRadius() const
166     {
167         return dialogCornerRadius_;
168     }
169 
170 protected:
171     AgingAdapationDialogTheme() = default;
172 
173 private:
174     double bigFontSizeScale_;
175     double largeFontSizeScale_;
176     double maxFontSizeScale_;
177     double bigDialogWidth_;
178     double maxDialogWidth_;
179     Dimension idealSize_;
180     Dimension dialogPropertyTop_;
181     Dimension dialogPropertyBottom_;
182     Dimension textPropertyLeft_;
183     Dimension textPropertyBottom_;
184     Dimension textPropertyRight_;
185     Dimension dialogFontSize_;
186     Dimension dialogCornerRadius_;
187     Color dialogIconColor_;
188     Color dialogFontColor_;
189     int32_t gridCount_;
190     int32_t maxLines_;
191 };
192 
193 } // namespace OHOS::Ace
194 
195 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIALOG_DIALOG_THEME_H
196