优化心率弹窗的退出方式
authorCaisking <Casiking@zhihuishixun.com>
Sat, 24 Jan 2026 11:04:32 +0000 (19:04 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Sat, 24 Jan 2026 11:04:32 +0000 (19:04 +0800)
code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalPresenter.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckAbnormalView.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidPresenter.h
code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.cpp
code/sdk/application/wearable/fd272/nativeapp/nativeui/health/CheckInvalidView.h

index 2b9441c..0101b4f 100644 (file)
 #include <chrono>
 #include <thread>
 #include <sys/time.h>
+#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<uint16_t>(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
index c3fb32b..d398514 100644 (file)
@@ -25,7 +25,7 @@ namespace OHOS
     class CheckAbnormalView;
     class CheckAbnormalPresenter : public Presenter<CheckAbnormalView>,
                                    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};
     };
 }
 
index ce04c40..e9b578f 100644 (file)
@@ -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);
     }
 }
index 848d6bd..4e1af37 100644 (file)
 #include <chrono>
 #include <thread>
 #include <sys/time.h>
+#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<uint16_t>(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
index f8916ce..21f072b 100644 (file)
@@ -24,7 +24,7 @@ namespace OHOS
     class CheckInvalidView;
     class CheckInvalidPresenter : public Presenter<CheckInvalidView>,
                                    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};
     };
 }
 
index 3d98a61..727f9cb 100644 (file)
@@ -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);
     }
    
 }
index 5ebce12..d952a26 100644 (file)
@@ -68,6 +68,7 @@ namespace OHOS
         void SetNoteLabel(UIResourceTextId viewId, int checkResult);
 
     private:
+        UIViewGroup *group = nullptr;
         // 提醒图标
         UIImageView *noteimage = nullptr;
         // 按键