From 3914295ca3585855dacd04043b4ff129e99cd751 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 2 Jul 2024 15:34:01 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E7=9D=A1=E7=9C=A0=E5=89=8D20?= =?utf8?q?=E5=88=86=E9=92=9F=E5=BC=B9=E7=AA=97=E6=8F=90=E9=86=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/AlarmClockTimerConfig.cpp | 120 ++++++++--- .../nativeui/sleep/include/SleepModel.h | 27 ++- .../nativeui/sleep/src/SleepModel.cpp | 77 +++++-- .../broadcast/include/broadcast_feature.h | 1 + .../broadcast/src/broadcast_implement.c | 1 + .../service/msg_center/CMakeLists.txt | 2 + .../include/notify/sleep_notification.h | 40 ++++ .../msg_center/src/msg_center_customer.cpp | 28 ++- .../src/notify/sleep_notification.cpp | 202 ++++++++++++++++++ 9 files changed, 454 insertions(+), 44 deletions(-) create mode 100644 code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h create mode 100644 code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp index 3779fb4b8..7d03c8b7a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp @@ -27,6 +27,8 @@ #include "ConfigModelC.h" #include "ConfigModel.h" #include "heartrate/include/HeartModel.h" +#include "sleep/include/SleepModel.h" +#include "cat1_server_hal.h" #ifdef __cplusplus extern "C" @@ -41,6 +43,7 @@ extern "C" static int sleep_time = 0; static int wake_up_time = 0; + static int sleep_notify_time = 0; static int sleep_time_hour = 0; static int sleep_time_min = 0; @@ -56,17 +59,69 @@ extern "C" int goal_hour = sleep_time >> 16; int goal_min = (sleep_time & 0X00FF); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_hour:%d goal_min:%d", goal_hour, goal_min); - if ((goal_min - SLEPPNOTIFY) >= 0) + + sleep_time_min = (goal_min >= SLEPPNOTIFY) ? goal_min - SLEPPNOTIFY : ((goal_min + 60) - SLEPPNOTIFY); // 避免分钟数为负 + sleep_time_hour = goal_hour; + if (goal_min < SLEPPNOTIFY) + { // 如果需要借位 + sleep_time_hour -= 1; // 小时减1 + } + // 确保小时数正确 + sleep_time_hour = (sleep_time_hour < 0) ? 23 : sleep_time_hour; // 处理从0点前20分钟的情况,变为前一天的23点40分 + + sleep_notify_time = (sleep_time_hour << 16) | sleep_time_min; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_time_hour:%d sleep_time_min:%d sleep_notify_time:%d", sleep_time_hour, sleep_time_min, sleep_notify_time); + } + void AlarmEventPublish(uint16_t topic, uint8_t *data, uint32_t size) + { + int32 ret; + + Request *request = NULL; + BroadcastApi *broadcastApi = NULL; + IUnknown *api = NULL; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish topic=%u!!", topic); + + /* alloc request */ + request = SAMGR_AllocRequestMsg(0, PLATFORM_CORE, BROADCAST_SVR_ID, size); + if (request == NULL) { - sleep_time_hour = goal_hour; - sleep_time_min = goal_min - SLEPPNOTIFY; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SAMGR_AllocRequestMsg failed"); + return; } - else + request->msgId = topic; + if (size > 0) + { + ret = memcpy_s(request->data, size, (const void *)data, size); + if (ret != EOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish memcpy_s rateDataTmp fail! ret = %d", ret); + return; + } + } + + request->len = size; + request->msgValue = 0; + + /* public request */ + api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME); + if (api == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed"); + SAMGR_FreeRequestMsg(request); + return; + } + ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi); + if (ret != 0 || broadcastApi == NULL) { - sleep_time_hour = goal_hour - 1; - sleep_time_min = goal_min - SLEPPNOTIFY + 60; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed"); + SAMGR_FreeRequestMsg(request); + return; } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_time_hour:%d sleep_time_min:%d", sleep_time_hour, sleep_time_min); + broadcastApi->PublishTopic((IUnknown *)broadcastApi, request); + broadcastApi->Release((IUnknown *)broadcastApi); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish end!!"); + + return; } void AlarmTimerEventPublish(uint16 topic, AlarmClockEventData data) { @@ -116,7 +171,7 @@ extern "C" return; } - + /*闹钟*/ static void AlarmCallBackProcA(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmCallBackProcA"); @@ -125,6 +180,7 @@ extern "C" std::bind(AlarmTimerEventPublish, TOPIC_EVENT_ALARM_RING, unuse)); } + /*NextDay*/ static void AlarmCallBackProcB(void) { AlarmClockEventData unuse; @@ -180,27 +236,41 @@ extern "C" WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d : %d", curTime.tm_hour, curTime.tm_min); on_time_CallBackProc(); } - // 进入睡眠模式 - if (curTime.tm_hour == ((sleep_time >> 16) && curTime.tm_min == (sleep_time & 0X00FF))) + // 睡眠总开关 + if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP)) { - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SLEEPING_MODE, NULL); - } - // 退出睡眠模式 - if (curTime.tm_hour == ((wake_up_time >> 16) && curTime.tm_min == (wake_up_time & 0X00FF))) - { - do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); - } - // 睡眠提醒[前提开启睡眠提醒] - if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_REMIND)) - { - // 提醒一次 - if (curTime.tm_hour == sleep_time_hour && curTime.tm_min == sleep_time_min && curTime.tm_sec == 0) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CONFIGMODEL_ITEM_SLEEP is OK"); + // 睡眠提醒[前提开启睡眠提醒] + if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_REMIND)) + { + // 提醒一次 + if ((curTime.tm_hour == sleep_time_hour) && (curTime.tm_min == sleep_time_min) && (curTime.tm_sec == 0)) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's bedtime in 20 minutes"); + printf("20分钟后要睡觉啦!\r\n"); + AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4); + // 设置状态为睡眠提醒 + OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::SLEEPNOTIFY); + } + } + // 进入睡眠模式 + if ((curTime.tm_hour == (sleep_time >> 16)) && (curTime.tm_min == (sleep_time & 0X00FF)) && (curTime.tm_sec == 0)) + { + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SLEEPING_MODE, NULL); + // 睡眠弹窗 + printf("要睡觉啦!\r\n"); + AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4); + // 设置状态为睡眠 + OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::SLEPP); + } + // 退出睡眠模式 + if ((curTime.tm_hour == (wake_up_time >> 16)) && (curTime.tm_min == (wake_up_time & 0X00FF)) && (curTime.tm_sec == 0)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's bedtime in 20 minutes"); - printf("20分钟后要睡觉啦!\r\n"); + printf("起床啦!\r\n"); + do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL); + // 早安提醒 } } - // 早安提醒[前提开启睡眠提醒] // 心率周期检测 [0 1 5 10] if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_DETECTED)) 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 00735930c..8651b3d7f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h @@ -68,6 +68,15 @@ namespace OHOS void set_sleep_data(SLEEP_T *data); bool save_sleep_data(SLEEP_T *data); + // 睡眠状态 + enum class SLEEPSTATE + { + NOSLEEP = 0, + SLEEPNOTIFY, + SLEPP, + WALK, + }; + class SleepModel { public: @@ -80,9 +89,16 @@ namespace OHOS int get_sleep_min(); int get_sleep_goal(); int get_sleep_total(); - std::string get_rest_str(); // 解析入睡时间 - std::string get_walk_str(); // 解析醒来时间 - std::string get_goal_str(); // 解析目标休息时间 + + std::string get_rest_str(); // 解析入睡时间 + std::string get_walk_str(); // 解析醒来时间 + std::string get_goal_str(); // 解析目标休息时间 + std::string get_notifiy(); // 获取提醒时间 + std::string get_sleep_notifiy(); // 获取睡眠时间 + std::string get_walk_notifiy(); // 获取起床时间 + + void set_sleep_state(SLEEPSTATE state); + SLEEPSTATE get_sleep_state(); private: SleepModel(); @@ -93,9 +109,14 @@ namespace OHOS std::string sleepStr{"--"}; std::string walkStr{"--"}; std::string goalStr{"--"}; + std::string goalnotifyStr{"--"}; + std::string goalsleepStr{"--"}; + std::string goalwalkStr{"--"}; uint8_t sleep_total_time = 0; uint8_t goal_total_time = 0; + + SLEEPSTATE sleepstate_ = SLEEPSTATE::NOSLEEP; }; } 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 255dbcedf..2c1731a33 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp @@ -1,12 +1,12 @@ /* * @Author: penglei 1624952103@qq.com - * @Date: 2024-06-26 19:36:48 + * @Date: SLEPPNOTIFY24-06-26 19:36:48 * @LastEditors: penglei 1624952103@qq.com - * @LastEditTime: 2024-06-28 16:52:58 + * @LastEditTime: SLEPPNOTIFY24-06-28 16:52:58 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp * @Description: * - * Copyright (c) 2024 by ${git_name_email}, All Rights Reserved. + * Copyright (c) SLEPPNOTIFY24 by ${git_name_email}, All Rights Reserved. */ #include "sleep/include/SleepModel.h" @@ -30,8 +30,10 @@ extern "C" errcode_t uapi_get_TIME_STR(uint32_t time, char *p_time, char separator, bool include_seconds, bool include_year); extern "C" int get_sleep_time_from_config_model(void); extern "C" int get_wake_up_time_from_config_model(); + namespace OHOS { +#define SLEPPNOTIFY 20 static NAP_T nap_data = {0}; static SLEEP_T sleep_data = {0}; @@ -236,31 +238,51 @@ namespace OHOS */ void SleepModel::set_sleep_goal() { + // 将原3个字符串清空 + goalsleepStr.clear(); + goalnotifyStr.clear(); + goalwalkStr.clear(); + int goal_sleep = get_sleep_time_from_config_model(); int goal_walk = get_wake_up_time_from_config_model(); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_sleep:%d goal_walk:%d", goal_sleep, goal_walk); - + /* -------------------------------------------------------------------------- */ // 提取小时部分(前2字节) int goal_sleep_hour = goal_sleep >> 16; // 提取分钟部分(后2字节) int goal_sleep_min = goal_sleep & 0x00FF; - std::ostringstream sleeposs; sleeposs << std::setfill('0') << std::setw(2) << goal_sleep_hour << ":" << std::setw(2) << goal_sleep_min; + // 睡眠时间点字符串 + goalsleepStr = sleeposs.str(); + + /* -------------------------------------------------------------------------- */ + // 需要配置提醒字符串 减去SLEPPNOTIFY分钟的计算 + int notify_min = (goal_sleep_min >= SLEPPNOTIFY) ? goal_sleep_min - SLEPPNOTIFY : ((goal_sleep_min + 60) - SLEPPNOTIFY); // 避免分钟数为负 + int notify_hour = goal_sleep_hour; + if (goal_sleep_min < SLEPPNOTIFY) + { // 如果需要借位 + notify_hour -= 1; // 小时减1 + } + // 确保小时数正确 + notify_hour = (notify_hour < 0) ? 23 : notify_hour; // 处理从0点前SLEPPNOTIFY分钟的情况,变为前一天的23点40分 + // 格式化提醒时间字符串 + std::ostringstream notifyoss; + notifyoss << std::setfill('0') << std::setw(2) << notify_hour << ":" << std::setw(2) << notify_min; + // 设置提醒字符串 + goalnotifyStr = notifyoss.str(); + /* -------------------------------------------------------------------------- */ - std::string goalsleepStr = sleeposs.str(); - - // 提取小时部分(前2字节) int goal_walk_hour = goal_walk >> 16; - // 提取分钟部分(后2字节) 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; + // 起床时间点字符串 + goalwalkStr = walkoss.str(); + /* -------------------------------------------------------------------------- */ - std::string goalwalkStr = walkoss.str(); - + // 睡眠字符串 以及总时长 goalStr = goalsleepStr + "-" + goalwalkStr; goal_total_time = goal_walk_hour * 60 + goal_walk_min; } @@ -284,19 +306,44 @@ namespace OHOS { return sleep_total_time; } - // 解析入睡时间 + // 获取入睡时间 std::string SleepModel::get_rest_str() { return sleepStr; } - // 解析醒来时间 + // 获取醒来时间 std::string SleepModel::get_walk_str() { return walkStr; } - // 解析目标休息时间 + // 获取目标休息时间 std::string SleepModel::get_goal_str() { return goalStr; } + // 获取提醒时间 + std::string SleepModel::get_sleep_notifiy() + { + return goalsleepStr; + } + // 获取睡眠时间 + std::string SleepModel::get_notifiy() + { + return goalnotifyStr; + } + // 获取起床时间 + std::string SleepModel::get_walk_notifiy() + { + return goalwalkStr; + } + // 设置睡眠状态 + void SleepModel::set_sleep_state(SLEEPSTATE state) + { + sleepstate_ = state; + } + // 获取睡眠状态 + SLEEPSTATE SleepModel::get_sleep_state() + { + return sleepstate_; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h index 69c556481..9a0fc1015 100644 --- a/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h +++ b/code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h @@ -90,6 +90,7 @@ typedef enum { TOPIC_EVENT_CANCEL_FIND_WATCH,//取消查找 TOPIC_EVENT_DRINKREMINDER,//喝水提醒 TOPIC_EVENT_MESSAGENOTE, //消息通知 + TOPIC_EVENT_SLEEPNOTE, //睡眠通知 TOPIC_END_NUM = 20000, } TopicNum; diff --git a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c index c6190ac19..5c2594cc6 100644 --- a/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c +++ b/code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c @@ -68,6 +68,7 @@ static const TopicToCore topicToCoreArray[] = { {TOPIC_EVENT_CANCEL_FIND_WATCH,A_CORE_MASK, 1}, {TOPIC_EVENT_DRINKREMINDER,A_CORE_MASK, 1}, {TOPIC_EVENT_MESSAGENOTE,A_CORE_MASK, 1}, + {TOPIC_EVENT_SLEEPNOTE,A_CORE_MASK, 1}, #ifdef SUPPORT_CAT1_MODEM {TOPIC_EVENT_CAT1_INCOMMING, A_CORE_MASK, 1}, {TOPIC_EVENT_CAT1_CALLCONNTED, A_CORE_MASK, 1}, diff --git a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt index 60cfd4e42..c514708ce 100644 --- a/code/sdk/application/wearable/service/msg_center/CMakeLists.txt +++ b/code/sdk/application/wearable/service/msg_center/CMakeLists.txt @@ -168,6 +168,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/transmitting.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sleep_notification.cpp ) else() set(SOURCES @@ -183,6 +184,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sedentaryReminder_notification.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/transmitting.cpp ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/message_notification.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/src/notify/sleep_notification.cpp ) endif() diff --git a/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h b/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h new file mode 100644 index 000000000..f898b36af --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h @@ -0,0 +1,40 @@ +/*** + * @Date: 2024-07-02 10:15:59 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-02 11:27:01 + * @FilePath: /FD230/code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h + */ +/*** + * @Date: 2024-06-20 09:43:23 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-06-20 09:47:45 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/service/msg_center/include/notify/message_notification.h + */ +#ifndef SLEEP_NOTIFICATION +#define SLEEP_NOTIFICATION + +#include "BaseView.h" +namespace OHOS +{ + UIViewGroup *CreateSleepNotifyView(void); + void FreeSleepView(void); + + class SleepViewEventListener : public UIView::OnTouchListener, public UIView::OnDragListener + { + public: + static SleepViewEventListener &GetInstance(); + bool OnRelease(UIView &view, const ReleaseEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + + private: + SleepViewEventListener(); + ~SleepViewEventListener(); + SleepViewEventListener(const SleepViewEventListener &) = delete; + const SleepViewEventListener &operator=(const SleepViewEventListener &) = delete; + bool X_DRAG_FLAG{false}; + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 820e8d355..625779c52 100644 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -29,7 +29,10 @@ #include "power_display_service.h" #include "cat1_server.h" #include "testchanging.h" + #include "message_notification.h" +#include "sleep_notification.h" + #include "testcat1.h" #include "testold.h" #include "testhrsenson.h" @@ -110,6 +113,7 @@ const PriorityMapper PRI_MAPPER[] = { {TOPIC_EVENT_CANCEL_FIND_WATCH,PRIORITY_TWO}, {TOPIC_EVENT_DRINKREMINDER,PRIORITY_TWO}, {TOPIC_EVENT_MESSAGENOTE,PRIORITY_TWO}, + {TOPIC_EVENT_SLEEPNOTE,PRIORITY_TWO}, }; static bool CheckPriority(const Topic topic) @@ -185,6 +189,7 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_CANCEL_FIND_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_DRINKREMINDER); MsgCenterSubscribeTopic(TOPIC_EVENT_MESSAGENOTE); + MsgCenterSubscribeTopic(TOPIC_EVENT_SLEEPNOTE); } static OHOS::UIViewGroup* ShowAlarmNotify(void) @@ -265,7 +270,11 @@ static OHOS::UIViewGroup* showMessageNotify(void) { return OHOS::CreateMessageView(); } - +/*显示睡眠提醒*/ +static OHOS::UIViewGroup* showSleepNotify(void) +{ + return OHOS::CreateSleepNotifyView(); +} void MsgCenterNotifyAlarmProc(const Topic topic, Request* req) { unused(req); @@ -662,6 +671,22 @@ void MsgCenterNotifyMessageProc(const Topic topic, Request* req) NotificationManager::GetInstance()->ShowNotify(showMessageNotify, (uint16_t)topic, true); } +//睡眠提醒通知 +void MsgCenterNotifySleepProc(const Topic topic, Request* req) +{ + unused(topic); + unused(req); + WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "MsgCenterNotifySleepProc !"); + //亮屏显示新信息弹窗 + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + if (display_api->get_screen_state() != SCREEN_ON) + { + display_api->turn_on_screen(); + } + display_api->set_screen_set_keepon_timeout(1000*5); + NotificationManager::GetInstance()->SetNotifyPriority(PRIORITY_TWO); + NotificationManager::GetInstance()->ShowNotify(showSleepNotify, (uint16_t)topic, true); +} #endif #ifdef SUPPORT_CAT1_MODEM @@ -1232,6 +1257,7 @@ static MsgCenterNotifyTable g_msgCenterNotifyTable[] = { {TOPIC_EVENT_CANCEL_FIND_WATCH,MsgCenterNotifyCanCelFindWatchProc}, {TOPIC_EVENT_DRINKREMINDER,MsgCenterNotifyDrinkReminderProc}, {TOPIC_EVENT_MESSAGENOTE,MsgCenterNotifyMessageProc}, + {TOPIC_EVENT_SLEEPNOTE,MsgCenterNotifySleepProc}, }; static MsgCenterNotifyTable *MsgCenterGetNotifyTblCb(uint8_t idx) 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 new file mode 100644 index 000000000..c1f4af6c5 --- /dev/null +++ b/code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp @@ -0,0 +1,202 @@ +#include "notification_manager.h" +#include "wearable_log.h" +#include "components/ui_button.h" +#include +#include "ui_service.h" +#include +#include "bleEvent.h" +#include "components/ui_label_ext.h" +#include "uicomponents/UIComponents.h" +#include "sleep/include/SleepModel.h" +#include "sleep_notification.h" +#include "string" +#include "vibrator_service.h" +#include "UiConfig.h" +extern "C" void custom_VibratorFunc(OHOS::VibratorType vibratorType); + +namespace OHOS +{ + + UIViewGroup *SleepGroupView{nullptr}; + + UILabel *sleeptitle{nullptr}; // 标题 + UIImageView *sleepicon{nullptr}; // 睡眠图标 + UILabelExt *sleepnotifylabel{nullptr}; // 详细label + UILabelButtonExt *sleepbutton{nullptr}; // 删除按键 + + static std::string titleStr, timeStr, sleepStr; + +#define DELETEBUTTON "delete_button" + + SleepViewEventListener::SleepViewEventListener() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepViewEventListener::SleepViewEventListener"); + } + + SleepViewEventListener::~SleepViewEventListener() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepViewEventListener::~SleepViewEventListener"); + } + + SleepViewEventListener &SleepViewEventListener::GetInstance() + { + static SleepViewEventListener instance; + return instance; + } + bool SleepViewEventListener::OnRelease(UIView &view, const ReleaseEvent &event) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepViewEventListener::OnRelease"); + UNUSED(event); + if (strcmp(view.GetViewId(), DELETEBUTTON) == 0) + { + NotificationManager::GetInstance()->StopNotify(); + } + + return true; + } + bool SleepViewEventListener::OnDrag(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepViewEventListener::OnDrag"); + UNUSED(view); + return true; + } + + bool SleepViewEventListener::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SleepViewEventListener::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + { + NotificationManager::GetInstance()->StopNotify(); + } + return true; + } + + /*创建信息弹窗*/ + UIViewGroup *CreateSleepNotifyView(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreateSleepNotifyView"); + SleepGroupView = new UIViewGroup(); + if (SleepGroupView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateSleepNotifyView] SleepGroupView new fail!!"); + return nullptr; + } + SleepGroupView->SetPosition(0, 0, 466, 466); + SleepGroupView->SetViewId("sleepnotify"); + SleepGroupView->SetTouchable(true); + SleepGroupView->SetDraggable(true); + UIView::OnDragListener *dragListener = static_cast(&SleepViewEventListener::GetInstance()); + if (dragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateSleepNotifyView] dragListener new fail!!"); + return nullptr; + } + SleepGroupView->SetOnDragListener(dragListener); + /*获取最新sleep*/ + SLEEPSTATE sleepsate = SleepModel::GetInstance().get_sleep_state(); + UIResourceTextId textId = STR_MORNNING; + switch (sleepsate) + { + case SLEEPSTATE::SLEEPNOTIFY: + titleStr = SleepModel::GetInstance().get_notifiy(); + textId = STR_DISTURB; // 即将开启勿扰 + break; + case SLEEPSTATE::SLEPP: + titleStr = SleepModel::GetInstance().get_rest_str(); + textId = STR_DISTURBNOTE; // 开启勿扰 + break; + case SLEEPSTATE::WALK: + titleStr = SleepModel::GetInstance().get_walk_str(); + break; + default: + break; + } + + /*初始化label*/ + /* -------------------------------------------------------------------------- */ + sleeptitle = new UILabel(); + if (sleeptitle == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleeptitle:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 + } + sleeptitle->SetPosition(83, 60, 300, 35); + sleeptitle->SetText(titleStr.c_str()); + sleeptitle->SetStyle(STYLE_TEXT_FONT, 30); + sleeptitle->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); + sleeptitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + sleeptitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + sleeptitle->SetVisible(true); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleeptitle is ok!"); + /* -------------------------------------------------------------------------- */ + /*初始化图片*/ + InitImageView(sleepicon, 193, 130, 80, 80, "image", PNG_APPLIST_SLEEP_IMAGE); + sleepicon->SetResizeMode(UIImageView::ImageResizeMode::SCALE_DOWN); + /* -------------------------------------------------------------------------- */ + /*初始化消息内容*/ + sleepnotifylabel = new UILabelExt(); + if (sleepnotifylabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepnotifylabel:: new UILabel fail"); + return nullptr; // 内存分配失败,返回 + } + sleepnotifylabel->SetPosition(53, 220, 360, 144); + sleepnotifylabel->SetViewId("sleepnotifylabel"); + sleepnotifylabel->SetTextId(textId); // 将开启勿扰模式 + sleepnotifylabel->SetTextColor(Color::Gray()); + sleepnotifylabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + sleepnotifylabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); // 换行裁剪 + sleepnotifylabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); // 居中显示 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepnotifylabel is ok"); + + /*加载清除按键*/ + InitButtonExt(sleepbutton, 0, 366, 466, 100, DELETEBUTTON, STR_KONW, 30); + const char *buttonImgSrc = "/user/res/466x100button.bin"; + sleepbutton->SetImageSrc(buttonImgSrc, buttonImgSrc); + UIView::OnTouchListener *TouchListener = static_cast(&SleepViewEventListener::GetInstance()); + if (TouchListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateSleepView] TouchListener new fail!!"); + return nullptr; + } + sleepbutton->SetOnTouchListener(TouchListener); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleepbutton"); + /* -------------------------------------------------------------------------- */ + SleepGroupView->Add(sleeptitle); + SleepGroupView->Add(sleepicon); + SleepGroupView->Add(sleepnotifylabel); + SleepGroupView->Add(sleepbutton); + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Create SleepGroupView succeed!!"); + // 震动提醒 + custom_VibratorFunc(VibratorType::VIBRATOR_TYPE_TWO); + return SleepGroupView; + } + /*释放消息弹窗视图*/ + void FreeSleepView(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FreeSleepView(void)"); + if (SleepGroupView != nullptr) + { + SleepGroupView->RemoveAll(); + + delete sleeptitle; + sleeptitle = nullptr; + + delete sleepicon; + sleepicon = nullptr; + + delete sleepnotifylabel; + sleepnotifylabel = nullptr; + + delete sleepbutton; + sleepbutton = nullptr; + + RootView::GetInstance()->Remove(SleepGroupView); + delete SleepGroupView; + SleepGroupView = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Free SleepView succeed!!"); + } + return; + } +} \ No newline at end of file -- 2.17.1