#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"
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;
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("开始校准");
}
}
+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) {
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);
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);
group_->Add(instructionLabel_);
group_->Add(backButton_);
group_->Add(measureButton_);
+
+ ApplyInstructionType(type);
return group_;
}