• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-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_NG_PATTERNS_TEXT_TIMER_PATTERN_H
17 #define FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TIMER_PATTERN_H
18 
19 #include <string>
20 
21 #include "base/geometry/dimension.h"
22 #include "base/memory/referenced.h"
23 #include "base/utils/noncopyable.h"
24 #include "core/components/texttimer/texttimer_controller.h"
25 #include "core/components_ng/pattern/pattern.h"
26 #include "core/components_ng/pattern/text/text_layout_property.h"
27 #include "core/components_ng/pattern/texttimer/text_timer_accessibility_property.h"
28 #include "core/components_ng/pattern/texttimer/text_timer_event_hub.h"
29 #include "core/components_ng/pattern/texttimer/text_timer_layout_algorithm.h"
30 #include "core/components_ng/pattern/texttimer/text_timer_layout_property.h"
31 #include "core/components_ng/property/property.h"
32 
33 namespace OHOS::Ace::NG {
34 class TextTimerPattern : public Pattern {
35     DECLARE_ACE_TYPE(TextTimerPattern, Pattern);
36 
37 public:
38     TextTimerPattern();
39     ~TextTimerPattern() override = default;
40 
CreateLayoutProperty()41     RefPtr<LayoutProperty> CreateLayoutProperty() override
42     {
43         return MakeRefPtr<TextTimerLayoutProperty>();
44     }
45 
CreateLayoutAlgorithm()46     RefPtr<LayoutAlgorithm> CreateLayoutAlgorithm() override
47     {
48         return MakeRefPtr<TextTimerLayoutAlgorithm>();
49     }
50 
CreateAccessibilityProperty()51     RefPtr<AccessibilityProperty> CreateAccessibilityProperty() override
52     {
53         return MakeRefPtr<TextTimerAccessibilityProperty>();
54     }
55 
CreateEventHub()56     RefPtr<EventHub> CreateEventHub() override
57     {
58         return MakeRefPtr<TextTimerEventHub>();
59     }
60 
GetTextTimerController()61     RefPtr<TextTimerController> GetTextTimerController() const
62     {
63         return textTimerController_;
64     }
65 
GetTextId()66     int32_t GetTextId()
67     {
68         if (!textId_.has_value()) {
69             textId_ = ElementRegister::GetInstance()->MakeUniqueId();
70         }
71         return textId_.value();
72     }
73 
74 private:
75     void OnAttachToFrameNode() override;
76     void OnModifyDone() override;
77     void Tick(uint64_t duration);
78     void InitTextTimerController();
79 
80     void InitTimerDisplay();
81     void UpdateTextTimer(uint32_t elapsedTime);
82     void FireChangeEvent();
83 
84     void HandleStart();
85     void HandlePause();
86     void HandleReset();
87 
88     uint64_t GetFormatDuration(uint64_t duration) const;
89     uint64_t GetMillisecondsDuration(uint64_t duration) const;
90 
91     static void UpdateTextLayoutProperty(
92         RefPtr<TextTimerLayoutProperty>& layoutProperty, RefPtr<TextLayoutProperty>& textLayoutProperty);
93     std::string GetFormat() const;
94     bool GetIsCountDown() const;
95     double GetInputCount() const;
96     RefPtr<FrameNode> GetTextNode();
97     void RegisterVisibleAreaChangeCallback();
98     void OnVisibleAreaChange(bool visible);
99 
100     RefPtr<TextTimerController> textTimerController_;
101     RefPtr<Scheduler> scheduler_;
102     RefPtr<FrameNode> textNode_;
103     uint64_t elapsedTime_ = 0; // millisecond.
104     uint64_t lastElapsedTime_ = 0;
105     bool isCountDown_ = false;
106     double inputCount_ = 0.0;
107     std::optional<int32_t> textId_;
108     bool isRegisteredAreaCallback_ = false;
109 
110     ACE_DISALLOW_COPY_AND_MOVE(TextTimerPattern);
111 };
112 } // namespace OHOS::Ace::NG
113 
114 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TIMER_PATTERN_H
115