From 88e348981dda720fa0f47bcc989f14b8e989e6fc Mon Sep 17 00:00:00 2001 From: Caisking Date: Tue, 3 Feb 2026 14:21:51 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E9=AA=91=E8=A1=8C=E7=9A=84?= =?utf8?q?=E8=B7=9D=E7=A6=BB=E7=9A=84=E5=A2=9E=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/traing/src/TraingEnddataView.cpp | 170 +++++++---------- .../nativeui/traing/src/TraingModel.cpp | 19 +- .../include/TraingCardPresenter.h | 180 +++++++++--------- 3 files changed, 178 insertions(+), 191 deletions(-) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataView.cpp index 5522b82a4..379033ade 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingEnddataView.cpp @@ -207,103 +207,90 @@ void TraingEnddataView ::InitializeLabels() { scrollView_->Add(labelstrong); scrollView_->Add(labelcalories); } -// 增加额外配置 +// 增加额外配置:骑行仅显示距离一行;算法支持运动显示距离/步数/配速/步幅/步频 void TraingEnddataView::BonusdataView() { - if (!TraingModel::GetInstance()->GetIsSpecial()) - return; - - std::vector canvasData = TraingModel::GetInstance()->GetCanvasData(); - int height_canvas = 0; - if (canvasData.size() > 0) { - height_canvas = 400; - } else { - height_canvas = 0; - } - - //需要局部变量 不然会重复增加 + TraingModel *model = TraingModel::GetInstance(); + std::vector canvasData = model->GetCanvasData(); + int height_canvas = (canvasData.size() > 0) ? CANVAS_SIZE : 0; int baseY_Init_Bonusdata = baseY + height_canvas; int startY_Unit_Init_Bonusdata = startY_Unit + height_canvas; int startY_Value_Init_Bonusdata = startY_Value + height_canvas; + int tagflge = model->GetSportTag() ? 1 : 0; + const int row0 = 4 + tagflge; + + // 骑行:只显示距离一行 + if (model->GetSportEvent() == UIResourceTextId::STR_EXERCISE_OUTDOORBIKING) { + InitImageView(imageLine8, 97, baseY_Init_Bonusdata + row0 * lineHeight, 80, 20, + "image8", LINE_IMAGE); + scrollView_->Add(imageLine8); + InitRollLabel(labelumile, 146, startY_Unit_Init_Bonusdata + labelInterval * row0, 240, 40, + "label10", STR_RANGE_MILE, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(labelmile, 146, startY_Value_Init_Bonusdata + row0 * labelInterval, 240, 60, + "label15", "--", DEFAULT_VECTOR_FONT_FILENAME, 40); + labelumile->SetTextColor(textColor); + labelmile->SetTextColor(Color::Blue()); + scrollView_->Add(labelumile); + scrollView_->Add(labelmile); + return; + } - bool isincludeTag = TraingModel::GetInstance()->GetSportTag(); - int tagflge = isincludeTag ? 1 : 0; - - // 初始化线条 - - InitImageView(imageLine8, 97, - baseY_Init_Bonusdata + (4 + tagflge) * lineHeight, 80, 20, - "image8", LINE_IMAGE); // imageLine8 - InitImageView(imageLine9, 97, - baseY_Init_Bonusdata + (5 + tagflge) * lineHeight, 80, 20, - "image9", LINE_IMAGE); // imageLine9 - InitImageView(imageLine10, 97, - baseY_Init_Bonusdata + (6 + tagflge) * lineHeight, 80, 20, - "image10", LINE_IMAGE); // imageLine10 - InitImageView(imageLine11, 97, - baseY_Init_Bonusdata + (7 + tagflge) * lineHeight, 80, 20, + if (!model->GetIsSpecial()) + return; + + // 算法支持运动:5 行线条 + InitImageView(imageLine8, 97, baseY_Init_Bonusdata + row0 * lineHeight, 80, 20, + "image8", LINE_IMAGE); + InitImageView(imageLine9, 97, baseY_Init_Bonusdata + (5 + tagflge) * lineHeight, 80, 20, + "image9", LINE_IMAGE); + InitImageView(imageLine10, 97, baseY_Init_Bonusdata + (6 + tagflge) * lineHeight, 80, 20, + "image10", LINE_IMAGE); + InitImageView(imageLine11, 97, baseY_Init_Bonusdata + (7 + tagflge) * lineHeight, 80, 20, "image11", LINE_IMAGE); - InitImageView(imageLine12, 97, - baseY_Init_Bonusdata + (8 + tagflge) * lineHeight, 80, 20, + InitImageView(imageLine12, 97, baseY_Init_Bonusdata + (8 + tagflge) * lineHeight, 80, 20, "image7", LINE_IMAGE); - scrollView_->Add(imageLine8); scrollView_->Add(imageLine9); scrollView_->Add(imageLine10); scrollView_->Add(imageLine11); scrollView_->Add(imageLine12); - // 初始化标签 // 距离 - InitRollLabel(labelumile, 146, - startY_Unit_Init_Bonusdata + labelInterval * (4 + tagflge), 240, - 40, "label10", STR_RANGE_MILE, DEFAULT_VECTOR_FONT_FILENAME, - 30); - InitLabel(labelmile, 146, - startY_Value_Init_Bonusdata + (4 + tagflge) * labelInterval, 240, - 60, "label15", "--", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitRollLabel(labelumile, 146, startY_Unit_Init_Bonusdata + labelInterval * row0, 240, 40, + "label10", STR_RANGE_MILE, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(labelmile, 146, startY_Value_Init_Bonusdata + row0 * labelInterval, 240, 60, + "label15", "--", DEFAULT_VECTOR_FONT_FILENAME, 40); labelumile->SetTextColor(textColor); labelmile->SetTextColor(Color::Blue()); // 步数 - InitRollLabel(labelusteps, 146, - startY_Unit_Init_Bonusdata + labelInterval * (5 + tagflge), 240, - 40, "label12", STR_STEP_NUMBER, DEFAULT_VECTOR_FONT_FILENAME, - 30); - InitLabel(labelsteps, 146, - startY_Value_Init_Bonusdata + (5 + tagflge) * labelInterval, 240, - 60, "label17", "--", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitRollLabel(labelusteps, 146, startY_Unit_Init_Bonusdata + labelInterval * (5 + tagflge), 240, 40, + "label12", STR_STEP_NUMBER, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(labelsteps, 146, startY_Value_Init_Bonusdata + (5 + tagflge) * labelInterval, 240, 60, + "label17", "--", DEFAULT_VECTOR_FONT_FILENAME, 40); labelusteps->SetTextColor(textColor); labelsteps->SetTextColor(Color::Green()); // 平均配速 - InitRollLabel(labeluavpace, 146, - startY_Unit_Init_Bonusdata + labelInterval * (6 + tagflge), 240, - 40, "label2", STR_AVG_PACE, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitLabel(labelavpace, 146, - startY_Value_Init_Bonusdata + (6 + tagflge) * labelInterval, 240, - 60, "label17", "--", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitRollLabel(labeluavpace, 146, startY_Unit_Init_Bonusdata + labelInterval * (6 + tagflge), 240, 40, + "label2", STR_AVG_PACE, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(labelavpace, 146, startY_Value_Init_Bonusdata + (6 + tagflge) * labelInterval, 240, 60, + "label17", "--", DEFAULT_VECTOR_FONT_FILENAME, 40); labeluavpace->SetTextColor(textColor); labelavpace->SetTextColor(Color::Green()); // 步幅 - InitRollLabel(labelustride, 146, - startY_Unit_Init_Bonusdata + labelInterval * (7 + tagflge), 240, - 40, "label2", STR_STEP_LENGTH, DEFAULT_VECTOR_FONT_FILENAME, - 30); - InitLabel(labelstride, 146, - startY_Value_Init_Bonusdata + (7 + tagflge) * labelInterval, 240, - 60, "label17", "77", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitRollLabel(labelustride, 146, startY_Unit_Init_Bonusdata + labelInterval * (7 + tagflge), 240, 40, + "label2", STR_STEP_LENGTH, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(labelstride, 146, startY_Value_Init_Bonusdata + (7 + tagflge) * labelInterval, 240, 60, + "label17", "77", DEFAULT_VECTOR_FONT_FILENAME, 40); labelustride->SetTextColor(textColor); labelstride->SetTextColor(Color::Green()); // 步频 - InitRollLabel(labelufreq, 146, - startY_Unit_Init_Bonusdata + labelInterval * (8 + tagflge), 240, - 40, "label2", STR_STEP_FREQUENCY, DEFAULT_VECTOR_FONT_FILENAME, - 30); - InitLabel(labelfreq, 146, - startY_Value_Init_Bonusdata + (8 + tagflge) * labelInterval, 240, - 60, "label17", "154", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitRollLabel(labelufreq, 146, startY_Unit_Init_Bonusdata + labelInterval * (8 + tagflge), 240, 40, + "label2", STR_STEP_FREQUENCY, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(labelfreq, 146, startY_Value_Init_Bonusdata + (8 + tagflge) * labelInterval, 240, 60, + "label17", "154", DEFAULT_VECTOR_FONT_FILENAME, 40); labelufreq->SetTextColor(textColor); labelfreq->SetTextColor(Color::Green()); @@ -318,43 +305,28 @@ void TraingEnddataView::BonusdataView() { scrollView_->Add(labelufreq); scrollView_->Add(labelfreq); } -// 配置退出相关位置 +// 配置退出相关位置:根据前方 Bonus 行数决定 Y,避免与「距离」「更多前往app」重叠 void TraingEnddataView::ExitView() { - - std::vector canvasData = TraingModel::GetInstance()->GetCanvasData(); - int height_canvas = 0; - if (canvasData.size() > 0) { - height_canvas = CANVAS_SIZE; - } else { - height_canvas = 0; - } + TraingModel *model = TraingModel::GetInstance(); + std::vector canvasData = model->GetCanvasData(); + int height_canvas = (canvasData.size() > 0) ? CANVAS_SIZE : 0; int startY_Value_Init_Exit = startY_Value + height_canvas; + int tagflge = model->GetSportTag() ? 1 : 0; - bool isincludeTag = TraingModel::GetInstance()->GetSportTag(); - int tagflge = isincludeTag ? 1 : 0; - - if (TraingModel::GetInstance()->GetIsSpecial()) { - // 初始化退出(最后 要根据前方配置设置位置) - // 是否为特殊运动 - // 是否包含目标 - InitRollLabel( - exitLabel, 80, - (startY_Value_Init_Exit + labelInterval * (8 + tagflge) + 100), 300, 40, - "label8", STR_MORE_APP, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitButtonExt( - exitButton, 42, - (startY_Value_Init_Exit + labelInterval * (8 + tagflge) + 160), 380, - 100, BUTTONBACK, STR_CLOSE, 30); + int exitRow; // 退出区域起始行,必须在前方最后一行之下 + if (model->GetIsSpecial()) { + exitRow = 8 + tagflge; // 特殊运动:时长/心率/强度/卡路里/目标 + 距离/步数/配速/步幅/步频 共 8 行 + } else if (model->GetSportEvent() == UIResourceTextId::STR_EXERCISE_OUTDOORBIKING) { + exitRow = 4 + tagflge; // 骑行:上方多一行「距离」,排在 (4+tagflge) 行之后 } else { - InitRollLabel( - exitLabel, 80, - (startY_Value_Init_Exit + labelInterval * (3 + tagflge) + 100), 300, 40, - "label8", STR_MORE_APP, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitButtonExt( - exitButton, 42, - (startY_Value_Init_Exit + labelInterval * (3 + tagflge) + 160), 380, - 100, BUTTONBACK, STR_CLOSE, 30); + exitRow = 3 + tagflge; // 普通:仅时长/心率/强度/卡路里(+ 目标) } + + int yLabel = startY_Value_Init_Exit + labelInterval * exitRow + 100; + int yButton = startY_Value_Init_Exit + labelInterval * exitRow + 160; + InitRollLabel(exitLabel, 80, yLabel, 300, 40, + "label8", STR_MORE_APP, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitButtonExt(exitButton, 42, yButton, 380, 100, BUTTONBACK, STR_CLOSE, 30); exitLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); scrollView_->Add(exitLabel); exitButton->SetOnClickListener(presenter_); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp index 310ab1908..f372e4eab 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingModel.cpp @@ -1407,10 +1407,25 @@ void TraingModel::SetSportdata(SportData *data) { */ /*保存数据*/ bool TraingModel::SaveSportData() { - + + // 骑行等需要GPS的运动:CYWEE无距离时,在结束时用GPS轨迹一次性计算,不实时计 + if (sportdata->distance == 0 && IsNeedGPS(sportId_) && gpsData.size() >= 2) { + uint32_t gpsDist = CalculateDistanceFromGPSTrack(); + if (gpsDist > 0) { + sportdata->distance = gpsDist; + if (sportdata->duration > 0) { + sportdata->apc = (sportdata->duration * 1000) / sportdata->distance; + if (sportdata->fpc <= 0) sportdata->fpc = sportdata->apc; + if (sportdata->spc <= 0) sportdata->spc = sportdata->apc; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, + "结束时用GPS轨迹计算距离: %u米, 平均配速=%d", gpsDist, sportdata->apc); + } + } + // 配置训练存储状态 uapi_dev_runtime_set_train_storage_status(1); - + Trainingdata data; data.src = Openingway; data.bt = static_cast(sportdata->sportType); diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h index 46660b0bb..0ba756476 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_card/include/TraingCardPresenter.h @@ -1,91 +1,91 @@ - -#ifndef _TraingCard_PRESENTER_H -#define _TraingCard_PRESENTER_H - -#include "ModelListenerSample.h" -#include "Presenter.h" -#include "TraingCardView.h" -#include "traing/training_card/include/TrainingControlView.h" -#include "traing/training_card/include/TrainingDataView.h" -#include "traing/training_card/include/TrainingDetailView.h" - -#ifdef SUPPORT_BLE_SERVICE -#include "bleInstruct.h" -#include "bleService.h" -#include - -#endif - -#include "components/root_view.h" -#include "components/ui_swipe_view.h" -#include "components/ui_view.h" - -#ifdef SUPPORT_CYWEE_SERVICE -#include "cywee_hal.h" -#include "cywee_service.h" -#endif - -#include "traing/include/TraingModel.h" -#include "uicomponents/UIComponents.h" - -namespace OHOS { -class TraingCardView; -class TrainingControlView; -class TrainingDataView; -class TrainingDetailView; -class TraingModel; -class TraingCardPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener, - public UISwipeView::OnSwipeListener, - public RootView::OnKeyActListener, - public ModelListenerSample { -public: - TraingCardPresenter(); - virtual ~TraingCardPresenter() override; - static TraingCardPresenter *GetInstance(void); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - void OnTickEvent() override{}; - void Notify() override {} - - bool OpenSensor(ExerciseClass type); - bool ControlSensor(ExerciseState state); - - void ModifiesTime(); - void RefreshData(SportData *sportdata); // 更新数据 - - void UpdateTimeOfControl(); - void UpdateTimeOfData(); - void UpdateDataView(); - void updataview(); - /*蓝牙开启运动*/ -#ifdef SUPPORT_BLE_SERVICE - bool send_sport_cmd(training_ble *cmd); -#endif - - /*控制*/ - void handleStartState(); - void handleEndState(); - void handlePauseState(); - void handleContinueState(); - -private: - // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDragStart(UIView &view, const DragEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - bool OnDragEnd(UIView &view, const DragEvent &event) override; - void OnSwipe(UISwipeView &view) override; - bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 - - int tag_ = 0; - bool opensensorstuats{false}; - bool Y_DRAG_FLAG{false}; // 标记是否为垂直滑动,用于阻止水平滑动 -}; -} // namespace OHOS - + +#ifndef _TraingCard_PRESENTER_H +#define _TraingCard_PRESENTER_H + +#include "ModelListenerSample.h" +#include "Presenter.h" +#include "TraingCardView.h" +#include "traing/training_card/include/TrainingControlView.h" +#include "traing/training_card/include/TrainingDataView.h" +#include "traing/training_card/include/TrainingDetailView.h" + +#ifdef SUPPORT_BLE_SERVICE +#include "bleInstruct.h" +#include "bleService.h" +#include + +#endif + +#include "components/root_view.h" +#include "components/ui_swipe_view.h" +#include "components/ui_view.h" + +#ifdef SUPPORT_CYWEE_SERVICE +#include "cywee_hal.h" +#include "cywee_service.h" +#endif + +#include "traing/include/TraingModel.h" +#include "uicomponents/UIComponents.h" + +namespace OHOS { +class TraingCardView; +class TrainingControlView; +class TrainingDataView; +class TrainingDetailView; +class TraingModel; +class TraingCardPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener, + public RootView::OnKeyActListener, + public ModelListenerSample { +public: + TraingCardPresenter(); + virtual ~TraingCardPresenter() override; + static TraingCardPresenter *GetInstance(void); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + void OnTickEvent() override{}; + void Notify() override {} + + bool OpenSensor(ExerciseClass type); + bool ControlSensor(ExerciseState state); + + void ModifiesTime(); + void RefreshData(SportData *sportdata); // 更新数据 + + void UpdateTimeOfControl(); + void UpdateTimeOfData(); + void UpdateDataView(); + void updataview(); + /*蓝牙开启运动*/ +#ifdef SUPPORT_BLE_SERVICE + bool send_sport_cmd(training_ble *cmd); +#endif + + /*控制*/ + void handleStartState(); + void handleEndState(); + void handlePauseState(); + void handleContinueState(); + +private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDragStart(UIView &view, const DragEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + void OnSwipe(UISwipeView &view) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + + int tag_ = 0; + bool opensensorstuats{false}; + bool Y_DRAG_FLAG{false}; // 标记是否为垂直滑动,用于阻止水平滑动 +}; +} // namespace OHOS + #endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file -- 2.17.1