• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 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 #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/text/text_pattern.h"
28 #include "core/components_ng/pattern/texttimer/text_timer_event_hub.h"
29 #include "core/components_ng/pattern/texttimer/text_timer_layout_property.h"
30 #include "core/components_ng/property/property.h"
31 #include "core/components_ng/render/paragraph.h"
32 
33 namespace OHOS::Ace::NG {
34 class TextTimerPattern : public TextPattern {
35     DECLARE_ACE_TYPE(TextTimerPattern, TextPattern);
36 
37 public:
38     TextTimerPattern();
39     ~TextTimerPattern() override = default;
40 
CreateLayoutProperty()41     RefPtr<LayoutProperty> CreateLayoutProperty() override
42     {
43         return MakeRefPtr<TextTimerLayoutProperty>();
44     }
45 
CreateEventHub()46     RefPtr<EventHub> CreateEventHub() override
47     {
48         return MakeRefPtr<TextTimerEventHub>();
49     }
50 
GetTextTimerController()51     RefPtr<TextTimerController> GetTextTimerController() const
52     {
53         return textTimerController_;
54     }
55 
56 private:
57     void OnModifyDone() override;
58     void Tick(uint64_t duration);
59     void InitTextTimerController();
60 
61     void InitTimerDisplay();
62     void UpdateTextTimer(uint32_t elapsedTime);
63     void FireChangeEvent() const;
64 
65     void HandleStart();
66     void HandlePause();
67     void HandleReset();
68 
69     std::string GetFormat() const;
70     bool GetIsCountDown() const;
71     double GetInputCount() const;
72 
73     RefPtr<TextTimerController> textTimerController_;
74     RefPtr<Scheduler> scheduler_;
75     uint64_t elapsedTime_ = 0; // millisecond.
76     bool isCountDown_ = false;
77     double inputCount_ = 0.0;
78 
79     ACE_DISALLOW_COPY_AND_MOVE(TextTimerPattern);
80 };
81 } // namespace OHOS::Ace::NG
82 
83 #endif // FOUNDATION_ACE_FRAMEWORKS_CORE_COMPONENTS_NG_PATTERNS_TEXT_TIMER_PATTERN_H
84