--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-23 17:32:20
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-24 18:13:52
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionPresenter.h
+ */
+#ifndef MOTION_RECOGNITION_PRESENTER_H
+#define MOTION_RECOGNITION_PRESENTER_H
+
+#include "Presenter.h"
+#include "View.h"
+#include "components/ui_toggle_button.h"
+
+namespace OHOS
+{
+ class MotionRecognitionView;
+ class MotionRecognitionPresenter : public Presenter<MotionRecognitionView>,
+ public UIView::OnClickListener,
+ public RootView::OnKeyActListener,
+ public UICheckBox::OnChangeListener,
+ public UIView::OnDragListener
+ {
+ public:
+ MotionRecognitionPresenter();
+ virtual ~MotionRecognitionPresenter();
+
+ void OnStart() override;
+ void OnPause() override;
+ void OnResume() override;
+ void OnStop() override;
+
+ static MotionRecognitionPresenter *GetInstance();
+
+ 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};
+ };
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-23 17:29:18
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-09-14 15:56:07
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/include/MotionRecognitionView.h
+ */
+#ifndef MOTION_RECOGNITION_VIEW_H
+#define MOTION_RECOGNITION_VIEW_H
+
+
+#include "View.h"
+
+#include "components/ui_scroll_view.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_image_view.h"
+#include "components/ui_toggle_button.h"
+namespace OHOS
+{
+ class MotionRecognitionPresenter;
+ class MotionRecognitionView : public View<MotionRecognitionPresenter>
+ {
+
+ public:
+ MotionRecognitionView();
+ virtual ~MotionRecognitionView();
+ static MotionRecognitionView *GetInstance(void);
+ UIToggleButton *GetMotionRecognitionToggleButton(void);
+ void OnStart() override;
+
+ private:
+ void MotionRecognitionViewInit(void);
+ void ClearAll(void);
+ UIScrollView *scrollView = nullptr;
+ UILabelExt *Title = nullptr;
+ UIImageView *MotionRecognitionImage = nullptr;
+ UILabelExt *MotionRecognitionLabel = nullptr;
+ UIToggleButton *MotionRecognitionToggleButton = nullptr;
+ UILabelExt *note{nullptr};
+ bool viewInitStatus{false};
+ };
+}
+#endif
\ No newline at end of file
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-28 14:17:43
+ * @LastEditors: penglei 1624952103@qq.com
+ * @LastEditTime: 2024-08-17 17:04:07
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/motionrecognition/src/MotionRecognitionPresenter.cpp
+ */
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "motionrecognition/include/MotionRecognitionPresenter.h"
+#include "motionrecognition/include/MotionRecognitionView.h"
+#include "common/key_code.h"
+#include <custom_utils.h>
+#include "ConfigModel.h"
+#include <UiConfig.h>
+#ifdef ENABLE_CYWEE
+#include "cywee_service.h"
+#endif
+#include "custom_runtime.h"
+
+#include "NativeRegisterManager.h"
+
+namespace OHOS
+{
+
+ REGIST_SLICE(VIEW_MOTION_RECOGNITION, MotionRecognitionView, MotionRecognitionPresenter);
+
+ // 当前Presenter属性实例化的内存指针
+ static MotionRecognitionPresenter *g_pMotionRecognitionPresenter = nullptr;
+
+ MotionRecognitionPresenter::MotionRecognitionPresenter()
+ {
+ g_pMotionRecognitionPresenter = this;
+ }
+
+ MotionRecognitionPresenter::~MotionRecognitionPresenter()
+ {
+ g_pMotionRecognitionPresenter = nullptr;
+ }
+
+ MotionRecognitionPresenter *MotionRecognitionPresenter::GetInstance()
+ {
+ return g_pMotionRecognitionPresenter;
+ }
+
+ 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;
+ // }
+
+ // 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;
+ }
+
+ bool MotionRecognitionPresenter::OnChange(UICheckBox::UICheckBoxState state)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionPresenter::OnChange");
+ switch (state)
+ {
+ case UICheckBox::SELECTED:
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is enable!");
+ #ifdef ENABLE_CYWEE
+ do_cywee_service_check_msg(CYWEE_SERVICE_CMD_OPEN_AR_ALERT,NULL);
+ #endif
+ ConfigModel::GetInstance()->SetMotionRecognition(true);
+ uapi_dev_runtime_set_motion_recognition_status(1);
+ break;
+ case UICheckBox::UNSELECTED:
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognition is disable!");
+ #ifdef ENABLE_CYWEE
+ do_cywee_service_check_msg(CYWEE_SERVICE_CMD_CLOSE_AR_ALERT,NULL);
+ #endif
+ ConfigModel::GetInstance()->SetMotionRecognition(false);
+ uapi_dev_runtime_set_motion_recognition_status(0);
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+
+ bool MotionRecognitionPresenter::OnDrag(UIView &view, const DragEvent &event)
+ {
+ UNUSED(view);
+ 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);
+ 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;
+ }
+
+ bool MotionRecognitionPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件
+ {
+ UNUSED(view);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionPresenter::OnKeyAct");
+ unsigned short keyID = event.GetKeyId();
+ unsigned short 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;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-23 17:28:52
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-11-05 14:24:02
+ * @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
+{
+
+ static MotionRecognitionView *g_pMotionRecognitionView{nullptr};
+
+ MotionRecognitionView::MotionRecognitionView()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionView");
+ g_pMotionRecognitionView = this;
+ }
+
+ MotionRecognitionView::~MotionRecognitionView()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::~MotionRecognitionView");
+
+ g_pMotionRecognitionView = nullptr;
+ }
+
+ MotionRecognitionView *MotionRecognitionView::GetInstance()
+ {
+ return g_pMotionRecognitionView;
+ }
+
+ void MotionRecognitionView::ClearAll(void)
+ {
+ if (scrollView != nullptr)
+ {
+ scrollView->RemoveAll();
+
+ if (Title != nullptr)
+ {
+ delete Title;
+ Title = nullptr;
+ }
+
+ if (MotionRecognitionImage != nullptr)
+ {
+ delete MotionRecognitionImage;
+ MotionRecognitionImage = nullptr;
+ }
+ if (MotionRecognitionLabel != nullptr)
+ {
+ delete MotionRecognitionLabel;
+ MotionRecognitionLabel = nullptr;
+ }
+
+ if (MotionRecognitionToggleButton != nullptr)
+ {
+ delete MotionRecognitionToggleButton;
+ MotionRecognitionToggleButton = nullptr;
+ }
+ if (note != nullptr)
+ {
+ delete note;
+ note = nullptr;
+ }
+
+ scrollView->ClearFocus();
+ delete scrollView;
+ scrollView = nullptr;
+ }
+ }
+
+ void MotionRecognitionView::MotionRecognitionViewInit(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionViewInit");
+ if (scrollView == nullptr)
+ {
+ scrollView = new UIScrollView();
+ scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+ scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ scrollView->SetScrollBlankSize(50);
+ scrollView->SetHorizontalScrollState(false);
+ scrollView->SetReboundSize(35);
+ scrollView->SetOnDragListener(presenter_);
+ scrollView->RequestFocus();
+ scrollView->SetRotateFactor(1.0);
+ /* -------------------------------------------------------------------------- */
+ Title = new UILabelExt();
+ if (Title == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::Title can not be nullptr!");
+ return;
+ }
+ Title->SetPosition(83, 50, 300, 40);
+ Title->SetStyle(STYLE_TEXT_FONT, 30);
+ Title->SetStyle(STYLE_LINE_HEIGHT, 35);
+ Title->SetTextId(STR_MOTION_RECOGNITION); /*运动识别*/
+ Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ Title->SetRollSpeed(23);
+ Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ Title->SetVisible(true);
+ /* -------------------------------------------------------------------------- */
+ if (MotionRecognitionImage == nullptr)
+ {
+ MotionRecognitionImage = new UIImageView();
+ }
+ MotionRecognitionImage->SetPosition(43, 120, 380, 100);
+ MotionRecognitionImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+ MotionRecognitionImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ MotionRecognitionImage->SetStyle(STYLE_BORDER_RADIUS, 100);
+ /* -------------------------------------------------------------------------- */
+ MotionRecognitionLabel = new UILabelExt();
+ if (MotionRecognitionLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::MotionRecognitionLabel can not be nullptr!");
+ return;
+ }
+ MotionRecognitionLabel->SetPosition(90, 153, 180, 40);
+ MotionRecognitionLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ MotionRecognitionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ MotionRecognitionLabel->SetTextId(STR_AUTO_DETECT); /*自动识别*/
+ MotionRecognitionLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
+ MotionRecognitionLabel->SetRollSpeed(23);
+ MotionRecognitionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ /* -------------------------------------------------------------------------- */
+ MotionRecognitionToggleButton = new UIToggleButton();
+ if (MotionRecognitionToggleButton == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::MotionRecognitionToggleButton is nullptr!");
+ return;
+ }
+ MotionRecognitionToggleButton->SetPosition(298, 145, 100, 50);
+ MotionRecognitionToggleButton->SetState(ConfigModel::GetInstance()->GetMotionRecognition());
+ MotionRecognitionToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+ MotionRecognitionToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE);
+ /* ----------------------------- onclickListener ---------------------------- */
+ // MotionRecognitionToggleButton->SetOnClickListener(presenter_);
+ MotionRecognitionToggleButton->SetOnChangeListener(presenter_);
+ /* -------------------------------------------------------------------------- */
+ if (note == nullptr)
+ {
+ note = new UILabelExt();
+ if (note == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::note can not be nullptr!");
+ return;
+ }
+ }
+ note->SetPosition(63, MotionRecognitionImage->GetY() + MotionRecognitionImage->GetHeight() + 20, 340, 80);
+ note->SetStyle(STYLE_TEXT_FONT, 20);
+ note->SetStyle(STYLE_LINE_HEIGHT, 40);
+ note->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
+ note->SetTextId(STR_MOTION_RECOGNITION_NOTE);//开启后,手表会在检测到你处于运动状态时发出提醒。支持的运动包括:走路、跑步、骑车、划船机、椭圆机。
+ note->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ note->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20);
+ /* -------------------------------------------------------------------------- */
+
+ viewInitStatus = true;
+ /* -------------------------------------------------------------------------- */
+ }
+ }
+
+ void MotionRecognitionView::OnStart()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MotionRecognitionView::OnStart");
+ View<MotionRecognitionPresenter>::OnStart();
+
+
+
+ if (!viewInitStatus)
+ {
+ MotionRecognitionViewInit();
+ }
+
+ // 增加按键监听
+ RootView::GetInstance()->SetOnKeyActListener(presenter_);
+
+ scrollView->Add(Title);
+ scrollView->Add(MotionRecognitionImage);
+ scrollView->Add(MotionRecognitionLabel);
+ scrollView->Add(MotionRecognitionToggleButton);
+ scrollView->Add(note);
+ AddViewToRootContainer(scrollView);
+ }
+
+
+ UIToggleButton *MotionRecognitionView::GetMotionRecognitionToggleButton(void)
+ {
+ return MotionRecognitionToggleButton;
+ }
+}
\ No newline at end of file