• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FOCUS_ANIMATION_FOCUS_ANIMATION_THEME_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FOCUS_ANIMATION_FOCUS_ANIMATION_THEME_H
18 
19 #include "core/components/common/properties/color.h"
20 #include "core/components/theme/theme.h"
21 #include "core/components/theme/theme_constants.h"
22 #include "core/components/theme/theme_constants_defines.h"
23 
24 namespace OHOS::Ace {
25 
26 /**
27  * FocusAnimationTheme defines color of FocusAnimationTheme. FocusAnimationTheme should be built
28  * using FocusAnimationTheme::Builder.
29  */
30 class FocusAnimationTheme : public virtual Theme {
31     DECLARE_ACE_TYPE(FocusAnimationTheme, Theme);
32 
33 public:
34     class Builder {
35     public:
36         Builder() = default;
37         ~Builder() = default;
38 
Build(const RefPtr<ThemeConstants> & themeConstants)39         RefPtr<FocusAnimationTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const
40         {
41             RefPtr<FocusAnimationTheme> theme = AceType::Claim(new FocusAnimationTheme());
42             if (!themeConstants) {
43                 return theme;
44             }
45             theme->color_ = themeConstants->GetColor(THEME_FOCUSANIMATION_COLOR);
46             auto themeStyle = themeConstants->GetThemeStyle();
47             if (!themeStyle) {
48                 return theme;
49             }
50             auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_FOCUS_ANIMATION, nullptr);
51             if (!pattern) {
52                 LOGW("find pattern of focus_animation fail");
53                 return theme;
54             }
55             theme->color_ = pattern->GetAttr<Color>("focus_animation_color", Color::BLUE);
56             return theme;
57         }
58     };
59 
60     ~FocusAnimationTheme() override = default;
61 
GetColor()62     const Color& GetColor() const
63     {
64         return color_;
65     }
66 
67 protected:
68     FocusAnimationTheme() = default;
69 
70 private:
71     Color color_;
72 };
73 
74 } // namespace OHOS::Ace
75 
76 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_FOCUS_ANIMATION_FOCUS_ANIMATION_THEME_H
77