ECGslice开始测量界面添加 1863/2
authorluozheng <1732036298@qq.com>
Wed, 18 Jun 2025 08:34:21 +0000 (16:34 +0800)
committerluozheng <1732036298@qq.com>
Wed, 18 Jun 2025 08:34:21 +0000 (16:34 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp
code/sdk/application/wearable/fd230app/nativeui/ecg/include/EcgStartTestView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/ecg/include/EcgView.h
code/sdk/application/wearable/fd230app/nativeui/ecg/src/EcgPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/ecg/src/EcgStartTestView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/ecg/src/EcgView.cpp

index 797f3ff..ccd967f 100644 (file)
@@ -251,7 +251,8 @@ set(SOURCES
     # ECG
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ecg/src/EcgModel.cpp 
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ecg/src/EcgPresenter.cpp 
-    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ecg/src/EcgView.cpp 
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ecg/src/EcgView.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ecg/src/EcgStartTestView.cpp 
 
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bluetooth/src/BluetoothDeviceListView.cpp
index f787403..f034b3b 100644 (file)
@@ -63,6 +63,7 @@ namespace OHOS
 #if defined(BOARD_W9) || defined(BOARD_N9)
         /*W9与N9的Slice写宏里面*/
         {VIEW_BLOOD_PRESSURE_CHECK, PNG_APPLIST_BP_MESSURE_IMAGE_BIG, PNG_APPLIST_BP_MESSURE_IMAGE, PNG_APPLIST_DEFAULT_IMG, "血压测量", STR_BP_CHECK, nullptr},
+        {VIEW_ECG, PNG_APPLIST_ECG_IMAGE_BIG, PNG_APPLIST_ECG_IMAGE, PNG_APPLIST_DEFAULT_IMG, "ECG", STR_BP_CHECK, nullptr},
 #endif
         {VIEW_SLEEP, PNG_APPLIST_SLEEP_IMAGE_BIG, PNG_APPLIST_SLEEP_IMAGE, PNG_APPLIST_DEFAULT_IMG, "睡眠", STR_SLEEP, nullptr},
         {VIEW_TRAINING, PNG_APPLIST_TRAINING_IMAGE_BIG, PNG_APPLIST_TRAINING_IMAGE, PNG_APPLIST_DEFAULT_IMG, "运动", STR_TRAINING, nullptr},
diff --git a/code/sdk/application/wearable/fd230app/nativeui/ecg/include/EcgStartTestView.h b/code/sdk/application/wearable/fd230app/nativeui/ecg/include/EcgStartTestView.h
new file mode 100644 (file)
index 0000000..c3cc6ba
--- /dev/null
@@ -0,0 +1,29 @@
+#ifndef ECG_START_TEST_VIEW_H
+#define ECG_START_TEST_VIEW_H
+
+#include "components/ui_view_group.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_button.h"
+#include "components/ui_label_button_ext.h"
+#include "components/ui_image_view.h"
+namespace OHOS
+{
+    static const char *STARTECGTESTBUTTON = "startEcgTestButton";//开始ecg测量
+    class EcgStartTestView
+    {
+    public:
+        EcgStartTestView();
+        ~EcgStartTestView();
+        static EcgStartTestView *GetInstance(void);
+        UIViewGroup* EcgStartTestInit();
+    private:
+        void ClearAll(void);
+        UIViewGroup* group{nullptr};
+        UILabelExt *titleLabel{nullptr};
+        UIImageView *image{nullptr};
+        UILabelButtonExt *startEcgTestButton{nullptr};
+    };
+
+
+}
+#endif
\ No newline at end of file
index 39114c7..57c6f38 100644 (file)
@@ -3,27 +3,39 @@
 
 #include "BaseView.h"
 #include "View.h"
-
+#include "components/ui_view_group.h"
+#include "ecg/include/EcgStartTestView.h"
 namespace OHOS
 {
+    typedef enum : uint8_t
+    {
+        ECGSTARTTESTVIEW = 0, // 开始测量界面
+        MAX_ECGVIEW,
+    } EcgViewID;
+
     class EcgPresenter;
     class EcgView : public View<EcgPresenter>
     {
-
     public:
         EcgView();
         ~EcgView();
         static EcgView *GetInstance(void);
 
+        bool ChangeEcgStartTestView(int16_t thisView);
+        bool ClickFunc(int16_t interface);
+        void ChangeView(int16_t hideView, int16_t showView);
+
         void OnStart() override;
         void OnSetUpView() override;
         void OnTearDownView() override;
         void OnStop() override;
 
+    private:
+        EcgStartTestView *p_EcgStartTestView{nullptr};
     private:
         void CreateEcgView(void);
         void ClearAll(void);
-
+        UIViewGroup *group[MAX_ECGVIEW]{nullptr};
         bool viewInitStatus{false};
     };
 }
index 04585d8..e53da21 100644 (file)
@@ -64,7 +64,12 @@ namespace OHOS
     bool EcgPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
         UNUSED(event);
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EcgPresenter::OnClick");
+        std::string viewId = view.GetViewId();
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EcgPresenter::OnClick,viewId = %s",viewId.c_str());
+        if(viewId == STARTECGTESTBUTTON)
+        {
+            
+        }
         return true;
     }
 
diff --git a/code/sdk/application/wearable/fd230app/nativeui/ecg/src/EcgStartTestView.cpp b/code/sdk/application/wearable/fd230app/nativeui/ecg/src/EcgStartTestView.cpp
new file mode 100644 (file)
index 0000000..9ae1ad1
--- /dev/null
@@ -0,0 +1,112 @@
+#include "ecg/include/EcgStartTestView.h"
+#include "ecg/include/EcgPresenter.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+    static EcgStartTestView *g_pEcgStartTestView{nullptr};
+    EcgStartTestView::EcgStartTestView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EcgStartTestView::EcgStartTestView");
+        g_pEcgStartTestView = this;
+    }
+    EcgStartTestView::~EcgStartTestView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EcgStartTestView::~EcgStartTestView");
+        ClearAll();
+        g_pEcgStartTestView = nullptr;
+    }
+    EcgStartTestView *EcgStartTestView::GetInstance(void)
+    {
+        return g_pEcgStartTestView;
+    }
+
+    void EcgStartTestView::ClearAll(void)
+    {
+        if (group)
+        {
+            group->RemoveAll();
+            delete titleLabel;
+            titleLabel = nullptr;
+            delete image;
+            image = nullptr;
+            delete startEcgTestButton;
+            startEcgTestButton = nullptr;
+            delete group;
+            group = nullptr;
+        }
+    }
+
+    UIViewGroup *EcgStartTestView::EcgStartTestInit()
+    {
+        if (group == nullptr)
+        {
+            group = new UIViewGroup();
+            if (group == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group null!");
+                return nullptr;
+            }
+        }
+        group->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+        group->SetTouchable(true);
+        group->SetDraggable(true);
+        UIView::OnDragListener *dragListener = (UIView::OnDragListener *)OHOS::EcgPresenter::GetInstance();
+        group->SetOnDragListener(dragListener);
+        if (titleLabel == nullptr)
+        {
+            titleLabel = new UILabelExt();
+            if (titleLabel == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel null!");
+                return nullptr;
+            }
+        }
+        titleLabel->SetPosition((HORIZONTAL_RESOLUTION - 300) / 2, 50, 300, 35);
+        titleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+        titleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+        titleLabel->SetText("ECG");
+        titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+        titleLabel->SetRollSpeed(23);
+        titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        group->Add(titleLabel);
+        /* -------------------------------------------------------------------------- */
+        if (image == nullptr)
+        {
+            image = new UIImageView();
+            if (image == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image null!");
+                return nullptr;
+            }
+        }
+        image->SetPosition((HORIZONTAL_RESOLUTION - 466) / 2, 150, 466, 300);
+        image->SetSrc("/user/res/BPCalibration/D.bin");
+        group->Add(image);
+        /* -------------------------------------------------------------------------- */
+        if (startEcgTestButton == nullptr)
+        {
+            startEcgTestButton = new UILabelButtonExt();
+            if (startEcgTestButton == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startEcgTestButton null!");
+                return nullptr;
+            }
+        }
+        startEcgTestButton->SetPosition((HORIZONTAL_RESOLUTION - 220) / 2, 360, 220, 70);
+        startEcgTestButton->SetStyle(STYLE_TEXT_FONT, 30);
+        startEcgTestButton->SetStyle(STYLE_LINE_HEIGHT, 35);
+        startEcgTestButton->SetAlign(TEXT_ALIGNMENT_CENTER);
+        startEcgTestButton->SetText("开始测量");
+        startEcgTestButton->SetViewId(STARTECGTESTBUTTON);
+        startEcgTestButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36);
+        startEcgTestButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        startEcgTestButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+        startEcgTestButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
+        UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::EcgPresenter::GetInstance();
+        startEcgTestButton->SetOnClickListener(clickListener);
+        group->Add(startEcgTestButton);
+        return group;
+    }
+}
\ No newline at end of file
index 25c4a37..3dc93f4 100644 (file)
@@ -27,11 +27,17 @@ namespace OHOS
     void EcgView::ClearAll(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EcgView::ClearAll");
+        if (p_EcgStartTestView)
+        {
+            delete p_EcgStartTestView;
+            p_EcgStartTestView = nullptr;
+        }
     }
 
     void EcgView::CreateEcgView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EcgView::CreateEcgView");
