From: Caisking <3449750381@qq.com> Date: Tue, 7 May 2024 11:10:11 +0000 (+0800) Subject: 优化心率血氧time的更新显示逻辑 X-Git-Tag: release_V1.2.70_20241020_135402~1025^2~26 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=51ba7f877482ab65d6ea930a818c502be145ce95;p=mirrors%2FFD230.git 优化心率血氧time的更新显示逻辑 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenPresenter.h index e23bf5bce..3324fe354 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenPresenter.h @@ -28,6 +28,8 @@ namespace OHOS MAX_BLOODVIEW, } BLOODVIEWID; + + class BloodOxygenView; class BloodOxygenPresenter : public Presenter, public UIView::OnClickListener, @@ -51,7 +53,7 @@ namespace OHOS bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 uint64_t GetCurrentTime(); - std::string GetTDOA(uint64_t new_time, uint64_t old_time); + int GetTDOA(uint64_t new_time, uint64_t old_time); private: bool CheckPointersValue(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenView.h b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenView.h index d654824ea..35db087c6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/include/BloodOxygenView.h @@ -1,4 +1,4 @@ -/*** +/*** * @Date: 2024-04-15 10:55:58 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-04-18 10:23:54 @@ -31,6 +31,7 @@ #include "bloodoxygen/include/BloodBandoffView.h" #include "bloodoxygen/include/BloodCheckView.h" #include "bloodoxygen/include/BloodResultView.h" +#include "components/ui_label_button_ext.h" #include "power_display_service.h" namespace OHOS @@ -50,7 +51,7 @@ namespace OHOS void OnTearDownView() override; void OnStart() override; static BloodOxygenView *GetInstance(void); - + bool ChangeBloodView(int16_t thisview); // 主视图 bool ChangeBandoffView(int16_t thisview); bool ChangeCheckView(int16_t thisview); @@ -60,13 +61,14 @@ namespace OHOS void ChangeView(int16_t hideView, int16_t showView); UIScrollView *GetBloodScrollView(int ViewId); void UpBloodText(); + private: // 增加图片 bool InitImageDisplay(void); // 初始化标签 bool InitLabel(void); // 添加label按键 - UILabelButton *CreateAndSetUIButton(const char *title); + UILabelButtonExt *CreateAndSetUIButton(const char *title); // 初始化界面 bool InitBloodView(void); bool SetOnDragListener(void); @@ -77,11 +79,11 @@ namespace OHOS UIScrollView *BloodScrollView[4]{nullptr}; UIViewGroup *group; - UIImageView *imageViewMain; // 背景图片 - UILabel *percent; // 心率值 - UILabel *timeLabel; // 检测时间 - UILabel *titleLabel; // 页面title - UILabelButton *testButton; // 检测按键 + UIImageView *imageViewMain; // 背景图片 + UILabelExt *percent; // 心率值 + UILabelExt *timeLabel; // 检测时间 + UILabelExt *titleLabel; // 页面title + UILabelButtonExt *testButton; // 检测按键 const power_display_svr_api_t *display_api = power_display_svr_get_api(); uint32_t display_time; diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp index c290b758e..5b5d4e08b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenPresenter.cpp @@ -62,32 +62,15 @@ namespace OHOS } // 获取时间差,现在传进来的是两个时间戳 - std::string BloodOxygenPresenter::GetTDOA(uint64_t new_time, uint64_t old_time) + int BloodOxygenPresenter::GetTDOA(uint64_t new_time, uint64_t old_time) { if (new_time == old_time || old_time > new_time) { - return "刚刚"; + return 0; } int time_diff = new_time - old_time; - if (time_diff > 60) - { - int hours = time_diff / 60; - int minutes = time_diff % 60; - std::stringstream ss; - ss << hours << "小时"; - if (minutes > 0) - { - ss << minutes << "分钟"; - } - return ss.str() + "前"; - } - else - { - std::stringstream ss; - ss << time_diff << "分钟前"; - return ss.str(); - } + return time_diff; } /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp index 9d13e05a7..c6bced889 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-05-07 18:22:47 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/bloodoxygen/src/BloodOxygenView.cpp + */ /* * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. * Description: bloodOxygen view @@ -10,6 +16,7 @@ #include "bloodoxygen/include/BloodOxygenPresenter.h" #include "displaybrightness/include/DisplayBrightnessModel.h" #include "power_display_service.h" +#include "uicomponents/UIComponents.h" namespace OHOS { // 按钮设置 @@ -75,22 +82,35 @@ namespace OHOS void BloodOxygenView::UpBloodText() { // 更新血氧数据 - uint16_t spo2_ = BloodOxygenModel::GetInstance()->GetSPO2data(); - if (spo2_ != 0) // 判断是否为默认数据 + uint16_t spo2 = BloodOxygenModel::GetInstance()->GetSPO2data(); + if (spo2 != 0) // 判断是否为默认数据 { // 更新数据 - std::string bloodoxygenStr = std::to_string(spo2_); + std::string bloodoxygenStr = std::to_string(spo2); percent->SetText(bloodoxygenStr.c_str()); - // 更新时间 + + // 获取时间差 uint32_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime(); uint32_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime(); - std::string TimeStr = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time) + "检测"; - timeLabel->SetText(TimeStr.c_str()); + int time_diff = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time); + + if (time_diff == 0) + { + timeLabel->SetTextId(STR_CHECKNEW); + } + else if (time_diff <= 60) + { + UpdateLabel(timeLabel, time_diff); + } + else + { + timeLabel->SetTextId(STR_CHECKLONG); + } } else { percent->SetText("--"); - timeLabel->SetText("暂无检测结果"); + timeLabel->SetTextId(STR_CHECKNO); } } @@ -101,7 +121,7 @@ namespace OHOS std::string bloodoxygenStr; std::string TimeStr; - percent = new UILabel(); + percent = new UILabelExt(); if (percent == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new percent fail"); @@ -111,28 +131,12 @@ namespace OHOS percent->Resize(200, 200); // widget's width and height percent->SetViewId("label2"); // Set style percent->SetStyle(STYLE_TEXT_FONT, PERCENT_FONT_SIZE); - uint16_t spo2_ = BloodOxygenModel::GetInstance()->GetSPO2data(); - if (spo2_ != 0) - { - bloodoxygenStr = std::to_string(spo2_); - // 更新时间 - uint64_t time = BloodOxygenPresenter::GetInstance()->GetCurrentTime(); - uint64_t check_time = BloodOxygenModel::GetInstance()->GetCheckTime(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time:%lld check_time:%lld", time, check_time); - TimeStr = BloodOxygenPresenter::GetInstance()->GetTDOA(time, check_time) + "检测"; - } - else - { - percent->SetText("--"); - TimeStr = "暂无测量数据"; - } percent->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); percent->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); percent->SetRollSpeed(0); percent->SetFont(DEFAULT_VECTOR_FONT_FILENAME, PERCENT_FONT_SIZE); - percent->SetText(bloodoxygenStr.c_str()); /* -------------------------------------------------------------------------- */ - timeLabel = new UILabel(); + timeLabel = new UILabelExt(); if (timeLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new timeLabel fail"); @@ -142,15 +146,14 @@ namespace OHOS timeLabel->Resize(280, 100); // widget's width and height timeLabel->SetViewId("label1"); // Set style timeLabel->SetStyle(STYLE_TEXT_FONT, TIMELABEL_FONT_SIZE); - /* -------------------------------------------------------------------------- */ - timeLabel->SetText(TimeStr.c_str()); - /* -------------------------------------------------------------------------- */ timeLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); timeLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); timeLabel->SetRollSpeed(0); timeLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TIMELABEL_FONT_SIZE); - /* -------------------------------------------------------------------------- */ - titleLabel = new UILabel(); + + UpBloodText(); + + titleLabel = new UILabelExt(); if (titleLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new titleLabel fail"); @@ -160,7 +163,7 @@ namespace OHOS titleLabel->Resize(200, 90); // widget's width and height titleLabel->SetViewId("label3"); // Set style titleLabel->SetStyle(STYLE_TEXT_FONT, TITLE_FONT_SIZE); - titleLabel->SetText("血氧饱和度"); + titleLabel->SetTextId(STR_BLOOD); titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); titleLabel->SetRollSpeed(0); @@ -169,10 +172,10 @@ namespace OHOS return true; } // 创建标签按键 - UILabelButton *BloodOxygenView::CreateAndSetUIButton(const char *title) + UILabelButtonExt *BloodOxygenView::CreateAndSetUIButton(const char *title) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::CreateAndSetUIButton"); - UILabelButton *btn = new UILabelButton(); + UILabelButtonExt *btn = new UILabelButtonExt(); if (btn == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::new UILabelButton fail"); @@ -180,7 +183,7 @@ namespace OHOS } btn->SetPosition(TESTBUTTON_X, TESTBUTTON_Y, BUTTON_WIDHT2, BUTTON_HEIGHT2); btn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffcd492c); - btn->SetText(title); + btn->SetTextId(STR_CHECK); // btn->SetTextColor(Color::Red()); btn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, BUTTON_LABEL_SIZE); btn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h index 192cca73e..6f8acc687 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h @@ -1,7 +1,7 @@ /*** * @Date: 2024-04-15 10:55:58 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-05-07 17:00:01 + * @LastEditTime: 2024-05-07 18:46:22 * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartBandoffView.h */ /*** diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartPresenter.h index 8e403a447..970ae3e75 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/include/HeartPresenter.h @@ -50,7 +50,7 @@ namespace OHOS bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 uint64_t GetCurrentTime(); - std::string GetTDOA(uint64_t new_time, uint64_t old_time); + int GetTDOA(uint64_t new_time, uint64_t old_time); private: bool CheckPointersValue(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartPresenter.cpp index 929a961d2..323581252 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartPresenter.cpp @@ -53,32 +53,15 @@ namespace OHOS return current_time; } - std::string HeartPresenter::GetTDOA(uint64_t new_time, uint64_t old_time) + int HeartPresenter::GetTDOA(uint64_t new_time, uint64_t old_time) { if (new_time == old_time || old_time > new_time) { - return "刚刚"; + return 0; } int time_diff = new_time - old_time; - if (time_diff > 60) - { - int hours = time_diff / 60; - int minutes = time_diff % 60; - std::stringstream ss; - ss << hours << "小时"; - if (minutes > 0) - { - ss << minutes << "分钟"; - } - return ss.str() + "前"; - } - else - { - std::stringstream ss; - ss << time_diff << "分钟前"; - return ss.str(); - } + return time_diff; } HeartPresenter::HeartPresenter() diff --git a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp index 0c5481591..fac88ccca 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartView.cpp @@ -82,28 +82,38 @@ namespace OHOS } void HeartView::UpHeartText() { - // 更新血氧数据 - uint64_t heart_ = HeartModel::GetInstance()->GetHeartdata(); - std::string heartStr; - std::string TimeStr; - if (heart_ != 0) // 判断是否为默认数据 + // 更新心率数据 + uint8_t heart = HeartModel::GetInstance()->GetHeartdata(); + if (heart != 0) // 判断是否为默认数据 { - heartStr = std::to_string(heart_); - // 更新时间 - uint64_t time = HeartPresenter::GetInstance()->GetCurrentTime(); - uint64_t check_time = HeartModel::GetInstance()->GetCheckTime(); - TimeStr = HeartPresenter::GetInstance()->GetTDOA(time, check_time) + "检测"; - // timeLabel->SetText(TimeStr.c_str()); - timeLabel->SetTextId(STR_CHECKTIME); - UpdateLabel(timeLabel, TimeStr); + // 更新心率数据 + std::string heartStr = std::to_string(heart); + percent->SetText(heartStr.c_str()); + + // 获取时间差 + uint32_t time = HeartPresenter::GetInstance()->GetCurrentTime(); + uint32_t check_time = HeartModel::GetInstance()->GetCheckTime(); + int time_diff = HeartPresenter::GetInstance()->GetTDOA(time, check_time); + + // 更新时间标签 + if (time_diff == 0) + { + timeLabel->SetTextId(STR_CHECKNEW); + } + else if (time_diff <= 60) + { + UpdateLabel(timeLabel, time_diff); + } + else + { + timeLabel->SetTextId(STR_CHECKLONG); + } } else { - heartStr = "--"; - // TimeStr = "暂无检测记录"; + percent->SetText("--"); timeLabel->SetTextId(STR_CHECKNO); } - percent->SetText(heartStr.c_str()); } // 初始化标签 @@ -157,28 +167,8 @@ namespace OHOS titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); titleLabel->SetRollSpeed(0); titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TITLE_FONT_SIZE); - /* -------------------------------------------------------------------------- */ - uint64_t heart_ = HeartModel::GetInstance()->GetHeartdata(); - std::string heartStr; - std::string TimeStr; - if (heart_ != 0) // 判断是否为默认数据 - { - heartStr = std::to_string(heart_); - // 更新时间 - uint64_t time = HeartPresenter::GetInstance()->GetCurrentTime(); - uint64_t check_time = HeartModel::GetInstance()->GetCheckTime(); - TimeStr = HeartPresenter::GetInstance()->GetTDOA(time, check_time) + "检测"; - // timeLabel->SetText(TimeStr.c_str()); - timeLabel->SetTextId(STR_CHECKTIME); - UpdateLabel(timeLabel, TimeStr); - } - else - { - heartStr = "--"; - // TimeStr = "暂无检测记录"; - timeLabel->SetTextId(STR_CHECKNO); - } - percent->SetText(heartStr.c_str()); + + UpHeartText(); /* -------------------------------------------------------------------------- */ return true; }