增加睡眠前20分钟弹窗提醒
authorCaisking <3449750381@qq.com>
Tue, 2 Jul 2024 07:34:01 +0000 (15:34 +0800)
committerCaisking <3449750381@qq.com>
Tue, 2 Jul 2024 07:34:01 +0000 (15:34 +0800)
code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp
code/sdk/application/wearable/fd230app/nativeui/sleep/include/SleepModel.h
code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepModel.cpp
code/sdk/application/wearable/service/broadcast/include/broadcast_feature.h
code/sdk/application/wearable/service/broadcast/src/broadcast_implement.c
code/sdk/application/wearable/service/msg_center/CMakeLists.txt
code/sdk/application/wearable/service/msg_center/include/notify/sleep_notification.h [new file with mode: 0644]
code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp
code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp [new file with mode: 0644]

index 3779fb4..7d03c8b 100644 (file)
@@ -27,6 +27,8 @@
 #include "ConfigModelC.h"\r
 #include "ConfigModel.h"\r
 #include "heartrate/include/HeartModel.h"\r
+#include "sleep/include/SleepModel.h"\r
+#include "cat1_server_hal.h"\r
 \r
 #ifdef __cplusplus\r
 extern "C"\r
@@ -41,6 +43,7 @@ extern "C"
 \r
     static int sleep_time = 0;\r
     static int wake_up_time = 0;\r
+    static int sleep_notify_time = 0;\r
     static int sleep_time_hour = 0;\r
     static int sleep_time_min = 0;\r
 \r
@@ -56,17 +59,69 @@ extern "C"
         int goal_hour = sleep_time >> 16;\r
         int goal_min = (sleep_time & 0X00FF);\r
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goal_hour:%d goal_min:%d", goal_hour, goal_min);\r
-        if ((goal_min - SLEPPNOTIFY) >= 0)\r
+\r
+        sleep_time_min = (goal_min >= SLEPPNOTIFY) ? goal_min - SLEPPNOTIFY : ((goal_min + 60) - SLEPPNOTIFY); // 避免分钟数为负\r
+        sleep_time_hour = goal_hour;\r
+        if (goal_min < SLEPPNOTIFY)\r
+        {                         // 如果需要借位\r
+            sleep_time_hour -= 1; // 小时减1\r
+        }\r
+        // 确保小时数正确\r
+        sleep_time_hour = (sleep_time_hour < 0) ? 23 : sleep_time_hour; // 处理从0点前20分钟的情况,变为前一天的23点40分\r
+\r
+        sleep_notify_time = (sleep_time_hour << 16) | sleep_time_min;\r
+        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);\r
+    }\r
+    void AlarmEventPublish(uint16_t topic, uint8_t *data, uint32_t size)\r
+    {\r
+        int32 ret;\r
+\r
+        Request *request = NULL;\r
+        BroadcastApi *broadcastApi = NULL;\r
+        IUnknown *api = NULL;\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish topic=%u!!", topic);\r
+\r
+        /* alloc request */\r
+        request = SAMGR_AllocRequestMsg(0, PLATFORM_CORE, BROADCAST_SVR_ID, size);\r
+        if (request == NULL)\r
         {\r
-            sleep_time_hour = goal_hour;\r
-            sleep_time_min = goal_min - SLEPPNOTIFY;\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SAMGR_AllocRequestMsg failed");\r
+            return;\r
         }\r
-        else\r
+        request->msgId = topic;\r
+        if (size > 0)\r
+        {\r
+            ret = memcpy_s(request->data, size, (const void *)data, size);\r
+            if (ret != EOK)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish memcpy_s rateDataTmp fail! ret = %d", ret);\r
+                return;\r
+            }\r
+        }\r
+\r
+        request->len = size;\r
+        request->msgValue = 0;\r
+\r
+        /* public request */\r
+        api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME);\r
+        if (api == NULL)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetFeatureApi failed");\r
+            SAMGR_FreeRequestMsg(request);\r
+            return;\r
+        }\r
+        ret = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);\r
+        if (ret != 0 || broadcastApi == NULL)\r
         {\r
-            sleep_time_hour = goal_hour - 1;\r
-            sleep_time_min = goal_min - SLEPPNOTIFY + 60;\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QueryInterface failed");\r
+            SAMGR_FreeRequestMsg(request);\r
+            return;\r
         }\r
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "sleep_time_hour:%d sleep_time_min:%d", sleep_time_hour, sleep_time_min);\r
+        broadcastApi->PublishTopic((IUnknown *)broadcastApi, request);\r
+        broadcastApi->Release((IUnknown *)broadcastApi);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChargerEventPublish end!!");\r
+\r
+        return;\r
     }\r
     void AlarmTimerEventPublish(uint16 topic, AlarmClockEventData data)\r
     {\r
@@ -116,7 +171,7 @@ extern "C"
 \r
         return;\r
     }\r
