From d8c3e08267c54ff4be333adde816099bda4ab38e Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Thu, 4 Jul 2024 21:12:52 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E6=8B=BC=E5=86=99=E9=94=99?= =?utf8?q?=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/sleep/include/SleepModel.h | 10 ++-- .../nativeui/sleep/include/SleepTimeView.h | 4 +- .../nativeui/sleep/src/SleepModel.cpp | 55 ++++++++++--------- .../nativeui/sleep/src/SleepTimeView.cpp | 28 +++++----- .../src/notify/sleep_notification.cpp | 14 ++--- 5 files changed, 57 insertions(+), 54 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h index 3b93eb1e1..39038e4f3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -79,7 +79,7 @@ namespace OHOS typedef struct { std::string sleeptime; // 睡眠时间 - std::string walktime; // 醒来时间 + std::string waketime; // 醒来时间 int totaltime; // 睡眠总时间 } SleepDataUI; class SleepModel @@ -96,11 +96,11 @@ namespace OHOS int get_sleep_total(); std::string get_rest_str(); // 解析入睡时间 - std::string get_walk_str(); // 解析醒来时间 + std::string get_wake_str(); // 解析醒来时间 std::string get_goal_str(); // 解析目标休息时间 std::string get_notifiy(); // 获取提醒时间 std::string get_sleep_notifiy(); // 获取睡眠时间 - std::string get_walk_notifiy(); // 获取起床时间 + std::string get_wake_notifiy(); // 获取起床时间 void set_sleep_state(SLEEPSTATE state); SLEEPSTATE get_sleep_state(); @@ -114,12 +114,12 @@ namespace OHOS virtual ~SleepModel(); std::string sleepStr{"--"}; - std::string walkStr{"--"}; + std::string wakeStr{"--"}; std::string goalStr{"--"}; std::string goalnotifyStr{"--"}; std::string goalsleepStr{"--"}; - std::string goalwalkStr{"--"}; + std::string goalwakeStr{"--"}; uint8_t sleep_total_time = 0; uint8_t goal_total_time = 0; 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 867cd550f..faa5c33f8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepTimeView.h @@ -58,11 +58,11 @@ namespace OHOS private: UILabelExt *resttitle{nullptr}; // 作息时间标题 UILabelExt *sleeptitle{nullptr}; // 入睡时间标题 - UILabelExt *walktitle{nullptr}; // 醒来标题 + UILabelExt *waketitle{nullptr}; // 醒来标题 UILabelExt *apptitle{nullptr}; // 详情 UILabelExt *goal{nullptr}; // 作息时间 UILabelExt *sleep{nullptr}; // 入睡时间 - UILabelExt *walk{nullptr}; // 醒来时间 + UILabelExt *wake{nullptr}; // 醒来时间 UIImageView *transverseline_1{nullptr}; // 横线1 UIImageView *transverseline_2{nullptr}; // 横线2 UIImageView *verticalline{nullptr}; // 竖线 diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp index d39024b6e..b768750c9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -221,8 +221,10 @@ namespace OHOS SleepDataUI *data = ReadSleepData(); if (data != nullptr) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ReadSleepData sleepStr %s wakeStr %s sleep_total_time %d", + data->sleeptime.c_str(), data->waketime.c_str(), data->totaltime); sleepStr = data->sleeptime; - walkStr = data->walktime; + wakeStr = data->waketime; sleep_total_time = data->totaltime; } } @@ -277,13 +279,13 @@ namespace OHOS SleepDataUI *data = new SleepDataUI(); cJSON *sleeptime_item = cJSON_GetObjectItem(sleep_root, "sleeptime"); - cJSON *walktime_item = cJSON_GetObjectItem(sleep_root, "walktime"); + cJSON *waketime_item = cJSON_GetObjectItem(sleep_root, "waketime"); cJSON *totaltime_item = cJSON_GetObjectItem(sleep_root, "totaltime"); - if (sleeptime_item && walktime_item && totaltime_item) + if (sleeptime_item && waketime_item && totaltime_item) { data->sleeptime = sleeptime_item->valuestring; - data->walktime = walktime_item->valuestring; + data->waketime = waketime_item->valuestring; data->totaltime = totaltime_item->valueint; } else @@ -295,6 +297,7 @@ namespace OHOS } cJSON_Delete(sleep_root); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ReadSleepData is ok!"); // 返回结构体 return data; } @@ -327,7 +330,7 @@ namespace OHOS } cJSON_AddItemToObject(sleep_root, "sleeptime", cJSON_CreateString(data.sleeptime.c_str())); - cJSON_AddItemToObject(sleep_root, "walktime", cJSON_CreateString(data.walktime.c_str())); + cJSON_AddItemToObject(sleep_root, "waketime", cJSON_CreateString(data.waketime.c_str())); cJSON_AddItemToObject(sleep_root, "totaltime", cJSON_CreateNumber(data.totaltime)); char *jsonData = cJSON_Print(sleep_root); @@ -345,7 +348,7 @@ namespace OHOS cJSON_free(sleep_root); free(jsonData); outFile.close(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UpdateHealthData JSON is ok"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateHealthData JSON is ok"); return true; } @@ -358,18 +361,18 @@ namespace OHOS } // 打印数据 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "fall_asleep_timestamp:%d wake_up_timestamp:%d total_time:%d", + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "fall_asleep_timestamp:%d wake_up_timestamp:%d total_time:%d", data->fall_asleep_timestamp, data->wake_up_timestamp, data->total_time); update_time_info(data->fall_asleep_timestamp, sleepStr); // 睡眠字符串 - update_time_info(data->wake_up_timestamp, walkStr); // 醒来 + update_time_info(data->wake_up_timestamp, wakeStr); // 醒来 // 更新睡眠总时间 sleep_total_time = data->total_time; // 睡眠总时长 SleepDataUI UIdata; UIdata.sleeptime = sleepStr; - UIdata.walktime = walkStr; + UIdata.waketime = wakeStr; UIdata.totaltime = sleep_total_time; // 数据存储 SaveSleepData(UIdata); @@ -399,12 +402,12 @@ namespace OHOS // 将原3个字符串清空 goalnotifyStr.clear(); goalsleepStr.clear(); - goalwalkStr.clear(); + goalwakeStr.clear(); int goal_sleep = get_sleep_time_from_config_model(); - int goal_walk = get_wake_up_time_from_config_model(); + int goal_wake = get_wake_up_time_from_config_model(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_sleep:%d goal_walk:%d", goal_sleep, goal_walk); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_sleep:%d goal_wake:%d", goal_sleep, goal_wake); /* -------------------------------------------------------------------------- */ // 提取小时部分(前2字节) int goal_sleep_hour = goal_sleep >> 16; @@ -432,28 +435,28 @@ namespace OHOS goalnotifyStr = notifyoss.str(); /* -------------------------------------------------------------------------- */ - int goal_walk_hour = goal_walk >> 16; - int goal_walk_min = goal_walk & 0x00FF; - std::ostringstream walkoss; - walkoss << std::setfill('0') << std::setw(2) << goal_walk_hour << ":" << std::setw(2) << goal_walk_min; + int goal_wake_hour = goal_wake >> 16; + int goal_wake_min = goal_wake & 0x00FF; + std::ostringstream wakeoss; + wakeoss << std::setfill('0') << std::setw(2) << goal_wake_hour << ":" << std::setw(2) << goal_wake_min; // 起床时间点字符串 - goalwalkStr = walkoss.str(); + goalwakeStr = wakeoss.str(); /* -------------------------------------------------------------------------- */ // 睡眠字符串 以及总时长 - goalStr = goalsleepStr + "-" + goalwalkStr; + goalStr = goalsleepStr + "-" + goalwakeStr; // goal_total_time 计算 int total_hours; - if (goal_walk_hour < goal_sleep_hour) + if (goal_wake_hour < goal_sleep_hour) { - total_hours = (goal_walk_hour + 24) - goal_sleep_hour; // 跨天情况 + total_hours = (goal_wake_hour + 24) - goal_sleep_hour; // 跨天情况 } else { - total_hours = goal_walk_hour - goal_sleep_hour; + total_hours = goal_wake_hour - goal_sleep_hour; } - int total_minutes = goal_walk_min - goal_sleep_min; + int total_minutes = goal_wake_min - goal_sleep_min; if (total_minutes < 0) { total_hours--; // 如果分钟差为负数,小时差减1 @@ -487,9 +490,9 @@ namespace OHOS return sleepStr; } // 获取实际醒来时间str - std::string SleepModel::get_walk_str() + std::string SleepModel::get_wake_str() { - return walkStr; + return wakeStr; } // 获取目标休息时间str std::string SleepModel::get_goal_str() @@ -508,9 +511,9 @@ namespace OHOS } // 获取 目标起床 时间点str - std::string SleepModel::get_walk_notifiy() + std::string SleepModel::get_wake_notifiy() { - return goalwalkStr; + return goalwakeStr; } // 设置睡眠状态 void SleepModel::set_sleep_state(SLEEPSTATE state) 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 d4d13bfd4..a3bdeb08f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepTimeView.cpp @@ -10,7 +10,7 @@ namespace OHOS static SleepTimeView *g_pSleepView{nullptr}; static std::string restStr; static std::string sleepStr; - static std::string walkStr; + static std::string wakeStr; SleepTimeView::SleepTimeView() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepTimeView::SleepTimeView"); @@ -36,7 +36,7 @@ namespace OHOS if (sleep_hour != 0 || sleep_min != 0) { sleep->SetText((SleepModel::GetInstance().get_rest_str()).c_str()); - walk->SetText((SleepModel::GetInstance().get_walk_str()).c_str()); + wake->SetText((SleepModel::GetInstance().get_wake_str()).c_str()); } goal->SetText((SleepModel::GetInstance().get_goal_str()).c_str()); } @@ -54,10 +54,10 @@ namespace OHOS delete sleeptitle; sleeptitle = nullptr; } - if (walktitle != nullptr) + if (waketitle != nullptr) { - delete walktitle; - walktitle = nullptr; + delete waketitle; + waketitle = nullptr; } if (apptitle != nullptr) { @@ -75,10 +75,10 @@ namespace OHOS delete sleep; sleep = nullptr; } - if (walk != nullptr) + if (wake != nullptr) { - delete walk; - walk = nullptr; + delete wake; + wake = nullptr; } if (transverseline_1 != nullptr) { @@ -141,7 +141,7 @@ namespace OHOS /* -------------------------------- 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(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初始化 ------------------------------- */ @@ -152,17 +152,17 @@ namespace OHOS sleepStr = "--"; InitLabelAdapt(sleep, 79, 238, 230, 47, "sleeplabel", sleepStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40); sleep->SetTextColor(Color::Purple()); - walkStr = "--"; - InitLabelAdapt(walk, 319, 238, 230, 47, "walklabel", walkStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40); - walk->SetTextColor(Color::Purple()); + wakeStr = "--"; + InitLabelAdapt(wake, 319, 238, 230, 47, "wakelabel", wakeStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 40); + wake->SetTextColor(Color::Purple()); /* -------------------------------- 将组件添加到根视图 ------------------------------- */ Add(resttitle); Add(sleeptitle); - Add(walktitle); + Add(waketitle); Add(apptitle); Add(goal); Add(sleep); - Add(walk); + Add(wake); Add(transverseline_1); Add(transverseline_2); Add(verticalline); diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp index 4a3a3c4b5..4b65b8bef 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp @@ -31,7 +31,7 @@ namespace OHOS UIImageView *sunnyicon{nullptr}; UIImageView *alarmicon{nullptr}; UILabelExt *nowlabel{nullptr}; - UILabelExt *walklabel{nullptr}; // 早安时间 + UILabelExt *wakelabel{nullptr}; // 早安时间 UILabelButtonExt *closebutton{nullptr}; // 关闭按键 UILabelButtonExt *nopbutton{nullptr}; // 小睡按键 @@ -82,7 +82,7 @@ namespace OHOS ConfigModel::GetInstance()->SetDnotdisturb(true); break; case SLEEPSTATE::WAKE: - titleStr = SleepModel::GetInstance().get_walk_notifiy(); + titleStr = SleepModel::GetInstance().get_wake_notifiy(); textId = STR_MORNNING; ConfigModel::GetInstance()->SetDnotdisturb(false); // 关闭勿扰 SetAlarmClockView(); // 设置为早安视图 @@ -165,8 +165,8 @@ namespace OHOS InitLabelExt(alarmtitle, 83, 50, 300, 45, "labletitle", STR_MORNNING, DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabelExt(nowlabel, 110, 243, 200, 60, "labletitle", STR_NOW, DEFAULT_VECTOR_FONT_FILENAME, 30); /*获取起床时间labe*/ - std::string walkStr = SleepModel::GetInstance().get_walk_notifiy(); - InitLabel(walklabel, 190, 245, 200, 60, "labletitle", walkStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); + std::string wakeStr = SleepModel::GetInstance().get_wake_notifiy(); + InitLabel(wakelabel, 190, 245, 200, 60, "labletitle", wakeStr.c_str(), DEFAULT_VECTOR_FONT_FILENAME, 30); /*设置按键*/ InitButtonExt(nopbutton, 58, 320, 170, 90, NOPBUTTON, STR_NAP, 30); nopbutton->SetOnTouchListener(static_cast(&SleepViewEventListener::GetInstance())); @@ -183,7 +183,7 @@ namespace OHOS SleepGroupView->Add(sunnyicon); SleepGroupView->Add(alarmicon); SleepGroupView->Add(nowlabel); - SleepGroupView->Add(walklabel); + SleepGroupView->Add(wakelabel); SleepGroupView->Add(nopbutton); SleepGroupView->Add(closebutton); @@ -225,8 +225,8 @@ namespace OHOS delete nowlabel; nowlabel = nullptr; - delete walklabel; - walklabel = nullptr; + delete wakelabel; + wakelabel = nullptr; delete closebutton; closebutton = nullptr; -- 2.17.1