From 47cc5a17ade8abc840baf2da21564ef48804c9bb Mon Sep 17 00:00:00 2001 From: Caisking Date: Sat, 13 Sep 2025 17:14:31 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E5=8A=A8GPS=EF=BC=8C?= =?utf8?q?=E5=8F=AA=E6=9C=89=E7=89=B9=E5=AE=9A=E8=BF=90=E5=8A=A8=E6=9C=89G?= =?utf8?q?PS?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../traing/include/TraingEnddataView.h | 2 + .../nativeui/traing/include/TraingModel.h | 3 ++ .../nativeui/traing/src/TraingEnddataView.cpp | 48 ++++++++++++++++++- .../nativeui/traing/src/TraingModel.cpp | 15 ++++++ .../traing/src/TraingNomalPresenter.cpp | 29 ++++++++--- .../nativeui/traing/src/TraingNomalView.cpp | 14 +++++- 6 files changed, 100 insertions(+), 11 deletions(-) diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingEnddataView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingEnddataView.h index e98707195..8741f1aff 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingEnddataView.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingEnddataView.h @@ -117,6 +117,8 @@ private: UILabelExt *labelstride = nullptr; // 训练步幅 UILabelExt *labelcalories = nullptr; // 训练卡路里 + UILabelExt *gpsNoTrackLabel = nullptr; // GPS轨迹失败提示标签 + UILabelExt *exitLabel = nullptr; // APP提醒 UILabelButtonExt *exitButton = nullptr; // 返回按键 diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingModel.h index 64f344b3e..5a04ff9cc 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/include/TraingModel.h @@ -403,6 +403,9 @@ public: bool GetSportExtraData(void); // 获取运动额外数据 uint8_t GetHeartRateData(void); // 获取心率数据 + //判断是不是需要GPS的运动 + bool IsNeedGPS(UIResourceTextId sportId_); + private: TraingModel(const TraingModel &) = delete; TraingModel &operator=(const TraingModel &) = delete; diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingEnddataView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingEnddataView.cpp index 3181ab815..968d2f8c8 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingEnddataView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingEnddataView.cpp @@ -172,6 +172,13 @@ void TraingEnddataView ::InitializeLabels() { scrollView_->Add(labelheart); scrollView_->Add(labelstrong); scrollView_->Add(labelcalories); + + // 初始化GPS轨迹失败提示标签(默认隐藏) + InitLabel(gpsNoTrackLabel, 33, 100 + CANVAS_SIZE/2 - 20, CANVAS_SIZE, 40, + "gpsNoTrackLabel", "未定位成功,没有GPS轨迹", DEFAULT_VECTOR_FONT_FILENAME, 24); + gpsNoTrackLabel->SetTextColor(Color::Red()); + gpsNoTrackLabel->SetVisible(false); // 默认隐藏 + scrollView_->Add(gpsNoTrackLabel); } // 增加额外配置 void TraingEnddataView::BonusdataView() { @@ -420,6 +427,10 @@ void TraingEnddataView::DeInit() { delete labelcalories; labelcalories = nullptr; } + if (gpsNoTrackLabel) { + delete gpsNoTrackLabel; + gpsNoTrackLabel = nullptr; + } /* 删除图片 label */ if (imageIcon) { @@ -656,6 +667,12 @@ void TraingEnddataView::InitData() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Stride length set: %s\r\n", strideStr.c_str()); // 打印步幅 } + // 判断是否需要GPS + if(TraingModel::GetInstance()->IsNeedGPS(enddata->sportId) == false) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); + return; + } #if defined(BOARD_W9) || defined(BOARD_N9) //读取一下gps文件 std::string gpsFilePath = @@ -689,6 +706,13 @@ void TraingEnddataView::OnStart() { GetRootContainer()->SetOnDragListener(presenter_); SetKeyActListener(); + + // 判断是否需要GPS + if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == false) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); + return; + } #if defined(BOARD_W9) || defined(BOARD_N9) ///////////////////////////gps轨迹测试////////////////////// canvas = new UICanvas(); @@ -697,8 +721,17 @@ void TraingEnddataView::OnStart() { canvas->SetPosition(33, 100); scrollView_->Add(canvas); GenerateTrackPoints(); - DrawTrackSegment(canvas); - DrawMarkers(canvas); + + // 检查是否有足够的GPS数据来绘制轨迹 + std::vector canvasData = TraingModel::GetInstance()->GetCanvasData(); + if (canvasData.size() >= 3) { + // 有足够数据,绘制轨迹 + DrawTrackSegment(canvas); + DrawMarkers(canvas); + } else { + // 数据不足,只显示提示标签(已在GenerateTrackPoints中处理) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GPS轨迹数据不足,不绘制轨迹"); + } #endif } @@ -717,8 +750,19 @@ void TraingEnddataView::GenerateTrackPoints() { std::vector canvasData = TraingModel::GetInstance()->GetCanvasData(); //最小轨迹点数限制,防止绘制失败 if (canvasData.size() < 3) { + // GPS数据不足,显示提示标签 + if (gpsNoTrackLabel) { + gpsNoTrackLabel->SetVisible(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GPS轨迹数据不足,显示提示标签"); + } return; } + + // GPS数据充足,隐藏提示标签 + if (gpsNoTrackLabel) { + gpsNoTrackLabel->SetVisible(false); + } + //将点位赋值 for (size_t i = 0; i < canvasData.size(); ++i) { seg1.points.push_back(canvasData[i]); diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingModel.cpp index b6d67d677..388b4a2ad 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingModel.cpp @@ -399,6 +399,21 @@ ExerciseClass TraingModel::GetSportId() { return ExerciseClass::FREE_TRAINING; } } +/*判断是否为需要Gps的运动*/ +bool TraingModel::IsNeedGPS(UIResourceTextId sportId_) { + //跑步 走路 骑行需要GPS + switch (sportId_) { + case UIResourceTextId::STR_EXERCISE_OUTDOORRUNNING: + case UIResourceTextId::STR_EXERCISE_OUTDOORWALKING: + case UIResourceTextId::STR_EXERCISE_INDOORRUNNING: + case UIResourceTextId::STR_EXERCISE_INDOORWALKING: + case UIResourceTextId::STR_EXERCISE_TREADMILL: + case UIResourceTextId::STR_EXERCISE_STROLLMACHINE: + return true; + default: + return false; + } +} /*判断是否为特殊运动*/ void TraingModel::IsSpecialSport(UIResourceTextId sportId_) { switch (sportId_) { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp index 1e2a2a7b1..451183906 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp @@ -107,14 +107,18 @@ namespace OHOS { //默认前往运动卡片 AppViewId viewid = VIEW_TRAININGCRAD; - #if defined(BOARD_W9) || defined(BOARD_N9) - bool gps_status = TraingModel::GetInstance()->GetGPSConnectState(); - if (!gps_status) + /*判断是否需要GPS*/ + if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == true) { - //未连接进入GPS提示界面 - viewid = VIEW_TRAINING_GPSNOTE; + #if defined(BOARD_W9) || defined(BOARD_N9) + bool gps_status = TraingModel::GetInstance()->GetGPSConnectState(); + if (!gps_status) + { + //未连接进入GPS提示界面 + viewid = VIEW_TRAINING_GPSNOTE; + } + #endif } - #endif NativeAbility::GetInstance().ChangeSlice(viewid); // 获取运动项目 ExerciseClass type = TraingModel::GetInstance()->GetSportId(); @@ -122,7 +126,12 @@ namespace OHOS TraingCardPresenter::GetInstance()->OpenSensor(type); // 设置为手表开启运动 TraingModel::GetInstance()->SetSportOpenWay(false); - enter_flag = true; + // 如果是进入运动卡片,设置进入标志位 + if(viewid == VIEW_TRAININGCRAD) + { + // 设置进入标志位 + enter_flag = true; + } } return true; } @@ -140,6 +149,12 @@ namespace OHOS void TraingNomalPresenter::Notify() { + /*判断是否需要GPS*/ + if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == false) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); + return; + } //获取gps定位状态 TraingNomalView::GetInstance()->updateview(); } diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalView.cpp index 52d28d696..82b412178 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/traing/src/TraingNomalView.cpp @@ -19,7 +19,11 @@ namespace OHOS TraingNomalView::TraingNomalView() { - TraingModel::GetInstance()->start_heart_gps(); + /*判断是否需要GPS*/ + if(TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()) == true) + { + TraingModel::GetInstance()->start_heart_gps(); + } g_pTraingNomalView = this; } @@ -61,8 +65,14 @@ namespace OHOS buttonGo_->SetOnClickListener(static_cast(TraingNomalPresenter::GetInstance())); buttonSet_->SetOnClickListener(static_cast(TraingNomalPresenter::GetInstance())); - AddViewToRootContainer(buttonGo_); + AddViewToRootContainer(buttonGo_); AddViewToRootContainer(buttonSet_); + /*判断是否需要GPS*/ + if(TraingModel::GetInstance()->IsNeedGPS(sport_id) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "该运动项不需要GPS"); + return; + } #if defined(BOARD_W9) || defined(BOARD_N9) InitUILabel(heartrate_label_, -32, 230, 200, 60, "heartrate_label_", "--", DEFAULT_VECTOR_FONT_FILENAME, 30); AddViewToRootContainer(heartrate_label_); -- 2.17.1