1 /* 2 * Copyright (c) 2021-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 16 #ifndef FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_PATTERN_LOCK_PATTERN_LOCK_THEME_H 17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_PATTERN_LOCK_PATTERN_LOCK_THEME_H 18 #include "base/utils/utils.h" 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 #include "core/components/theme/theme_manager.h" 24 #include "core/pipeline/pipeline_base.h" 25 namespace OHOS::Ace::V2 { 26 class PatternLockTheme : public virtual Theme { 27 DECLARE_ACE_TYPE(PatternLockTheme, Theme); 28 29 public: 30 class Builder { 31 public: 32 Builder() = default; 33 ~Builder() = default; 34 35 static constexpr Dimension DEFAULT_SIDE_LENGTH = 288.0_vp; 36 static constexpr Dimension DEFAULT_CIRCLE_RADIUS = 6.0_vp; 37 static constexpr Dimension DEFAULT_PATH_STROKE_WIDTH = 12.0_vp; 38 static constexpr Dimension DEFAULT_ACTIVE_CIRCLE_RADIUS = 7.0_vp; 39 static constexpr Dimension DEFAULT_BACKGROUND_CIRCLE_RADIUS = 11.0_vp; 40 static constexpr Dimension DEFAULT_LIGHT_RING_CIRCLE_RADIUS_START = 6.0_vp; 41 static constexpr Dimension DEFAULT_LIGHT_RING_CIRCLE_RADIUS_END = 37.5_vp; 42 static constexpr Dimension DEFAULT_HOVER_CIRCLE_RADIUS = 11.0_vp; 43 static constexpr Dimension HOTSPOT_CIRCLE_RADIUS = 48.0_vp; 44 static constexpr Dimension FOCUS_PADDING_RADIUS = 2.0_vp; 45 static constexpr Dimension FOCUS_PAINT_WIDTH = 2.0_vp; 46 47 static constexpr Dimension DEFAULT_SIDE_LENGTH_API9 = 300.0_vp; 48 static constexpr Dimension DEFAULT_CIRCLE_RADIUS_API9 = 14.0_vp; 49 static constexpr Dimension DEFAULT_PATH_STROKE_WIDTH_API9 = 34.0_vp; 50 static constexpr Dimension DEFAULT_ACTIVE_CIRCLE_RADIUS_API9 = 16.0_vp; 51 static constexpr Dimension DEFAULT_BACKGROUND_CIRCLE_RADIUS_API9 = 26.0_vp; 52 Build(const RefPtr<ThemeConstants> & themeConstants)53 RefPtr<PatternLockTheme> Build(const RefPtr<ThemeConstants>& themeConstants) const 54 { 55 RefPtr<PatternLockTheme> theme = AceType::Claim(new PatternLockTheme()); 56 if (!themeConstants) { 57 return theme; 58 } 59 auto pipeline = PipelineBase::GetCurrentContext(); 60 CHECK_NULL_RETURN_NOLOG(pipeline, theme); 61 theme->wrongColor_ = Color::RED; 62 theme->correctColor_ = Color::BLUE; 63 theme->hoverColor_ = Color::BLACK; 64 theme->focusColor_ = Color::BLACK; 65 theme->lightRingRadiusStart_ = DEFAULT_LIGHT_RING_CIRCLE_RADIUS_START; 66 theme->lightRingRadiusEnd_ = DEFAULT_LIGHT_RING_CIRCLE_RADIUS_END; 67 theme->hoverRadius_ = DEFAULT_HOVER_CIRCLE_RADIUS; 68 theme->hotSpotCircleRadius_ = HOTSPOT_CIRCLE_RADIUS; 69 theme->focusPaddingRadius_ = FOCUS_PADDING_RADIUS; 70 theme->focusPaintWidth_ = FOCUS_PAINT_WIDTH; 71 if (pipeline->GetMinPlatformVersion() < static_cast<int32_t>(PlatformVersion::VERSION_TEN)) { 72 theme->regularColor_ = Color::BLACK; 73 theme->activeColor_ = Color::BLACK; 74 theme->selectedColor_ = Color::BLACK; 75 theme->pathColor_ = Color::BLUE; 76 theme->sideLength_ = DEFAULT_SIDE_LENGTH_API9; 77 theme->circleRadius_ = DEFAULT_CIRCLE_RADIUS_API9; 78 theme->pathStrokeWidth_ = DEFAULT_PATH_STROKE_WIDTH_API9; 79 theme->activeCircleRadius_ = DEFAULT_ACTIVE_CIRCLE_RADIUS_API9; 80 theme->backgroundCircleRadius_ = DEFAULT_BACKGROUND_CIRCLE_RADIUS_API9; 81 } else { 82 theme->sideLength_ = DEFAULT_SIDE_LENGTH; 83 theme->circleRadius_ = DEFAULT_CIRCLE_RADIUS; 84 theme->pathStrokeWidth_ = DEFAULT_PATH_STROKE_WIDTH; 85 theme->activeCircleRadius_ = DEFAULT_ACTIVE_CIRCLE_RADIUS; 86 theme->backgroundCircleRadius_ = DEFAULT_BACKGROUND_CIRCLE_RADIUS; 87 ParsePattern(themeConstants->GetThemeStyle(), theme); 88 } 89 return theme; 90 } 91 ParsePattern(const RefPtr<ThemeStyle> & themeStyle,const RefPtr<PatternLockTheme> & theme)92 void ParsePattern(const RefPtr<ThemeStyle>& themeStyle, const RefPtr<PatternLockTheme>& theme) const 93 { 94 if (themeStyle == nullptr || theme == nullptr) { 95 return; 96 } 97 auto pattern = themeStyle->GetAttr<RefPtr<ThemeStyle>>(THEME_PATTERN_PATTERN_LOCK, nullptr); 98 if (pattern) { 99 theme->regularColor_ = pattern->GetAttr<Color>("regular_color", Color::BLACK); 100 theme->activeColor_ = pattern->GetAttr<Color>("selected_color", Color::BLACK); 101 theme->selectedColor_ = pattern->GetAttr<Color>("selected_color", Color::BLACK); 102 theme->wrongColor_ = pattern->GetAttr<Color>("wrong_color", Color::BLACK); 103 theme->correctColor_ = pattern->GetAttr<Color>("correct_color", Color::BLACK); 104 theme->pathColor_ = pattern->GetAttr<Color>("path_color", Color::BLACK); 105 theme->hoverColor_ = pattern->GetAttr<Color>("hover_color", Color::BLACK); 106 theme->focusColor_ = pattern->GetAttr<Color>("focus_color", Color::BLACK); 107 } 108 } 109 }; 110 ~PatternLockTheme() override = default; GetRegularColor()111 const Color& GetRegularColor() const 112 { 113 return regularColor_; 114 } GetSelectedColor()115 const Color& GetSelectedColor() const 116 { 117 return selectedColor_; 118 } GetActiveColor()119 const Color& GetActiveColor() const 120 { 121 return activeColor_; 122 } GetPathColor()123 const Color& GetPathColor() const 124 { 125 return pathColor_; 126 } 127 GetWrongColor()128 const Color& GetWrongColor() const 129 { 130 return wrongColor_; 131 } 132 GetCorrectColor()133 const Color& GetCorrectColor() const 134 { 135 return correctColor_; 136 } 137 GetHoverColor()138 const Color& GetHoverColor() const 139 { 140 return hoverColor_; 141 } 142 GetFocusColor()143 const Color& GetFocusColor() const 144 { 145 return focusColor_; 146 } 147 GetSideLength()148 Dimension GetSideLength() const 149 { 150 return sideLength_; 151 } 152 GetCircleRadius()153 Dimension GetCircleRadius() const 154 { 155 return circleRadius_; 156 } 157 GetPathStrokeWidth()158 Dimension GetPathStrokeWidth() const 159 { 160 return pathStrokeWidth_; 161 } 162 GetActiveCircleRadiusScale()163 float GetActiveCircleRadiusScale() const 164 { 165 if (!NearZero(circleRadius_.Value())) { 166 return activeCircleRadius_.Value() / circleRadius_.Value(); 167 } 168 return 1; 169 } 170 GetBackgroundRadiusScale()171 float GetBackgroundRadiusScale() const 172 { 173 if (!NearZero(circleRadius_.Value())) { 174 return backgroundCircleRadius_.Value() / circleRadius_.Value(); 175 } 176 return 1; 177 } 178 GetLightRingCircleRadiusStartScale()179 float GetLightRingCircleRadiusStartScale() const 180 { 181 if (!NearZero(circleRadius_.Value())) { 182 return lightRingRadiusStart_.Value() / circleRadius_.Value(); 183 } 184 return 1; 185 } 186 GetLightRingCircleRadiusEndScale()187 float GetLightRingCircleRadiusEndScale() const 188 { 189 if (!NearZero(circleRadius_.Value())) { 190 return lightRingRadiusEnd_.Value() / circleRadius_.Value(); 191 } 192 return 1; 193 } 194 GetHoverRadiusScale()195 float GetHoverRadiusScale() const 196 { 197 if (!NearZero(circleRadius_.Value())) { 198 return hoverRadius_.Value() / circleRadius_.Value(); 199 } 200 return 1; 201 } 202 GetHotSpotCircleRadius()203 Dimension GetHotSpotCircleRadius() const 204 { 205 return hotSpotCircleRadius_; 206 } 207 GetFocusPaddingRadius()208 Dimension GetFocusPaddingRadius() const 209 { 210 return focusPaddingRadius_; 211 } 212 GetFocusPaintWidth()213 Dimension GetFocusPaintWidth() const 214 { 215 return focusPaintWidth_; 216 } 217 218 protected: 219 PatternLockTheme() = default; 220 221 private: 222 Color regularColor_; 223 Color selectedColor_; 224 Color activeColor_; 225 Color pathColor_; 226 Color wrongColor_; 227 Color correctColor_; 228 Color hoverColor_; 229 Color focusColor_; 230 Dimension sideLength_; 231 Dimension circleRadius_; 232 Dimension pathStrokeWidth_; 233 Dimension activeCircleRadius_; 234 Dimension backgroundCircleRadius_; 235 Dimension lightRingRadiusStart_; 236 Dimension lightRingRadiusEnd_; 237 Dimension hoverRadius_; 238 Dimension hotSpotCircleRadius_; 239 Dimension focusPaddingRadius_; 240 Dimension focusPaintWidth_; 241 }; 242 } // namespace OHOS::Ace::V2 243 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_V2_PATTERN_LOCK_PATTERN_LOCK_THEME_H 244