From 8aae0301cf491f589545ecfac822b9c169b6ea87 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Fri, 20 Jun 2025 17:32:36 +0800 Subject: [PATCH] =?utf8?q?=E6=83=85=E7=BB=AA=E6=B5=8B=E9=87=8F=E7=95=8C?= =?utf8?q?=E9=9D=A2slice=E6=B7=BB=E5=8A=A0=EF=BC=8C=E6=95=B0=E6=8D=AE?= =?utf8?q?=E4=BA=A4=E4=BA=92=E9=80=BB=E8=BE=91=E5=BE=85=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230app/CMakeLists.txt | 10 + .../nativelauncher/include/NativeLauncher.h | 1 + .../nativelauncher/include/UiConfig.h | 2 + .../nativelauncher/src/NativeLauncher.cpp | 16 ++ .../nativeui/emotion/include/EmoModel.h | 21 ++ .../nativeui/emotion/include/EmoPresenter.h | 39 +++ .../emotion/include/EmoTestAnalysisView.h | 26 ++ .../include/EmoTestFailedNoValueView.h | 29 ++ .../include/EmoTestFailedNoWearingView.h | 30 ++ .../emotion/include/EmoTestResultView.h | 27 ++ .../nativeui/emotion/include/EmoTestView.h | 34 +++ .../nativeui/emotion/include/EmoView.h | 60 ++++ .../nativeui/emotion/src/EmoModel.cpp | 120 ++++++++ .../nativeui/emotion/src/EmoPresenter.cpp | 192 +++++++++++++ .../emotion/src/EmoTestAnalysisView.cpp | 154 +++++++++++ .../emotion/src/EmoTestFailedNoValueView.cpp | 115 ++++++++ .../src/EmoTestFailedNoWearingView.cpp | 134 +++++++++ .../emotion/src/EmoTestResultView.cpp | 116 ++++++++ .../nativeui/emotion/src/EmoTestView.cpp | 132 +++++++++ .../fd230app/nativeui/emotion/src/EmoView.cpp | 259 ++++++++++++++++++ 20 files changed, 1517 insertions(+) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoModel.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoPresenter.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestAnalysisView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoValueView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoWearingView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestResultView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoModel.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestAnalysisView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoValueView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoWearingView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestResultView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoView.cpp diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 38baa360f..72f0aead9 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -262,6 +262,16 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ecg/src/EcgTestResultView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/ecg/src/EcgTestNeedAppOrNetworkView.cpp + # emotion + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoTestView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoTestAnalysisView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoTestResultView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoTestFailedNoWearingView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/emotion/src/EmoTestFailedNoValueView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bluetooth/src/BluetoothDeviceCaseListAdapter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bluetooth/src/BluetoothDeviceListView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/bluetooth/src/BluetoothPresenter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 1154017f7..efcffe18e 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -137,6 +137,7 @@ namespace OHOS void InitBloodPressureCheckSlice(void); void InitECGSlice(void); + void InitEmotionSlice(void); private: void InitAllNativeSlices(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index bb70ba01f..e9510d6e9 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -572,6 +572,7 @@ namespace OHOS static constexpr const char *PNG_APPLIST_SPO2_IMAGE = APP_LIST_PATH "/booldoxygen.bin"; // 血氧 static constexpr const char *PNG_APPLIST_BP_MESSURE_IMAGE = APP_LIST_PATH "/blood_pressure.bin"; // 血压测量 static constexpr const char *PNG_APPLIST_ECG_IMAGE = APP_LIST_PATH "/ecg.bin"; // 心电(ECG)测量 + static constexpr const char *PNG_APPLIST_EMOTION_IMAGE = APP_LIST_PATH "/emotion.bin"; // 情绪测量 static constexpr const char *PNG_APPLIST_BP_IMAGE = APP_LIST_PATH "/bp_calibration.bin"; // 血压校准 static constexpr const char *PNG_APPLIST_HEART_IMAGE = APP_LIST_PATH "/heart.bin"; // 心率 static constexpr const char *PNG_APPLIST_SETTING_IMAGE = APP_LIST_PATH "/setting.bin"; // 设置 @@ -611,6 +612,7 @@ namespace OHOS static constexpr const char *PNG_APPLIST_SPO2_IMAGE_BIG = APP_LIST_PATH "/applist_big_icon/booldoxygen.bin"; // 血氧 static constexpr const char *PNG_APPLIST_BP_MESSURE_IMAGE_BIG = APP_LIST_PATH "/applist_big_icon/blood_pressure.bin"; // 血压测量 static constexpr const char *PNG_APPLIST_BP_IMAGE_BIG = APP_LIST_PATH "/applist_big_icon/bp_calibration.bin"; // 血压校准 + static constexpr const char *PNG_APPLIST_EMOTION_IMAGE_BIG = APP_LIST_PATH "/applist_big_icon/emotion.bin"; // 情绪测量 static constexpr const char *PNG_APPLIST_ECG_IMAGE_BIG = APP_LIST_PATH "/applist_big_icon/ecg.bin"; // 心电(ECG)测量 static constexpr const char *PNG_APPLIST_HEART_IMAGE_BIG = APP_LIST_PATH "/applist_big_icon/heart.bin"; // 心率 static constexpr const char *PNG_APPLIST_SETTING_IMAGE_BIG = APP_LIST_PATH "/applist_big_icon/setting.bin"; // 设置 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index e2b84944d..37c020c9b 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -117,6 +117,9 @@ /*ECG*/ #include "ecg/include/EcgPresenter.h" #include "ecg/include/EcgView.h" +/*情绪测量*/ +#include "emotion/include/EmoPresenter.h" +#include "emotion/include/EmoView.h" /*心率监测*/ #include "heartrate/include/HeartDetectionView.h" #include "heartrate/include/HeartDetectionPresenter.h" @@ -460,6 +463,8 @@ namespace OHOS {VIEW_BLOOD_PRESSURE_CHECK, &NativeLauncher::InitBloodPressureCheckSlice}, /*ECG*/ {VIEW_ECG, &NativeLauncher::InitECGSlice}, + /*情绪测量*/ + {VIEW_EMOTION, &NativeLauncher::InitEmotionSlice}, /*心率检测*/ {VIEW_HEART_CHECK, &NativeLauncher::InitHeartCheckSlice}, {VIEW_HEART_RESULT, &NativeLauncher::InitHeartResultSlice}, @@ -1371,6 +1376,17 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_ECG, ECGView); } + void NativeLauncher::InitEmotionSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitEmotionSlice"); + SliceProxy *EmotionView = new AbilitySliceProxy; + if (EmotionView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmotionView is nullptr"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_EMOTION, EmotionView); + } // 心率监测界面 void NativeLauncher::InitHeartCheckSlice(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoModel.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoModel.h new file mode 100644 index 000000000..3ddf08d89 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoModel.h @@ -0,0 +1,21 @@ +#ifndef EMOTION_MODEL_H +#define EMOTION_MODEL_H +#include "stdint.h" +namespace OHOS +{ + class EmoModel + { + public: + static EmoModel &GetInstance(void); + void start_emotest_timer(int type, uint32_t interval = 1000); + void stop_emotest_timer(void); + + private: + EmoModel(); + ~EmoModel(); + EmoModel(const EmoModel &) = delete; + EmoModel &operator=(const EmoModel &) = delete; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoPresenter.h new file mode 100644 index 000000000..80f0b6d42 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoPresenter.h @@ -0,0 +1,39 @@ +#ifndef EMOTION_PRESENTER_H +#define EMOTION_PRESENTER_H + +#include "Presenter.h" +#include "View.h" + +namespace OHOS +{ + class EmoView; + class EmoModel; + class EmoPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener + { + public: + EmoPresenter(); + virtual ~EmoPresenter(); + static EmoPresenter *GetInstance(); + void ChangeViewOperator(int16_t hideView, int16_t showView); + + void OnStart() override; + void OnResume() override; + void OnPause() override; + void OnStop() override; + + + private: + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + + EmoModel *model; + bool X_DRAG_FLAG{false}; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestAnalysisView.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestAnalysisView.h new file mode 100644 index 000000000..d08e52929 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestAnalysisView.h @@ -0,0 +1,26 @@ +#ifndef EMOTION_TEST_ANALYSIS_VIEW_H +#define EMOTION_TEST_ANALYSIS_VIEW_H + +#include "components/ui_view_group.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_animator.h" +namespace OHOS +{ + class EmoTestAnalysisView + { + public: + EmoTestAnalysisView(); + ~EmoTestAnalysisView(); + static EmoTestAnalysisView *GetInstance(void); + UIViewGroup *EmoTestAnalysisInit(); + void startorstopAnalysisAni(bool state); + + private: + void ClearAll(void); + UIViewGroup *group{nullptr}; + UILabelExt *remindLabel{nullptr}; + UIImageAnimatorView *EmoAnaAni{nullptr}; + ImageAnimatorInfo EmoAnaAniImageInfo[30]; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoValueView.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoValueView.h new file mode 100644 index 000000000..6fd3feaa4 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoValueView.h @@ -0,0 +1,29 @@ +#ifndef EMOTION_TEST_FAILED_NO_VALUE_VIEW_H +#define EMOTION_TEST_FAILED_NO_VALUE_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" +#include "components/ui_scroll_view.h" +namespace OHOS +{ + static const char *EMO_RESET_TEST_BTN = "emoResetTestBtn";//重新测量Emo + class EmoTestFailedNoValueView + { + public: + EmoTestFailedNoValueView(); + ~EmoTestFailedNoValueView(); + static EmoTestFailedNoValueView *GetInstance(void); + UIViewGroup *EmoTestFailedNoValueInit(); + + private: + void ClearAll(void); + UIViewGroup *group{nullptr}; + UILabelExt *titleLabel{nullptr}; + UIImageView *image{nullptr}; + UILabelButtonExt *resetTestBtn{nullptr}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoWearingView.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoWearingView.h new file mode 100644 index 000000000..63d4e2b90 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestFailedNoWearingView.h @@ -0,0 +1,30 @@ +#ifndef EMO_TEST_FAILED_NO_WEARING_VIEW_H +#define EMO_TEST_FAILED_NO_WEARING_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" +#include "components/ui_scroll_view.h" +namespace OHOS +{ + static const char *EMORESETTESTBTN = "EMORESETTESTBTN";//重新测量 + class EmoTestFailedNoWearingView + { + public: + EmoTestFailedNoWearingView(); + ~EmoTestFailedNoWearingView(); + static EmoTestFailedNoWearingView *GetInstance(void); + UIViewGroup *EmoTestFailedNoWearingInit(); + + private: + void ClearAll(void); + UIViewGroup *group{nullptr}; + UILabelExt *titleLabel{nullptr}; + UILabelExt *remindLabel{nullptr}; + UIImageView *image{nullptr}; + UILabelButtonExt *resetTestBtn{nullptr}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestResultView.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestResultView.h new file mode 100644 index 000000000..6d62e2bbf --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestResultView.h @@ -0,0 +1,27 @@ +#ifndef EMOTION_TEST_RESULT_VIEW_H +#define EMOTION_TEST_RESULT_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 +{ + class EmoTestResultView + { + public: + EmoTestResultView(); + ~EmoTestResultView(); + static EmoTestResultView *GetInstance(void); + UIViewGroup* EmotionTestResultInit(); + private: + void ClearAll(void); + UIViewGroup* group{nullptr}; + UILabelExt *titleLabel{nullptr}; + UILabelExt *emotionLabel{nullptr}; + UILabelExt *remindLabel{nullptr}; + }; + +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestView.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestView.h new file mode 100644 index 000000000..2388b7a05 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoTestView.h @@ -0,0 +1,34 @@ +#ifndef EMOTION_TEST_VIEW_H +#define EMOTION_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 *STARTEMOTIONTESTBUTTON = "startEmotionTestButton"; // 开始emotion测量 + class EmoTestView + { + public: + EmoTestView(); + ~EmoTestView(); + static EmoTestView *GetInstance(void); + UIViewGroup *EmoTestInit(); + UILabelButtonExt *GetStartEmotionTestButton(); + bool GetTestButtonState(); + void SetTestButtonState(bool state); + + private: + void ClearAll(void); + UIViewGroup *group{nullptr}; + UILabelExt *titleLabel{nullptr}; + UIImageView *image{nullptr}; + UILabelExt *showEmoValLabel{nullptr}; + UILabelButtonExt *startEmotionTestButton{nullptr}; + bool state{false}; + }; + +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoView.h b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoView.h new file mode 100644 index 000000000..154311cad --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/include/EmoView.h @@ -0,0 +1,60 @@ +#ifndef EMOTION_VIEW_H +#define EMOTION_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "emotion/include/EmoTestView.h" +#include "emotion/include/EmoTestAnalysisView.h" +#include "emotion/include/EmoTestResultView.h" +#include "emotion/include/EmoTestFailedNoWearingView.h" +#include "emotion/include/EmoTestFailedNoValueView.h" +namespace OHOS +{ + typedef enum : uint8_t + { + EMOTIONTESTVIEW = 0, // 测量界面 + EMOTIONTESTFAILNOVALUE, // 测量失败无值 + EMOTIONTESTFAILNOWEARING, // 测量失败未佩戴 + EMOTIONTESTANALYSISVIEW, // 测量分析界面 + EMOTIONTESTRESULTVIEW, // 测量结果界面 + MAX_EMOVIEW, + } EmoViewID; + + class EmoPresenter; + class EmoView : public View + { + public: + EmoView(); + ~EmoView(); + static EmoView *GetInstance(void); + bool ChangeEmoTestView(int16_t thisView); + bool ChangeEmoTestAnalysisView(int16_t thisView); + bool ChangeEmoTestResultView(int16_t thisView); + bool ChangeEmoTestFailedNoWearingView(int16_t thisView); + bool ChangeEmoTestFailedNoValueView(int16_t thisView); + bool ClickFunc(int16_t interface); + void ChangeView(int16_t hideView, int16_t showView); + UIViewGroup *GetEmotionGroupView(uint16_t index); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + EmoTestView *emoTestView{nullptr}; + EmoTestAnalysisView *emoTestAnalysisView{nullptr}; + EmoTestResultView *emoTestResultView{nullptr}; + EmoTestFailedNoWearingView *emoTestFailedNoWearingView{nullptr}; + EmoTestFailedNoValueView *emoTestFailedNoValueView{nullptr}; + + private: + void CreateEmoView(void); + void ClearAll(void); + UIViewGroup *group[MAX_EMOVIEW]{nullptr}; + + bool viewInitStatus{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoModel.cpp new file mode 100644 index 000000000..7fab95087 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoModel.cpp @@ -0,0 +1,120 @@ +#include "emotion/include/EmoModel.h" +#include "wearable_log.h" +#include "cmsis_os2.h" +#include "cmsis_os.h" +#include +#include "emotion/include/EmoView.h" +#include "emotion/include/EmoPresenter.h" +namespace OHOS +{ + EmoModel::EmoModel() {} + + EmoModel::~EmoModel() {} + + EmoModel &EmoModel::GetInstance() + { + static EmoModel instance; + return instance; + } + + static osTimerId_t g_EmoTestHandle = nullptr; + static int16_t emoTestingTime = 3; + static int16_t emoTestAnalysisTime = 5; + static int16_t emoTestResultTime = 3; + + static void EmoTestCallbackProc(int type) + { + switch (type) + { + case EMOTIONTESTVIEW: + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "emoTestingTime:%d", emoTestingTime); + emoTestingTime--; + if (emoTestingTime <= 0) + { + EmoModel::GetInstance().stop_emotest_timer(); + if (EmoPresenter::GetInstance()) + { + EmoPresenter::GetInstance()->ChangeViewOperator(EMOTIONTESTVIEW, EMOTIONTESTANALYSISVIEW); + } + } + } + break; + case EMOTIONTESTANALYSISVIEW: + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "emoTestAnalysisTime:%d", emoTestAnalysisTime); + emoTestAnalysisTime--; + if (emoTestAnalysisTime <= 0) + { + EmoModel::GetInstance().stop_emotest_timer(); + if (EmoPresenter::GetInstance()) + { + EmoPresenter::GetInstance()->ChangeViewOperator(EMOTIONTESTANALYSISVIEW, EMOTIONTESTRESULTVIEW); + } + } + } + break; + default: + break; + } + } + + static void EmoTestCallback(int type) + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(&EmoTestCallbackProc, type)); + } + + void EmoModel::start_emotest_timer(int type, uint32_t interval) + { + /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ + if (g_EmoTestHandle != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); + return; + } + /* --------------------------------- 2.创建定时器 -------------------------------- */ + g_EmoTestHandle = osTimerNew((osTimerFunc_t)EmoTestCallback, osTimerPeriodic, (void *)type, nullptr); + // 检查定时器创建是否成功 + if (g_EmoTestHandle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); + return; + } + /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ + int tick = osMs2Tick(interval); + /* --------------------------------- 4.启动定时器 -------------------------------- */ + osStatus_t ret = osTimerStart(g_EmoTestHandle, tick); + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + if (g_EmoTestHandle != nullptr) + { + ret = osTimerDelete(g_EmoTestHandle); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + return; + } + } + g_EmoTestHandle = nullptr; + return; + } + } + void EmoModel::stop_emotest_timer(void) + { + if (g_EmoTestHandle != nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop_emotest_timer"); + osTimerStop(g_EmoTestHandle); + osStatus_t ret = osTimerDelete(g_EmoTestHandle); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); + } + g_EmoTestHandle = nullptr; + emoTestingTime = 3; + emoTestAnalysisTime = 5; + } + } +} diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoPresenter.cpp new file mode 100644 index 000000000..c104dd585 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoPresenter.cpp @@ -0,0 +1,192 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "common/key_code.h" +#include +#include "UiConfig.h" +#include "emotion/include/EmoPresenter.h" +#include "emotion/include/EmoView.h" +#include "emotion/include/EmoModel.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static EmoPresenter *g_pEmoPresenter = nullptr; + + EmoPresenter::EmoPresenter() + { + model = &EmoModel::GetInstance(); + g_pEmoPresenter = this; + } + + EmoPresenter::~EmoPresenter() + { + g_pEmoPresenter = nullptr; + } + + EmoPresenter *EmoPresenter::GetInstance() + { + return g_pEmoPresenter; + } + + // 启动时执行的逻辑 + void EmoPresenter::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoPresenter::OnStart"); + Presenter::OnStart(); + } + + // 页面已经展示后的调用逻辑 + void EmoPresenter::OnResume(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoPresenter::OnResume"); + Presenter::OnResume(); + if (view_ == nullptr) + { + return; + } + } + + // 页面准备切换到后台前执行的逻辑 + void EmoPresenter::OnPause(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoPresenter::OnPause"); + Presenter::OnPause(); + } + + // 页面完全置于后台时的逻辑。 + void EmoPresenter::OnStop(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoPresenter::OnStop"); + Presenter::OnStop(); + model->stop_emotest_timer(); + } + + void EmoPresenter::ChangeViewOperator(int16_t hideView, int16_t showView) + { + view_->ChangeView(hideView, showView); + switch (showView) + { + case EMOTIONTESTANALYSISVIEW: + { + if (EmoTestAnalysisView::GetInstance()) + { + EmoTestAnalysisView::GetInstance()->startorstopAnalysisAni(true); + } + model->start_emotest_timer(EMOTIONTESTANALYSISVIEW); + } + break; + default: + break; + } + /* -------------------------------------------------------------------------- */ + if (hideView == EMOTIONTESTVIEW) + { + if (EmoTestView::GetInstance() != nullptr) + { + UILabelButtonExt *startEmotionTestButton = EmoTestView::GetInstance()->GetStartEmotionTestButton(); + if (startEmotionTestButton) + { + startEmotionTestButton->SetTouchable(true); + std::string str = startEmotionTestButton->GetText(); + if (str == "测量中") + { + startEmotionTestButton->SetText("测量"); + } + startEmotionTestButton->Invalidate(); + } + } + } + else if (hideView == EMOTIONTESTANALYSISVIEW) + { + if (EmoTestAnalysisView::GetInstance() != nullptr) + { + EmoTestAnalysisView::GetInstance()->startorstopAnalysisAni(false); + } + } + } + + bool EmoPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(event); + std::string viewId = view.GetViewId(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EcgPresenter::OnClick,viewId = %s", viewId.c_str()); + if (viewId == STARTEMOTIONTESTBUTTON) + { + if (EmoTestView::GetInstance() != nullptr) + { + UILabelButtonExt *startEmotionTestButton = EmoTestView::GetInstance()->GetStartEmotionTestButton(); + if (startEmotionTestButton) + { + std::string str = startEmotionTestButton->GetText(); + if (str == "测量") + { + startEmotionTestButton->SetText("测量中"); + startEmotionTestButton->SetTouchable(false); + model->start_emotest_timer(EMOTIONTESTVIEW); + EmoTestView::GetInstance()->SetTestButtonState(true); + } + else if (str == "测量中") + { + startEmotionTestButton->SetText("测量"); + EmoTestView::GetInstance()->SetTestButtonState(false); + } + startEmotionTestButton->Invalidate(); + } + } + } + else if(viewId == EMORESETTESTBTN) + { + ChangeViewOperator(EMOTIONTESTFAILNOWEARING, EMOTIONTESTVIEW); + } + else if(viewId == EMO_RESET_TEST_BTN) + { + ChangeViewOperator(EMOTIONTESTFAILNOVALUE, EMOTIONTESTVIEW); + } + return true; + } + + bool EmoPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + EmoPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool EmoPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && EmoPresenter::X_DRAG_FLAG) + { + if (&view == view_->GetEmotionGroupView(EMOTIONTESTVIEW)) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + else if (&view == view_->GetEmotionGroupView(EMOTIONTESTRESULTVIEW)) + { + view_->ChangeView(EMOTIONTESTRESULTVIEW, EMOTIONTESTVIEW); + } + EmoPresenter::X_DRAG_FLAG = false; + } + return true; + } + + bool EmoPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoPresenter::OnKeyAct"); + uint16_t keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestAnalysisView.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestAnalysisView.cpp new file mode 100644 index 000000000..a5b85358a --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestAnalysisView.cpp @@ -0,0 +1,154 @@ +#include "emotion/include/EmoTestAnalysisView.h" +#include "emotion/include/EmoPresenter.h" +#include "wearable_log.h" +#include "UiConfig.h" +#include "common/image_cache_manager.h" +namespace OHOS +{ + + const char *EmoAnaAniImagePath[] = { + PNG_ECG_IMAGE_00, + PNG_ECG_IMAGE_01, + PNG_ECG_IMAGE_02, + PNG_ECG_IMAGE_03, + PNG_ECG_IMAGE_04, + PNG_ECG_IMAGE_05, + PNG_ECG_IMAGE_06, + PNG_ECG_IMAGE_07, + PNG_ECG_IMAGE_08, + PNG_ECG_IMAGE_09, + PNG_ECG_IMAGE_10, + PNG_ECG_IMAGE_11, + PNG_ECG_IMAGE_12, + PNG_ECG_IMAGE_13, + PNG_ECG_IMAGE_14, + PNG_ECG_IMAGE_15, + PNG_ECG_IMAGE_16, + PNG_ECG_IMAGE_17, + PNG_ECG_IMAGE_18, + PNG_ECG_IMAGE_19, + PNG_ECG_IMAGE_20, + PNG_ECG_IMAGE_21, + PNG_ECG_IMAGE_22, + PNG_ECG_IMAGE_23, + PNG_ECG_IMAGE_24, + PNG_ECG_IMAGE_25, + PNG_ECG_IMAGE_26, + PNG_ECG_IMAGE_27, + PNG_ECG_IMAGE_28, + PNG_ECG_IMAGE_29, + }; + + static EmoTestAnalysisView *g_pEmoTestAnalysisView = nullptr; + EmoTestAnalysisView::EmoTestAnalysisView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestAnalysisView::EmoTestAnalysisView"); + g_pEmoTestAnalysisView = this; + } + + EmoTestAnalysisView::~EmoTestAnalysisView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestAnalysisView::~EmoTestAnalysisView"); + ClearAll(); + g_pEmoTestAnalysisView = nullptr; + } + + EmoTestAnalysisView *EmoTestAnalysisView::GetInstance(void) + { + return g_pEmoTestAnalysisView; + } + + void EmoTestAnalysisView::ClearAll(void) + { + if (group) + { + group->RemoveAll(); + delete group; + group = nullptr; + delete remindLabel; + remindLabel = nullptr; + if (EmoAnaAni) + { + EmoAnaAni->Stop(); + delete EmoAnaAni; + EmoAnaAni = nullptr; + } + } + } + + void EmoTestAnalysisView::startorstopAnalysisAni(bool state) + { + if (EmoAnaAni) + { + if (state) + { + EmoAnaAni->Start(); + } + else + { + EmoAnaAni->Stop(); + } + } + } + + UIViewGroup *EmoTestAnalysisView::EmoTestAnalysisInit() + { + 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::EmoPresenter::GetInstance(); + // group->SetOnDragListener(dragListener); + /* -------------------------------------------------------------------------- */ + EmoAnaAni = new UIImageAnimatorView(); + if (EmoAnaAni == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayBindAni::AlipayInitImageAni new EmoAnaAni fail"); + return nullptr; + } + for (uint8_t i = 0; i < (sizeof(EmoAnaAniImagePath) / sizeof(EmoAnaAniImagePath[0])); i++) + { + EmoAnaAniImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(EmoAnaAniImagePath[i]); + EmoAnaAniImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; + EmoAnaAniImageInfo[i].pos.x = 0; + EmoAnaAniImageInfo[i].pos.y = 0; + EmoAnaAniImageInfo[i].width = 466; + EmoAnaAniImageInfo[i].height = 466; + } + EmoAnaAni->SetPosition(0, 0, 466, 466); + EmoAnaAni->SetImageAnimatorSrc(EmoAnaAniImageInfo, (sizeof(EmoAnaAniImagePath) / sizeof(EmoAnaAniImagePath[0])), 100); + EmoAnaAni->SetRepeat(true); + EmoAnaAni->SetAutoEnable(false); + EmoAnaAni->SetResizeMode(UIImageView::FILL); + group->Add(EmoAnaAni); + /* -------------------------------------------------------------------------- */ + if (remindLabel == nullptr) + { + remindLabel = new UILabelExt(); + if (remindLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "remindLabel null!"); + return nullptr; + } + } + remindLabel->SetPosition((HORIZONTAL_RESOLUTION - 300) / 2, 360, 300, 35); + remindLabel->SetStyle(STYLE_TEXT_FONT, 30); + remindLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + remindLabel->SetText("数据分析中,请耐心等待结果"); + // remindLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0x3a, 0x3a, 0xff)); + remindLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + remindLabel->SetRollSpeed(23); + remindLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + remindLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(remindLabel); + return group; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoValueView.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoValueView.cpp new file mode 100644 index 000000000..9d80d8b14 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoValueView.cpp @@ -0,0 +1,115 @@ +#include "emotion/include/EmoTestFailedNoValueView.h" +#include "emotion/include/EmoPresenter.h" +#include "wearable_log.h" + +namespace OHOS +{ + static EmoTestFailedNoValueView *g_pEmoTestFailedNoValueView = nullptr; + EmoTestFailedNoValueView::EmoTestFailedNoValueView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestFailedNoValueView::EmoTestFailedNoValueView"); + g_pEmoTestFailedNoValueView = this; + } + + EmoTestFailedNoValueView::~EmoTestFailedNoValueView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestFailedNoValueView::~EmoTestFailedNoValueView"); + ClearAll(); + g_pEmoTestFailedNoValueView = nullptr; + } + + EmoTestFailedNoValueView *EmoTestFailedNoValueView::GetInstance(void) + { + return g_pEmoTestFailedNoValueView; + } + + void EmoTestFailedNoValueView::ClearAll(void) + { + if (group) + { + group->RemoveAll(); + delete group; + group = nullptr; + delete titleLabel; + titleLabel = nullptr; + delete image; + image = nullptr; + delete resetTestBtn; + resetTestBtn = nullptr; + } + } + + UIViewGroup *EmoTestFailedNoValueView::EmoTestFailedNoValueInit() + { + 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::EmoPresenter::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("测量失败"); + 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(131, 131, 466, 300); + image->SetSrc("/user/res/BPCalibration/error.bin"); + group->Add(image); + /* -------------------------------------------------------------------------- */ + if (resetTestBtn == nullptr) + { + resetTestBtn = new UILabelButtonExt(); + if (resetTestBtn == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "resetTestBtn null!"); + return nullptr; + } + } + resetTestBtn->SetPosition((HORIZONTAL_RESOLUTION - 220) / 2, 365, 220, 70); + resetTestBtn->SetStyle(STYLE_TEXT_FONT, 30); + resetTestBtn->SetStyle(STYLE_LINE_HEIGHT, 35); + resetTestBtn->SetAlign(TEXT_ALIGNMENT_CENTER); + resetTestBtn->SetText("重新测量"); + resetTestBtn->SetViewId(EMO_RESET_TEST_BTN); + resetTestBtn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36); + resetTestBtn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + resetTestBtn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + resetTestBtn->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::EmoPresenter::GetInstance(); + resetTestBtn->SetOnClickListener(clickListener); + group->Add(resetTestBtn); + return group; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoWearingView.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoWearingView.cpp new file mode 100644 index 000000000..944c821b8 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestFailedNoWearingView.cpp @@ -0,0 +1,134 @@ +#include "emotion/include/EmoTestFailedNoWearingView.h" +#include "emotion/include/EmoPresenter.h" +#include "wearable_log.h" + +namespace OHOS +{ + static EmoTestFailedNoWearingView *g_pEmoTestFailedNoWearingView = nullptr; + EmoTestFailedNoWearingView::EmoTestFailedNoWearingView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestFailedNoWearingView::EmoTestFailedNoWearingView"); + g_pEmoTestFailedNoWearingView = this; + } + + EmoTestFailedNoWearingView::~EmoTestFailedNoWearingView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestFailedNoWearingView::~EmoTestFailedNoWearingView"); + ClearAll(); + g_pEmoTestFailedNoWearingView = nullptr; + } + + EmoTestFailedNoWearingView *EmoTestFailedNoWearingView::GetInstance(void) + { + return g_pEmoTestFailedNoWearingView; + } + + void EmoTestFailedNoWearingView::ClearAll(void) + { + if (group) + { + group->RemoveAll(); + delete group; + group = nullptr; + delete titleLabel; + titleLabel = nullptr; + delete image; + image = nullptr; + delete resetTestBtn; + resetTestBtn = nullptr; + } + } + + UIViewGroup *EmoTestFailedNoWearingView::EmoTestFailedNoWearingInit() + { + 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::EmoPresenter::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("测量失败"); + 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 (remindLabel == nullptr) + { + remindLabel = new UILabelExt(); + if (remindLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "remindLabel null!"); + return nullptr; + } + } + remindLabel->SetPosition((HORIZONTAL_RESOLUTION - 300) / 2, 100, 300, 35); + remindLabel->SetStyle(STYLE_TEXT_FONT, 30); + remindLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + remindLabel->SetText("请正确佩戴手表检测"); + remindLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + remindLabel->SetRollSpeed(23); + remindLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + remindLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(remindLabel); + /* -------------------------------------------------------------------------- */ + if (image == nullptr) + { + image = new UIImageView(); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image null!"); + return nullptr; + } + } + image->SetPosition(131, 140, 466, 300); + image->SetSrc("/user/res/BPCalibration/error.bin"); + group->Add(image); + /* -------------------------------------------------------------------------- */ + if (resetTestBtn == nullptr) + { + resetTestBtn = new UILabelButtonExt(); + if (resetTestBtn == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "resetTestBtn null!"); + return nullptr; + } + } + resetTestBtn->SetPosition((HORIZONTAL_RESOLUTION - 220) / 2, 365, 220, 70); + resetTestBtn->SetStyle(STYLE_TEXT_FONT, 30); + resetTestBtn->SetStyle(STYLE_LINE_HEIGHT, 35); + resetTestBtn->SetAlign(TEXT_ALIGNMENT_CENTER); + resetTestBtn->SetText("重新测量"); + resetTestBtn->SetViewId(EMORESETTESTBTN); + resetTestBtn->SetStyle(STYLE_BACKGROUND_COLOR, 0xffff5a36); + resetTestBtn->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + resetTestBtn->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + resetTestBtn->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::EmoPresenter::GetInstance(); + resetTestBtn->SetOnClickListener(clickListener); + group->Add(resetTestBtn); + return group; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestResultView.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestResultView.cpp new file mode 100644 index 000000000..dcdda0705 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestResultView.cpp @@ -0,0 +1,116 @@ +#include "emotion/include/EmoTestResultView.h" +#include "emotion/include/EmoPresenter.h" +#include "wearable_log.h" + +namespace OHOS +{ + static EmoTestResultView *g_pEmoResetTestOfSuccView{nullptr}; + EmoTestResultView::EmoTestResultView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoTestResultView::EmoTestResultView"); + g_pEmoResetTestOfSuccView = this; + } + EmoTestResultView::~EmoTestResultView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestResultView::~EmoTestResultView"); + ClearAll(); + g_pEmoResetTestOfSuccView = nullptr; + } + EmoTestResultView *EmoTestResultView::GetInstance(void) + { + return g_pEmoResetTestOfSuccView; + } + + void EmoTestResultView::ClearAll(void) + { + if (group) + { + group->RemoveAll(); + delete titleLabel; + titleLabel = nullptr; + delete emotionLabel; + emotionLabel = nullptr; + delete remindLabel; + remindLabel = nullptr; + delete group; + group = nullptr; + } + } + + UIViewGroup *EmoTestResultView::EmotionTestResultInit() + { + 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::EmoPresenter::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("情绪"); + 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 (emotionLabel == nullptr) + { + emotionLabel = new UILabelExt(); + if (emotionLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "emotionLabel null!"); + return nullptr; + } + } + emotionLabel->SetPosition((HORIZONTAL_RESOLUTION - 300) / 2, 100, 300, 35); + emotionLabel->SetStyle(STYLE_TEXT_FONT, 30); + emotionLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + emotionLabel->SetText("愉悦"); + emotionLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + emotionLabel->SetTextColor(Color::GetColorFromRGBA(0xff, 0x4c, 0x6b, 0x00)); + emotionLabel->SetRollSpeed(23); + emotionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + emotionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(emotionLabel); + /* -------------------------------------------------------------------------- */ + if (remindLabel == nullptr) + { + remindLabel = new UILabelExt(); + if (remindLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "remindLabel null!"); + return nullptr; + } + } + remindLabel->SetPosition((HORIZONTAL_RESOLUTION - 400) / 2, emotionLabel->GetHeight() + emotionLabel->GetY() + 100, 400, 35); + remindLabel->SetStyle(STYLE_TEXT_FONT, 30); + remindLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + remindLabel->SetText("既心情顾虑、忧虑不安又感到精神压抑、感情低落、心情沉闷,是一种复杂的负面情绪状态"); + remindLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + remindLabel->SetRollSpeed(23); + remindLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + remindLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(remindLabel); + /* -------------------------------------------------------------------------- */ + return group; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestView.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestView.cpp new file mode 100644 index 000000000..3639daee0 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoTestView.cpp @@ -0,0 +1,132 @@ +#include "emotion/include/EmoPresenter.h" +#include "emotion/include/EmoTestView.h" +#include "wearable_log.h" + +namespace OHOS +{ + static EmoTestView *p_gEmoTestView = nullptr; + EmoTestView::EmoTestView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestView::EmoTestView"); + p_gEmoTestView = this; + } + EmoTestView::~EmoTestView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoTestView::~EmoTestView"); + p_gEmoTestView = nullptr; + } + + EmoTestView *EmoTestView::GetInstance(void) + { + return p_gEmoTestView; + } + + UILabelButtonExt *EmoTestView::GetStartEmotionTestButton() + { + return startEmotionTestButton; + } + + bool EmoTestView::GetTestButtonState() + { + return state; + } + + void EmoTestView::SetTestButtonState(bool val) + { + state = val; + } + + UIViewGroup *EmoTestView::EmoTestInit() + { + 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::EmoPresenter::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("情绪"); + 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 - 190) / 2, 90, 190, 300); + image->SetSrc("/user/res/BPCalibration/J2.bin"); + group->Add(image); + /* -------------------------------------------------------------------------- */ + if (showEmoValLabel == nullptr) + { + showEmoValLabel = new UILabelExt(); + if (showEmoValLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showEmoValLabel null!"); + return nullptr; + } + } + showEmoValLabel->SetPosition((HORIZONTAL_RESOLUTION - 190) / 2, 240, 190, 100); + showEmoValLabel->SetStyle(STYLE_TEXT_FONT, 100); + showEmoValLabel->SetStyle(STYLE_LINE_HEIGHT, 100); + showEmoValLabel->SetText("---"); + showEmoValLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + showEmoValLabel->SetRollSpeed(23); + showEmoValLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showEmoValLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 100); + group->Add(showEmoValLabel); + /* -------------------------------------------------------------------------- */ + if (startEmotionTestButton == nullptr) + { + startEmotionTestButton = new UILabelButtonExt(); + if (startEmotionTestButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startEmotionTestButton null!"); + return nullptr; + } + } + startEmotionTestButton->SetPosition((HORIZONTAL_RESOLUTION - 220) / 2, 360, 220, 70); + startEmotionTestButton->SetStyle(STYLE_TEXT_FONT, 30); + startEmotionTestButton->SetStyle(STYLE_LINE_HEIGHT, 35); + startEmotionTestButton->SetAlign(TEXT_ALIGNMENT_CENTER); + startEmotionTestButton->SetText("测量"); + startEmotionTestButton->SetViewId(STARTEMOTIONTESTBUTTON); + startEmotionTestButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4c6b00); + startEmotionTestButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + startEmotionTestButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + startEmotionTestButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + UIView::OnClickListener *clickListener = (UIView::OnClickListener *)OHOS::EmoPresenter::GetInstance(); + startEmotionTestButton->SetOnClickListener(clickListener); + group->Add(startEmotionTestButton); + return group; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoView.cpp b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoView.cpp new file mode 100644 index 000000000..4deccaae8 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/emotion/src/EmoView.cpp @@ -0,0 +1,259 @@ +#include "emotion/include/EmoPresenter.h" +#include "emotion/include/EmoView.h" +#include "wearable_log.h" + +namespace OHOS +{ + + static EmoView *g_pEmoView{nullptr}; + + EmoView::EmoView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoView::EmoView"); + g_pEmoView = this; + } + + EmoView::~EmoView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoView::~EmoView"); + ClearAll(); + g_pEmoView = nullptr; + } + + EmoView *EmoView::GetInstance() + { + return g_pEmoView; + } + + void EmoView::ClearAll(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoView::ClearAll"); + if (emoTestView) + { + delete emoTestView; + emoTestView = nullptr; + } + if (emoTestAnalysisView) + { + delete emoTestAnalysisView; + emoTestAnalysisView = nullptr; + } + if (emoTestResultView) + { + delete emoTestResultView; + emoTestResultView = nullptr; + } + if (emoTestFailedNoWearingView) + { + delete emoTestFailedNoWearingView; + emoTestFailedNoWearingView = nullptr; + } + if (emoTestFailedNoValueView) + { + delete emoTestFailedNoValueView; + emoTestFailedNoValueView = nullptr; + } + } + + void EmoView::CreateEmoView(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoView::CreateEmoView"); + ChangeView(MAX_EMOVIEW, EMOTIONTESTVIEW); + } + + void EmoView::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoView::OnStart"); + View::OnStart(); + 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_->SetOnDragListener(presenter_); + container_->SetTouchable(true); + container_->SetDraggable(true); + + if (!viewInitStatus) + { + CreateEmoView(); + viewInitStatus = true; + } + + RootView::GetInstance()->SetOnKeyActListener(presenter_); + return; + } + void EmoView::OnSetUpView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoView::OnSetUpView"); + View::OnSetUpView(); + Draw(); + return; + } + + void EmoView::OnTearDownView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoView::OnTearDownView"); + View::OnTearDownView(); + return; + } + + void EmoView::OnStop() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoView::OnStop"); + View::OnStop(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + RootView::GetInstance()->ClearOnKeyActListener(); + return; + } + + UIViewGroup *EmoView::GetEmotionGroupView(uint16_t index) + { + return group[index]; + } + + bool EmoView::ChangeEmoTestView(int16_t thisView) + { + if (group[thisView] == nullptr) + { + emoTestView = new EmoTestView(); + if (emoTestView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new scrollView[%d] fail", thisView); + return false; + } + // 初始化视图并添加到视图组 + group[thisView] = emoTestView->EmoTestInit(); + container_->Add(group[thisView]); + } + return true; + } + + bool EmoView::ChangeEmoTestAnalysisView(int16_t thisView) + { + if (group[thisView] == nullptr) + { + emoTestAnalysisView = new EmoTestAnalysisView(); + if (emoTestAnalysisView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new scrollView[%d] fail", thisView); + return false; + } + // 初始化视图并添加到视图组 + group[thisView] = emoTestAnalysisView->EmoTestAnalysisInit(); + container_->Add(group[thisView]); + } + return true; + } + + bool EmoView::ChangeEmoTestResultView(int16_t thisView) + { + if (group[thisView] == nullptr) + { + emoTestResultView = new EmoTestResultView(); + if (emoTestResultView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new scrollView[%d] fail", thisView); + return false; + } + // 初始化视图并添加到视图组 + group[thisView] = emoTestResultView->EmotionTestResultInit(); + container_->Add(group[thisView]); + } + return true; + } + + bool EmoView::ChangeEmoTestFailedNoWearingView(int16_t thisView) + { + if (group[thisView] == nullptr) + { + emoTestFailedNoWearingView = new EmoTestFailedNoWearingView(); + if (emoTestFailedNoWearingView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new scrollView[%d] fail", thisView); + return false; + } + // 初始化视图并添加到视图组 + group[thisView] = emoTestFailedNoWearingView->EmoTestFailedNoWearingInit(); + container_->Add(group[thisView]); + } + return true; + } + bool EmoView::ChangeEmoTestFailedNoValueView(int16_t thisView) + { + if (group[thisView] == nullptr) + { + emoTestFailedNoValueView = new EmoTestFailedNoValueView(); + if (emoTestFailedNoValueView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new scrollView[%d] fail", thisView); + return false; + } + // 初始化视图并添加到视图组 + group[thisView] = emoTestFailedNoValueView->EmoTestFailedNoValueInit(); + container_->Add(group[thisView]); + } + return true; + } + + struct EmoViewMapper + { + const int16_t viewId; // 视图ID + bool (EmoView::*func)(int16_t); // 对应的视图切换函数指针 + }; + + static const EmoViewMapper ViewMapper[] = { + {EMOTIONTESTVIEW, &EmoView::ChangeEmoTestView}, + {EMOTIONTESTANALYSISVIEW, &EmoView::ChangeEmoTestAnalysisView}, + {EMOTIONTESTRESULTVIEW, &EmoView::ChangeEmoTestResultView}, + {EMOTIONTESTFAILNOWEARING, &EmoView::ChangeEmoTestFailedNoWearingView}, + {EMOTIONTESTFAILNOVALUE, &EmoView::ChangeEmoTestFailedNoValueView}, + }; + + bool EmoView::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 EmoView::ChangeView(int16_t hideView, int16_t showView) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "EmoView::ChangeView"); + if (hideView > MAX_EMOVIEW) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "EmoView:: SystemViewId Overstep ones bounds"); + return; + } + if (hideView != MAX_EMOVIEW) + { + if (group[hideView] == nullptr) + { + return; + } + group[hideView]->SetVisible(false); + } + ClickFunc(showView); + group[showView]->SetVisible(true); + container_->Invalidate(); + } +} \ No newline at end of file -- 2.17.1