运动识别优化修改
authorluozheng <1732036298@qq.com>
Wed, 24 Jul 2024 10:37:31 +0000 (18:37 +0800)
committerluozheng <1732036298@qq.com>
Wed, 24 Jul 2024 10:37:31 +0000 (18:37 +0800)
code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionPresenter.h
code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionView.h
code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionView.cpp

index c976098..a7b6e63 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-23 17:32:20
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-23 17:42:37
+ * @LastEditTime: 2024-07-24 18:13:52
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionPresenter.h
  */
 #ifndef MOTION_RECOGNITION_PRESENTER_H
@@ -10,6 +10,7 @@
 
 #include "Presenter.h"
 #include "View.h"
+#include "components/ui_toggle_button.h"
 
 namespace OHOS
 {
@@ -17,6 +18,7 @@ namespace OHOS
     class MotionRecognitionPresenter : public Presenter<MotionRecognitionView>,
                                        public UIView::OnClickListener,
                                        public RootView::OnKeyActListener,
+                                       public UICheckBox::OnChangeListener,
                                        public UIView::OnDragListener
     {
     public:
@@ -32,9 +34,11 @@ namespace OHOS
 
     private:
         bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnChange(UICheckBox::UICheckBoxState state);
         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};
     };
 }
 
index de1ee91..58cb3e3 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-23 17:29:18
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-06 17:48:35
+ * @LastEditTime: 2024-07-24 18:03:56
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionView.h
  */
 #ifndef MOTION_RECOGNITION_VIEW_H
@@ -39,6 +39,7 @@ namespace OHOS
         UIImageView *MotionRecognitionImage = nullptr;
         UILabelExt *MotionRecognitionLabel = nullptr;
         UIToggleButton *MotionRecognitionToggleButton = nullptr;
+        bool viewInitStatus{false};
     };
 }
 #endif
\ No newline at end of file
index 46cf3c7..de578f7 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-28 14:17:43
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-24 14:26:22
+ * @LastEditTime: 2024-07-24 18:16:48
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/src/MotionRecognitionPresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -12,6 +12,7 @@
 #include "common/key_code.h"
 #include <custom_utils.h>
 #include "ConfigModel.h"
+#include <UiConfig.h>
 
 namespace OHOS
 {
@@ -36,68 +37,98 @@ namespace OHOS
 
     void MotionRecognitionPresenter::OnStart()
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStart");
         Presenter<MotionRecognitionView>::OnStart();
     }
 
     void MotionRecognitionPresenter::OnPause(void)
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnPause");
         Presenter<MotionRecognitionView>::OnPause();
     }
 
     void MotionRecognitionPresenter::OnResume(void)
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnResume");
         Presenter<MotionRecognitionView>::OnResume();
     }
 
     void MotionRecognitionPresenter::OnStop(void)
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStop");
         Presenter<MotionRecognitionView>::OnStop();
     }
 
     bool MotionRecognitionPresenter::OnClick(UIView &view, const ClickEvent &event)
     {
+        UNUSED(view);
         UNUSED(event);
-        MotionRecognitionView *p_MotionRecognitionView = MotionRecognitionView::GetInstance();
-        if (p_MotionRecognitionView == nullptr)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " MotionRecognitionView::GetInstance() fail!");
-            return false;
-        }
+        // MotionRecognitionView *p_MotionRecognitionView = MotionRecognitionView::GetInstance();
+        // if (p_MotionRecognitionView == nullptr)
+        // {
+        //     WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " MotionRecognitionView::GetInstance() fail!");
+        //     return false;
+        // }
+
+        // UIToggleButton *toggleButton = dynamic_cast<UIToggleButton *>(&view);
+        // if (p_MotionRecognitionView->GetMotionRecognitionToggleButton() == toggleButton)
+        // {
+        //     if (toggleButton != nullptr)
+        //     {
+        //         if (toggleButton->GetState() == true)
+        //         {
+        //             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is enable!");
+        //             ConfigModel::GetInstance()->SetMotionRecognition(true);
+        //         }
+        //         else
+        //         {
+        //             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is disable!");
+        //             ConfigModel::GetInstance()->SetMotionRecognition(false);
+        //         }
+        //     }
+        // }
+
+        return true;
+    }
 
