* @Date: 2024-08-15 18:39:02
* @LastEditors: Caisking 3449750381@qq.com
* @LastEditTime: 2024-09-05 14:36:17
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp
+ * @FilePath:
+ * /FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp
*/
/***
* @Date: 2024-04-15 10:55:58
* @LastEditors: Caisking 3449750381@qq.com
* @LastEditTime: 2024-07-29 15:35:06
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp
+ * @FilePath:
+ * /FD230/code/sdk/application/wearable/fd230app/nativeui/heartrate/src/HeartChartView.cpp
*/
-#include "UiConfig.h"
-#include "wearable_log.h"
#include "HeartChartView.h"
#include "HeartModel.h"
+#include "UiConfig.h"
+#include "heart_blood/health_service/health_service.h"
+#include "power_display_service.h"
#include "ui_image_animator.h"
-#include "HeartChartView.h"
#include "ui_resource_string.h"
-#include "power_display_service.h"
#include "uicomponents/UIComponents.h"
-#include "heart_blood/health_service/health_service.h"
-namespace OHOS
-{
- static HeartChartView *g_pHeartCheckView = nullptr;
-
- // 动态刷新设置
- static constexpr uint16_t IMAGE_SIZE = 180;
- static constexpr uint16_t IMAGE_POSITION_Y = 134;
- static constexpr uint16_t IMAGE_POSITION_X = 150;
- static constexpr uint16_t Chart_IMAGE_ANIMATORVIEW_SIZE = 20;
- static constexpr uint16_t Chart_IMAGE_ANIMATORVIEW_SPEED = 40;
- // 图片路径
- static constexpr const char *BACKGROUND_IMAGE_PATH = "/user/res/heart_chart/background.bin";
- static constexpr const char *BUTTOM_ICON_PATH = "/user/res/heart_chart/buttomicon.bin";
- static constexpr const char *TOP_ICON_PATH = "/user/res/heart_chart/topicon.bin";
- static constexpr const char *HEART_ICON_PATH = "/user/res/heart_chart/hearticon.bin";
- // 心形心跳
- static constexpr int HEARTBEAT_IMAGE_WIDTH = 92;
- static constexpr int HEARTBEAT_IMAGE_HEIGHT = 92;
- static constexpr int HEARTBEAT_IMAGE_X = 85;
- static constexpr int HEARTBEAT_IMAGE_Y = 50;
- static constexpr int HEARTBEAT_IMAGE_NUM = 19;
- static constexpr int HEARTBEAT_DELAY = 50;
- // 心跳image
- static ImageAnimatorInfo g_heartImageInfo[HEARTBEAT_IMAGE_NUM] = {
- {PNG_A004_070_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_071_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_072_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_073_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_074_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_075_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_076_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_077_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_078_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_079_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
-
- {PNG_A004_080_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_081_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_082_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_083_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_084_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_085_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_086_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_087_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- {PNG_A004_088_IMAGE_PATH, {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y}, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT, IMG_SRC_FILE_PATH},
- };
-
- HeartChartView::HeartChartView()
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartBandoffView::HeartBandoffView");
- g_pHeartCheckView = this;
- }
- HeartChartView::~HeartChartView()
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::~HeartChartView");
-
- imageAnimator->Stop();
- /*
- UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
- UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
- */
-
- delete CurrentHeartText;
- CurrentHeartText = nullptr;
- delete MaxHeartText;
- MaxHeartText = nullptr;
- delete MinHeartText;
- MinHeartText = nullptr;
- delete UHeartText;
- UHeartText = nullptr;
- delete RestHeartText;
- RestHeartText = nullptr;
- delete TopimageView;
- TopimageView = nullptr;
- delete BottomimageView;
- BottomimageView = nullptr;
- delete CoordinateimageView;
- CoordinateimageView = nullptr;
- delete HeartIconView;
- HeartIconView = nullptr;
- delete imageAnimator;
- imageAnimator = nullptr;
-
- heartchart->ClearDataSerial();
- delete heartSerial;
- heartSerial = nullptr;
- delete heartchart;
- heartchart = nullptr;
-
- g_pHeartCheckView = this;
- }
- HeartChartView *HeartChartView::GetInstance(void)
- {
- return g_pHeartCheckView;
- }
-
- /* 更新显示数据 */
- void HeartChartView::UpdateShowHeart()
- {
- // 获取当前心率
- uint16_t heart_ = HeartModel::GetInstance()->GetShowHeartdata();
- std::string heartrateStr = (heart_ == 0) ? "--" : (heart_ < 50 ? "--" : std::to_string(heart_));
-
- // 更新当前心率显示
- if (CurrentHeartText != nullptr)
- {
- CurrentHeartText->SetText(heartrateStr.c_str());
- }
-
- // 获取最大心率
- uint16_t heartmax_ = HeartModel::GetInstance()->GetShowMaxHeartdata();
- std::string heartmaxStr = (heartmax_ == 0) ? "--" : (heartmax_ < 50 ? "--" : std::to_string(heartmax_));
-
- // 更新最大心率显示
- if (MaxHeartText != nullptr)
- {
- MaxHeartText->SetText(heartmaxStr.c_str());
- }
-
- // 获取最小心率
- uint16_t heartmin_ = HeartModel::GetInstance()->GetShowMinHeartdata();
- std::string heartminStr = (heartmin_ == 0) ? "--" : (heartmin_ < 50 ? "--" : std::to_string(heartmin_));
-
- // 更新最小心率显示
- if (MinHeartText != nullptr)
- {
- MinHeartText->SetText(heartminStr.c_str());
- }
- }
- void HeartChartView::Update_data_Chart(int serialIndex)
- {
- if (heartchart == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Update_data_Chart fail %d", serialIndex);
- return;
- }
- /*清除原数据*/
- heartSerial->ClearData();
-
- /*设置单个项*/
- heartdata[serialIndex].x = serialIndex;
- heartdata[serialIndex].y = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);
-
- /*重新添加*/
- heartSerial->AddPoints(heartdata, 24);
- heartSerial->SetLineColor(Color::Red());
- heartSerial->SetFillColor(Color::Red());
- heartSerial->EnableGradient(true);
-
- heartchart->AddDataSerial(heartSerial);
- heartchart->Invalidate();
- }
- void HeartChartView::CleanAllDataView()
- {
- if (heartchart == nullptr || MaxHeartText == nullptr || MinHeartText == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " CleanAllDataView fail");
- return;
- }
- for (int serialIndex = 0; serialIndex < 24; serialIndex++)
- {
- heartdata[serialIndex].x = serialIndex;
- heartdata[serialIndex].y = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);
- }
-
- /*清空原数据*/
- heartSerial->ClearData();
- heartSerial->AddPoints(heartdata, 24);
- heartSerial->SetLineColor(Color::Red());
- heartSerial->SetFillColor(Color::Red());
- heartSerial->EnableGradient(true);
-
- heartchart->AddDataSerial(heartSerial);
- // heartchart->RefreshChart();
-
- /*更新最大最小值*/
- SetDataTopAndBottom();
- }
- /*设置最大最小数据*/
- void HeartChartView::SetDataTopAndBottom()
- {
- int MaxHeart = HeartModel::GetInstance()->GetHeartRateMax();
- int MinHeart = HeartModel::GetInstance()->GetHeartRateMin();
-
- if (MaxHeartText != nullptr)
- {
- MaxHeartText->SetText(MaxHeart > 0 ? (std::to_string(MaxHeart)).c_str() : "--");
- }
-
- if (MinHeartText != nullptr)
- {
- MinHeartText->SetText(MinHeart > 0 ? (std::to_string(MinHeart)).c_str() : "--");
- }
-
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaxHeart: %d, MinHeart: %d", MaxHeart, MinHeart);
- }
- /*设置曲线图数据*/
- void HeartChartView::SetDataChart()
- {
- if (heartchart == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Init_data_Chart new chart fail");
- return;
- }
- heartSerial = new UIChartDataSerial();
- heartSerial->SetMaxDataCount(24);
+#include "wearable_log.h"
+namespace OHOS {
+static HeartChartView *g_pHeartCheckView = nullptr;
+
+// 动态刷新设置
+static constexpr uint16_t IMAGE_SIZE = 180;
+static constexpr uint16_t IMAGE_POSITION_Y = 134;
+static constexpr uint16_t IMAGE_POSITION_X = 150;
+static constexpr uint16_t Chart_IMAGE_ANIMATORVIEW_SIZE = 20;
+static constexpr uint16_t Chart_IMAGE_ANIMATORVIEW_SPEED = 40;
+// 图片路径
+static constexpr const char *BACKGROUND_IMAGE_PATH =
+ "/user/res/heart_chart/background.bin";
+static constexpr const char *BUTTOM_ICON_PATH =
+ "/user/res/heart_chart/buttomicon.bin";
+static constexpr const char *TOP_ICON_PATH =
+ "/user/res/heart_chart/topicon.bin";
+static constexpr const char *HEART_ICON_PATH =
+ "/user/res/heart_chart/hearticon.bin";
+// 心形心跳
+static constexpr int HEARTBEAT_IMAGE_WIDTH = 54;
+static constexpr int HEARTBEAT_IMAGE_HEIGHT = 50;
+static constexpr int HEARTBEAT_IMAGE_X = 111;
+static constexpr int HEARTBEAT_IMAGE_Y = 57;
+static constexpr int HEARTBEAT_IMAGE_NUM = 21;
+static constexpr int HEARTBEAT_DELAY = 50;
+// 心跳image
+static ImageAnimatorInfo g_heartImageInfo[HEARTBEAT_IMAGE_NUM] = {
+ {PNG_A004_070_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_071_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_072_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_073_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_074_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_075_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_076_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_077_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_078_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_079_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_080_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_081_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_082_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_083_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_084_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_085_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_086_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_087_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_088_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_089_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+ {PNG_A004_090_IMAGE_PATH,
+ {HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y},
+ HEARTBEAT_IMAGE_WIDTH,
+ HEARTBEAT_IMAGE_HEIGHT,
+ IMG_SRC_FILE_PATH},
+};
+
+HeartChartView::HeartChartView() {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartBandoffView::HeartBandoffView");
+ g_pHeartCheckView = this;
+}
+HeartChartView::~HeartChartView() {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::~HeartChartView");
+
+ // imageAnimator->Stop();
+ heartchart->ClearDataSerial();
+ delete heartSerial;
+ heartSerial = nullptr;
+
+ UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
+ UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
+
+#if 0
+ delete displayheart_;
+ displayheart_ = nullptr;
+ delete maxheart_;
+ maxheart_ = nullptr;
+ delete minheart_;
+ minheart_ = nullptr;
+ delete UHeartText;
+ UHeartText = nullptr;
+ delete RestHeartText;
+ RestHeartText = nullptr;
+ delete TopimageView;
+ TopimageView = nullptr;
+ delete BottomimageView;
+ BottomimageView = nullptr;
+ delete CoordinateimageView;
+ CoordinateimageView = nullptr;
+ delete HeartIconView;
+ HeartIconView = nullptr;
+ delete imageAnimator;
+ imageAnimator = nullptr;
+
+ heartchart->ClearDataSerial();
+ delete heartSerial;
+ heartSerial = nullptr;
+ delete heartchart;
+ heartchart = nullptr;
+#endif
+ g_pHeartCheckView = this;
+}
+HeartChartView *HeartChartView::GetInstance(void) { return g_pHeartCheckView; }
+
+/* 更新显示数据 */
+void HeartChartView::UpdateShowHeart() {
+ // 获取当前心率
+ uint16_t heart_ = HeartModel::GetInstance()->GetShowHeartdata();
+ std::string heartrateStr =
+ (heart_ == 0) ? "--" : (heart_ < 50 ? "--" : std::to_string(heart_));
+
+ // 更新当前心率显示
+ if (displayheart_ != nullptr) {
+ displayheart_->SetText(heartrateStr.c_str());
+ }
+
+ // 获取最大心率
+ uint16_t heartmax_ = HeartModel::GetInstance()->GetShowMaxHeartdata();
+ std::string heartmaxStr =
+ (heartmax_ == 0) ? "--"
+ : (heartmax_ < 50 ? "--" : std::to_string(heartmax_));
+
+ // 更新最大心率显示
+ if (maxheart_ != nullptr) {
+ maxheart_->SetText(heartmaxStr.c_str());
+ }
+
+ // 获取最小心率
+ uint16_t heartmin_ = HeartModel::GetInstance()->GetShowMinHeartdata();
+ std::string heartminStr =
+ (heartmin_ == 0) ? "--"
+ : (heartmin_ < 50 ? "--" : std::to_string(heartmin_));
+
+ // 更新最小心率显示
+ if (minheart_ != nullptr) {
+ minheart_->SetText(heartminStr.c_str());
+ }
+}
+void HeartChartView::Update_data_Chart(int serialIndex) {
+ if (heartchart == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Update_data_Chart fail %d",
+ serialIndex);
+ return;
+ }
+ /*清除原数据*/
+ heartSerial->ClearData();
+
+ /*设置单个项*/
+ heartdata[serialIndex].x = serialIndex;
+ heartdata[serialIndex].y =
+ HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);
+
+ /*重新添加*/
+ heartSerial->AddPoints(heartdata, 24);
+ heartSerial->SetLineColor(Color::Red());
+ heartSerial->SetFillColor(Color::Red());
+ heartSerial->EnableGradient(true);
+
+ heartchart->AddDataSerial(heartSerial);
+ heartchart->Invalidate();
+
+ //更新为刚刚检测
+ SetLastHeart();
+}
+void HeartChartView::CleanAllDataView() {
+ if (heartchart == nullptr || maxheart_ == nullptr || minheart_ == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " CleanAllDataView fail");
+ return;
+ }
+ for (int serialIndex = 0; serialIndex < 24; serialIndex++) {
+ heartdata[serialIndex].x = serialIndex;
+ heartdata[serialIndex].y =
+ HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);
+ }
+
+ /*清空原数据*/
+ heartSerial->ClearData();
+ heartSerial->AddPoints(heartdata, 24);
+ heartSerial->SetLineColor(Color::Red());
+ heartSerial->SetFillColor(Color::Red());
+ heartSerial->EnableGradient(true);
+
+ heartchart->AddDataSerial(heartSerial);
+ // heartchart->RefreshChart();
+
+ /*更新最大最小值*/
+ SetDataTopAndBottom();
+}
+/*设置最大最小数据*/
+void HeartChartView::SetDataTopAndBottom() {
+ int MaxHeart = HeartModel::GetInstance()->GetHeartRateMax();
+ int MinHeart = HeartModel::GetInstance()->GetHeartRateMin();
+
+ if (maxheart_ != nullptr) {
+ maxheart_->SetText(MaxHeart > 0 ? (std::to_string(MaxHeart)).c_str()
+ : "--");
+ }
+
+ if (minheart_ != nullptr) {
+ minheart_->SetText(MinHeart > 0 ? (std::to_string(MinHeart)).c_str()
+ : "--");
+ }
+
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaxHeart: %d, MinHeart: %d", MaxHeart,
+ MinHeart);
+}
+/*设置曲线图数据*/
+void HeartChartView::SetDataChart() {
+ if (heartchart == nullptr) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Init_data_Chart new chart fail");
+ return;
+ }
+ heartSerial = new UIChartDataSerial();
+ heartSerial->SetMaxDataCount(24);
#if HEART_DATA_TEST
- Point temp[] = {
- {0, 150}, {1, 250}, {2, 170}, {3, 0}, {4, 140}, {5, 190}, {6, 100}, {7, 40}, {8, 10}, {9, 100}, {10, 60}, {11, 20}, {12, 150}, {13, 250}, {14, 170}, {15, 140}, {16, 78}, {17, 80}, {18, 100}, {19, 20}, {20, 100}, {21, 100}, {22, 100}, {23, 100}};
- std::copy(std::begin(temp), std::end(temp), heartdata);
+ Point temp[] = {{0, 150}, {1, 250}, {2, 170}, {3, 0}, {4, 140},
+ {5, 190}, {6, 100}, {7, 40}, {8, 10}, {9, 100},
+ {10, 60}, {11, 20}, {12, 150}, {13, 250}, {14, 170},
+ {15, 140}, {16, 78}, {17, 80}, {18, 100}, {19, 20},
+ {20, 100}, {21, 100}, {22, 100}, {23, 100}};
+ std::copy(std::begin(temp), std::end(temp), heartdata);
#else
- for (int serialIndex = 0; serialIndex < 24; serialIndex++)
- {
- heartdata[serialIndex].x = serialIndex;
- heartdata[serialIndex].y = HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);
- }
+ for (int serialIndex = 0; serialIndex < 24; serialIndex++) {
+ heartdata[serialIndex].x = serialIndex;
+ heartdata[serialIndex].y =
+ HealthService::GetInstance()->GetHourlyHeartRate(serialIndex);
+ }
#endif
- heartSerial->AddPoints(heartdata, 24);
- heartSerial->SetLineColor(Color::Red());
- heartSerial->SetFillColor(Color::Red());
- heartSerial->EnableGradient(true);
-
- heartchart->AddDataSerial(heartSerial);
- heartchart->Invalidate();
- }
- /*设置心率动画*/
- void HeartChartView::HeartImageAnimator()
- {
- imageAnimator = new UIImageAnimatorView();
- if (imageAnimator == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartRateView::[HeartbeatImageAnimator] new imageAnimator fail");
- return;
- }
- imageAnimator->SetPosition(HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y, HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT);
- imageAnimator->SetImageAnimatorSrc(g_heartImageInfo, HEARTBEAT_IMAGE_NUM, HEARTBEAT_DELAY);
- imageAnimator->SetRepeat(true);
- container_->Add(imageAnimator);
- imageAnimator->Start();
- }
- /*初始化心率曲线*/
- void HeartChartView::InitChartView(void)
- {
- if (heartchart == nullptr)
- {
- heartchart = new UIChartPolyline();
- }
- heartchart->SetPosition(95, 178);
- heartchart->Resize(320, 110);
- heartchart->SetViewId("uiChart");
- heartchart->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
-
- UIXAxis &heartXAxis = heartchart->GetXAxis();
- UIYAxis &heartYAxis = heartchart->GetYAxis();
- heartXAxis.SetMarkNum(1);
- heartXAxis.SetDataRange(0, 24);
- heartXAxis.SetLineColor(Color::GetColorFromRGBA(0, 0, 0, 0));
- heartYAxis.SetMarkNum(1);
- heartYAxis.SetDataRange(0, 220);
- heartYAxis.SetLineColor(Color::GetColorFromRGBA(0, 0, 0, 0));
-
- heartchart->SetGradientOpacity(25, 180);
- // heartchart->SetGradientOpacity(255, 0);
-
- container_->Add(heartchart);
- }
- /*初始化检测界面*/
- bool HeartChartView::HeartViewInit()
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartChartViewInit is begin");
- // 初始化图片
- InitImageView(CoordinateimageView, 38, 130, 390, 200, "CoordinateimageView", BACKGROUND_IMAGE_PATH);
- InitImageView(TopimageView, 131, 350, 21, 12, "TopimageView", TOP_ICON_PATH);
- InitImageView(BottomimageView, 267, 350, 21, 12, "BottomimageView", BUTTOM_ICON_PATH);
- // 初始化心率值
- InitLabel(CurrentHeartText, 172, 62, 102, 79, "CurrentHeartText", "--", GILROY_BOLD_FONT, 65);
- InitRollLabel(UHeartText, 283, 85, 100, 35, "UHeartText", STR_TIMES_PER_MIN, DEFAULT_VECTOR_FONT_FILENAME, 30);
- InitLabelAdapt(MaxHeartText, 160, 336, 102, 79, "MaxHeartText", "--", DEFAULT_VECTOR_FONT_FILENAME, 35);
- InitLabelAdapt(MinHeartText, 295, 336, 102, 79, "MinHeartText", "--", DEFAULT_VECTOR_FONT_FILENAME, 35);
-
- container_->Add(CoordinateimageView);
- container_->Add(TopimageView);
- container_->Add(BottomimageView);
- container_->Add(CurrentHeartText);
- container_->Add(UHeartText);
- container_->Add(MaxHeartText);
- container_->Add(MinHeartText);
-
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartChartViewInit is ok");
- return true;
- }
-
- void HeartChartView::OnStart()
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnStart");
- View<HeartChartPresenter>::OnStart();
-
- SetContainerView(new UIViewGroup());
- container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-
- if (!HeartViewInit())
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartChartView::InitHeartView fail");
- }
-
- HeartImageAnimator();
- InitChartView();
- SetDataChart();
- SetDataTopAndBottom();
-
- SetContainerView(container_);
- container_->SetDraggable(true);
- container_->SetTouchable(true);
- container_->SetOnDragListener(presenter_);
-
- // 增加按键监听
- RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::HeartChartPresenter::GetInstance();
- RootView::GetInstance()->SetOnKeyActListener(keyactListener);
- }
- void HeartChartView::OnSetUpView()
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnSetUpView");
- View<HeartChartPresenter>::OnSetUpView();
-
- Draw();
- }
- void HeartChartView::OnTearDownView()
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnTearDownView");
- View<HeartChartPresenter>::OnTearDownView();
- return;
- }
-
- void HeartChartView::OnStop()
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnStop");
- View<HeartChartPresenter>::OnStop();
- if (container_ != nullptr)
- {
- container_->RemoveAll();
- delete container_;
- container_ = nullptr;
- }
- return;
- }
+ heartSerial->AddPoints(heartdata, 24);
+ heartSerial->SetLineColor(Color::Red());
+ heartSerial->SetFillColor(Color::Red());
+ heartSerial->EnableGradient(true);
+
+ heartchart->AddDataSerial(heartSerial);
+ heartchart->Invalidate();
+}
+/*设置心率动画*/
+void HeartChartView::HeartImageAnimator() {
+ imageAnimator = new UIImageAnimatorView();
+ if (imageAnimator == nullptr) {
+ WEARABLE_LOGE(
+ WEARABLE_LOG_MODULE_APP,
+ "HeartRateView::[HeartbeatImageAnimator] new imageAnimator fail");
+ return;
+ }
+ imageAnimator->SetPosition(HEARTBEAT_IMAGE_X, HEARTBEAT_IMAGE_Y,
+ HEARTBEAT_IMAGE_WIDTH, HEARTBEAT_IMAGE_HEIGHT);
+ imageAnimator->SetImageAnimatorSrc(g_heartImageInfo, HEARTBEAT_IMAGE_NUM,
+ HEARTBEAT_DELAY);
+ imageAnimator->SetRepeat(true);
+ container_->Add(imageAnimator);
+ imageAnimator->Start();
+}
+/*初始化心率曲线*/
+void HeartChartView::InitChartView(void) {
+ if (heartchart == nullptr) {
+ heartchart = new UIChartPolyline();
+ }
+ heartchart->SetPosition(80, 199);
+ heartchart->Resize(313, 122);
+ heartchart->SetViewId("uiChart1");
+ heartchart->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+
+ UIXAxis &heartXAxis = heartchart->GetXAxis();
+ heartXAxis.SetMarkNum(24);
+ heartXAxis.SetDataRange(0, 24);
+ heartXAxis.SetLineColor(Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+
+ UIYAxis &heartYAxis = heartchart->GetYAxis();
+ heartYAxis.SetMarkNum(4);
+ heartYAxis.SetDataRange(0, 220);
+ heartYAxis.SetLineColor(Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+
+ heartchart->SetGradientOpacity(78, 64);
+
+ // Add to rootView
+ container_->Add(heartchart);
+}
+
+//初始化label
+/*
+需要显示一个动态心率的效果
+有5个label代表 曲线图的y轴
+ 最大心率+10
+ 最大心率+10-(最小心率-10)*3/4
+ 最大心率+10-(最小心率-10)*2/4
+ 最大心率+10-(最小心率-10)*1/4
+ 最小心率-10
+*/
+void HeartChartView::InitChartLabel() {
+ //当前心率值
+ InitLabel(displayheart_, 133, 32, 200, 100, "label", "--", GILROY_BOLD_FONT,
+ 65);
+ // 单位
+ InitRollLabel(uheart_, 283, 52, 100, 60, "label", STR_TIMES_PER_MIN,
+ DEFAULT_VECTOR_FONT_FILENAME, 30);
+ uheart_->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
+ //上一次检测信息
+ InitLabel(lastheart_, 53, 130, 360, 35, "label", "--",
+ DEFAULT_VECTOR_FONT_FILENAME, 30);
+ //最小心率 不居中
+ InitLabelAdapt(minheart_, 293, 380, 200, 35, "label", "--",
+ DEFAULT_VECTOR_FONT_FILENAME, 35);
+ //最大心率 不居中
+ InitLabelAdapt(maxheart_, 158, 380, 200, 35, "label", "--",
+ DEFAULT_VECTOR_FONT_FILENAME, 35);
+
+ //动态心率最大
+ InitLabel(maxheart_dynamic_, 30, 190, 50, 20, "label", "220",
+ DEFAULT_VECTOR_FONT_FILENAME, 20);
+ maxheart_dynamic_->SetTextColor(
+ Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+ //动态心率3/4
+ InitLabel(maxheart_dynamic_3_, 30, 218, 50, 20, "label", "160",
+ DEFAULT_VECTOR_FONT_FILENAME, 20);
+ maxheart_dynamic_3_->SetTextColor(
+ Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+ //动态心率2/4
+ InitLabel(maxheart_dynamic_2_, 30, 247, 50, 20, "label", "100",
+ DEFAULT_VECTOR_FONT_FILENAME, 20);
+ maxheart_dynamic_2_->SetTextColor(
+ Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+ //动态心率1/4
+ InitLabel(maxheart_dynamic_1_, 30, 277, 50, 20, "label", "40",
+ DEFAULT_VECTOR_FONT_FILENAME, 20);
+ maxheart_dynamic_1_->SetTextColor(
+ Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+ //动态心率最小
+ InitLabel(minheart_dynamic_, 30, 306, 50, 20, "label", "0",
+ DEFAULT_VECTOR_FONT_FILENAME, 20);
+ minheart_dynamic_->SetTextColor(
+ Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+
+ container_->Add(displayheart_);
+ container_->Add(uheart_);
+ container_->Add(lastheart_);
+ container_->Add(minheart_);
+ container_->Add(maxheart_);
+ container_->Add(maxheart_dynamic_);
+ container_->Add(maxheart_dynamic_3_);
+ container_->Add(maxheart_dynamic_2_);
+ container_->Add(maxheart_dynamic_1_);
+ container_->Add(minheart_dynamic_);
+}
+
+void HeartChartView::InitChartImageView() {
+
+ if (minRateIconView_ == nullptr) {
+ minRateIconView_ = new UIImageView();
+ }
+ minRateIconView_->SetPosition(266, 394);
+ minRateIconView_->Resize(100, 100);
+ minRateIconView_->SetViewId("minRateIcon");
+ minRateIconView_->SetSrc(BUTTOM_ICON_PATH);
+ if (maxRateIconView_ == nullptr) {
+ maxRateIconView_ = new UIImageView();
+ }
+ maxRateIconView_->SetPosition(129, 394);
+ maxRateIconView_->Resize(100, 100);
+ maxRateIconView_->SetViewId("maxRateIcon");
+ maxRateIconView_->SetSrc(TOP_ICON_PATH);
+
+ if (chartBackgroundView_ == nullptr) {
+ chartBackgroundView_ = new UIImageView();
+ }
+ chartBackgroundView_->SetPosition(30, 160);
+ chartBackgroundView_->Resize(100, 100);
+ chartBackgroundView_->SetViewId("chartBackground");
+ chartBackgroundView_->SetSrc(BACKGROUND_IMAGE_PATH);
+
+ container_->Add(chartBackgroundView_);
+ container_->Add(minRateIconView_);
+ container_->Add(maxRateIconView_);
+#if 0
+ if (heartIconView_ == nullptr) {
+ heartIconView_ = new UIImageView();
+ }
+ heartIconView_->SetPosition(111, 57);
+ heartIconView_->Resize(100, 100);
+ heartIconView_->SetViewId("heartIcon");
+ heartIconView_->SetSrc(HEART_ICON_PATH);
+
+ container_->Add(heartIconView_);
+ heartIconView_->SetVisible(true);
+
+ if (lineView_ == nullptr) {
+ lineView_ = new UIImageView();
+ }
+ lineView_->SetPosition(230, 385);
+ lineView_->Resize(1, 26);
+ lineView_->SetViewId("lineView");
+ lineView_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff666666);
+ lineView_->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+
+ container_->Add(lineView_);
+ lineView_->SetVisible(true);
+#endif
+}
+
+//更新图表配置
+void HeartChartView::UpdateChartConfig() {
+ if (minheart_dynamic_ == nullptr || maxheart_dynamic_1_ == nullptr ||
+ maxheart_dynamic_2_ == nullptr || maxheart_dynamic_3_ == nullptr ||
+ heartchart == nullptr) {
+ return;
+ }
+
+ // 获取动态心率数据
+ HeartModel::GetInstance()->SetArrayData();
+ uint16_t *dynamicArray = HeartModel::GetInstance()->GetArrayData();
+
+ //更新label
+ if (dynamicArray) {
+ minheart_dynamic_->SetText(std::to_string(dynamicArray[0]).c_str());
+ maxheart_dynamic_1_->SetText(std::to_string(dynamicArray[1]).c_str());
+ maxheart_dynamic_2_->SetText(std::to_string(dynamicArray[2]).c_str());
+ maxheart_dynamic_3_->SetText(std::to_string(dynamicArray[3]).c_str());
+ maxheart_dynamic_->SetText(std::to_string(dynamicArray[4]).c_str());
+ }
+ //更新chart
+ UIYAxis &heartYAxis = heartchart->GetYAxis();
+ heartYAxis.SetMarkNum(4);
+ heartYAxis.SetDataRange(dynamicArray[0], dynamicArray[4]);
+ heartYAxis.SetLineColor(Color::GetColorFromRGBA(0x33, 0x33, 0x33, 0xff));
+ heartchart->Invalidate();
+}
+//更新上一次检测信息
+void HeartChartView::SetLastHeart() {
+ if (lastheart_ == nullptr)
+ return;
+ std::string lastStr = HeartModel::GetInstance()->GetCheckString();
+ lastheart_->SetText(lastStr.c_str());
+}
+/*初始化检测界面*/
+bool HeartChartView::HeartViewInit() {
+
+ //图片
+ InitChartImageView();
+ //标签
+ InitChartLabel();
+
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartChartViewInit is ok");
+ return true;
+}
+UIViewGroup *HeartChartView::GetchartGroup() {
+ SetContainerView(new UIViewGroup());
+ container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
+ Screen::GetInstance().GetHeight());
+ if (!HeartViewInit()) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+ "HeartChartView::InitHeartView fail");
+ }
+ HeartImageAnimator();
+ InitChartView();
+ UpdateChartConfig();
+ SetDataChart();
+ SetLastHeart();
+ SetDataTopAndBottom();
+ return container_;
+}
+void HeartChartView::OnStart() {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnStart");
+ View<HeartChartPresenter>::OnStart();
+
+ SetContainerView(new UIViewGroup());
+ container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
+ Screen::GetInstance().GetHeight());
+
+ if (!HeartViewInit()) {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+ "HeartChartView::InitHeartView fail");
+ }
+
+ HeartImageAnimator();
+ InitChartView();
+ UpdateChartConfig();
+ SetDataChart();
+ SetLastHeart();
+ SetDataTopAndBottom();
+
+ SetContainerView(container_);
+ container_->SetDraggable(true);
+ container_->SetTouchable(true);
+ container_->SetOnDragListener(presenter_);
+
+ // 增加按键监听
+ RootView::OnKeyActListener *keyactListener =
+ (RootView::OnKeyActListener *)OHOS::HeartChartPresenter::GetInstance();
+ RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+}
+void HeartChartView::OnSetUpView() {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnSetUpView");
+ View<HeartChartPresenter>::OnSetUpView();
+
+ Draw();
+}
+void HeartChartView::OnTearDownView() {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnTearDownView");
+ View<HeartChartPresenter>::OnTearDownView();
+ return;
+}
+
+void HeartChartView::OnStop() {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::OnStop");
+ View<HeartChartPresenter>::OnStop();
+ if (container_ != nullptr) {
+ container_->RemoveAll();
+ delete container_;
+ container_ = nullptr;
+ }
+ return;
}
+} // namespace OHOS