-\r
+    /*闹钟*/\r
     static void AlarmCallBackProcA(void)\r
     {\r
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AlarmCallBackProcA");\r
@@ -125,6 +180,7 @@ extern "C"
             std::bind(AlarmTimerEventPublish, TOPIC_EVENT_ALARM_RING, unuse));\r
     }\r
 \r
+    /*NextDay*/\r
     static void AlarmCallBackProcB(void)\r
     {\r
         AlarmClockEventData unuse;\r
@@ -180,27 +236,41 @@ extern "C"
             WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "time: %d : %d", curTime.tm_hour, curTime.tm_min);\r
             on_time_CallBackProc();\r
         }\r
-        // 进入睡眠模式\r
-        if (curTime.tm_hour == ((sleep_time >> 16) && curTime.tm_min == (sleep_time & 0X00FF)))\r
+        // 睡眠总开关\r
+        if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP))\r
         {\r
-            do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SLEEPING_MODE, NULL);\r
-        }\r
-        // 退出睡眠模式\r
-        if (curTime.tm_hour == ((wake_up_time >> 16) && curTime.tm_min == (wake_up_time & 0X00FF)))\r
-        {\r
-            do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL);\r
-        }\r
-        // 睡眠提醒[前提开启睡眠提醒]\r
-        if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_REMIND))\r
-        {\r
-            // 提醒一次\r
-            if (curTime.tm_hour == sleep_time_hour && curTime.tm_min == sleep_time_min && curTime.tm_sec == 0)\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CONFIGMODEL_ITEM_SLEEP is OK");\r
+            // 睡眠提醒[前提开启睡眠提醒]\r
+            if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_SLEEP_REMIND))\r
+            {\r
+                // 提醒一次\r
+                if ((curTime.tm_hour == sleep_time_hour) && (curTime.tm_min == sleep_time_min) && (curTime.tm_sec == 0))\r
+                {\r
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's bedtime in 20 minutes");\r
+                    printf("20分钟后要睡觉啦!\r\n");\r
+                    AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4);\r
+                    // 设置状态为睡眠提醒\r
+                    OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::SLEEPNOTIFY);\r
+                }\r
+            }\r
+            // 进入睡眠模式\r
+            if ((curTime.tm_hour == (sleep_time >> 16)) && (curTime.tm_min == (sleep_time & 0X00FF)) && (curTime.tm_sec == 0))\r
+            {\r
+                do_cywee_service_check_msg(CYWEE_SERVICE_CMD_SLEEPING_MODE, NULL);\r
+                // 睡眠弹窗\r
+                printf("要睡觉啦!\r\n");\r
+                AlarmEventPublish(TOPIC_EVENT_SLEEPNOTE, (uint8_t *)sleep_notify_time, 4);\r
+                // 设置状态为睡眠\r
+                OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::SLEPP);\r
+            }\r
+            // 退出睡眠模式\r
+            if ((curTime.tm_hour == (wake_up_time >> 16)) && (curTime.tm_min == (wake_up_time & 0X00FF)) && (curTime.tm_sec == 0))\r
             {\r
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "It's bedtime in 20 minutes");\r
-                printf("20分钟后要睡觉啦!\r\n");\r
+                printf("起床啦!\r\n");\r
+                do_cywee_service_check_msg(CYWEE_SERVICE_CMD_NAP_SEDENTARY_MODE, NULL);\r
+                // 早安提醒\r
             }\r
         }\r
-        // 早安提醒[前提开启睡眠提醒]\r
 \r
         // 心率周期检测 [0 1 5 10]\r
         if (OHOS::ConfigModel::GetInstance()->get_configData_int(OHOS::ConfigModel::CONFIGMODEL_ITEM_HEARTRATE_DETECTED))\r
index 0073593..8651b3d 100644 (file)
@@ -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;
     };
 }
 
index 255dbce..2c1731a 100644 (file)
@@ -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"
 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;
     }
-    // è§£æ\9e\90入睡时间
+    // è\8e·å\8f\96入睡时间
     std::string SleepModel::get_rest_str()
     {
         return sleepStr;
     }
-    // è§£æ\9e\90醒来时间
+    // è\8e·å\8f\96醒来时间
     std::string SleepModel::get_walk_str()
     {
         return walkStr;
     }
-    // è§£æ\9e\90目标休息时间
+    // è\8e·å\8f\96目标休息时间
     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
index 69c5564..9a0fc10 100644 (file)
@@ -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;
 
index c6190ac..5c2594c 100644 (file)
@@ -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},
index 60cfd4e..c514708 100644 (file)
@@ -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 (file)
index 0000000..f898b36
--- /dev/null
@@ -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
index 820e8d3..625779c 100644 (file)
 #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 (file)
index 0000000..c1f4af6
--- /dev/null
@@ -0,0 +1,202 @@
+#include "notification_manager.h"
+#include "wearable_log.h"
+#include "components/ui_button.h"
+#include <iostream>
+#include "ui_service.h"
+#include <graphic_service.h>
+#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<UIView::OnDragListener *>(&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<UIView::OnTouchListener *>(&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