-        UIToggleButton *toggleButton = dynamic_cast<UIToggleButton *>(&view);
-        if (p_MotionRecognitionView->GetMotionRecognitionToggleButton() == toggleButton)
+    bool MotionRecognitionPresenter::OnChange(UICheckBox::UICheckBoxState state)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionPresenter::OnChange");
+        switch (state)
         {
-            if (toggleButton != nullptr)
-            {
-                if (toggleButton->GetState() == true)
-                {
-                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is enable!");
-                    ConfigModel::GetInstance()->SetMotionRecognition(true);
-                }
-                else
-                {
-                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is disable!");
-                    ConfigModel::GetInstance()->SetMotionRecognition(false);
-                }
-            }
+        case UICheckBox::SELECTED:
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is enable!");
+            ConfigModel::GetInstance()->SetMotionRecognition(true);
+            break;
+        case UICheckBox::UNSELECTED:
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is disable!");
+            ConfigModel::GetInstance()->SetMotionRecognition(false);
+            break;
+        default:
+            break;
         }
-
         return true;
     }
 
     bool MotionRecognitionPresenter::OnDrag(UIView &view, const DragEvent &event)
     {
         UNUSED(view);
-        UNUSED(event);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionPresenter::OnDrag");
+        if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+        {
+            X_DRAG_FLAG = true;
+        }
         return true;
     }
 
     bool MotionRecognitionPresenter::OnDragEnd(UIView &view, const DragEvent &event)
     {
         UNUSED(view);
-        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionPresenter::OnDragEnd");
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG)
         {
             NativeAbility::GetInstance().Back();
+            X_DRAG_FLAG = false;
         }
         return true;
     }
index a618084..8d77801 100644 (file)
@@ -2,13 +2,15 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-23 17:28:52
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-06 17:52:26
+ * @LastEditTime: 2024-07-24 18:16:10
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionView.cpp
  */
 #include "motionrecognition/include/MotionRecognitionPresenter.h"
 #include "motionrecognition/include/MotionRecognitionView.h"
 #include "wearable_log.h"
 #include "ConfigModel.h"
+#include <ui_resource_string.h>
+#include <UiConfig.h>
 namespace OHOS
 {
 
@@ -23,7 +25,7 @@ namespace OHOS
     MotionRecognitionView::~MotionRecognitionView()
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::~MotionRecognitionView");
-        ClearAll();
+
         g_pMotionRecognitionView = nullptr;
     }
 
