From 89afa9a34c2fb12a780b1b67dede094fbd2858d9 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 3 Jul 2024 20:35:13 +0800 Subject: [PATCH] =?utf8?q?=E4=B9=85=E5=9D=90=E6=8F=90=E9=86=92=E4=BF=AE?= =?utf8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../notify/sedentaryReminder_notification.cpp | 30 ++++++++++++++----- .../peripheral/config/include/ConfigModel.h | 8 ++--- .../peripheral/config/src/ConfigModel.cpp | 14 ++++----- 3 files changed, 34 insertions(+), 18 deletions(-) diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp index 81e776367..97de0afa7 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/sedentaryReminder_notification.cpp @@ -23,8 +23,8 @@ namespace OHOS UILabelExt *SedentaryReminderLabel{nullptr}; UIButton *SedentaryReminderButton{nullptr}; - static constexpr const int X_DRAG_OFFSET = 20; - static constexpr const int DOUBLES = 2; + static constexpr const int X_DRAG_OFFSET = 20; + static constexpr const int DOUBLES = 2; static constexpr const char *SEDENTARY_REMINDER_GROUPVIEWID = "sedentary_reminder_groupviewid"; static constexpr const char *SEDENTARY_REMINDER_BUTTONVIEWID = "sedentary_reminder_buttonviewid"; @@ -91,14 +91,30 @@ namespace OHOS time_t now = time(0); tm *ltm = localtime(&now); int currentHour = ltm->tm_hour; + int currentMinute = ltm->tm_min; - std::string ReminderTime = ConfigModel::GetInstance()->GetSedentaryReminderTime(); - // 判断是否在提醒时间段内 - if (ReminderTime.find(std::to_string(currentHour)) != std::string::npos) + // 获取提醒时间段 + int ReminderTime = ConfigModel::GetInstance()->GetSedentaryReminderTime(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ReminderTime = %d ",ReminderTime); + + // 解析开始时间 + int startHour = (ReminderTime >> 24) & 0xFF; // 前8位是小时 + int startMinute = (ReminderTime >> 16) & 0xFF; // 后8位是分钟 + + // 解析结束时间 + int endHour = (ReminderTime >> 8) & 0xFF; // 中间8位是小时 + int endMinute = ReminderTime & 0xFF; // 后8位是分钟 + + // 判断当前时间是否在提醒时间段内 + if (currentHour > startHour || (currentHour == startHour && currentMinute >= startMinute)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's time to remind the user to move!"); - return true; + if (currentHour < endHour || (currentHour == endHour && currentMinute < endMinute)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's time to remind the user to move!"); + return true; + } } + return false; } diff --git a/code/sdk/drivers/peripheral/config/include/ConfigModel.h b/code/sdk/drivers/peripheral/config/include/ConfigModel.h index fb1141d0e..c59bab126 100644 --- a/code/sdk/drivers/peripheral/config/include/ConfigModel.h +++ b/code/sdk/drivers/peripheral/config/include/ConfigModel.h @@ -253,14 +253,14 @@ namespace OHOS void SetDrinkFreq(const int value); int GetDrinkFreq(); /* ------------------------------ 久坐提醒相关set与get ----------------------------- */ - void SetSedentarySwitch(const bool value); - bool GetSedentarySwitch(); + void SetSedentarySwitch(const int value); + int GetSedentarySwitch(); void SetSedentaryInterval(const int value); int GetSedentaryInterval(); - void SetSedentaryReminderTime(const std::string& value); - std::string GetSedentaryReminderTime(); + void SetSedentaryReminderTime(const int value); + int GetSedentaryReminderTime(); /* ---------------------------------- 运动识别相关set与get ---------------------------------- */ void SetMotionRecognition(bool state); diff --git a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp index ace4e6b72..cbaac6802 100644 --- a/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp +++ b/code/sdk/drivers/peripheral/config/src/ConfigModel.cpp @@ -893,15 +893,15 @@ namespace OHOS } // 设置久坐提醒开关 - void ConfigModel::SetSedentarySwitch(const bool value) + void ConfigModel::SetSedentarySwitch(const int value) { set_condigData_Bool(CONFIGMODEL_ITEM_SEDENTARY_SWITCH,value); } // 获取久坐提醒开关 - bool ConfigModel::GetSedentarySwitch() + int ConfigModel::GetSedentarySwitch() { - return get_configData_bool(CONFIGMODEL_ITEM_SEDENTARY_SWITCH); + return get_configData_int(CONFIGMODEL_ITEM_SEDENTARY_SWITCH); } // 设置久坐提醒时间间隔 @@ -917,15 +917,15 @@ namespace OHOS } // 设置久坐提醒时间段 - void ConfigModel::SetSedentaryReminderTime(const std::string& value) + void ConfigModel::SetSedentaryReminderTime(const int value) { - set_condigData_String(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME,value.c_str()); + set_condigData_Int(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME,value); } // 获取久坐提醒时间段 - std::string ConfigModel::GetSedentaryReminderTime() + int ConfigModel::GetSedentaryReminderTime() { - return get_configData_string(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME); + return get_configData_int(CONFIGMODEL_ITEM_SEDENTARY_REMINDERTIME); } /* -------------------------------------------------------------------------- */ -- 2.17.1