From 3a67c718d928be5df4d2dd8b1e4859ed7addb8ff Mon Sep 17 00:00:00 2001 From: Caisking Date: Sat, 24 Jan 2026 19:04:32 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E5=BF=83=E7=8E=87=E5=BC=B9?= =?utf8?q?=E7=AA=97=E7=9A=84=E9=80=80=E5=87=BA=E6=96=B9=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../health/CheckAbnormalPresenter.cpp | 48 ++++++++++++++++++- .../nativeui/health/CheckAbnormalPresenter.h | 8 +++- .../nativeui/health/CheckAbnormalView.cpp | 5 ++ .../nativeui/health/CheckInvalidPresenter.cpp | 48 ++++++++++++++++++- .../nativeui/health/CheckInvalidPresenter.h | 8 +++- .../nativeui/health/CheckInvalidView.cpp | 39 ++++++++++++--- .../nativeui/health/CheckInvalidView.h | 1 + 7 files changed, 145 insertions(+), 12 deletions(-) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp index 2b9441ce5..0101b4fc4 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp @@ -37,6 +37,10 @@ #include #include #include +#include "UiConfig.h" +#include "NativeAbility.h" +#include "gfx_utils/graphic_math.h" +#include "custom_runtime.h" #ifdef SUPPORT_PPG_SERVICE #include "ppg_service.h" @@ -87,13 +91,16 @@ namespace OHOS } void CheckAbnormalPresenter::OnPause(void) {} - void CheckAbnormalPresenter::OnResume(void) {} + void CheckAbnormalPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + } void CheckAbnormalPresenter::OnStop(void) {} bool CheckAbnormalPresenter::OnClick(UIView &view, const ClickEvent &event) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodPresenter::OnClick"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckAbnormalPresenter::OnClick"); if (strcmp(view.GetViewId(), CLICK_BLOOD_STOP) == 0) { @@ -128,4 +135,41 @@ namespace OHOS return true; } + bool CheckAbnormalPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckAbnormalPresenter::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) + { + NativeAbility::GetInstance().Back(); + } + return true; + } + + bool CheckAbnormalPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckAbnormalPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) + { + X_DRAG_FLAG = true; + } + return true; + } + + bool CheckAbnormalPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckAbnormalPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(); + X_DRAG_FLAG = false; + } + return true; + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.h index c3fb32bfb..d3985145f 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.h @@ -25,7 +25,7 @@ namespace OHOS class CheckAbnormalView; class CheckAbnormalPresenter : public Presenter, public UIView::OnClickListener, - + public RootView::OnKeyActListener, public UIView::OnDragListener { public: @@ -39,6 +39,12 @@ namespace OHOS void OnStop() override; bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + + private: + bool X_DRAG_FLAG{false}; }; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalView.cpp index ce04c4032..e9b578f94 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalView.cpp @@ -24,6 +24,7 @@ #include "vibrator_service.h" #include "custom_runtime.h" +#include "key/include/KeyInputListener.h" namespace OHOS { @@ -185,5 +186,9 @@ namespace OHOS { custom_VibratorFunc_int(0); } + + // 增加按键监听 + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::CheckAbnormalPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp index 848d6bdd1..4e1af3771 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp @@ -37,6 +37,10 @@ #include #include #include +#include "UiConfig.h" +#include "NativeAbility.h" +#include "gfx_utils/graphic_math.h" +#include "custom_runtime.h" #ifdef SUPPORT_PPG_SERVICE #include "ppg_service.h" @@ -82,13 +86,16 @@ namespace OHOS } void CheckInvalidPresenter::OnPause(void) {} - void CheckInvalidPresenter::OnResume(void) {} + void CheckInvalidPresenter::OnResume(void) + { + RootView::GetInstance()->SetOnKeyActListener(this); + } void CheckInvalidPresenter::OnStop(void) {} bool CheckInvalidPresenter::OnClick(UIView &view, const ClickEvent &event) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodPresenter::OnClick"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckInvalidPresenter::OnClick"); if (strcmp(view.GetViewId(), CLICK_HEALTH_KONW) == 0) { @@ -97,4 +104,41 @@ namespace OHOS return true; } + bool CheckInvalidPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckInvalidPresenter::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) + { + NativeAbility::GetInstance().Back(); + } + return true; + } + + bool CheckInvalidPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckInvalidPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) + { + X_DRAG_FLAG = true; + } + return true; + } + + bool CheckInvalidPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CheckInvalidPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(); + X_DRAG_FLAG = false; + } + return true; + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.h index f8916ce9d..21f072bd3 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.h @@ -24,7 +24,7 @@ namespace OHOS class CheckInvalidView; class CheckInvalidPresenter : public Presenter, public UIView::OnClickListener, - + public RootView::OnKeyActListener, public UIView::OnDragListener { public: @@ -38,6 +38,12 @@ namespace OHOS void OnStop() override; bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + + private: + bool X_DRAG_FLAG{false}; }; } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.cpp index 3d98a619e..727f9cbe5 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.cpp @@ -114,7 +114,7 @@ namespace OHOS kownButton->SetImageSrc(PNG_466x100BUTTON_IMAGE, PNG_466x100BUTTON_IMAGE); kownButton->SetOnClickListener(presenter_); - AddViewToRootContainer(kownButton); + group->Add(kownButton); return true; } /*** @@ -131,9 +131,9 @@ namespace OHOS noteLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); noteLabel->SetRollSpeed(23); - AddViewToRootContainer(titleLabel); - AddViewToRootContainer(remindLabel); - AddViewToRootContainer(noteLabel); + group->Add(titleLabel); + group->Add(remindLabel); + group->Add(noteLabel); return true; } /*** @@ -147,7 +147,7 @@ namespace OHOS noteimage->SetPosition(193, 120, 80, 80); noteimage->SetSrc(BLOOD_PATH_NOTE); - AddViewToRootContainer(noteimage); + group->Add(noteimage); return true; } /*** @@ -157,6 +157,21 @@ namespace OHOS bool CheckInvalidView::CheckInvalidViewInit() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "bool CheckInvalidView::InitView()"); + // 创建group容器 + if (group == nullptr) + { + group = new UIViewGroup(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CheckInvalidViewInit: group new fail!!"); + return false; + } + group->SetPosition(0, 0, 466, 466); + group->SetStyle(STYLE_BACKGROUND_OPA, 0); + group->SetTouchable(true); + group->SetDraggable(true); + group->SetOnDragListener(presenter_); + } if (!Initbackground()) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Initbackground error!"); @@ -169,6 +184,9 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddButton error!"); }; + + // 将group添加到根容器 + AddViewToRootContainer(group); return true; } /*** @@ -177,6 +195,10 @@ namespace OHOS */ void CheckInvalidView::DeInit() { + if (group != nullptr) + { + group->RemoveAll(); + } if (kownButton != nullptr) { delete kownButton; @@ -202,6 +224,11 @@ namespace OHOS delete noteimage; noteimage = nullptr; } + if (group != nullptr) + { + delete group; + group = nullptr; + } } void CheckInvalidView::OnStart() @@ -223,7 +250,7 @@ namespace OHOS // 增加按键监听 RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::CheckInvalidPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } } diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.h index 5ebce1205..d952a26d5 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.h @@ -68,6 +68,7 @@ namespace OHOS void SetNoteLabel(UIResourceTextId viewId, int checkResult); private: + UIViewGroup *group = nullptr; // 提醒图标 UIImageView *noteimage = nullptr; // 按键 -- 2.17.1