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_abstract_clock.h 28 * 29 * @brief Declares the <b>UIAbstractClock</b> class that provides the functions related to clocks. 30 * 31 * @since 1.0 32 * @version 1.0 33 */ 34 35 #ifndef UI_ABSTRACT_CLOCK_H 36 #define UI_ABSTRACT_CLOCK_H 37 38 #include "components/ui_view_group.h" 39 40 namespace OHOS { 41 /** 42 * @brief An abstract class that contains functions for converting units of time (hour, minute, and second), 43 * setting and obtaining the time. 44 * 45 * @since 1.0 46 * @version 1.0 47 */ 48 class UIAbstractClock : public UIViewGroup { 49 public: 50 /** 51 * @brief Represents 60 seconds per minute. 52 */ 53 static constexpr uint8_t ONE_MINUTE_IN_SECOND = 60; 54 55 /** 56 * @brief Represents 60 minutes per hour. 57 */ 58 static constexpr uint8_t ONE_HOUR_IN_MINUTE = 60; 59 60 /** 61 * @brief Represents 24 hours per day. 62 */ 63 static constexpr uint8_t ONE_DAY_IN_HOUR = 24; 64 65 /** 66 * @brief Represents 12 hours every half day. 67 */ 68 static constexpr uint8_t HALF_DAY_IN_HOUR = 12; 69 70 /** 71 * @brief A default constructor used to create a <b>UIAbstractClock</b> instance. 72 * 73 * @since 1.0 74 * @version 1.0 75 */ UIAbstractClock()76 UIAbstractClock() : currentHour_(0), currentMinute_(0), currentSecond_(0), mode_(WorkMode::NORMAL) {} 77 78 /** 79 * @brief A constructor used to create a <b>UIAbstractClock</b> instance with 80 * time elements (hour, minute and second). 81 * 82 * @param hour Indicates the hour. 83 * @param minute Indicates the minute. 84 * @param second Indicates the second. 85 * @since 1.0 86 * @version 1.0 87 */ UIAbstractClock(uint8_t hour,uint8_t minute,uint8_t second)88 UIAbstractClock(uint8_t hour, uint8_t minute, uint8_t second) 89 : currentHour_(hour), currentMinute_(minute), currentSecond_(second) 90 { 91 } 92 93 /** 94 * @brief A destructor used to delete the <b>UIAbstractClock</b> instance. 95 * 96 * @since 1.0 97 * @version 1.0 98 */ ~UIAbstractClock()99 virtual ~UIAbstractClock() {} 100 101 /** 102 * @brief Obtains the view type. 103 * 104 * @return Returns <b>UI_ABSTRACT_CLOCK</b>, as defined in {@link UIViewType}. 105 * @since 1.0 106 * @version 1.0 107 */ GetViewType()108 UIViewType GetViewType() const override 109 { 110 return UI_ABSTRACT_CLOCK; 111 } 112 113 /** 114 * @brief Sets the time in 24-hour format. 115 * 116 * @param hour Indicates the hour to set, within [0, 23] after the modulo operation. 117 * @param minute Indicates the minute to set, within [0, 59] after the modulo operation. 118 * @param second Indicates the second to set, within [0, 59] after the modulo operation. 119 * @since 1.0 120 * @version 1.0 121 */ 122 void SetTime24Hour(uint8_t hour, uint8_t minute, uint8_t second); 123 124 /** 125 * @brief Sets the time in 12-hour format. 126 * 127 * @param hour Indicates the hour to set, within [0, 11] after the modulo operation. 128 * @param minute Indicates the minute to set, within [0, 59] after the modulo operation. 129 * @param second Indicates the second to set, within [0, 59] after the modulo operation. 130 * @param am Specifies whether it is in the morning. <b>true</b> indicates that it is in the morning, 131 * and <b> false</b> indicates that it is in the afternoon. 132 * @since 1.0 133 * @version 1.0 134 */ 135 void SetTime12Hour(uint8_t hour, uint8_t minute, uint8_t second, bool am); 136 137 /** 138 * @brief Obtains the current number of hours. 139 * 140 * @return Returns the current number of hours. 141 * @since 1.0 142 * @version 1.0 143 */ GetCurrentHour()144 uint8_t GetCurrentHour() const 145 { 146 return currentHour_; 147 } 148 149 /** 150 * @brief Obtains the current number of minutes. 151 * 152 * @return Returns the current number of minutes. 153 * @since 1.0 154 * @version 1.0 155 */ GetCurrentMinute()156 uint8_t GetCurrentMinute() const 157 { 158 return currentMinute_; 159 } 160 161 /** 162 * @brief Obtains the current number of seconds. 163 * 164 * @return Returns the current number of seconds. 165 * @since 1.0 166 * @version 1.0 167 */ GetCurrentSecond()168 uint8_t GetCurrentSecond() const 169 { 170 return currentSecond_; 171 } 172 173 /** 174 * @brief Increases the time by one second. 175 * 176 * @since 1.0 177 * @version 1.0 178 */ 179 void IncOneSecond(); 180 181 /** 182 * @brief Updates this clock. 183 * 184 * @param clockInit Specifies whether it is the first initialization. <b>true</b> indicates it is the first 185 * initialization, and <b> false</b> indicates the opposite case. 186 * @since 1.0 187 * @version 1.0 188 */ 189 virtual void UpdateClock(bool clockInit); 190 191 /** 192 * @brief Enumerates the working modes of this clock. 193 */ 194 enum WorkMode { 195 /** Always on (drawing not updated) */ 196 ALWAYS_ON, 197 /** Normal (drawing updated with the time change) */ 198 NORMAL, 199 }; 200 201 /** 202 * @brief Sets the working mode for this clock. 203 * 204 * @param newMode Indicates the working mode to set. For details, see {@link WorkMode}. 205 * @since 1.0 206 * @version 1.0 207 */ 208 virtual void SetWorkMode(WorkMode newMode); 209 210 /** 211 * @brief Obtains the working mode of this clock. 212 * 213 * @return Returns the working mode, as defined in {@link WorkMode}. 214 * @since 1.0 215 * @version 1.0 216 */ GetWorkMode()217 virtual WorkMode GetWorkMode() const 218 { 219 return mode_; 220 } 221 222 protected: 223 /** 224 * @brief Represents the current number of hours. 225 */ 226 uint8_t currentHour_; 227 228 /** 229 * @brief Represents the current number of minutes. 230 */ 231 uint8_t currentMinute_; 232 233 /** 234 * @brief Represents the current number of seconds. 235 */ 236 uint8_t currentSecond_; 237 238 /** 239 * @brief Represents the current working mode of this clock. 240 */ 241 WorkMode mode_; 242 }; 243 } // namespace OHOS 244 #endif // UI_ABSTRACT_CLOCK_H 245