From a4fbd67e81ef2c8e751dbdd54bb7e4fdc36e0b9a Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Fri, 4 Oct 2024 13:51:38 +0800 Subject: [PATCH] =?utf8?q?=E7=9D=A1=E7=9C=A0=EF=BC=9A=E5=A2=9E=E5=8A=A0?= =?utf8?q?=E5=B0=8F=E7=9D=A1UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/sleep/include/SleepControlView.h | 5 + .../nativeui/sleep/include/SleepNapView.h | 69 +++++++++ .../nativeui/sleep/src/SleepControlView.cpp | 20 ++- .../nativeui/sleep/src/SleepNapView.cpp | 144 ++++++++++++++++++ .../fd230app/nativeui/sleep/src/SleepView.cpp | 2 +- 5 files changed, 238 insertions(+), 2 deletions(-) create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h create mode 100644 code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepNapView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h index c552368b7..289656ee8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepControlView.h @@ -19,6 +19,7 @@ #include "components/ui_swipe_view.h" #include "sleep/include/SleepControlView.h" #include "sleep/include/SleepTimeView.h" +# include "sleep/include/SleepNapView.h" #include "sleep/include/SleepControlPresenter.h" namespace OHOS @@ -27,6 +28,7 @@ namespace OHOS { MAINSLEEPVIEW = 0, // 主视图 SLEEPTIMEVIEW, // 详细视图 + SLEEPNAPVIEW, //小睡 MAX_SLEEPVIEW, } SleepControlPageId; @@ -45,9 +47,11 @@ namespace OHOS AppGroupView *SleepPageInit(void); AppGroupView *SleepTimePageInit(void); + AppGroupView *SleepNapPageInit(void); SleepView *GetSleepView(void); SleepTimeView *GetSleepTimeView(void); + SleepNapView *GetSleepNapView(void); UISwipeView *GetSleepControlPageView(void); void ChangeView(int16_t hideView, int16_t showView); @@ -61,6 +65,7 @@ namespace OHOS private: SleepView *sleepView{nullptr}; SleepTimeView *sleeptimeView{nullptr}; + SleepNapView *sleepnapView{nullptr}; private: int16_t maxPage = MAX_SLEEPVIEW; diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h new file mode 100644 index 000000000..3ba5228e6 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h @@ -0,0 +1,69 @@ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditNap: 2024-07-01 15:10:12 + * @FilePath: + * /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h + */ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditNap: 2024-06-25 17:29:03 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h + */ +/*** + * @Date: 2024-06-25 14:50:26 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditNap: 2024-06-25 16:30:55 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepNapView.h + */ + +#ifndef Sleep_Nap_VIEW_H +#define Sleep_Nap_VIEW_H + +#include "BaseView.h" +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_circle_progress.h" +#include "components/ui_image_animator.h" +#include "components/ui_image_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_scroll_view.h" +#include "components/ui_view_group.h" + +#include "AppGroupView.h" +#include "wearable_log.h" +#include + +namespace OHOS { +class SleepNapView : public AppGroupView { + +public: + SleepNapView(); + virtual ~SleepNapView(); + static SleepNapView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + void SleepDataRefresh(); + +private: + UILabelExt *napsleeptitle{nullptr}; + UILabelExt *napwaketitle{nullptr}; + UILabelExt *naptitle{nullptr}; + UILabelExt *napsleep{nullptr}; + UILabelExt *napwake{nullptr}; + UILabelExt *apptitle{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/src/SleepControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp index dbaaaf2f3..4bc6ea88b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepControlView.cpp @@ -53,6 +53,9 @@ namespace OHOS delete sleeptimeView; sleeptimeView = nullptr; + delete sleepnapView; + sleepnapView = nullptr; + delete SleepSwipeViewList; SleepSwipeViewList = nullptr; } @@ -155,7 +158,10 @@ namespace OHOS { return sleeptimeView; } - + SleepNapView *SleepControlView::GetSleepNapView(void) + { + return sleepnapView; + } AppGroupView *SleepControlView::SleepPageInit(void) { sleepView = new SleepView(); @@ -179,6 +185,17 @@ namespace OHOS return sleeptimeView; } + AppGroupView *SleepControlView::SleepNapPageInit(void) + { + sleepnapView = new SleepNapView(); + if (sleepnapView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepnapView::new SleepNapView fail!"); + return nullptr; + } + + return sleepnapView; + } struct SleepControlViewMapper { @@ -189,6 +206,7 @@ namespace OHOS static const SleepControlViewMapper g_pageMapper[] = { {MAINSLEEPVIEW, &SleepControlView::SleepPageInit}, {SLEEPTIMEVIEW, &SleepControlView::SleepTimePageInit}, + {SLEEPNAPVIEW, &SleepControlView::SleepNapPageInit}, }; AppGroupView *SleepControlView::CreatePage(uint8_t SleepControlPageId) diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepNapView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepNapView.cpp new file mode 100644 index 000000000..602a15e50 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepNapView.cpp @@ -0,0 +1,144 @@ +#include "sleep/include/SleepNapView.h" +#include "ConfigModel.h" +#include "common/image_cache_manager.h" +#include "sleep/include/SleepModel.h" +#include "string" +#include "uicomponents/UIComponents.h" +namespace OHOS { + +static SleepNapView *g_pSleepNapView{nullptr}; +static std::string restStr; +static std::string sleepStr; +static std::string wakeStr; +static std::string napsleepStr; +static std::string napwakeStr; +SleepNapView::SleepNapView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepNapView::SleepNapView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pSleepNapView = this; +} + +SleepNapView::~SleepNapView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepNapView::~SleepNapView"); + ClearAll(); + + g_pSleepNapView = nullptr; +} + +void SleepNapView::SleepDataRefresh() { + + int nap_hour = SleepModel::GetInstance().get_nap_hour(); + int nap_min = SleepModel::GetInstance().get_nap_min(); + + //小睡数据 + if (nap_hour != 0 || nap_min != 0) { + if (napsleep != nullptr && napwake != nullptr) { + napsleep->SetText((SleepModel::GetInstance().get_napsleep_str()).c_str()); + napwake->SetText((SleepModel::GetInstance().get_napwake_str()).c_str()); + } + } +} + +void SleepNapView::ClearAll() { + RemoveAll(); + + 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; + } + + if (napsleeptitle != nullptr) { + delete napsleeptitle; + napsleeptitle = nullptr; + } + if (napwaketitle != nullptr) { + delete napwaketitle; + napwaketitle = nullptr; + } + if (napwake != nullptr) { + delete napwake; + napwake = nullptr; + } + if (napsleep != nullptr) { + delete napsleep; + napsleep = nullptr; + } + if (naptitle != nullptr) { + delete naptitle; + naptitle = nullptr; + } +} + +SleepNapView *SleepNapView::GetInstance() { return g_pSleepNapView; } + + +bool SleepNapView::InitPage(void) { + /* ---------------------------------- 线条初始化 + * --------------------------------- */ + CreateLine(transverseline_1, 0, 169, 466, 2, "transverseline_1"); + CreateLine(transverseline_2, 0, 296, 466, 2, "transverseline_2"); + CreateLine(verticalline, 232, 191, 2, 82, "verticalline"); + /* -------------------------------- title初始化 + * -------------------------------- */ + InitLabel(naptitle, 83, 90, 300, 35, "resttitle", "小睡数据", + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(napsleeptitle, 21, 203, 200, 35, "sleeptitle", STR_SLEEPTIME, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(napwaketitle, 213, 203, 300, 35, "waketitle", 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初始化 + * ------------------------------- */ + napsleepStr = "--"; + InitLabel(napsleep, 10, 238, 230, 47, "sleeplabel", napsleepStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME, 40); + napsleep->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + napwakeStr = "--"; + InitLabel(napwake, 245, 238, 230, 47, "wakelabel", napwakeStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME, 40); + napwake->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + /* -------------------------------------------------------------------------- + */ + /* -------------------------------- 将组件添加到根视图 + * ------------------------------- */ + Add(transverseline_1); + Add(transverseline_2); + Add(verticalline); + + Add(naptitle); + Add(napsleeptitle); + Add(napwaketitle); + Add(napsleep); + Add(napwake); + Add(apptitle); + + return true; +} + +bool SleepNapView::InitView(void *caller) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepNapView InitView %p", caller); + if (InitPage() == false) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepNapView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + SleepDataRefresh(); + return true; +} + +// 获取视图初始化状态 +bool SleepNapView::GetInitViewState(void) { return viewInitStatus; } +} // namespace OHOS \ 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 index 400ade332..2c09e1c1a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp @@ -159,7 +159,7 @@ namespace OHOS minute->SetTextColor(Color::Gray()); /*初始化image*/ InitImageView(roomimage, 192, 127, 82, 82, "image", roomimagePath); - InitImageView(upiconimage, 213, 360, 40, 40, "image", upimagePath); + InitImageView(upiconimage, 213, 420, 40, 40, "image", upimagePath); InitImageView(progress_image, 28, 80, 100, 100, "image", prossimagePath); /*初始化目标时间*/ InitLabelExt(sleep_update_time, 83, 330, 300, 35, "lablegoal", STR_SLEEPMGOAL, DEFAULT_VECTOR_FONT_FILENAME, 30); -- 2.17.1