@@ -68,7 +70,7 @@ namespace OHOS
 
     void MotionRecognitionView::MotionRecognitionViewInit(void)
     {
-
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionViewInit");
         if (scrollView == nullptr)
         {
             scrollView = new UIScrollView();
@@ -77,13 +79,7 @@ namespace OHOS
             scrollView->SetScrollBlankSize(50);
             scrollView->SetHorizontalScrollState(false);
             scrollView->SetReboundSize(35);
-            UIView::OnDragListener *draglistener = static_cast<UIView::OnDragListener *>(MotionRecognitionPresenter::GetInstance());
-            if (draglistener == nullptr)
-            {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::draglistener can not be nullptr!");
-                return;
-            }
-            scrollView->SetOnDragListener(draglistener);
+            scrollView->SetOnDragListener(presenter_);
             /* -------------------------------------------------------------------------- */
             Title = new UILabelExt();
             if (Title == nullptr)
@@ -94,11 +90,10 @@ namespace OHOS
             Title->SetPosition(83, 50, 300, 40);
             Title->SetStyle(STYLE_TEXT_FONT, 30);
             Title->SetStyle(STYLE_LINE_HEIGHT, 35);
-            //Title->SetText("运动识别");
-            Title->SetTextId(STR_MOTION_RECOGNITION);
-            Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
+            Title->SetTextId(STR_MOTION_RECOGNITION); /*运动识别*/
+            Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
             Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
-            //Title->SetRollSpeed(40);
+            Title->SetRollSpeed(70);
             Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
             Title->SetVisible(true);
             /* -------------------------------------------------------------------------- */
@@ -120,10 +115,9 @@ namespace OHOS
             MotionRecognitionLabel->SetPosition(90, 153, 180, 40);
             MotionRecognitionLabel->SetStyle(STYLE_TEXT_FONT, 30);
             MotionRecognitionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-            //MotionRecognitionLabel->SetText("自动识别");
-            MotionRecognitionLabel->SetTextId(STR_AUTO_DETECT);
+            MotionRecognitionLabel->SetTextId(STR_AUTO_DETECT); /*自动识别*/
             MotionRecognitionLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
-            //MotionRecognitionLabel->SetRollSpeed(40);
+            MotionRecognitionLabel->SetRollSpeed(70);
             MotionRecognitionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
             /* -------------------------------------------------------------------------- */
             MotionRecognitionToggleButton = new UIToggleButton();
@@ -135,48 +129,70 @@ namespace OHOS
             MotionRecognitionToggleButton->SetPosition(298, 145, 100, 50);
             MotionRecognitionToggleButton->SetState(ConfigModel::GetInstance()->GetMotionRecognition());
             MotionRecognitionToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
-            const char *selectedImg = "/user/res/TOGGLEBUTTON_ON.bin";
-            const char *unSelectedImg = "/user/res/TOGGLEBUTTON_OFF.bin";
-            MotionRecognitionToggleButton->SetImages(selectedImg, unSelectedImg);
+            MotionRecognitionToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE);
             /* ----------------------------- onclickListener ---------------------------- */
-            UIView::OnClickListener *toggleButtonClick = static_cast<UIView::OnClickListener *>(MotionRecognitionPresenter::GetInstance());
-            MotionRecognitionToggleButton->SetOnClickListener(toggleButtonClick);
+            // MotionRecognitionToggleButton->SetOnClickListener(presenter_);
+            MotionRecognitionToggleButton->SetOnChangeListener(presenter_);
+
+            viewInitStatus = true;
+            /* -------------------------------------------------------------------------- */
         }
     }
 
     void MotionRecognitionView::OnStart()
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStart");
         View<MotionRecognitionPresenter>::OnStart();
-        MotionRecognitionViewInit();
+        SetContainerView(new UIViewGroup());
+        if (GetContainer() == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetContainerView fail!!");
+            return;
+        }
+        container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+        container_->SetTouchable(true);
+        container_->SetDraggable(true);
+
+        if (!viewInitStatus)
+        {
+            MotionRecognitionViewInit();
+        }
+
         // 增加按键监听
-        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MotionRecognitionPresenter::GetInstance();
-        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+        RootView::GetInstance()->SetOnKeyActListener(presenter_);
     }
 
     void MotionRecognitionView::OnSetUpView()
     {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnSetUpView");
         View<MotionRecognitionPresenter>::OnSetUpView();
         scrollView->Add(Title);
         scrollView->Add(MotionRecognitionImage);
         scrollView->Add(MotionRecognitionLabel);
         scrollView->Add(MotionRecognitionToggleButton);
-        RootView::GetInstance()->Add(scrollView);
+        container_->Add(scrollView);
         Draw();
     }
 
     void MotionRecognitionView::OnTearDownView()
     {
-
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnTearDownView");
         View<MotionRecognitionPresenter>::OnTearDownView();
         return;
     }
 
     void MotionRecognitionView::OnStop()
     {
-
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStop");
         View<MotionRecognitionPresenter>::OnStop();
-        RootView::GetInstance()->RemoveAll();
+        if (container_ != nullptr)
+        {
+            container_->RemoveAll();
+            delete container_;
+            container_ = nullptr;
+        }
         RootView::GetInstance()->ClearOnKeyActListener();
+        ClearAll();
         return;
     }