From 2f59ec2eab7095b4e30622c22a048b9b995f18be Mon Sep 17 00:00:00 2001 From: Caisking Date: Sat, 24 Jan 2026 19:18:11 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96GPS=E7=9B=B8=E5=85=B3=E6=8F=90?= =?utf8?q?=E9=86=92=E7=9A=84=E5=BC=B9=E7=AA=97=E9=80=80=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/TraingEphemerisNotePresenter.h | 7 ++- .../include/TraingGPSnotePresenter.h | 7 ++- .../training_GPS/include/TraingGPSnoteView.h | 4 +- .../src/TraingEphemerisNotePresenter.cpp | 20 +++++++ .../src/TraingEphemerisNoteView.cpp | 2 + .../src/TraingGPSnotePresenter.cpp | 52 ++++++++++++++++--- .../training_GPS/src/TraingGPSnoteView.cpp | 18 +++---- 7 files changed, 87 insertions(+), 23 deletions(-) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h index d172b88cc..54ca223a7 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingEphemerisNotePresenter.h @@ -4,6 +4,8 @@ #include "key/include/KeyInputListener.h" #include "Presenter.h" #include "TraingEphemerisNoteView.h" +#include "components/root_view.h" +#include "events/key_event.h" namespace OHOS { @@ -11,7 +13,8 @@ namespace OHOS class TraingEphemerisNotePresenter : public Presenter, public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnDragListener, + public RootView::OnKeyActListener { public: TraingEphemerisNotePresenter(); @@ -27,6 +30,8 @@ namespace OHOS 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 X_DRAG_FLAG{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnotePresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnotePresenter.h index 98fd93515..45a050f1e 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnotePresenter.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnotePresenter.h @@ -4,6 +4,8 @@ #include "key/include/KeyInputListener.h" #include "Presenter.h" #include "TraingGPSnoteView.h" +#include "components/root_view.h" +#include "events/key_event.h" namespace OHOS { @@ -11,7 +13,8 @@ namespace OHOS class TraingGPSnotePresenter : public Presenter, public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnDragListener, + public RootView::OnKeyActListener { public: TraingGPSnotePresenter(); @@ -27,6 +30,8 @@ namespace OHOS 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 X_DRAG_FLAG{false}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnoteView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnoteView.h index c24c9026c..6e423c5d3 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnoteView.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/include/TraingGPSnoteView.h @@ -25,8 +25,8 @@ #include "TraingGPSnotePresenter.h" namespace OHOS { -#define BUTTONBACK "button1" -#define BUTTONGO "button2" +#define GPSBUTTONBACK "button_back_gps" +#define GPSBUTTONGO "button_go_gps" class TraingGPSnotePresenter; class TraingGPSnoteView : public View { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp index 2678c38e0..8be437ca7 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNotePresenter.cpp @@ -12,6 +12,8 @@ #include "traing/include/TraingModel.h" #include "traing/include/TraingNomalPresenter.h" + + #include "NativeRegisterManager.h" namespace OHOS { @@ -61,6 +63,7 @@ namespace OHOS bool TraingEphemerisNotePresenter::OnClick(UIView &view, const ClickEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OnClick view.GetViewId() is %s", view.GetViewId()); // 根据控件id查找是哪个控件触发了点击回调 if (strcmp(view.GetViewId(), BUTTONTRAIN) == 0) { @@ -81,5 +84,22 @@ namespace OHOS } return true; } + + //增加按键退出 + bool TraingEphemerisNotePresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + + // 按键按下时退出到训练主界面 + if (keyState == 1) // 1表示按下 + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + return true; + } + UNUSED(view); + UNUSED(keyID); + return true; + } } // namespace OHOS diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp index edd0924d7..ab5aa54f3 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingEphemerisNoteView.cpp @@ -136,6 +136,8 @@ namespace OHOS void TraingEphemerisNoteView::OnStart() { PreLoad(); + // 注册按键监听 + RootView::GetInstance()->SetOnKeyActListener(presenter_); } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp index c30e2993f..d1850885d 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnotePresenter.cpp @@ -13,6 +13,12 @@ // #include "TraingGPSnoteView.h" #include "NativeRegisterManager.h" +#include "UiConfig.h" +#include "gfx_utils/graphic_math.h" +#include "custom_runtime.h" +#include "custom_utils.h" +#include "common/key_code.h" +#include "components/root_view.h" namespace OHOS { REGIST_SLICE(VIEW_TRAINING_GPSNOTE, TraingGPSnoteView, TraingGPSnotePresenter); @@ -44,39 +50,71 @@ namespace OHOS void TraingGPSnotePresenter::OnResume(void) { + RootView::GetInstance()->SetOnKeyActListener(this); } bool TraingGPSnotePresenter::OnDrag(UIView &view, const DragEvent &event) { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) + { + X_DRAG_FLAG = true; + } return true; } bool TraingGPSnotePresenter::OnDragEnd(UIView &view, const DragEvent &event) { - - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); NativeAbility::GetInstance().ChangeSlice(preSlice); + X_DRAG_FLAG = false; } - UNUSED(view); return true; } bool TraingGPSnotePresenter::OnClick(UIView &view, const ClickEvent &event) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnClick %s", view.GetViewId()); // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), BUTTONBACK) == 0) + if (strcmp(view.GetViewId(), GPSBUTTONBACK) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnClick BUTTONBACK"); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnClick preSlice is %d", preSlice); + NativeAbility::GetInstance().ChangeSlice(preSlice); + return true; } - if (strcmp(view.GetViewId(), BUTTONGO) == 0) + if (strcmp(view.GetViewId(), GPSBUTTONGO) == 0) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnClick BUTTONGO"); NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCRAD); - // 启动运动相关资源 ExerciseClass type = TraingModel::GetInstance()->GetSportId(); TraingCardPresenter::GetInstance()->OpenSensor(type); TraingModel::GetInstance()->SetSportOpenWay(false); + return true; + } + return false; + } + + //增加按键退出 + bool TraingGPSnotePresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingGPSnotePresenter::OnKeyAct"); + + + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); } return true; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnoteView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnoteView.cpp index 8583e0922..29840d43a 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnoteView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/traing/training_GPS/src/TraingGPSnoteView.cpp @@ -12,6 +12,7 @@ #include "uicomponents/UIComponents.h" #include "traing/Training_UiConfig.h" #include "ui_resource_image.h" +#include "components/root_view.h" namespace OHOS { @@ -51,6 +52,7 @@ namespace OHOS scrollView1_->SetReboundSize(100); scrollView1_->SetScrollBlankSize(52); scrollView1_->SetHorizontalScrollState(false); + scrollView1_->SetOnDragListener(presenter_); // Add to rootView AddViewToRootContainer(scrollView1_); scrollView1_->SetVisible(true); @@ -60,13 +62,13 @@ namespace OHOS scrollView1_->Add(image1_); // 初始化button - InitButtonExt(button_wait, 118, 334, 230, 80, BUTTONBACK, STR_SET_TARGET, 30); + InitButtonExt(button_wait, 118, 334, 230, 80, GPSBUTTONBACK, STR_SET_TARGET, 30); button_wait->SetText("继续等待"); button_wait->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c); scrollView1_->Add(button_wait); button_wait->SetOnClickListener(presenter_); - InitButtonExt(button_go, 118, 434, 230, 80, BUTTONGO, STR_SET_TARGET, 30); + InitButtonExt(button_go, 118, 434, 230, 80, GPSBUTTONGO, STR_SET_TARGET, 30); button_go->SetText("直接开始"); scrollView1_->Add(button_go); button_go->SetOnClickListener(presenter_); @@ -148,18 +150,10 @@ namespace OHOS { // 创建 draglistener 实例并设置为拖动监听器 - UIView::OnDragListener *draglistener = static_cast(TraingGPSnotePresenter::GetInstance()); - if (draglistener == nullptr) - { - return; - } - GetRootContainer()->SetOnDragListener(draglistener); - - GetRootContainer()->SetTouchable(true); - GetRootContainer()->SetDraggable(true); PreLoad(); - + // 注册按键监听 + RootView::GetInstance()->SetOnKeyActListener(presenter_); } } -- 2.17.1