开始ecg测量说明增加滑动效果
authorxue <2144439972@qq.com>
Mon, 15 Jun 2026 02:35:45 +0000 (10:35 +0800)
committerxue <2144439972@qq.com>
Mon, 15 Jun 2026 02:35:45 +0000 (10:35 +0800)
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPInstructionView.h
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/include/BPMainView.h
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPInstructionView.cpp
code/sdk/application/wearable/n9/nativeapp/nativeui/bloodpressure/src/BPMainPresenter.cpp

index 1170de7..719edb1 100644 (file)
@@ -4,6 +4,7 @@
 #include "components/ui_image_view.h"
 #include "components/ui_label.h"
 #include "components/ui_label_button.h"
+#include "components/ui_swipe_view.h"
 #include "components/ui_view_group.h"
 
 namespace OHOS {
@@ -31,10 +32,23 @@ public:
   static BPInstructionView *GetInstance();
   UIViewGroup *InitView(BPInstructionType type);
   void UpdateForType(BPInstructionType type);
+  bool IsInstructionSwipeView(const UISwipeView *view) const; //判断是否是指导界面滑动视图
+  void OnSwipePageChanged(uint16_t page); //指导界面滑动视图页码改变回调
 
 private:
-  void ApplyInstructionType(BPInstructionType type);
+  static bool IsSwipeableInstructionType(BPInstructionType type); //判断是否是可滑动指导界面类型
+  void ApplyInstructionContent(BPInstructionType type); //应用指导界面内容
+  void ApplyInstructionType(BPInstructionType type); //应用指导界面类型
+  void UpdateLayoutForType(BPInstructionType type); //更新指导界面布局
+  void EnsureInstructionSwipeView(); //确保指导界面滑动视图
+
+  BPInstructionType currentType_{BP_INSTRUCTION_TYPE_SEAT}; //当前指导界面类型
   UIViewGroup *group_{nullptr};
+  UISwipeView *instructionSwipeView_{nullptr};
+  UIViewGroup *swipePageSeat_{nullptr};
+  UIViewGroup *swipePageWear_{nullptr};
+  UIImageView *swipeSeatImage_{nullptr};
+  UIImageView *swipeWearImage_{nullptr};
   UIImageView *imageView_{nullptr};
   UILabel *instructionLabel_{nullptr};
   UILabelButton *backButton_{nullptr};
index 705456c..4ca69ac 100644 (file)
@@ -54,6 +54,7 @@ public:
   void RefreshCurrentView();
   /** AT^BPUIVIEW 调试用:切换到指定子界面,subType 用于说明页/异常页子类型 */
   void ShowAtTestPage(int16_t viewId, int16_t subType = 0);
+  void SetInstructionSubType(int16_t subType) { instructionSubType_ = subType; }
 
 private:
   void DeInit();
index 3dee2da..5ed2c97 100644 (file)
@@ -1,7 +1,9 @@
 #include "bloodpressure/include/BPInstructionView.h"
 #include "bloodpressure/include/BPMainPresenter.h"
+#include "bloodpressure/include/BPMainView.h"
 #include "bloodpressure/include/BPViewClickIds.h"
 #include "UiConfig.h"
+#include "common/screen.h"
 #include "uicomponents/UIComponents.h"
 #include "wearable_log.h"
 
@@ -9,16 +11,35 @@ namespace OHOS {
 
 static BPInstructionView *g_pBPInstructionView = nullptr;
 
+static constexpr int16_t kInstructionImageX = 141;
+static constexpr int16_t kInstructionImageY = 36;
+static constexpr int16_t kInstructionImageW = 184;
+static constexpr int16_t kInstructionImageH = 184;
+static constexpr int16_t kInstructionSwipeAreaH = 220;
+
 BPInstructionView::BPInstructionView() { g_pBPInstructionView = this; }
 
 BPInstructionView::~BPInstructionView() {
   if (group_ != nullptr) {
     group_->RemoveAll();
+    if (instructionSwipeView_ != nullptr) {
+      instructionSwipeView_->RemoveAll();
+    }
+    delete swipeSeatImage_;
+    delete swipeWearImage_;
+    delete swipePageSeat_;
+    delete swipePageWear_;
+    delete instructionSwipeView_;
     delete imageView_;
     delete instructionLabel_;
     delete backButton_;
     delete measureButton_;
     delete group_;
+    instructionSwipeView_ = nullptr;
+    swipePageSeat_ = nullptr;
+    swipePageWear_ = nullptr;
+    swipeSeatImage_ = nullptr;
+    swipeWearImage_ = nullptr;
     imageView_ = nullptr;
     instructionLabel_ = nullptr;
     backButton_ = nullptr;
@@ -30,38 +51,42 @@ BPInstructionView::~BPInstructionView() {
 
 BPInstructionView *BPInstructionView::GetInstance() { return g_pBPInstructionView; }
 
-void BPInstructionView::ApplyInstructionType(BPInstructionType type) {
-  if (imageView_ == nullptr || instructionLabel_ == nullptr || measureButton_ == nullptr) {
+bool BPInstructionView::IsSwipeableInstructionType(BPInstructionType type) { //判断是否是可滑动指导界面类型
+  return type == BP_INSTRUCTION_TYPE_SEAT || type == BP_INSTRUCTION_TYPE_WEAR;
+}
+
+bool BPInstructionView::IsInstructionSwipeView(const UISwipeView *view) const { //判断是否是指导界面滑动视图
+  return view != nullptr && view == instructionSwipeView_;
+}
+
+void BPInstructionView::ApplyInstructionContent(BPInstructionType type) { //应用指导界面内容
+  if (instructionLabel_ == nullptr || measureButton_ == nullptr) {
     return;
   }
+  measureButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff0176ff);
   switch (type) {
     case BP_INSTRUCTION_TYPE_SEAT:
-      imageView_->SetSrc(BLOOD_PATH_SEAT);
       instructionLabel_->SetText("双脚着地,端坐在椅子上\n双手手背朝上,手臂平放在桌子上");
       instructionLabel_->SetPosition(8, 230, 450, 70);
       measureButton_->SetText("开始测量");
       break;
     case BP_INSTRUCTION_TYPE_WEAR:
-      imageView_->SetSrc(BLOOD_PATH_WEAR);
       instructionLabel_->SetText("手表和手腕之间仅限一指距离\n偏紧佩戴手表");
-      instructionLabel_->SetPosition(38, 230, 370, 70);
+      instructionLabel_->SetPosition(38, 230, 390, 70);
       measureButton_->SetText("开始测量");
       break;
     case BP_INSTRUCTION_TYPE_BELT_LOOSE:
-      imageView_->SetSrc(BLOOD_PATH_BELT_LOOSE);
       instructionLabel_->SetText("表带过松\n请调整松紧后重试");
       instructionLabel_->SetPosition(113, 230, 240, 70);
       measureButton_->SetText("重新测量");
       measureButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36);
       break;
     case BP_INSTRUCTION_TYPE_FIRST:
-      imageView_->SetSrc(BLOOD_PATH_FIRST);
       instructionLabel_->SetText("坐姿端正,手臂平放桌面\n手表与心脏同高");
       instructionLabel_->SetPosition(68, 230, 330, 70);
       measureButton_->SetText("开始校准");
       break;
     case BP_INSTRUCTION_TYPE_SECOND:
-      imageView_->SetSrc(BLOOD_PATH_SECOND);
       instructionLabel_->SetText("测量同一只手,保持相同姿势\n准备完成后开始校准");
       instructionLabel_->SetPosition(38, 230, 390, 70);
       measureButton_->SetText("开始校准");
@@ -71,6 +96,105 @@ void BPInstructionView::ApplyInstructionType(BPInstructionType type) {
   }
 }
 
+void BPInstructionView::ApplyInstructionType(BPInstructionType type) {
+  currentType_ = type;
+  ApplyInstructionContent(type);
+  if (IsSwipeableInstructionType(type)) {
+    UpdateLayoutForType(type);
+    return;
+  }
+  if (imageView_ == nullptr) {
+    return;
+  }
+  switch (type) {
+    case BP_INSTRUCTION_TYPE_BELT_LOOSE:
+      imageView_->SetSrc(BLOOD_PATH_BELT_LOOSE);
+      break;
+    case BP_INSTRUCTION_TYPE_FIRST:
+      imageView_->SetSrc(BLOOD_PATH_FIRST);
+      break;
+    case BP_INSTRUCTION_TYPE_SECOND:
+      imageView_->SetSrc(BLOOD_PATH_SECOND);
+      break;
+    default:
+      break;
+  }
+}
+
+void BPInstructionView::EnsureInstructionSwipeView() {
+  if (instructionSwipeView_ != nullptr || group_ == nullptr) {
+    return;
+  }
+
+  const int16_t screenW = Screen::GetInstance().GetWidth();
+  instructionSwipeView_ = new UISwipeView(UISwipeView::HORIZONTAL);
+  if (instructionSwipeView_ == nullptr) {
+    return;
+  }
+  instructionSwipeView_->SetPosition(0, 0, screenW, kInstructionSwipeAreaH);
+  instructionSwipeView_->SetAnimatorTime(200);
+  instructionSwipeView_->SetDraggable(true);
+  instructionSwipeView_->SetTouchable(true);
+  instructionSwipeView_->SetOnSwipeListener(
+      static_cast<UISwipeView::OnSwipeListener *>(BPMainPresenter::GetInstance()));
+
+  swipePageSeat_ = new UIViewGroup();
+  swipePageWear_ = new UIViewGroup();
+  if (swipePageSeat_ == nullptr || swipePageWear_ == nullptr) {
+    return;
+  }
+  swipePageSeat_->SetPosition(0, 0, screenW, kInstructionSwipeAreaH);
+  swipePageWear_->SetPosition(0, 0, screenW, kInstructionSwipeAreaH);
+
+  InitImageView(swipeSeatImage_, kInstructionImageX, kInstructionImageY, kInstructionImageW,
+                kInstructionImageH, "bp_instruction_image_seat", BLOOD_PATH_SEAT);
+  InitImageView(swipeWearImage_, kInstructionImageX, kInstructionImageY, kInstructionImageW,
+                kInstructionImageH, "bp_instruction_image_wear", BLOOD_PATH_WEAR);
+  if (swipeSeatImage_ != nullptr) {
+    swipePageSeat_->Add(swipeSeatImage_);
+  }
+  if (swipeWearImage_ != nullptr) {
+    swipePageWear_->Add(swipeWearImage_);
+  }
+
+  instructionSwipeView_->Add(swipePageSeat_);
+  instructionSwipeView_->Add(swipePageWear_);
+  group_->Add(instructionSwipeView_);
+}
+
+void BPInstructionView::UpdateLayoutForType(BPInstructionType type) {
+  const bool swipeable = IsSwipeableInstructionType(type);
+  EnsureInstructionSwipeView();
+  if (instructionSwipeView_ != nullptr) {
+    instructionSwipeView_->SetVisible(swipeable);
+    instructionSwipeView_->SetDraggable(swipeable);
+    if (swipeable) {
+      const uint16_t page = type == BP_INSTRUCTION_TYPE_WEAR ? 1 : 0;
+      instructionSwipeView_->SetCurrentPage(page, false);
+    }
+  }
+  if (imageView_ != nullptr) {
+    imageView_->SetVisible(!swipeable);
+  }
+}
+
+void BPInstructionView::OnSwipePageChanged(uint16_t page) {
+  if (!IsSwipeableInstructionType(currentType_)) {
+    return;
+  }
+  BPInstructionType type =
+      page == 0 ? BP_INSTRUCTION_TYPE_SEAT : BP_INSTRUCTION_TYPE_WEAR;
+  if (type == currentType_) {
+    return;
+  }
+  currentType_ = type;
+  ApplyInstructionContent(type);
+  BPMainView *mainView = BPMainView::GetInstance();
+  if (mainView != nullptr) {
+    mainView->SetInstructionSubType(static_cast<int16_t>(type));
+  }
+}
+
 void BPInstructionView::UpdateForType(BPInstructionType type) { ApplyInstructionType(type); }
 
 UIViewGroup *BPInstructionView::InitView(BPInstructionType type) {
@@ -81,7 +205,8 @@ UIViewGroup *BPInstructionView::InitView(BPInstructionType type) {
   group_->SetPosition(0, 0, Screen::GetInstance().GetWidth(),
                       Screen::GetInstance().GetHeight());
 
-  InitImageView(imageView_, 141, 36, 184, 184, "bp_instruction_image", BLOOD_PATH_SEAT);
+  InitImageView(imageView_, kInstructionImageX, kInstructionImageY, kInstructionImageW,
+                kInstructionImageH, "bp_instruction_image", BLOOD_PATH_SEAT);
   InitUILabel(instructionLabel_, 53, 230, 360, 70, "bp_instruction_label", "",
               DEFAULT_VECTOR_FONT_FILENAME, 30);
   instructionLabel_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
@@ -90,8 +215,6 @@ UIViewGroup *BPInstructionView::InitView(BPInstructionType type) {
   InitLabelButton(measureButton_, 238, 320, 170, 90, BP_CLICK_MEASURE, "开始", 26);
   measureButton_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff0176ff);
 
-  ApplyInstructionType(type);
-
   auto *clickListener = static_cast<UIView::OnClickListener *>(BPMainPresenter::GetInstance());
   auto *dragListener = static_cast<UIView::OnDragListener *>(BPMainPresenter::GetInstance());
   backButton_->SetOnClickListener(clickListener);
@@ -102,6 +225,8 @@ UIViewGroup *BPInstructionView::InitView(BPInstructionType type) {
   group_->Add(instructionLabel_);
   group_->Add(backButton_);
   group_->Add(measureButton_);
+
+  ApplyInstructionType(type);
   return group_;
 }
 
index 8238672..c6266fc 100644 (file)
@@ -457,7 +457,11 @@ bool BPMainPresenter::OnDragEnd(UIView &view, const DragEvent &event) {
 }
 
 void BPMainPresenter::OnSwipe(UISwipeView &view) {
-  UNUSED(view);
+  BPInstructionView *instructionView = BPInstructionView::GetInstance();
+  if (instructionView != nullptr && instructionView->IsInstructionSwipeView(&view)) {
+    instructionView->OnSwipePageChanged(view.GetCurrentPage());
+    return;
+  }
   BPHistoryView *historyView = BPHistoryView::GetInstance();
   if (historyView != nullptr) {
     historyView->OnRecordPageChanged(view.GetCurrentPage());