优化心率UI
authorCaisking <Casiking@zhihuishixun.com>
Thu, 12 Mar 2026 09:10:15 +0000 (17:10 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Thu, 12 Mar 2026 09:10:15 +0000 (17:10 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/include/HeartChartView.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartChartView.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/heartrate/src/HeartNoteView.cpp

index 52ac29a..f8e14e4 100644 (file)
@@ -163,88 +163,52 @@ HeartChartView::HeartChartView() {
 }
 HeartChartView::~HeartChartView() {
   WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartView::~HeartChartView");
-  if (scrollView) {
-    scrollView->RemoveAll();
-
-    if (displayheart_) {
-      delete displayheart_;
-      displayheart_ = nullptr;
-    }
-    if (maxheart_) {
-      delete maxheart_;
-      maxheart_ = nullptr;
-    }
-    if (minheart_) {
-      delete minheart_;
-      minheart_ = nullptr;
-    }
-    if (uheart_) {
-      delete uheart_;
-      uheart_ = nullptr;
-    }
-    if (lastheart_) {
-      delete lastheart_;
-      lastheart_ = nullptr;
-    }
-    if (maxheart_dynamic_) {
-      delete maxheart_dynamic_;
-      maxheart_dynamic_ = nullptr;
-    }
-    if (maxheart_dynamic_3_) {
-      delete maxheart_dynamic_3_;
-      maxheart_dynamic_3_ = nullptr;
-    }
-    if (maxheart_dynamic_2_) {
-      delete maxheart_dynamic_2_;
-      maxheart_dynamic_2_ = nullptr;
-    }
-    if (maxheart_dynamic_1_) {
-      delete maxheart_dynamic_1_;
-      maxheart_dynamic_1_ = nullptr;
-    }
-    if (minheart_dynamic_) {
-      delete minheart_dynamic_;
-      minheart_dynamic_ = nullptr;
-    }
-
-    if (maxRateIconView_) {
-      delete maxRateIconView_;
-      maxRateIconView_ = nullptr;
-    }
-    if (minRateIconView_) {
-      delete minRateIconView_;
-      minRateIconView_ = nullptr;
-    }
-    if (chartBackgroundView_) {
-      delete chartBackgroundView_;
-      chartBackgroundView_ = nullptr;
-    }
-    if (heartIconView_) {
-      delete heartIconView_;
-      heartIconView_ = nullptr;
-    }
-
-    if (imageAnimator) {
-      imageAnimator->Stop();
-      delete imageAnimator;
-      imageAnimator = nullptr;
-    }
-
-    if (heartSerial) {
-      heartchart->ClearDataSerial();
-      delete heartSerial;
-      heartSerial = nullptr;
-    }
+  g_pHeartCheckView = nullptr;  // 提前置空,防止析构期间被其他线程使用
+  if (!viewInitStatus_ || scrollView == nullptr) {
+    return;
+  }
+  scrollView->RemoveAll();
+
+  // 释放 Label
+  if (displayheart_) { delete displayheart_; displayheart_ = nullptr; }
+  if (maxheart_) { delete maxheart_; maxheart_ = nullptr; }
+  if (minheart_) { delete minheart_; minheart_ = nullptr; }
+  if (uheart_) { delete uheart_; uheart_ = nullptr; }
+  if (lastheart_) { delete lastheart_; lastheart_ = nullptr; }
+  if (maxheart_dynamic_) { delete maxheart_dynamic_; maxheart_dynamic_ = nullptr; }
+  if (maxheart_dynamic_3_) { delete maxheart_dynamic_3_; maxheart_dynamic_3_ = nullptr; }
+  if (maxheart_dynamic_2_) { delete maxheart_dynamic_2_; maxheart_dynamic_2_ = nullptr; }
+  if (maxheart_dynamic_1_) { delete maxheart_dynamic_1_; maxheart_dynamic_1_ = nullptr; }
+  if (minheart_dynamic_) { delete minheart_dynamic_; minheart_dynamic_ = nullptr; }
+
+  // 释放 ImageView
+  if (maxRateIconView_) { delete maxRateIconView_; maxRateIconView_ = nullptr; }
+  if (minRateIconView_) { delete minRateIconView_; minRateIconView_ = nullptr; }
+  if (chartBackgroundView_) { delete chartBackgroundView_; chartBackgroundView_ = nullptr; }
+  if (heartIconView_) { delete heartIconView_; heartIconView_ = nullptr; }
+
+  // 先 Stop 再释放 Animator
+  if (imageAnimator) {
+    imageAnimator->Stop();
+    delete imageAnimator;
+    imageAnimator = nullptr;
+  }
 
+  // Chart 与 Serial:先 ClearDataSerial 解除引用,再 delete
+  if (heartSerial) {
     if (heartchart) {
-      delete heartchart;
-      heartchart = nullptr;
+      heartchart->ClearDataSerial();
     }
-
-    delete scrollView;
-    scrollView = nullptr;
+    delete heartSerial;
+    heartSerial = nullptr;
+  }
+  if (heartchart) {
+    delete heartchart;
+    heartchart = nullptr;
   }
-  g_pHeartCheckView = nullptr;
+
+  delete scrollView;
+  scrollView = nullptr;
 }
 HeartChartView *HeartChartView::GetInstance(void) { return g_pHeartCheckView; }
 
@@ -616,6 +580,7 @@ bool HeartChartView::HeartViewInit() {
   InitChartLabel();
 
   WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HeartChartViewInit is ok");
+  viewInitStatus_ = true;
   return true;
 }
 UIScrollView *HeartChartView::GetchartGroup() {
index 501c592..21b663a 100644 (file)
@@ -98,7 +98,7 @@ UIScrollView *HeartNoteView::CreateHeartNoteView(void) {
 
   InitButtonExt(ReButton, 238, 320, 170, 90, CLICK_HEART_RESTART, STR_RECHECK,
                 30);
-  ReButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff0D6EFF); // 设置按键颜色
+  ReButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff0d62ff); // 品牌蓝
   UIView::OnClickListener *buttonClickre =
       static_cast<UIView::OnClickListener *>(
           HeartChartPresenter::GetInstance());