From bb23f97b6ae6056ca9f488d65f6a03c5ecc58cf7 Mon Sep 17 00:00:00 2001 From: Caisking Date: Mon, 5 Jan 2026 17:38:26 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E8=BF=90=E5=8A=A8=E7=95=8C?= =?utf8?q?=E9=9D=A2=E7=9A=84=E6=BB=91=E5=8A=A8=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../traing/include/TraingNomalPresenter.h | 2 +- .../nativeui/traing/include/TraingNomalView.h | 1 + .../nativeui/traing/src/TraingEnddataView.cpp | 24 ++----- .../traing/src/TraingNomalPresenter.cpp | 19 +++-- .../nativeui/traing/src/TraingNomalView.cpp | 69 +++++++++++-------- 5 files changed, 63 insertions(+), 52 deletions(-) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalPresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalPresenter.h index d8191b437..db13d7579 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalPresenter.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalPresenter.h @@ -34,8 +34,8 @@ namespace OHOS // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 - // bool OnDragEnd(UIView& view, const DragEvent& event) override; bool enter_flag{false}; }; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalView.h index 310f59241..e9118e7c2 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalView.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/include/TraingNomalView.h @@ -63,6 +63,7 @@ namespace OHOS TraingNomalView(TraingNomalView &&) = delete; TraingNomalView &operator=(TraingNomalView &&) = delete; + UIViewGroup *group = nullptr; UILabelExt *sporttitle_ = nullptr; UIButton *buttonGo_ = nullptr; UILabelButtonExt *buttonSet_ = nullptr; 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 cc3a60cc4..096c6cc67 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 @@ -393,9 +393,6 @@ void TraingEnddataView::DeInit() { // 确保 scrollView_ 存在,并移除所有组件 if (scrollView_) { scrollView_->RemoveAll(); - delete scrollView_; - scrollView_ = nullptr; - } // 删除所有 UILabelExt 类型指针 if (labelutime) { @@ -558,7 +555,6 @@ void TraingEnddataView::DeInit() { canvas = nullptr; } - if (scrollView_) { delete scrollView_; scrollView_ = nullptr; } @@ -732,14 +728,7 @@ void TraingEnddataView::InitData() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingEnddataView data initialization complete.\r\n"); } -// 设置按键监听 -static void SetKeyActListener() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); - // 增加按键监听 - RootView::OnKeyActListener *keyactListener = - (RootView::OnKeyActListener *)OHOS::TraingEnddataPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); -} + void TraingEnddataView::OnStart() { bool isNeedGPS = TraingModel::GetInstance()->IsNeedGPS(TraingModel::GetInstance()->GetSportEvent()); @@ -766,9 +755,9 @@ void TraingEnddataView::OnStart() { PreLoad(); InitData(); // 刷新数据 - GetRootContainer()->SetDraggable(true); - GetRootContainer()->SetTouchable(true); - GetRootContainer()->SetOnDragListener(presenter_); + scrollView_->SetDraggable(true); + scrollView_->SetTouchable(true); + scrollView_->SetOnDragListener(presenter_); // 检查是否有足够的GPS数据来绘制轨迹 if (isNeedGPS == false) { @@ -788,10 +777,11 @@ void TraingEnddataView::OnStart() { DrawTrackSegment(canvas); DrawMarkers(canvas); } else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS轨迹数据不足,不绘制轨迹"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GPS轨迹数据不足,不绘制轨迹"); } #endif - SetKeyActListener(); + + RootView::GetInstance()->SetOnKeyActListener(presenter_); } //////////////////////////////gps轨迹测试///////////////////////////////////// diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp index 527a405e0..ea6204dc7 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp @@ -97,11 +97,18 @@ namespace OHOS bool TraingNomalPresenter::OnDrag(UIView &view, const DragEvent &event) { UNUSED(view); - if ((event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) && (event.GetDeltaX() > X_DRAG_OFFSET) && - (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) - { - NavigateBack(); - } + // 在拖拽过程中不处理退出,只允许事件继续传播 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingNomalPresenter::OnDrag"); + return true; + } + + bool TraingNomalPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + // 在拖拽结束时判断是否满足退出条件 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingNomalPresenter::OnDragEnd"); + NavigateBack(); + return true; } @@ -171,6 +178,6 @@ namespace OHOS return; } //获取gps定位状态 - TraingNomalView::GetInstance()->updateview(); + // TraingNomalView::GetInstance()->updateview(); } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalView.cpp index f541b6f68..a84079121 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/src/TraingNomalView.cpp @@ -11,6 +11,10 @@ #include "traing/include/TraingModel.h" #include "uicomponents/UIComponents.h" #include "traing/Training_UiConfig.h" +#include "layout/grid_layout.h" +#include "font/ui_font.h" +#include +#include "cmsis_os.h" namespace OHOS { @@ -38,12 +42,17 @@ namespace OHOS /* InitView:初始化界面*/ void TraingNomalView ::InitView() { + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group is nullptr in InitView"); + return; + } UIResourceTextId sport_id = TraingModel::GetInstance()->GetSportEvent(); // 初始化Lable InitLabelExt(sporttitle_, 83, 50, 300, 35, "label1", sport_id, DEFAULT_VECTOR_FONT_FILENAME, 30); - AddViewToRootContainer(sporttitle_); + group->Add(sporttitle_); // 初始化Button InitButton(buttonGo_, 133, 133, 200, 200, BUTTONGO); @@ -61,8 +70,8 @@ namespace OHOS buttonGo_->SetOnClickListener(static_cast(TraingNomalPresenter::GetInstance())); buttonSet_->SetOnClickListener(static_cast(TraingNomalPresenter::GetInstance())); - AddViewToRootContainer(buttonGo_); - AddViewToRootContainer(buttonSet_); + group->Add(buttonGo_); + group->Add(buttonSet_); /*判断是否需要GPS*/ if(TraingModel::GetInstance()->IsNeedGPS(sport_id) == false) { @@ -71,9 +80,9 @@ namespace OHOS } #if defined(SUPPORT_GNSS) InitUILabel(heartrate_label_, -32, 230, 200, 60, "heartrate_label_", "--", DEFAULT_VECTOR_FONT_FILENAME, 30); - AddViewToRootContainer(heartrate_label_); + group->Add(heartrate_label_); InitUILabel(gps_label_, 295, 230, 200, 60, "label_time", "GPS", DEFAULT_VECTOR_FONT_FILENAME, 30); - AddViewToRootContainer(gps_label_); + group->Add(gps_label_); // 获取gps状态 bool gps_status = TraingModel::GetInstance()->GetGPSConnectState(); @@ -90,14 +99,17 @@ namespace OHOS InitImageView(gps_image_, 375, 193, 100, 100, "gps_image", GPS_2_IMAGE); buttonGo_->SetImageSrc(GO_2_IMAGE, GO_2_IMAGE); } - AddViewToRootContainer(gps_image_); + group->Add(gps_image_); InitImageView(heartrate_image_, 48, 193, 100, 100, "heartrate_image_", HEARTRATE_1_IMAGE); - AddViewToRootContainer(heartrate_image_); + group->Add(heartrate_image_); #endif } /* DeInit:删除组件*/ void TraingNomalView::DeInit() { + if (group != nullptr) + { + group->RemoveAll(); if (sporttitle_ != nullptr) { @@ -136,6 +148,9 @@ namespace OHOS heartrate_image_ = nullptr; } #endif + delete group; + group = nullptr; + } } void TraingNomalView::PreLoad(void) @@ -146,32 +161,27 @@ namespace OHOS viewiInitStatus = true; } } - // 设置按键监听 - static void SetKeyActListener() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); - // 增加按键监听 - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::TraingNomalPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); - } + void TraingNomalView::OnStart() { - + // 创建group容器 + group = new UIViewGroup(); + group->SetPosition(0, 0); + group->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - // 创建 draglistener 实例并设置为拖动监听器 - UIView::OnDragListener *draglistener = static_cast(TraingNomalPresenter::GetInstance()); - if (draglistener == nullptr) - { - return; - } - GetRootContainer()->SetOnDragListener(draglistener); - - GetRootContainer()->SetTouchable(true); - GetRootContainer()->SetDraggable(true); + // 设置拖拽监听器 + group->SetDraggable(true); + group->SetTouchable(true); + group->SetOnDragListener(presenter_); + // 初始化视图(所有视图将添加到group中) PreLoad(); - SetKeyActListener(); + // 将group添加到根容器 + AddViewToRootContainer(group); + + // 设置按键监听 + RootView::GetInstance()->SetOnKeyActListener(presenter_); } // 更新训练目标 [考虑 通用目标 特殊目标] @@ -225,7 +235,10 @@ namespace OHOS gps_image_->SetSrc(image); buttonGo_->SetImageSrc(button_image_path.c_str(), button_image_path.c_str()); //刷新一下 - GetRootContainer()->Invalidate(); + if (group != nullptr) + { + group->Invalidate(); + } return true; } } -- 2.17.1