From fdb3af5c3a96baa73599a989e74a16fdf348df2a Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 25 Jun 2024 19:03:37 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E7=9D=A1=E7=9C=A0Slice?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../uicomponents/UIComponents.cpp | 2 +- .../wearable/fd230app/CMakeLists.txt | 7 + .../nativelauncher/include/AppViewIDs.h | 42 ++-- .../nativelauncher/include/NativeLauncher.h | 8 +- .../nativelauncher/include/UiConfig.h | 1 + .../nativelauncher/src/NativeLauncher.cpp | 44 ++-- .../nativeui/applist/src/ApplistModel.cpp | 2 +- .../nativeui/sleep/include/SleepCardView.h | 0 .../sleep/include/SleepControlPresenter.h | 66 ++++++ .../nativeui/sleep/include/SleepControlView.h | 65 ++++++ .../nativeui/sleep/include/SleepModel.h | 0 .../nativeui/sleep/include/SleepTimeView.h | 67 ++++++ .../nativeui/sleep/include/SleepView.h | 59 +++++ .../nativeui/sleep/src/SleepCardView.cpp | 0 .../sleep/src/SleepControlPresenter.cpp | 114 ++++++++++ .../nativeui/sleep/src/SleepControlView.cpp | 203 ++++++++++++++++++ .../nativeui/sleep/src/SleepModel.cpp | 0 .../nativeui/sleep/src/SleepTimeView.cpp | 184 ++++++++++++++++ .../fd230app/nativeui/sleep/src/SleepView.cpp | 183 ++++++++++++++++ 19 files changed, 1003 insertions(+), 44 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepCardView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepCardView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp diff --git a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp index e8d5680b4..eefda1419 100644 --- a/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp +++ b/code/sdk/application/wearable/CustomUIComponentTool/uicomponents/UIComponents.cpp @@ -49,7 +49,7 @@ namespace OHOS label->SetFont(fontName, fontSize); // 设置标签的文本和其他属性 label->SetText(text); - label->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label->SetRollSpeed(0); // 设置标签可见 diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index c7393c32d..cb109d15e 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -619,6 +619,13 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/saveele/src/SaveBatPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/saveele/src/SaveBatView.cpp + #睡眠 + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sleep/src/SleepView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sleep/src/SleepTimeView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sleep/src/SleepControlView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sleep/src/SleepControlPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/sleep/src/SleepModel.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhoneView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/phone/src/PhonePresenter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 3ef0123c3..d46d2980d 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -41,10 +41,8 @@ typedef enum : uint16_t VIEW_INCOMING_CALL, // 来电界面 VIEW_COMPASS, // 指南针界面 VIEW_CONNECT_PHONE, // 连接手机界面 - VIEW_INDOORWALK, // 室内步行 VIEW_SHUTDOWN_OR_REBOOT, // 关机或重启界面 VIEW_WEATHER, // 天气 - VIEW_GOAL, // 每日目标 VIEW_SYSTEM, // 系统 VIEW_SOUND_VIBRATION, // 声音与震动 VIEW_SYSTEM_VOLUME, // 系统音量 @@ -67,10 +65,9 @@ typedef enum : uint16_t VIEW_RESPIRATORY_TRAINING, // 呼吸训练 VIEW_THEME_STYLE, // 主题样式 VIEW_AI_VOICE, // AI Voice(人工智能语音) - - /* ----------------------------------- 录音 ----------------------------------- */ + VIEW_SET_DESKTOP, // 显示方式 VIEW_RECORD, - /* ---------------------------------- 界面 ---------------------------------- */ + /* ----------------------------------------------------------------------------- */ VIEW_DIAL, // 切换表盘 VIEW_MESSAGE, // 信息通知 VIEW_MESSAGE_SHOW, // 信息详细界面 @@ -81,6 +78,10 @@ typedef enum : uint16_t VIEW_SAVEELE, // 省电模式 VIEW_SAVEBAT, // 省电模式界面 VIEW_TAKEPHOTOS, // 拍照界面 + VIEW_SLEEP, // 睡眠界面 + VIEW_SET_CARD, // 卡片管理 + VIEW_ADD_CARD, // 添加卡片 + VIEW_SET_DIAL, // 切换表盘 /* ----------------------------------- 训练 ----------------------------------- */ VIEW_TRAINING, // 训练 VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外) @@ -99,30 +100,25 @@ typedef enum : uint16_t VIEW_TRAININGAQUATIC, // 水上运动列表 VIEW_TRAININGOTHER, // 其他列表 /* -------------------------------------------------------------------------- */ - VIEW_MAIN_TEMP, // 体温界面(暂时不用) - VIEW_OFFLINEVOICE, // 语音助手界面(暂时不用) - VIEW_MAIN_ACTIVITY, // 记录步数界面(暂时不用) - VIEW_UISAMPLE, // 示例(暂时不用) - - VIEW_PHONE, // 电话 - VIEW_PHONECALL, // 拨号 - VIEW_PHONERING, // 拨号界面 - VIEW_PHONECALLING, // 来电 - VIEW_PHONECALLUP, // 通话界面 - VIEW_PHONEDIR, // 电话簿 - + VIEW_MAIN_TEMP, // 体温界面(暂时不用) + VIEW_OFFLINEVOICE, // 语音助手界面(暂时不用) + VIEW_MAIN_ACTIVITY, // 记录步数界面(暂时不用) + VIEW_UISAMPLE, // 示例(暂时不用) + VIEW_INDOORWALK, // 室内步行 + VIEW_PHONE, // 电话 + VIEW_PHONECALL, // 拨号 + VIEW_PHONERING, // 拨号界面 + VIEW_PHONECALLING, // 来电 + VIEW_PHONECALLUP, // 通话界面 + VIEW_PHONEDIR, // 电话簿 VIEW_MAIN_PHONE, // 主电话Slice VIEW_DIALING_METHOD, // 拨号方式 - - VIEW_TEST, // 测试 + VIEW_TEST, // 测试 + VIEW_GOAL, // 每日目标 /* -------------------------------------------------------------------------- */ #ifdef SUPPORT_ALIPAY_SEC VIEW_MAIN_ALIPAY, #endif - VIEW_SET_DESKTOP, // 主题样式//显示方式 - VIEW_SET_CARD, // 卡片管理 - VIEW_ADD_CARD, // 添加卡片 - VIEW_SET_DIAL, // 切换表盘 VIEW_MAX_INTER_APP, // 在此之前添加native应用ID. VIEW_EXTERN_APP = 0xFFFE, // 三方应用 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 99a9b5efa..6e9fc2fdc 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -26,7 +26,7 @@ namespace OHOS void InitWeekStepSlice(void); void InitBluetoothSlice(void); void InitWifiView(void); - void InitMainBloodOxyView(void); + void InitMainBloodSlice(void); void InitMainCallerLogView(void); void InitMainMakePhoneView(void); void InitCompassSlice(void); @@ -74,7 +74,7 @@ namespace OHOS void InitMessageSlice(void); void InitMessageShowSlice(void); void InitTakePhotosSlice(void); - + void InitSleepSlice(void); /* ----------------------------------- 训练 ----------------------------------- */ void InitTraingSlice(void); void InitTraingNomalSlice(void); @@ -96,15 +96,13 @@ namespace OHOS void InitSecondaryFunction(void); void InitFastTrainingSlice(void); void InitFastTrainingAttentionSlice(void); - + /* -------------------------------------------------------------------------- */ void InitPhoneSlice(void); void InitPhoneCallSlice(void); void InitPhoneDirSlice(void); void InitPhoneCallingSlice(void); void InitPhoneCallupSlice(void); void InitPhoneRingSlice(void); - - /* -------------------------------------------------------------------------- */ void InitMainPhoneSlice(void); void InitDialingMethodSlice(void); /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h index e3b0f99d0..b44e99a94 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/UiConfig.h @@ -274,6 +274,7 @@ namespace OHOS static constexpr const char *PNG_APPLIST_GOAL_IMAGE = APP_LIST_PATH "/sport.bin"; // 每日目标 static constexpr const char *PNG_APPLIST_VOICE_IMAGE = APP_LIST_PATH "/voice.bin"; // 声音 static constexpr const char *PNG_APPLIST_AIVOICE_IMAGE = APP_LIST_PATH "/aivoice.bin"; // AI Voice(人工智能语音) + static constexpr const char *PNG_APPLIST_SLEEP_IMAGE = APP_LIST_PATH "/sleeping.bin"; // 睡眠 /* ---------------------------------- 快速训练 ---------------------------------- */ static constexpr const char *PNG_TRAING_BOUTTONMORE_IMAGE = APP_RES_PATH "/Training/More.bin"; diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 3b646de74..17ffb62a8 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -93,6 +93,9 @@ #include "takephotos/include/TakephotosView.h" #include "takephotos/include/TakephotosPresenter.h" #include "takephotos/include/TakephotosModel.h" +/*睡眠*/ +#include "sleep/include/SleepControlView.h" +#include "sleep/include/SleepControlPresenter.h" #include "secondaryfunction/include/SecondaryFunctionPresenter.h" #include "secondaryfunction/include/SecondaryFunctionView.h" @@ -315,14 +318,6 @@ namespace OHOS {VIEW_TEST, &NativeLauncher::InittestSlice}, /* -------------------------------------------------------------------------- */ - /*消息通知*/ - {VIEW_MESSAGE, &NativeLauncher::InitMessageSlice}, - {VIEW_MESSAGE_SHOW, &NativeLauncher::InitMessageShowSlice}, - /*省电模式*/ - {VIEW_SAVEELE, &NativeLauncher::InitSaveEleSlice}, - {VIEW_SAVEBAT, &NativeLauncher::InitSaveBatSlice}, - /*遥控拍照*/ - {VIEW_TAKEPHOTOS, &NativeLauncher::InitTakePhotosSlice}, /* ----------------------------------- 训练 ----------------------------------- */ {VIEW_TRAINING, &NativeLauncher::InitTraingSlice}, // 训练 {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice}, // 正常训练初始界面 @@ -340,8 +335,16 @@ namespace OHOS {VIEW_TRAININGAQUATIC, &NativeLauncher::InitTraingAquaticSlice}, // 水上训练 {VIEW_TRAININGOTHER, &NativeLauncher::InitTraingOtherSlice}, // 水上训练 /* -------------------------------------------------------------------------- */ + /*消息通知*/ + {VIEW_MESSAGE, &NativeLauncher::InitMessageSlice}, + {VIEW_MESSAGE_SHOW, &NativeLauncher::InitMessageShowSlice}, + /*省电模式*/ + {VIEW_SAVEELE, &NativeLauncher::InitSaveEleSlice}, + {VIEW_SAVEBAT, &NativeLauncher::InitSaveBatSlice}, + /*遥控拍照*/ + {VIEW_TAKEPHOTOS, &NativeLauncher::InitTakePhotosSlice}, /*血氧检测*/ - {VIEW_BLOODOXY, &NativeLauncher::InitMainBloodOxyView}, + {VIEW_BLOODOXY, &NativeLauncher::InitMainBloodSlice}, /*心率检测*/ {VIEW_HEART, &NativeLauncher::InitHeartSlice}, /*设置主题样式*/ @@ -352,6 +355,8 @@ namespace OHOS {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice}, /*设置表盘*/ {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice}, + /*睡眠界面*/ + {VIEW_SLEEP, &NativeLauncher::InitSleepSlice}, /* -------------------------------------------------------------------------- */ #ifdef SUPPORT_ALIPAY_SEC @@ -567,9 +572,9 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_HEART, heartView); } - void NativeLauncher::InitMainBloodOxyView(void) + void NativeLauncher::InitMainBloodSlice(void) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitMainBloodOxyView"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitMainBloodSlice"); SliceProxy *bloodOxygenView = new AbilitySliceProxy; if (bloodOxygenView == nullptr) { @@ -1051,8 +1056,6 @@ namespace OHOS SliceProxy *TraingOtherview = new AbilitySliceProxy; NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGOTHER, TraingOtherview); } - /* -------------------------------------------------------------------------- */ - // 省电模式 void NativeLauncher::InitSaveEleSlice(void) { @@ -1089,6 +1092,19 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_TAKEPHOTOS, takephotosview); } + // 睡眠 + void NativeLauncher::InitSleepSlice(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSleepSlice"); + SliceProxy *sleepview = new AbilitySliceProxy; + if (sleepview == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepview"); + return; + } + NativeAbility::GetInstance().AddSliceProxy(VIEW_SLEEP, sleepview); + } + /* -------------------------------------------------------------------------- */ // 查找手机 void NativeLauncher::InitFindPhoneSlice(void) { @@ -1245,7 +1261,7 @@ namespace OHOS } NativeAbility::GetInstance().AddSliceProxy(VIEW_THEME_STYLE, ThemeStyle); } - + /*Ai Voice(人工智能语音)*/ void NativeLauncher::InitAiVoiceSlice(void) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index e70f87443..438f125fe 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -72,7 +72,7 @@ namespace OHOS {VIEW_SET_DIAL, PNG_APPLIST_CHANGEDIAL_IMAGE, PNG_APPLIST_CHANGEDIAL_IMAGE, "更换表盘", STR_WATCH_FACE, nullptr}, {VIEW_THEME_STYLE, PNG_APPLIST_THEME_IMAGE, PNG_APPLIST_THEME_IMAGE, "显示方式", STR_DISPLAY_MODE, nullptr}, {VIEW_SET_CARD, PNG_APPLIST_CARDSET_IMAGE, PNG_APPLIST_CARDSET_IMAGE, "卡片管理", STR_CARD_MANAGEMENT, nullptr}, - {VIEW_SLEEP, PNG_APPLIST_RECORD_IMAGE, PNG_APPLIST_RECORD_IMAGE, "睡眠", STR_SLEEP, nullptr}, + {VIEW_SLEEP, PNG_APPLIST_SLEEP_IMAGE, PNG_APPLIST_SLEEP_IMAGE, "睡眠", STR_SLEEP, nullptr}, {VIEW_RECORD, PNG_APPLIST_RECORD_IMAGE, PNG_APPLIST_RECORD_IMAGE, "录音", STR_RECORD, nullptr}, {VIEW_RESPIRATORY_TRAINING, PNG_APPLIST_BREATHE_IMAGE, PNG_APPLIST_BREATHE_IMAGE, "呼吸训练", STR_BREATH_TRAINING, nullptr}, {VIEW_TAKEPHOTOS, PNG_APPLIST_TACKEPHOTOS_IMAGE, PNG_APPLIST_TACKEPHOTOS_IMAGE, "遥控拍照", STR_REMOTE_SHOOTING, nullptr}, diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepCardView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepCardView.h new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h new file mode 100644 index 000000000..c1e48caeb --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h @@ -0,0 +1,66 @@ +/*** + * @Date: 2024-06-25 10:32:53 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:35:04 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h + */ +/*** + * @Date: 2024-06-25 10:32:53 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:33:56 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h + */ +/*** + * @Date: 2024-06-25 10:32:53 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 15:31:40 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlPresenter.h + */ +#ifndef Sleep_CONTROL_PRESENTER_H +#define Sleep_CONTROL_PRESENTER_H + +#include "Presenter.h" +#include "View.h" +#include "sleep/include/SleepView.h" +#include "sleep/include/SleepModel.h" +#include "sleep/include/SleepControlView.h" +namespace OHOS +{ + class SleepViewOnSwipeListener : public UISwipeView::OnSwipeListener + { + public: + SleepViewOnSwipeListener() {} + ~SleepViewOnSwipeListener() {} + void OnSwipe(UISwipeView &view) override; + }; + + class SleepControlView; + class SleepControlPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener + { + public: + SleepControlPresenter(); + virtual ~SleepControlPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SleepControlPresenter *GetInstance(); + + 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; + void OnSwipe(UISwipeView &view) override; + + bool X_DRAG_FLAG{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h new file mode 100644 index 000000000..216e0c166 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h @@ -0,0 +1,65 @@ +/*** + * @Date: 2024-06-25 10:41:08 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:26:24 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h + */ + +#ifndef SleepControl_VIEW_H +#define SleepControl_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_swipe_view.h" +#include "sleep/include/SleepControlView.h" +#include "sleep/include/SleepTimeView.h" +#include "sleep/include/SleepControlPresenter.h" + +namespace OHOS +{ + typedef enum + { + MAINSLEEPVIEW = 0, // 主视图 + SLEEPTIMEVIEW, // 详细视图 + MAX_SLEEPVIEW, + } SleepControlPageId; + +#define SLEEPVIEW "sleepview" + + class SleepControlPresenter; + class SleepControlView : public View + { + + public: + SleepControlView(); + virtual ~SleepControlView(); + static SleepControlView *GetInstance(void); + UISwipeView *SleepControlViewInit(void); + void ClearAll(void); + + AppGroupView *SleepPageInit(void); + AppGroupView *SleepimePageInit(void); + + SleepView *GetSleepView(void); + SleepTimeView *GetSleepTimeView(void); + + UIView *GetSleepControlPageView(void); + + public: + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + SleepView *sleepView{nullptr}; + SleepTimeView *sleeptimeView{nullptr}; + + private: + int16_t maxPage = MAX_SLEEPVIEW; + UISwipeView *SleepSwipeViewList{nullptr}; + AppGroupView *recordCard[MAX_SLEEPVIEW]{nullptr}; + AppGroupView *CreatePage(uint8_t SleepControlPageId); + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h new file mode 100644 index 000000000..254087266 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h @@ -0,0 +1,67 @@ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:29:03 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h + */ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 16:30:55 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h + */ + +#ifndef Sleep_Time_VIEW_H +#define Sleep_Time_VIEW_H + +#include "BaseView.h" +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" + +#include "wearable_log.h" +#include "AppGroupView.h" +#include + +namespace OHOS +{ + class SleepTimeView : public AppGroupView + { + + public: + SleepTimeView(); + virtual ~SleepTimeView(); + static SleepTimeView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + void SleepDataRefresh(); + + private: + const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); + void FreeImagePathsArray(const char **imagePaths, const int numImages); + void DumpWeatherInfo(); + + private: + UILabelExt *resttitle{nullptr}; // 作息时间标题 + UILabelExt *sleeptitle{nullptr}; // 入睡时间标题 + UILabelExt *walktitle{nullptr}; // 醒来标题 + UILabelExt *apptitle{nullptr}; // 详情 + UILabelExt *rest{nullptr}; // 作息时间 + UILabelExt *sleep{nullptr}; // 入睡时间 + UILabelExt *walk{nullptr}; // 醒来时间 + UIImageView *transverseline_1{nullptr}; // 横线1 + UIImageView *transverseline_2{nullptr}; // 横线2 + UIImageView *verticalline{nullptr}; // 竖线 + bool viewInitStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepView.h new file mode 100644 index 000000000..2d4214fed --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepView.h @@ -0,0 +1,59 @@ +/*** + * @Date: 2024-06-25 10:32:22 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 17:52:16 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepView.h + */ + +#ifndef Sleep_VIEW_H +#define Sleep_VIEW_H + +#include "BaseView.h" +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" + +#include "wearable_log.h" +#include "AppGroupView.h" +#include + +namespace OHOS +{ + class SleepView : public AppGroupView + { + public: + SleepView(); + virtual ~SleepView(); + static SleepView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + void SleepDataRefresh(); // 刷新睡眠数据 + + private: + UICircleProgress *circleProgress_{nullptr}; // 进度条 + + UILabelExt *title{nullptr}; + UILabelExt *hour{nullptr}; + UILabelExt *minute{nullptr}; + + UILabel *time_hour{nullptr}; // 睡眠时间[小时] + UILabel *time_minute{nullptr}; // 睡眠时间[分钟] + UILabelExt *goaltime{nullptr}; // 目标时间 + + UIImageView *roomimage{nullptr}; + UIImageView *upiconimage{nullptr}; + UIImageView *progress_image = nullptr; + + bool viewInitStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepCardView.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp new file mode 100644 index 000000000..0c8461608 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlPresenter.cpp @@ -0,0 +1,114 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "sleep/include/SleepControlPresenter.h" +#include "common/key_code.h" +#include "common/key_code.h" +#include +#include +#include "UiConfig.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static SleepControlPresenter *g_pSleepControlPresenter = nullptr; + + SleepControlPresenter::SleepControlPresenter() + { + // SleepModel = &SleepModel::GetInstance(); + g_pSleepControlPresenter = this; + } + + SleepControlPresenter::~SleepControlPresenter() + { + + g_pSleepControlPresenter = nullptr; + } + + SleepControlPresenter *SleepControlPresenter::GetInstance() + { + + return g_pSleepControlPresenter; + } + + void SleepControlPresenter::OnStart() + { + Presenter::OnStart(); + } + + void SleepControlPresenter::OnPause(void) + { + Presenter::OnPause(); + } + + void SleepControlPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void SleepControlPresenter::OnStop(void) + { + Presenter::OnStop(); + } + + bool SleepControlPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + SleepControlPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool SleepControlPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " SleepControlPresenter::OnDragEnd"); + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && SleepControlPresenter::X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(); + } + return true; + } + + bool SleepControlPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " SleepControlPresenter::OnClick"); + + UNUSED(view); + UNUSED(event); + return true; + } + + // 增加按键事件 + bool SleepControlPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(); + } + return true; + } + + void SleepControlPresenter::OnSwipe(UISwipeView &view) {} +#if 0 + void SleepControlViewOnSwipeListener::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepControlViewOnSwipeListener::OnSwipe,current tab index = %d", view.GetCurrentPage()); + if (view.GetCurrentPage() == SleepControlView) + { + view.SetIntercept(false); + } + else + { + view.SetIntercept(true); + } + return; + } +#endif +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp new file mode 100644 index 000000000..f732bf87d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp @@ -0,0 +1,203 @@ +/*** + * @Date: 2024-06-25 10:41:15 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-25 14:54:49 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlControlView.cpp + */ + +#include "sleep/include/SleepControlView.h" +#include "sleep/include/SleepControlPresenter.h" +#include "sleep/include/SleepModel.h" +#include "wearable_log.h" +namespace OHOS +{ + static SleepControlView *g_pSleepControlView{nullptr}; + SleepControlView::SleepControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepControlView::SleepControlView"); + g_pSleepControlView = this; + } + + SleepControlView::~SleepControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepControlView::~SleepControlView"); + ClearAll(); + g_pSleepControlView = nullptr; + } + + SleepControlView *SleepControlView::GetInstance(void) + { + return g_pSleepControlView; + } + + void SleepControlView::ClearAll(void) + { + if (SleepSwipeViewList != nullptr) + { + for (int32_t i = 0; i < maxPage; i++) + { + recordCard[i] = nullptr; + } + SleepSwipeViewList->RemoveAll(); + + delete sleepView; + sleepView = nullptr; + + delete sleeptimeView; + sleeptimeView = nullptr; + + delete SleepSwipeViewList; + SleepSwipeViewList = nullptr; + } + } + /*初始化主睡眠界面VIEW*/ + UISwipeView *SleepControlView::SleepControlViewInit(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepControlView::SleepControlViewInit"); + SleepSwipeViewList = new UISwipeView(UISwipeView::VERTICAL); + if (nullptr == SleepSwipeViewList) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepSwipeViewList new fail!!"); + return nullptr; + } + + SleepSwipeViewList->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SleepSwipeViewList->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + // SleepSwipeViewList->SetAnimatorTime(50); + SleepSwipeViewList->SetDraggable(true); + SleepSwipeViewList->SetTouchable(true); + for (uint16_t i = 0; i < maxPage; i++) + { + recordCard[i] = CreatePage(i); + if (nullptr == recordCard[i]) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "recordCard[%d] is nullptr!!", i); + return nullptr; + } + recordCard[i]->InitView(this); + SleepSwipeViewList->Add(recordCard[i]); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepControlView InitPage over!!"); + return SleepSwipeViewList; + } + + /*获取睡眠主界面*/ + UIView *SleepControlView::GetSleepControlPageView() + { + return dynamic_cast(SleepControlViewInit()); + } + /*OnStart 增加界面控制*/ + void SleepControlView::OnStart() + { + View::OnStart(); + RootView::GetInstance()->Add(GetSleepControlPageView()); + + if (SleepSwipeViewList == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepSwipeViewList is nullptr!"); + return; + } + + auto sleepPresenter = dynamic_cast(OHOS::SleepControlPresenter::GetInstance()); + if (sleepPresenter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to get SleepControlPresenter instance"); + return; + } + + SleepSwipeViewList->SetOnClickListener(sleepPresenter); + SleepSwipeViewList->SetOnDragListener(sleepPresenter); + SleepSwipeViewList->SetOnSwipeListener(sleepPresenter); + + RootView::OnKeyActListener *keyactListener = dynamic_cast(sleepPresenter); + if (keyactListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to set key act listener"); + return; + } + + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + } + void SleepControlView::OnSetUpView() + { + View::OnSetUpView(); + Draw(); + } + + void SleepControlView::OnTearDownView() + { + View::OnTearDownView(); + return; + } + + void SleepControlView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); + RootView::GetInstance()->RemoveAll(); + return; + } + + SleepView *SleepControlView::GetSleepView(void) + { + return sleepView; + } + + SleepTimeView *SleepControlView::GetSleepTimeView(void) + { + return sleeptimeView; + } + + AppGroupView *SleepControlView::SleepPageInit(void) + { + sleepView = new SleepView(); + if (sleepView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepView::new SleepView fail!"); + return nullptr; + } + + return sleepView; + } + + AppGroupView *SleepControlView::SleepimePageInit(void) + { + sleeptimeView = new SleepTimeView(); + if (sleeptimeView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleeptimeView::new SleepTimeView fail!"); + return nullptr; + } + + return sleeptimeView; + } + + struct SleepControlViewMapper + { + const int16_t viewId; + AppGroupView *(SleepControlView::*func)(void); + }; + + static const SleepControlViewMapper g_pageMapper[] = { + {MAINSLEEPVIEW, &SleepControlView::SleepPageInit}, + {SLEEPTIMEVIEW, &SleepControlView::SleepimePageInit}, + }; + + AppGroupView *SleepControlView::CreatePage(uint8_t SleepControlPageId) + { + uint16_t i; + AppGroupView *view = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage SleepControlPageId:%d", SleepControlPageId); + + for (i = 0; i < sizeof(g_pageMapper) / sizeof(g_pageMapper[0]); i++) + { + if (g_pageMapper[i].viewId == SleepControlPageId) + { // 正确使用 SleepControlPageId 来匹配视图ID + view = (this->*(g_pageMapper[i].func))(); // 如果找到匹配项,则调用相应的函数创建视图 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage view:%p", view); + return view; // 返回创建的视图 + } + } + return nullptr; // 如果没有找到匹配的视图ID,返回 nullptr + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp new file mode 100644 index 000000000..e69de29bb diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp new file mode 100644 index 000000000..8289c5d3c --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp @@ -0,0 +1,184 @@ +#include "sleep/include/SleepTimeView.h" +#include "ConfigModel.h" +#include "sleep/include/SleepModel.h" +#include "common/image_cache_manager.h" +#include "uicomponents/UIComponents.h" +#include "string" +namespace OHOS +{ + + static SleepTimeView *g_pSleepView{nullptr}; + static std::string restStr; + static std::string sleepStr; + static std::string walkStr; + SleepTimeView::SleepTimeView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::SleepTimeView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pSleepView = this; + } + + SleepTimeView::~SleepTimeView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepTimeView::~SleepTimeView"); + ClearAll(); + g_pSleepView = nullptr; + } + + void SleepTimeView::SleepDataRefresh() + { +#if 0 + rest->SetText(); + sleep->SetText(); + walk->SetText(); +#endif + } + + void SleepTimeView::ClearAll() + { + RemoveAll(); + if (resttitle != nullptr) + { + delete resttitle; + resttitle = nullptr; + } + if (sleeptitle != nullptr) + { + delete sleeptitle; + sleeptitle = nullptr; + } + if (walktitle != nullptr) + { + delete walktitle; + walktitle = nullptr; + } + if (apptitle != nullptr) + { + delete apptitle; + apptitle = nullptr; + } + if (rest != nullptr) + { + delete rest; + rest = nullptr; + } + + if (sleep != nullptr) + { + delete sleep; + sleep = nullptr; + } + if (walk != nullptr) + { + delete walk; + walk = nullptr; + } + if (transverseline_1 != nullptr) + { + delete transverseline_1; + transverseline_1 = nullptr; + } + if (transverseline_2 != nullptr) + { + delete transverseline_2; + transverseline_2 = nullptr; + } + if (verticalline != nullptr) + { + delete verticalline; + verticalline = nullptr; + } + } + + SleepTimeView *SleepTimeView::GetInstance() + { + return g_pSleepView; + } + + // 初始化天气页面 + bool SleepTimeView::InitPage(void) + { + /* ---------------------------------- 线条初始化 --------------------------------- */ + if (transverseline_1 == nullptr) + { + transverseline_1 = new UIImageView(); + } + transverseline_1->SetPosition(0, 169); + transverseline_1->Resize(466, 2); + transverseline_1->SetViewId("image1"); + transverseline_1->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + transverseline_1->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + transverseline_1->SetVisible(true); + + if (transverseline_2 == nullptr) + { + transverseline_2 = new UIImageView(); + } + transverseline_2->SetPosition(232, 191); + transverseline_2->Resize(2, 82); + transverseline_2->SetViewId("image2"); + transverseline_2->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + transverseline_2->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + transverseline_2->SetVisible(true); + + if (verticalline == nullptr) + { + verticalline = new UIImageView(); + } + verticalline->SetPosition(0, 296); + verticalline->Resize(466, 2); + verticalline->SetViewId("image1"); + verticalline->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + verticalline->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + verticalline->SetVisible(true); + /* -------------------------------- title初始化 -------------------------------- */ + InitLabelExt(resttitle, 83, 50, 300, 35, "resttitle", STR_REATTIME, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(sleeptitle, 21, 203, 200, 35, "sleeptitle", STR_SLEEPTIME, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(walktitle, 213, 203, 300, 35, "walktitle", STR_WALKTIME, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(apptitle, 93, 300, 300, 200, "apptitle", STR_APPMORE, DEFAULT_VECTOR_FONT_FILENAME, 26); + apptitle->SetTextColor(Color::Gray()); + /* ------------------------------- 数据label初始化 ------------------------------- */ + restStr = "--"; + InitLabel(rest, 211, 95, 230, 47, "restlabel", restStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); + rest->SetTextColor(Color::Gray()); + sleepStr = "--"; + InitLabel(sleep, 99, 238, 230, 47, "sleeplabel", sleepStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); + sleep->SetTextColor(Color::Purple()); + walkStr = "--"; + InitLabel(walk, 321, 238, 230, 47, "walklabel", walkStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); + walk->SetTextColor(Color::Purple()); + /* -------------------------------- 将组件添加到根视图 ------------------------------- */ + Add(resttitle); + Add(sleeptitle); + Add(walktitle); + Add(apptitle); + Add(rest); + Add(sleep); + Add(walk); + Add(transverseline_1); + Add(transverseline_2); + Add(verticalline); + return true; + } + + bool SleepTimeView::InitView(void *caller) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + return true; + } + + // 获取视图初始化状态 + bool SleepTimeView::GetInitViewState(void) + { + return viewInitStatus; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp new file mode 100644 index 000000000..b959a4441 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp @@ -0,0 +1,183 @@ +#include "sleep/include/SleepView.h" +#include "ConfigModel.h" +#include "sleep/include/SleepModel.h" +#include "common/image_cache_manager.h" +#include "uicomponents/UIComponents.h" +namespace OHOS +{ + static constexpr char *roomimagePath = "/user/res/Sleep/room.bin"; + static constexpr char *upimagePath = "/user/res/Sleep/up.bin"; + static constexpr const char *prossimagePath = "/user/res/step/step_b.bin"; + + static SleepView *g_pSleepView{nullptr}; + SleepView::SleepView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepView::SleepView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pSleepView = this; + } + + SleepView::~SleepView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepView::~SleepView"); + ClearAll(); + g_pSleepView = nullptr; + } + + void SleepView::SleepDataRefresh() + { +#if 0 + time_minute->SetText(SleepModel::GetInstance().getstepnew()); + time_hour->SetText(SleepModel::GetInstance().getstepSleep()); + circleProgress_->SetValue(SleepModel::GetInstance().getstepvalue()); +#endif + Invalidate(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Updata SleppTime!"); + RootView::GetInstance()->Invalidate(); + } + + void SleepView::ClearAll() + { + RemoveAll(); + if (circleProgress_ != nullptr) + { + delete circleProgress_; + circleProgress_ = nullptr; + } + if (time_hour != nullptr) + { + delete time_hour; + time_hour = nullptr; + } + if (time_minute != nullptr) + { + delete time_minute; + time_minute = nullptr; + } + if (goaltime != nullptr) + { + delete goaltime; + goaltime = nullptr; + } + if (roomimage != nullptr) + { + delete roomimage; + roomimage = nullptr; + } + if (upiconimage != nullptr) + { + delete upiconimage; + upiconimage = nullptr; + } + if (progress_image != nullptr) + { + delete progress_image; + progress_image = nullptr; + } + } + + SleepView *SleepView::GetInstance() + { + return g_pSleepView; + } + + /*初始化界面*/ + bool SleepView::InitPage(void) + { + /*初始化title*/ + InitLabelExt(title, 83, 50, 300, 35, "labletitle", STR_SLEEP_YESTERDAY, DEFAULT_VECTOR_FONT_FILENAME, 30); + /*初始化单位*/ + InitLabelExt(hour, 157, 246, 75, 75, "lablehour", STR_HOUR, DEFAULT_VECTOR_FONT_FILENAME, 26); + hour->SetTextColor(Color::Gray()); + InitLabelExt(minute, 299, 246, 100, 75, "lableminute", STR_MIN, DEFAULT_VECTOR_FONT_FILENAME, 26); + minute->SetTextColor(Color::Gray()); + /*初始化image*/ + InitImageView(roomimage, 192, 127, 82, 82, "image", roomimagePath); + InitImageView(upiconimage, 213, 360, 40, 40, "image", upimagePath); + InitImageView(progress_image, 28, 80, 100, 100, "image", prossimagePath); + /*初始化目标时间*/ + InitLabelExt(goaltime, 83, 312, 300, 35, "lablegoal", STR_SLEEPMGOAL, DEFAULT_VECTOR_FONT_FILENAME, 30); + goaltime->SetTextColor(Color::Gray()); + /*初始化睡眠时间*/ + time_hour = new UILabel(); + time_hour->SetPosition(84, 237); + time_hour->Resize(40, 75); + time_hour->SetViewId("time_hour"); + time_hour->SetText("--"); + time_hour->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + time_hour->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + time_hour->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 80); + + time_minute = new UILabel(); + time_minute->SetPosition(230, 237); + time_minute->Resize(40, 75); + time_minute->SetViewId("time_minute"); + time_minute->SetText("--"); + time_minute->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + time_minute->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + time_minute->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 80); + /* --------------------------------- 初始化进度条 --------------------------------- */ + circleProgress_ = new UICircleProgress(); + if (circleProgress_ == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "circleProgress new fail"); + return false; + } + circleProgress_->SetPosition(-1, 0); + circleProgress_->Resize(466, 466); + circleProgress_->SetViewId("circleProgress"); + circleProgress_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + circleProgress_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + circleProgress_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00); + circleProgress_->SetBackgroundStyle(STYLE_LINE_HEIGHT, 200); + circleProgress_->SetBackgroundStyle(STYLE_LINE_WIDTH, 21); + circleProgress_->SetBackgroundStyle(STYLE_LINE_OPA, 0x00); + circleProgress_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6); + circleProgress_->SetForegroundStyle(STYLE_BORDER_WIDTH, 200); + circleProgress_->SetForegroundStyle(STYLE_BORDER_RADIUS, 200); + circleProgress_->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000); + circleProgress_->SetForegroundStyle(STYLE_LINE_HEIGHT, 35); + circleProgress_->SetForegroundStyle(STYLE_LINE_COLOR, 0xff5320E2); + circleProgress_->SetForegroundStyle(STYLE_LINE_WIDTH, 20); + circleProgress_->SetCenterPosition(233, 229); + circleProgress_->SetRadius(205); + circleProgress_->SetStartAngle(320); + circleProgress_->SetEndAngle(40); + circleProgress_->SetValue(50); + circleProgress_->SetBackgroundImagePosition(36, 26); + /* -------------------------------- 将组件添加到根视图 ------------------------------- */ + Add(progress_image); + Add(circleProgress_); + Add(title); + Add(hour); + Add(minute); + Add(time_hour); + Add(time_minute); + Add(goaltime); + Add(upiconimage); + Add(roomimage); + + viewInitStatus = true; + return true; + } + + bool SleepView::InitView(void *caller) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepView InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + return true; + } + + bool SleepView::GetInitViewState(void) + { + return viewInitStatus; + } +} \ No newline at end of file -- 2.17.1