2 * Copyright (c) 2022 CompanyNameMagicTag.
\r
3 * Licensed under the Apache License, Version 2.0 (the "License");
\r
4 * you may not use this file except in compliance with the License.
\r
5 * You may obtain a copy of the License at
\r
7 * http://www.apache.org/licenses/LICENSE-2.0
\r
9 * Unless required by applicable law or agreed to in writing, software
\r
10 * distributed under the License is distributed on an "AS IS" BASIS,
\r
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
12 * See the License for the specific language governing permissions and
\r
13 * limitations under the License.
\r
16 #include "ui_resource_image.h"
\r
17 #include "components/ui_label.h"
\r
18 #include "common/image_cache_manager.h"
\r
19 #include "MainClockView.h"
\r
20 #include "custom_utils.h"
\r
23 static MainClockView *g_pMainClockView = nullptr;
\r
25 static constexpr uint16_t FONT_DEFAULT_SIZE = 25;
\r
26 static constexpr uint16_t FONT_TEXT_SIZE = 24;
\r
27 static constexpr uint16_t STEP_LABEL_X = 100;
\r
28 static constexpr uint16_t STEP_LABEL_Y = 230;
\r
29 static constexpr uint16_t BATTERYP_LABEL_X = 315;
\r
30 static constexpr uint16_t BATTERYP_LABEL_Y = 230;
\r
31 static constexpr uint16_t TEXT_WIDTH = 60;
\r
32 static constexpr uint16_t TEXT_HEIGHT = 35;
\r
33 static constexpr uint16_t POINT_POSITION_X = 202;
\r
34 static constexpr uint16_t POINT_POSITION_Y = 16;
\r
35 static constexpr uint16_t SECOND_POINT_POSITION_Y = 16;
\r
36 static constexpr uint16_t POINT_CENTER_X = 25;
\r
37 static constexpr uint16_t POINT_CENTER_Y = 211;
\r
38 static constexpr uint16_t STEP_CHAR_NUM = 255;
\r
39 static constexpr int16_t STEP_LABLE_WIDTH = 75;
\r
40 static constexpr int16_t STEP_LABLE_SIZE = 35;
\r
41 static constexpr uint16_t WEEKLABEL_POSITION_X = 247;
\r
42 static constexpr uint16_t WEEKLABEL_POSITION_Y = 122;
\r
43 static constexpr uint16_t HEARTRATELABEL_POSITION_X = 198;
\r
44 static constexpr uint16_t HEARTRATELABEL_POSITION_Y = 330;
\r
45 static constexpr uint16_t HEARTRATE_POSITION_X = 156;
\r
46 static constexpr uint16_t HEARTRATE_POSITION_Y = 260;
\r
47 static constexpr uint16_t PROGRESS_POSITION_X = 53;
\r
48 static constexpr uint16_t PROGRESS_POSITION_Y = 54;
\r
49 static constexpr uint16_t BIGCIRCLE_POSITION_X = 202;
\r
50 static constexpr uint16_t BIGCIRCLE_POSITION_Y = 202;
\r
51 static constexpr uint16_t MEDCIRCLE_POSITION_X = 202;
\r
52 static constexpr uint16_t MEDCIRCLE_POSITION_Y = 202;
\r
53 static constexpr uint16_t SMALLCIRCLE_POSITION_X = 202;
\r
54 static constexpr uint16_t SMALLCIRCLE_POSITION_Y = 202;
\r
55 static constexpr uint16_t WEEKDAY_POSITION_X = 193;
\r
56 static constexpr uint16_t WEEKDAY_POSITION_Y = 127;
\r
58 MainClockView::MainClockView()
\r
60 GRAPHIC_LOGD("MainClockView::MainClockView\n");
\r
61 g_pMainClockView = this;
\r
64 MainClockView::~MainClockView()
\r
66 GRAPHIC_LOGD("MainClockView::~MainClockView\n");
\r
67 if (clockAnimator != nullptr) {
\r
68 clockAnimator->Stop();
\r
69 delete clockAnimator;
\r
70 clockAnimator = nullptr;
\r
72 mainSweepClock->RemoveAll();
\r
76 stepLabel = nullptr;
\r
77 delete batteryLabel;
\r
78 batteryLabel = nullptr;
\r
82 secondHand = nullptr;
\r
84 minuteHand = nullptr;
\r
88 weekLabel = nullptr;
\r
89 delete heartRateLabel;
\r
90 heartRateLabel = nullptr;
\r
92 heartRate = nullptr;
\r
94 hand24Hour = nullptr;
\r
100 bigCircle = nullptr;
\r
102 medCircle = nullptr;
\r
103 delete smallCircle;
\r
104 smallCircle = nullptr;
\r
105 Remove(mainSweepClock);
\r
106 delete mainSweepClock;
\r
107 mainSweepClock = nullptr;
\r
108 g_pMainClockView = nullptr;
\r
109 ImageCacheManager::GetInstance().UnloadAllInMultiRes(CLOCK_IAMGES);
\r
112 MainClockView *MainClockView::GetInstance(void)
\r
114 return g_pMainClockView;
\r
117 void MainClockView::InitStepValue()
\r
119 GRAPHIC_LOGD("MainClockView::InitStepValue\n");
\r
121 char stepChar[STEP_CHAR_NUM] = {0};
\r
122 if (sprintf_s(stepChar, STEP_CHAR_NUM, "%d", 115200) == -1) { // 115200: default step count
\r
123 GRAPHIC_LOGE("MainClockView::InitStepValue error\n");
\r
126 if (stepLabel == nullptr) {
\r
127 GRAPHIC_LOGE("MainClockView::InitStepValue nullptr\n");
\r
130 stepLabel->SetText(stepChar);
\r
131 stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::RELEASED);
\r
132 stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::PRESSED);
\r
133 stepLabel->SetStyleForState(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT, UIButton::INACTIVE);
\r
136 bool MainClockView::InitLabelView(void)
\r
138 stepLabel = new UILabelButton();
\r
139 if (stepLabel == nullptr) {
\r
140 GRAPHIC_LOGE("stepLabel new fail\n");
\r
143 stepLabel->SetPosition(STEP_LABEL_X, STEP_LABEL_Y);
\r
144 stepLabel->Resize(STEP_LABLE_WIDTH, STEP_LABLE_SIZE);
\r
145 stepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
\r
146 stepLabel->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT);
\r
147 stepLabel->SetTouchable(true);
\r
150 batteryLabel = new UILabel();
\r
151 if (batteryLabel == nullptr) {
\r
152 GRAPHIC_LOGE("batteryLabel new fail\n");
\r
155 batteryLabel->SetPosition(BATTERYP_LABEL_X, BATTERYP_LABEL_Y, TEXT_WIDTH, TEXT_HEIGHT);
\r
157 battery_getvolpower(&power);
\r
159 sprintf(tmp,"%d%c",power,'%');
\r
160 batteryLabel->SetText(tmp);
\r
161 batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
\r
162 batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
\r
163 batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT);
\r
165 heartRateLabel = new UILabel();
\r
166 if (heartRateLabel == nullptr) {
\r
167 GRAPHIC_LOGE("heartRateLabel new fail\n");
\r
170 heartRateLabel->SetPosition(HEARTRATELABEL_POSITION_X, HEARTRATELABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT);
\r
171 heartRateLabel->SetText("--");
\r
172 heartRateLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
\r
173 heartRateLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_DEFAULT_SIZE);
\r
174 heartRateLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_OPAQUE);
\r
176 weekLabel = new UILabel();
\r
177 if (weekLabel == nullptr) {
\r
178 GRAPHIC_LOGE("weekLabel new fail\n");
\r
181 weekLabel->SetPosition(WEEKLABEL_POSITION_X, WEEKLABEL_POSITION_Y, TEXT_WIDTH, TEXT_HEIGHT);
\r
182 weekLabel->SetText("2");
\r
183 weekLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, FONT_TEXT_SIZE);
\r
184 weekLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT);
\r
188 bool MainClockView::InitCenterCircleView(void)
\r
190 bigCircle = new Image();
\r
191 if (bigCircle == nullptr) {
\r
192 GRAPHIC_LOGE("bigCircle new fail\n");
\r
195 if (!LoadClockImage(bigCircle, CLOCK_BIGCIRCLE_IMAGE_PATH)) {
\r
199 medCircle = new Image();
\r
200 if (medCircle == nullptr) {
\r
201 GRAPHIC_LOGE("medCircle new fail\n");
\r
204 if (!LoadClockImage(medCircle, CLOCK_MEDCIRCLE_IMAGE_PATH)) {
\r
208 smallCircle = new Image();
\r
209 if (smallCircle == nullptr) {
\r
210 GRAPHIC_LOGE("smallCircle new fail\n");
\r
213 if (!LoadClockImage(smallCircle, CLOCK_CIRCLE_IMAGE_PATH)) {
\r
219 bool MainClockView::InitHandView(void)
\r
221 secondHand = new Image();
\r
222 if (secondHand == nullptr) {
\r
223 GRAPHIC_LOGE("secondHand new fail\n");
\r
226 if (!LoadClockImage(secondHand, CLOCK_SECONDHAND)) {
\r
230 minuteHand = new Image();
\r
231 if (minuteHand == nullptr) {
\r
232 GRAPHIC_LOGE("minuteHand new fail\n");
\r
235 if (!LoadClockImage(minuteHand, CLOCK_MINUTEHAND)) {
\r
238 hourHand = new Image();
\r
239 if (hourHand == nullptr) {
\r
240 GRAPHIC_LOGE("hourHand new fail\n");
\r
243 if (!LoadClockImage(hourHand, CLOCK_HOURHAND)) {
\r
247 hand24Hour = new Image();
\r
248 if (hand24Hour == nullptr) {
\r
249 GRAPHIC_LOGE("hand24Hour new fail\n");
\r
252 if (!LoadClockImage(hand24Hour, CLOCK_HAND24HOUR_IMAGE_PATH)) {
\r
258 bool MainClockView::LoadClockImage(Image *view, uint32_t resId)
\r
260 std::string file = CLOCK_IAMGES;
\r
261 ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file);
\r
262 if (image == nullptr) {
\r
263 GRAPHIC_LOGE("LoadClockImage %x fail\n", resId);
\r
266 view->SetSrc(image);
\r
270 bool MainClockView::LoadClockImage(UIImageView *view, uint32_t resId)
\r
272 std::string file = CLOCK_IAMGES;
\r
273 ImageInfo* image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file);
\r
274 if (image == nullptr) {
\r
275 GRAPHIC_LOGE("LoadClockImage %x fail\n", resId);
\r
278 view->SetSrc(image);
\r
282 bool MainClockView::InitSweepClock(void)
\r
284 curFace = new UIImageView();
\r
285 if (curFace == nullptr) {
\r
286 GRAPHIC_LOGE("curFace new fail\n");
\r
289 curFace->SetPosition(0, 0);
\r
291 if (!LoadClockImage(curFace, CLOCK_MAIN_FACE_IMAGE)) {
\r
295 if (!InitLabelView()) {
\r
298 if (!InitCenterCircleView()) {
\r
301 heartRate = new UIImageView();
\r
302 if (heartRate == nullptr) {
\r
303 GRAPHIC_LOGE("heartRate new fail\n");
\r
306 heartRate->SetPosition(HEARTRATE_POSITION_X, HEARTRATE_POSITION_Y);
\r
307 if (!LoadClockImage(heartRate, CLOCK_HEARTRATE_IMAGE_PATH)) {
\r
311 progress = new UIImageView();
\r
312 if (progress == nullptr) {
\r
313 GRAPHIC_LOGE("progress new fail\n");
\r
316 progress->SetPosition(PROGRESS_POSITION_X, PROGRESS_POSITION_Y);
\r
317 if (!LoadClockImage(progress, CLOCK_PROGRESS_IMAGE_PATH)) {
\r
322 weekDay = new UIImageView();
\r
323 if (weekDay == nullptr) {
\r
324 GRAPHIC_LOGE("weekDay new fail\n");
\r
327 weekDay->SetPosition(WEEKDAY_POSITION_X, WEEKDAY_POSITION_Y);
\r
328 if (!LoadClockImage(weekDay, CLOCK_THURSDAY_IMAGE_PATH)) {
\r
334 bool MainClockView::InitView()
\r
336 mainSweepClock = new UISweepClock();
\r
337 if (mainSweepClock == nullptr) {
\r
338 GRAPHIC_LOGE("mainSweepClock new fail\n");
\r
341 if (!InitSweepClock()) {
\r
345 mainSweepClock->Add(curFace);
\r
346 mainSweepClock->Add(stepLabel);
\r
347 mainSweepClock->Add(heartRate);
\r
348 mainSweepClock->Add(weekLabel);
\r
349 mainSweepClock->Add(heartRateLabel);
\r
350 mainSweepClock->Add(weekDay);
\r
351 mainSweepClock->Add(progress);
\r
352 mainSweepClock->Add(batteryLabel);
\r
353 Add(mainSweepClock);
\r
355 mainSweepClock->SetDragParentInstead(true);
\r
356 mainSweepClock->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
\r
358 // {214, 3}: position x, y {14, 223}: center x, y
\r
359 mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand,
\r
360 { POINT_POSITION_X, SECOND_POINT_POSITION_Y }, { POINT_CENTER_X, POINT_CENTER_Y });
\r
361 mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand,
\r
362 { POINT_POSITION_X, POINT_POSITION_Y }, { POINT_CENTER_X, POINT_CENTER_Y });
\r
363 mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand, { POINT_POSITION_X, POINT_POSITION_Y },
\r
364 { POINT_CENTER_X, POINT_CENTER_Y });
\r
365 mainSweepClock->SetHandCircleImage(UISweepClock::HandType::SECOND_HAND, *smallCircle,
\r
366 { SMALLCIRCLE_POSITION_X, SMALLCIRCLE_POSITION_Y });
\r
367 mainSweepClock->SetHandCircleImage(UISweepClock::HandType::MINUTE_HAND, *medCircle,
\r
368 { MEDCIRCLE_POSITION_X, MEDCIRCLE_POSITION_Y });
\r
369 mainSweepClock->SetHandCircleImage(UISweepClock::HandType::HOUR_HAND, *bigCircle,
\r
370 { BIGCIRCLE_POSITION_X, BIGCIRCLE_POSITION_Y });
\r
372 mainSweepClock->SetInitTime24Hour(0, 0, 0);
\r
373 mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL);
\r
376 callBack = new ClockDialAnimatorCallback(mainSweepClock);
\r
377 if (callBack == nullptr) {
\r
378 GRAPHIC_LOGE("callBack new fail\n");
\r
381 clockAnimator = new Animator(callBack, mainSweepClock, 0, true);
\r
382 if (clockAnimator == nullptr) {
\r
383 GRAPHIC_LOGE("clockAnimator new fail\n");
\r
386 clockAnimator->Start();
\r
387 SetCoverable(true);
\r
391 void MainClockView::RefreshStep(int step)
\r
393 char stepChar[STEP_CHAR_NUM] = {0};
\r
395 (void)sprintf_s(stepChar, STEP_CHAR_NUM, "%d", step);
\r
396 stepLabel->SetText(stepChar);
\r
399 void MainClockView::RefreshHeartRate(int value)
\r
402 heartRateLabel->SetText("--");
\r
405 char heartRateChar[STEP_CHAR_NUM] = {0};
\r
407 (void)sprintf_s(heartRateChar, STEP_CHAR_NUM, "%d", value);
\r
408 heartRateLabel->SetText(heartRateChar);
\r
411 void MainClockView::InitDateTime(void)
\r
416 localtime_r(&seconds, &pTM);
\r
417 mainSweepClock->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec);
\r