1 /*
2  * Copyright (c) 2020-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 /**
17  * @addtogroup UI_Components
18  * @{
19  *
20  * @brief Defines UI components such as buttons, texts, images, lists, and progress bars.
21  *
22  * @since 1.0
23  * @version 1.0
24  */
25 
26 /**
27  * @file ui_repeate_button.h
28  *
29  * @brief Defines the attributes and common functions of a repeat button.
30  *
31  * If a repeat button is clicked and hold, the click event is triggered continuously.
32  *
33  * @since 1.0
34  * @version 1.0
35  */
36 
37 #ifndef GRAPHIC_LITE_UI_REPEAT_BUTTON_H
38 #define GRAPHIC_LITE_UI_REPEAT_BUTTON_H
39 
40 #include "components/ui_button.h"
41 
42 namespace OHOS {
43 /**
44  * @brief Represents a repeat button.
45  *
46  * If a repeat button is clicked and hold, the click event is triggered continuously.
47  *
48  * @see UIButton
49  * @since 1.0
50  * @version 1.0 */
51 class UIRepeatButton : public UIButton {
52 public:
53     /**
54      * @brief A constructor used to create a <b>UIRepeatButton</b> instance.
55      *
56      * @since 1.0
57      * @version 1.0
58      */
59     UIRepeatButton();
60 
61     /**
62      * @brief A destructor used to delete the <b>UIRepeatButton</b> instance.
63      *
64      * @since 1.0
65      * @version 1.0
66      */
67     virtual ~UIRepeatButton();
68 
69     /**
70      * @brief Obtains the component type.
71      *
72      * @return Returns the component type, as defined in {@link UIViewType}.
73      * @since 1.0
74      * @version 1.0
75      */
GetViewType()76     UIViewType GetViewType() const override
77     {
78         return UI_REPEAT_BUTTON;
79     }
80 
81     /**
82      * @brief Sets the interval between two consecutive click events.
83      *
84      * @param interval Indicates the interval to set.
85 
86      * @since 1.0
87      * @version 1.0
88      */
SetInterval(uint16_t interval)89     virtual void SetInterval(uint16_t interval)
90     {
91         ticksInterval_ = interval;
92     }
93 
94     /**
95      * @brief Obtains the interval between two consecutive click events.
96      *
97      * @return Returns the interval between two consecutive click events.
98      * @since 1.0
99      * @version 1.0
100      */
GetInterval()101     virtual uint16_t GetInterval() const
102     {
103         return ticksInterval_;
104     }
105 
106     /**
107      * @fn  void UIRepeatButton::OnClickEvent(const ClickEvent& event)
108      *
109      * @brief   The action of click event.
110      *
111      * @param [in]  event   click event.
112      * @return Returns <b>true</b> if the event is consumed; returns <b>false</b> otherwise.
113      */
114     bool OnClickEvent(const ClickEvent& event) override;
115 
116     /**
117      * @fn  void UIRepeatButton::OnReleaseEvent(const ReleaseEvent& event)
118      *
119      * @brief   The action of release event.
120      *
121      * @param [in]  event   release event.
122      */
123     bool OnReleaseEvent(const ReleaseEvent& event) override;
124 
125     /**
126      * @fn  void UIRepeatButton::OnLongPressEvent(const ReleaseEvent& event)
127      *
128      * @brief   The action of long press event.
129      *
130      * @param [in]  event   long press event.
131      */
132     bool OnLongPressEvent(const LongPressEvent& event) override;
133 
134     /**
135      * @fn  void UIRepeatButton::HandleTickEvent()
136      *
137      * @brief   handle the event of long pressing.
138      */
139     void HandleTickEvent();
140 
141 private:
142     uint16_t ticksInterval_;
143     ClickEvent event_;
144     bool longPressed_;
145     static UIRepeatButton* repeatButton_;
146     uint32_t timerRepeatID_;
147 
148     void OnDraw(BufferInfo& gfxDstBuffer, const Rect& invalidatedArea) override;
149     inline void SetEvent(const ClickEvent& event);
150 };
151 } // namespace OHOS
152 
153 #endif // GRAPHIC_LITE_UI_REPEAT_BUTTON_H
154