be8bfeee6a98cee571e166a1f034b9503464500a
[mirrors/FD230.git] /
1 /***
2  * @Date: 2024-04-15 10:55:58
3  * @LastEditors: Caisking 3449750381@qq.com
4  * @LastEditTime: 2024-08-02 09:35:58
5  * @FilePath:
6  * /FD230/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDataView.cpp
7  */
8
9 #include "traing/training_card/include/TrainingDataView.h"
10 #include "traing/training_card/include/TraingCardView.h"
11
12 #include "UiConfig.h"
13 #include "common/image_cache_manager.h"
14 #include "components/ui_button.h"
15 #include "components/ui_label_ext.h"
16 #include "custom_runtime.h"
17 #include "traing/Training_UiConfig.h"
18 #include "traing/include/TraingModel.h"
19 #include "ui_resource_image.h"
20 #include "ui_resource_string.h"
21 #include "uicomponents/UIComponents.h"
22 #include <ui_scroll_view.h>
23
24 namespace OHOS {
25
26 static TrainingDataView *g_pTrainingDataView{nullptr};
27
28 TrainingDataView::TrainingDataView() {
29   SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
30   g_pTrainingDataView = this;
31 }
32
33 TrainingDataView::~TrainingDataView() {
34   DeInit();
35   g_pTrainingDataView = nullptr;
36 }
37
38 TrainingDataView *TrainingDataView::GetInstance() {
39   return g_pTrainingDataView;
40 }
41
42 /* InitView:初始化界面*/
43 bool TrainingDataView ::InitPage() {
44   // 初始化Image
45   InitImageView(image_progress, 13, 13, 440, 386, "image1", PROGRESS_IMAGE);
46   InitImageView(image_heart, 88, 295, 50, 50, "image2", SPORT_HEARTRATE_IMAGE);
47   InitImageView(image_iconup, 225, 396, 16, 10, "image4", INCO_UP_IMAGE);
48   InitImageView(image_iconpoint, 193, 421, 80, 20, "image5", DATA_POINT_IMAGE);
49   Add(image_progress);
50   Add(image_heart);
51   Add(image_iconup);
52   Add(image_iconpoint);
53
54   // 初始化进度条
55   circleProgress = new UICircleProgress();
56   circleProgress->SetPosition(0, 0);
57   circleProgress->Resize(466, 466);
58   circleProgress->SetViewId("circleProgress");
59   circleProgress->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
60   circleProgress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
61   circleProgress->SetBackgroundStyle(STYLE_LINE_WIDTH, 12);
62   circleProgress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6);
63   circleProgress->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000);
64   circleProgress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff4fC34C);
65   circleProgress->SetForegroundStyle(STYLE_LINE_WIDTH, 10);
66   circleProgress->SetCenterPosition(235, 235);
67   circleProgress->SetRadius(215);
68   circleProgress->SetStartAngle(215);
69   circleProgress->SetEndAngle(505);
70   circleProgress->SetCapType(CAP_ROUND);
71   circleProgress->SetValue(0);
72   Add(circleProgress);
73
74   // 初始化Lable
75   UIResourceTextId sport_id = TraingModel::GetInstance()->GetSportEvent();
76   InitLabelExt(sportlabel, 83, 120, 300, 35, "label2", sport_id,
77                DEFAULT_VECTOR_FONT_FILENAME, 30);
78   sportlabel->SetTextColor(Color::Gray());
79   //数字统一使用DEFAULT_VECTOR_FONT_FILENAME_EN
80   InitLabel(curtimelabel, 155, 60, 150, 50, "label1", "23:54",
81             DEFAULT_VECTOR_FONT_FILENAME_EN, 40);
82   InitLabel(timerlabel, 0, 163, 466, 150, "label3", "00:00:00",
83             DEFAULT_VECTOR_FONT_FILENAME_EN, 80);
84   InitLabel(heartlabel, 85, 284, 230, 80, "label4", "--",
85             DEFAULT_VECTOR_FONT_FILENAME_EN, 60);
86   InitLabel(ubpmlabel, 218, 284, 230, 80, "label5", "bpm",
87             DEFAULT_VECTOR_FONT_FILENAME, 60);
88   ubpmlabel->SetTextColor(Color::Gray());
89   Add(curtimelabel);
90   Add(sportlabel);
91   Add(timerlabel);
92   Add(heartlabel);
93   Add(ubpmlabel);
94
95   return true;
96
97 #if 0
98   //  初始化Button
99   InitButton(buttonNote, 275, 350, 26, 26, BUTTONNOTE);
100   // Set additional property
101   buttonNote->SetImageSrc(NOTE_IMAGE, NOTE_IMAGE);
102   buttonNote->SetOnClickListener(static_cast<UIView::OnClickListener *>(TraingCardPresenter::GetInstance()));
103   Add(buttonNote);
104 #endif
105   // 增加上拉卡片
106   // SetCoverable(true);
107 }
108
109 /* DeInit:删除组件 */
110 void TrainingDataView::DeInit() {
111   RemoveAll();
112   if (curtimelabel != nullptr) {
113     delete curtimelabel;
114     curtimelabel = nullptr;
115   }
116   if (sportlabel != nullptr) {
117     delete sportlabel;
118     sportlabel = nullptr;
119   }
120   if (timerlabel != nullptr) {
121     delete timerlabel;
122     timerlabel = nullptr;
123   }
124   if (heartlabel != nullptr) {
125     delete heartlabel;
126     heartlabel = nullptr;
127   }
128   if (ubpmlabel != nullptr) {
129     delete ubpmlabel;
130     ubpmlabel = nullptr;
131   }
132
133   // 删除button
134   if (buttonNote != nullptr) {
135     delete buttonNote;
136     buttonNote = nullptr;
137   }
138
139   // 删除Image
140   if (image_iconup != nullptr) {
141     delete image_iconup;
142     image_iconup = nullptr;
143   }
144   if (image_iconpoint != nullptr) {
145     delete image_iconpoint;
146     image_iconpoint = nullptr;
147   }
148   if (image_heart != nullptr) {
149     delete image_heart;
150     image_heart = nullptr;
151   }
152   if (image_progress != nullptr) {
153     delete image_progress;
154     image_progress = nullptr;
155   }
156
157   //删除进度条圆圈
158   if (circleProgress != nullptr) {
159     delete circleProgress;
160     circleProgress = nullptr;
161   }
162 }
163
164 UILabelExt *TrainingDataView::GetTimeLabel() { return timerlabel; }
165 UILabelExt *TrainingDataView::GetHeartLabel() { return heartlabel; }
166 UICircleProgress *TrainingDataView::GetProgress() { return circleProgress; }
167 /*更新当前时间*/
168 void TrainingDataView::UpdataTime() {
169   if (curtimelabel == nullptr) // 防止刷新空组件
170     return;
171
172   // 获取当前时间
173   struct tm pTM;
174   time_t seconds;
175   time(&seconds);
176   localtime_r(&seconds, &pTM);
177
178   // 解析时间
179   int hour = pTM.tm_hour;
180   //需要判断显示的格式
181   if (uapi_dev_runtime_get_time_hour_show_model() == 12) {
182     if (pTM.tm_hour > 12)
183       hour = pTM.tm_hour - 12;
184   }
185
186   int minute = pTM.tm_min;
187
188   // 将时间和日期转换为字符串
189   std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" +
190                            (minute < 10 ? "0" : "") + std::to_string(minute);
191   curtimelabel->SetText(stringtime.c_str());
192 }
193
194 bool TrainingDataView::InitView(void *caller) {
195   WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TrainingDataView InitView %p",
196                 caller);
197   if (InitPage() == false) {
198     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingDataView::InitPage fail");
199     return false;
200   }
201   SetDraggable(true);
202   SetTouchable(true);
203   return true;
204 }
205 } // namespace OHOS