+        ChangeView(MAX_ECGVIEW, ECGSTARTTESTVIEW);
     }
 
     void EcgView::OnStart()
@@ -45,7 +51,6 @@ namespace OHOS
             return;
         }
         container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
-        container_->SetOnDragListener(presenter_);
         container_->SetTouchable(true);
         container_->SetDraggable(true);
 
@@ -58,6 +63,74 @@ namespace OHOS
         RootView::GetInstance()->SetOnKeyActListener(presenter_);
         return;
     }
+
+    bool EcgView::ChangeEcgStartTestView(int16_t thisView)
+    {
+        // 检查视图是否已初始化
+        if (group[thisView] == nullptr)
+        {
+            p_EcgStartTestView = new EcgStartTestView();
+            if (p_EcgStartTestView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new scrollView[%d] fail", thisView);
+                return false;
+            }
+            // 初始化视图并添加到视图组
+            group[thisView] = p_EcgStartTestView->EcgStartTestInit();
+            container_->Add(group[thisView]);
+        }
+        return true;
+    }
+    struct EcgViewMapper
+    {
+        const int16_t viewId;           // 视图ID
+        bool (EcgView::*func)(int16_t); // 对应的视图切换函数指针
+    };
+
+    static const EcgViewMapper ViewMapper[] = {
+        {ECGSTARTTESTVIEW, &EcgView::ChangeEcgStartTestView},
+    };
+
+    bool EcgView::ClickFunc(int16_t interface)
+    {
+        int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
+
+        for (int i = 0; i < funcSize; i++)
+        {
+            if (interface == ViewMapper[i].viewId)
+            {
+                bool jug = (this->*(ViewMapper[i].func))(interface);
+                if (jug == false)
+                {
+                    return false;
+                }
+                return true;
+            }
+        }
+        return false;
+    }
+
+    void EcgView::ChangeView(int16_t hideView, int16_t showView)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EcgView::ChangeView");
+        if (hideView > MAX_ECGVIEW)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EcgView:: SystemViewId Overstep ones bounds");
+            return;
+        }
+        if (hideView != MAX_ECGVIEW)
+        {
+            if (group[hideView] == nullptr)
+            {
+                return;
+            }
+            group[hideView]->SetVisible(false);
+        }
+        ClickFunc(showView);
+        group[showView]->SetVisible(true);
+        container_->Invalidate();
+    }
+
     void EcgView::OnSetUpView()
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EcgView::OnSetUpView");