• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #include "core/components/theme/app_theme.h"
17 
18 #include "core/components/theme/theme_constants_defines.h"
19 
20 namespace OHOS::Ace {
21 
Build(const RefPtr<ThemeConstants> & themeConstants) const22 RefPtr<AppTheme> AppTheme::Builder::Build(const RefPtr<ThemeConstants>& themeConstants) const
23 {
24     RefPtr<AppTheme> theme = AceType::Claim(new AppTheme());
25     if (!themeConstants) {
26         LOGI("Build AppTheme error, themeConstants is null!");
27         return theme;
28     }
29     auto themeStyle = themeConstants->GetThemeStyle();
30     if (!themeStyle) {
31         LOGI("Build AppTheme error, no theme resource, use prebuild color!");
32         theme->backgroundColor_ = themeConstants->GetColor(THEME_APP_BACKGROUND);
33         return theme;
34     }
35     if (themeStyle->HasAttr(THEME_ATTR_BG_COLOR) && !themeConstants->HasCustomStyle(THEME_APP_BACKGROUND)) {
36         // Get from resource.
37         theme->backgroundColor_ = themeStyle->GetAttr<Color>(THEME_ATTR_BG_COLOR, Color::BLACK);
38     } else {
39         // Get from prebuild or custom color.
40         theme->backgroundColor_ = themeConstants->GetColor(THEME_APP_BACKGROUND);
41     }
42     return theme;
43 }
44 
45 } // namespace OHOS::Ace
46