From: Caisking <3449750381@qq.com> Date: Fri, 4 Oct 2024 05:51:13 +0000 (+0800) Subject: 睡眠:增加睡眠目标显示 X-Git-Tag: release_V1.2.70_20241020_135402~205 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=6cf4deb684467e79d13788696b726a69638118a5;p=mirrors%2FFD230.git 睡眠:增加睡眠目标显示 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h index f44d3d90e..3012dde53 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h @@ -1,20 +1,23 @@ -/*** +/*** * @Date: 2024-06-25 14:50:26 * @LastEditors: Caisking 3449750381@qq.com * @LastEditTime: 2024-07-01 15:10:12 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h + * @FilePath: + * /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 17:29:03 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h + * @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 + * @FilePath: + * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h */ #ifndef Sleep_Time_VIEW_H @@ -24,48 +27,47 @@ #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 "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 "wearable_log.h" #include "AppGroupView.h" +#include "wearable_log.h" #include -namespace OHOS -{ - class SleepTimeView : public AppGroupView - { +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(); +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: - void DumpWeatherInfo(); +private: + void DumpWeatherInfo(); - private: - UILabelExt *resttitle{nullptr}; // 作息时间标题 - UILabelExt *sleeptitle{nullptr}; // 入睡时间标题 - UILabelExt *waketitle{nullptr}; // 醒来标题 - UILabelExt *apptitle{nullptr}; // 详情 - UILabelExt *goal{nullptr}; // 作息时间 - UILabelExt *sleep{nullptr}; // 入睡时间 - UILabelExt *wake{nullptr}; // 醒来时间 - UIImageView *transverseline_1{nullptr}; // 横线1 - UIImageView *transverseline_2{nullptr}; // 横线2 - UIImageView *verticalline{nullptr}; // 竖线 - bool viewInitStatus{false}; - }; +private: + UILabelExt *resttitle{nullptr}; // 作息时间标题 + UILabelExt *sleeptitle{nullptr}; // 入睡时间标题 + UILabelExt *waketitle{nullptr}; // 醒来标题 + UILabelExt *goaltime{nullptr}; // 目标时长 + UILabelExt *goal{nullptr}; // 作息时间 + UILabelExt *sleep{nullptr}; // 入睡时间 + UILabelExt *wake{nullptr}; // 醒来时间 + UIImageView *transverseline_1{nullptr}; // 横线1 + UIImageView *transverseline_2{nullptr}; // 横线2 + UIImageView *verticalline{nullptr}; // 竖线 + UIImageView *upiconimage{nullptr}; + bool viewInitStatus{false}; +}; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp index dda33b95b..7483468bb 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp @@ -1,198 +1,192 @@ #include "sleep/include/SleepTimeView.h" #include "ConfigModel.h" -#include "sleep/include/SleepModel.h" #include "common/image_cache_manager.h" -#include "uicomponents/UIComponents.h" +#include "sleep/include/SleepModel.h" #include "string" -namespace OHOS -{ - - static SleepTimeView *g_pSleepView{nullptr}; - static std::string restStr; - static std::string sleepStr; - static std::string wakeStr; - SleepTimeView::SleepTimeView() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::SleepTimeView"); - SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - SetViewIndex(0); // 视图索引 - - g_pSleepView = this; - } +#include "uicomponents/UIComponents.h" +namespace OHOS { - SleepTimeView::~SleepTimeView() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepTimeView::~SleepTimeView"); - ClearAll(); +static SleepTimeView *g_pSleepView{nullptr}; +static std::string restStr; +static std::string sleepStr; +static std::string wakeStr; +static constexpr char *upimagePath = "/user/res/Sleep/up.bin"; +SleepTimeView::SleepTimeView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::SleepTimeView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 - g_pSleepView = nullptr; - } + g_pSleepView = this; +} - void SleepTimeView::SleepDataRefresh() - { - int sleep_hour = SleepModel::GetInstance().get_sleep_hour(); - int sleep_min = SleepModel::GetInstance().get_sleep_min(); - - // 有数据则刷新 - if (sleep_hour != 0 || sleep_min != 0) - { - if (sleep != nullptr && wake != nullptr) - { - sleep->SetText((SleepModel::GetInstance().get_rest_str()).c_str()); - wake->SetText((SleepModel::GetInstance().get_wake_str()).c_str()); - } - } - if (goal != nullptr) - { - goal->SetText((SleepModel::GetInstance().get_goal_str()).c_str()); - } - } +SleepTimeView::~SleepTimeView() { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SleepTimeView::~SleepTimeView"); + ClearAll(); - void SleepTimeView::ClearAll() - { - RemoveAll(); - if (resttitle != nullptr) - { - delete resttitle; - resttitle = nullptr; - } - if (sleeptitle != nullptr) - { - delete sleeptitle; - sleeptitle = nullptr; - } - if (waketitle != nullptr) - { - delete waketitle; - waketitle = nullptr; - } - if (apptitle != nullptr) - { - delete apptitle; - apptitle = nullptr; - } - if (goal != nullptr) - { - delete goal; - goal = nullptr; - } - - if (sleep != nullptr) - { - delete sleep; - sleep = nullptr; - } - if (wake != nullptr) - { - delete wake; - wake = 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; - } - } + g_pSleepView = nullptr; +} - SleepTimeView *SleepTimeView::GetInstance() - { - return g_pSleepView; - } +void SleepTimeView::SleepDataRefresh() { + int sleep_hour = SleepModel::GetInstance().get_sleep_hour(); + int sleep_min = SleepModel::GetInstance().get_sleep_min(); + int sleep_goal = SleepModel::GetInstance().get_sleep_goal(); - // 初始化天气页面 - 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(waketitle, 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初始化 ------------------------------- */ - restStr = "--"; - InitLabel(goal, 83, 90, 300, 50, "restlabel", restStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40); - // goal->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - goal->SetTextColor(Color::Gray()); - sleepStr = "--"; - InitLabel(sleep, 10, 238, 230, 47, "sleeplabel", sleepStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40); - sleep->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); - wakeStr = "--"; - InitLabel(wake, 245, 238, 230, 47, "wakelabel", wakeStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40); - wake->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); - /* -------------------------------- 将组件添加到根视图 ------------------------------- */ - Add(resttitle); - Add(sleeptitle); - Add(waketitle); - Add(apptitle); - Add(goal); - Add(sleep); - Add(wake); - Add(transverseline_1); - Add(transverseline_2); - Add(verticalline); - return true; + // 有数据则刷新 + if (sleep_hour != 0 || sleep_min != 0) { + if (sleep != nullptr && wake != nullptr) { + sleep->SetText((SleepModel::GetInstance().get_rest_str()).c_str()); + wake->SetText((SleepModel::GetInstance().get_wake_str()).c_str()); } + } + if (goal != nullptr) { + goal->SetText((SleepModel::GetInstance().get_goal_str()).c_str()); + } + // 更新目标时间 + if (goaltime != nullptr) { + UpdateLabel(goaltime, sleep_goal, STR_SLEEPMGOAL); + } +} - 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); - SleepDataRefresh(); - return true; - } +void SleepTimeView::ClearAll() { + RemoveAll(); + if (resttitle != nullptr) { + delete resttitle; + resttitle = nullptr; + } + if (sleeptitle != nullptr) { + delete sleeptitle; + sleeptitle = nullptr; + } + if (waketitle != nullptr) { + delete waketitle; + waketitle = nullptr; + } + if (goaltime != nullptr) { + delete goaltime; + goaltime = nullptr; + } + if (goal != nullptr) { + delete goal; + goal = nullptr; + } - // 获取视图初始化状态 - bool SleepTimeView::GetInitViewState(void) - { - return viewInitStatus; - } -} \ No newline at end of file + if (sleep != nullptr) { + delete sleep; + sleep = nullptr; + } + if (wake != nullptr) { + delete wake; + wake = nullptr; + } + if (upiconimage != nullptr) { + delete upiconimage; + upiconimage = 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); + InitImageView(upiconimage, 213, 420, 40, 40, "image", upimagePath); + + /* -------------------------------- 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(waketitle, 213, 203, 300, 35, "waketitle", STR_WALKTIME, + DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(goaltime, 83, 350, 300, 50, "lablegoal", STR_SLEEPMGOAL, + DEFAULT_VECTOR_FONT_FILENAME, 30); + goaltime->SetTextColor(Color::Gray()); + /* ------------------------------- 数据label初始化 + * ------------------------------- */ + restStr = "--"; + InitLabel(goal, 83, 90, 300, 50, "restlabel", restStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME, 40); + // goal->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + goal->SetTextColor(Color::Gray()); + sleepStr = "--"; + InitLabel(sleep, 10, 238, 230, 47, "sleeplabel", sleepStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME, 40); + sleep->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + wakeStr = "--"; + InitLabel(wake, 245, 238, 230, 47, "wakelabel", wakeStr.c_str(), + DEFAULT_VECTOR_FONT_FILENAME, 40); + wake->SetTextColor(Color::GetColorFromRGBA(0x53, 0x20, 0xE2, 0xff)); + + /* -------------------------------- 将组件添加到根视图 + * ------------------------------- */ + Add(resttitle); + Add(sleeptitle); + Add(waketitle); + Add(goaltime); + Add(goal); + Add(sleep); + Add(wake); + Add(transverseline_1); + Add(transverseline_2); + Add(verticalline); + Add(upiconimage); + 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); + SleepDataRefresh(); + return true; +} + +// 获取视图初始化状态 +bool SleepTimeView::GetInitViewState(void) { return viewInitStatus; } +} // namespace OHOS \ No newline at end of file