From 63222a3a8dcd72d9af5d1149f82ec4d8047eddd7 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 24 Jul 2024 18:37:31 +0800 Subject: [PATCH] =?utf8?q?=E8=BF=90=E5=8A=A8=E8=AF=86=E5=88=AB=E4=BC=98?= =?utf8?q?=E5=8C=96=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/MotionRecognitionPresenter.h | 6 +- .../include/MotionRecognitionView.h | 3 +- .../src/MotionRecognitionPresenter.cpp | 81 +++++++++++++------ .../src/MotionRecognitionView.cpp | 74 ++++++++++------- 4 files changed, 108 insertions(+), 56 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionPresenter.h index c97609888..a7b6e63b9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionPresenter.h @@ -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, 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}; }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionView.h b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionView.h index de1ee9181..58cb3e3db 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionView.h @@ -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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp index 46cf3c7cd..de578f75e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp @@ -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 #include "ConfigModel.h" +#include namespace OHOS { @@ -36,68 +37,98 @@ namespace OHOS void MotionRecognitionPresenter::OnStart() { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStart"); Presenter::OnStart(); } void MotionRecognitionPresenter::OnPause(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnPause"); Presenter::OnPause(); } void MotionRecognitionPresenter::OnResume(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnResume"); Presenter::OnResume(); } void MotionRecognitionPresenter::OnStop(void) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStop"); Presenter::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(&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(&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; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionView.cpp b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionView.cpp index a61808436..8d7780107 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionView.cpp @@ -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 +#include 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(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(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::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::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::OnTearDownView(); return; } void MotionRecognitionView::OnStop() { - + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStop"); View::OnStop(); - RootView::GetInstance()->RemoveAll(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } RootView::GetInstance()->ClearOnKeyActListener(); + ClearAll(); return; } -- 2.17.1