1 /* 2 * Copyright (c) 2025 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 FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_CLOCK_TEXT_CLOCK_THEME_WRAPPER_H 17 #define FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_CLOCK_TEXT_CLOCK_THEME_WRAPPER_H 18 19 #include <memory> 20 21 #include "base/memory/ace_type.h" 22 #include "core/components/text_clock/text_clock_theme.h" 23 #include "core/components_ng/token_theme/token_theme_wrapper.h" 24 25 namespace OHOS::Ace::NG { 26 27 class TextClockThemeWrapper : public TextClockTheme, public TokenThemeWrapper { 28 DECLARE_ACE_TYPE(TextClockThemeWrapper, TextClockTheme); 29 30 public: 31 class WrapperBuilder : public Builder { 32 public: 33 WrapperBuilder() = default; 34 ~WrapperBuilder() override = default; 35 BuildWrapper(const RefPtr<ThemeConstants> & themeConstants)36 RefPtr<TokenThemeWrapper> BuildWrapper(const RefPtr<ThemeConstants>& themeConstants) const 37 { 38 auto wrapper = AceType::MakeRefPtr<TextClockThemeWrapper>(); 39 auto theme = AceType::DynamicCast<TextClockTheme>(wrapper); 40 if (!themeConstants) { 41 return wrapper; 42 } 43 InitThemeDefaultsClock(theme); 44 ParsePattern(themeConstants, theme); 45 return wrapper; 46 } 47 }; 48 49 ~TextClockThemeWrapper() override = default; 50 ApplyTokenTheme(const TokenTheme & theme)51 void ApplyTokenTheme(const TokenTheme& theme) override 52 { 53 if (const auto& colors = theme.Colors(); colors) { 54 textStyleClock_.SetTextColor(colors->FontSecondary()); 55 } 56 } 57 58 protected: 59 TextClockThemeWrapper() = default; 60 }; 61 62 } // namespace OHOS::Ace::NG 63 #endif // FRAMEWORKS_CORE_COMPONENTS_NG_PATTERN_TEXT_CLOCK_TEXT_CLOCK_THEME_WRAPPER_H 64