• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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::MakeRefPtr<AgingAdapationDialogTheme>();
50             InitTheme(theme, themeConstants);
51             return theme;
52         }
53 
54     protected:
InitTheme(const RefPtr<AgingAdapationDialogTheme> & theme,const RefPtr<ThemeConstants> & themeConstants)55         void InitTheme(
56             const RefPtr<AgingAdapationDialogTheme>& theme, const RefPtr<ThemeConstants>& themeConstants) const
57         {
58             CHECK_NULL_VOID(theme);
59             CHECK_NULL_VOID(themeConstants);
60             // init theme from global data
61             auto themeStyle = themeConstants->GetThemeStyle();
62             CHECK_NULL_VOID(themeStyle);
63             RefPtr<ThemeStyle> dialogPattern = themeConstants->GetPatternByName(THEME_PATTERN_AGING_ADAPATION_DIALOG);
64             CHECK_NULL_VOID(dialogPattern);
65             theme->dialogIconColor_ = dialogPattern->GetAttr<Color>("aging_dialog_icon_primary", Color(0xff182431));
66             theme->dialogFontColor_ = dialogPattern->GetAttr<Color>("aging_dialog_font_primary", Color(0xff182431));
67             theme->bigFontSizeScale_ = dialogPattern->GetAttr<double>("big_font_size_scale", 0.0);
68             theme->largeFontSizeScale_ = dialogPattern->GetAttr<double>("large_font_size_scale", 0.0);
69             theme->maxFontSizeScale_ = dialogPattern->GetAttr<double>("max_font_size_scale", 0.0);
70             theme->bigDialogWidth_ = dialogPattern->GetAttr<double>("big_dialog_width", 0.0);
71             theme->maxDialogWidth_ = dialogPattern->GetAttr<double>("max_dialog_width", 0.0);
72             theme->idealSize_ = dialogPattern->GetAttr<Dimension>("ideal_size", 0.0_vp);
73             theme->dialogPropertyTop_ = dialogPattern->GetAttr<Dimension>("dialog_property_top", 0.0_vp);
74             theme->dialogPropertyBottom_ = dialogPattern->GetAttr<Dimension>("dialog_property_bottom", 0.0_vp);
75             theme->textPropertyLeft_ = dialogPattern->GetAttr<Dimension>("text_property_left", 0.0_vp);
76             theme->textPropertyBottom_ = dialogPattern->GetAttr<Dimension>("text_property_bottom", 0.0_vp);
77             theme->textPropertyRight_ = dialogPattern->GetAttr<Dimension>("text_property_right", 0.0_vp);
78             theme->dialogFontSize_ = dialogPattern->GetAttr<Dimension>("dialog_font_size", 0.0_fp);
79             theme->gridCount_ = GRID_COUNT;
80             theme->maxLines_ = MAX_LINES;
81             theme->dialogCornerRadius_ = dialogPattern->GetAttr<Dimension>("dialog_corner_radius_level10", 0.0_vp);
82         }
83     };
84 
85     ~AgingAdapationDialogTheme() override = default;
86 
GetBigFontSizeScale()87     const double& GetBigFontSizeScale() const
88     {
89         return bigFontSizeScale_;
90     }
91 
GetLargeFontSizeScale()92     const double& GetLargeFontSizeScale() const
93     {
94         return largeFontSizeScale_;
95     }
96 
GetMaxFontSizeScale()97     const double& GetMaxFontSizeScale() const
98     {
99         return maxFontSizeScale_;
100     }
101 
GetBigDialogWidth()102     const double& GetBigDialogWidth() const
103     {
104         return bigDialogWidth_;
105     }
106 
GetMaxDialogWidth()107     const double& GetMaxDialogWidth() const
108     {
109         return maxDialogWidth_;
110     }
111 
GetIdealSize()112     const Dimension& GetIdealSize() const
113     {
114         return idealSize_;
115     }
116 
GetDialogPropertyTop()117     const Dimension& GetDialogPropertyTop() const
118     {
119         return dialogPropertyTop_;
120     }
121 
GetDialogPropertyBottom()122     const Dimension& GetDialogPropertyBottom() const
123     {
124         return dialogPropertyBottom_;
125     }
126 
GetTextPropertyLeft()127     const Dimension& GetTextPropertyLeft() const
128     {
129         return textPropertyLeft_;
130     }
131 
GetTextPropertyBottom()132     const Dimension& GetTextPropertyBottom() const
133     {
134         return textPropertyBottom_;
135     }
136 
GetTextPropertyRight()137     const Dimension& GetTextPropertyRight() const
138     {
139         return textPropertyRight_;
140     }
141 
GetDialogFontSize()142     const Dimension& GetDialogFontSize() const
143     {
144         return dialogFontSize_;
145     }
146 
GetDialogIconColor()147     const Color& GetDialogIconColor() const
148     {
149         return dialogIconColor_;
150     }
151 
SetDialogIconColor(const Color & color)152     void SetDialogIconColor(const Color& color)
153     {
154         dialogIconColor_ = color;
155     }
156 
GetDialogFontColor()157     const Color& GetDialogFontColor() const
158     {
159         return dialogFontColor_;
160     }
161 
SetDialogFontColor(const Color & color)162     void SetDialogFontColor(const Color& color)
163     {
164         dialogFontColor_ = color;
165     }
166 
GetGridCount()167     const int32_t& GetGridCount() const
168     {
169         return gridCount_;
170     }
171 
GetMaxLines()172     const int32_t& GetMaxLines() const
173     {
174         return maxLines_;
175     }
176 
GetDialogCornerRadius()177     const Dimension& GetDialogCornerRadius() const
178     {
179         return dialogCornerRadius_;
180     }
181 
182 protected:
183     AgingAdapationDialogTheme() = default;
184 
185 private:
186     double bigFontSizeScale_;
187     double largeFontSizeScale_;
188     double maxFontSizeScale_;
189     double bigDialogWidth_;
190     double maxDialogWidth_;
191     Dimension idealSize_;
192     Dimension dialogPropertyTop_;
193     Dimension dialogPropertyBottom_;
194     Dimension textPropertyLeft_;
195     Dimension textPropertyBottom_;
196     Dimension textPropertyRight_;
197     Dimension dialogFontSize_;
198     Dimension dialogCornerRadius_;
199     Color dialogIconColor_;
200     Color dialogFontColor_;
201     int32_t gridCount_;
202     int32_t maxLines_;
203 };
204 
205 } // namespace OHOS::Ace
206 
207 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_DIALOG_DIALOG_THEME_H
208