配置睡眠提醒闹铃为一分钟
authorCaisking <3449750381@qq.com>
Fri, 16 Aug 2024 10:20:18 +0000 (18:20 +0800)
committerCaisking <3449750381@qq.com>
Fri, 16 Aug 2024 10:20:18 +0000 (18:20 +0800)
code/sdk/application/wearable/fd230app/nativeui/alarmclocktimerconfig/src/AlarmClockTimerConfig.cpp
code/sdk/application/wearable/service/msg_center/src/notify/sleep_notification.cpp

index 9b96853..239c9f1 100644 (file)
@@ -383,6 +383,11 @@ extern "C"
                 // uapi_dev_runtime_set_sleep_status(0);\r
                 //  do_cywee_service_check_msg(CYWEE_SERVICE_CMD_GET_SLEEP_DATA, NULL);\r
                 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "起床啦!");\r
+                if (OHOS::ConfigModel::GetInstance()->GetDnotdisturb())\r
+                {\r
+                    OHOS::ConfigModel::GetInstance()->SetDnotdisturb(false); // 关闭勿扰\r
+                    SendMsgToUIService(UI_UPDATE_DNOTDISTURB_MODE, 0, nullptr, 0);\r
+                }\r
                 if (curTime.tm_hour == wake_time_hour && curTime.tm_min == wake_time_min && curTime.tm_sec == 0)\r
                 {\r
                     OHOS::SleepModel::GetInstance().set_sleep_state(OHOS::SLEEPSTATE::WAKE);\r
@@ -391,11 +396,6 @@ extern "C"
                     OHOS::SleepModel::GetInstance().ReInitData(); // 更新睡眠数据\r
                     SendMsgToUIService(UI_UPDATE_SLEEP_DATA, 0, nullptr, 0);\r
                 }\r
-                if (OHOS::ConfigModel::GetInstance()->GetDnotdisturb())\r
-                {\r
-                    OHOS::ConfigModel::GetInstance()->SetDnotdisturb(false); // 关闭勿扰\r
-                    SendMsgToUIService(UI_UPDATE_DNOTDISTURB_MODE, 0, nullptr, 0);\r
-                }\r
                 {\r
                     mmi_sleep_mode_flag_set(false); // switch off\r
 \r
index 04f34fe..10c4f28 100644 (file)
@@ -17,6 +17,7 @@
 
 namespace OHOS
 {
+#define MAX_SLEEP_RING 8
 
     UIViewGroup *SleepGroupView{nullptr};
 
@@ -147,13 +148,13 @@ namespace OHOS
         SleepGroupView->Add(sleepbutton);
 
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create SleepGroupView succeed!!");
-        
-        if(true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb())
+
+        if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb())
         {
             ui_api_vibrate_once_func();
         }
 
-        ScreenTurnOn(5000); // 亮屏操作 5000ms 5秒关闭        
+        ScreenTurnOn(100000); // 亮屏操作 100000ms 10秒关闭
 
         return SleepGroupView;
     }
@@ -192,10 +193,12 @@ namespace OHOS
         SleepGroupView->Add(closebutton);
 
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create SleepGroupView succeed!!");
-        if(true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb())
+        if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb())
         {
             ui_api_vibrate_once_func();
         }
+
+        ScreenTurnOn(600000); // 亮屏操作 600000ms 60秒关闭
     }
     /*释放消息弹窗视图*/
     void FreeSleepView(void)
@@ -279,13 +282,13 @@ namespace OHOS
         /*关闭闹钟*/
         if (strcmp(view.GetViewId(), CLOSEBUTTON) == 0)
         {
-            AlarmClockModel::GetInstance()->PopInterCancelMusic();
+            SleepViewEventListener::GetInstance().PopInterCancelMusic();
             NotificationManager::GetInstance()->StopNotify();
         }
         /*小睡按键*/
         if (strcmp(view.GetViewId(), NOPBUTTON) == 0)
         {
-            AlarmClockModel::GetInstance()->PopInterCancelMusic();
+            SleepViewEventListener::GetInstance().PopInterCancelMusic();
             SleepModel::GetInstance().Sleep_StartTimer(300000); // 开启一个5分钟的定时器
             NotificationManager::GetInstance()->StopNotify();
         }
@@ -306,7 +309,7 @@ namespace OHOS
         {
             // 如果是早安闹钟需要关闭闹钟
             if (SLEEPSTATE::WAKE == SleepModel::GetInstance().get_sleep_state())
-                AlarmClockModel::GetInstance()->PopInterCancelMusic();
+                SleepViewEventListener::GetInstance().PopInterCancelMusic();
             NotificationManager::GetInstance()->StopNotify();
         }
         return true;
@@ -447,7 +450,6 @@ namespace OHOS
      */
     void SleepViewEventListener::PopInterPlayMusic(void)
     {
-        ScreenTurnOn(15000); // 亮屏操作 15000ms 15秒关闭
         // 将"开启闹铃铃声"任务发布到异步线程
         GraphicService::GetInstance()->PostGraphicEvent(
             std::bind(&SleepViewEventListener::SleepRingPlayStart, &SleepViewEventListener::GetInstance()));
@@ -514,18 +516,22 @@ namespace OHOS
         GraphicService::GetInstance()->PostGraphicEvent(Stop);
     }
 
-    /*响应外部的音频中断事件*/
+    /* 响应外部的音频中断事件 */
     void SleepRingPlayerListener::OnInterrupt(int32_t type, int32_t hint)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnInterrupt go in, type %d, hint %d.", type, hint);
-        if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_PAUSE)
-        {
-            isDelayed_ = true;
-        }
 
-        if (type == INTERRUPT_TYPE_BEGIN && hint == INTERRUPT_HINT_STOP)
+        // 处理外部中断
+        if (type == INTERRUPT_TYPE_BEGIN)
         {
-            StopSleepRing();
+            if (hint == INTERRUPT_HINT_PAUSE)
+            {
+                isDelayed_ = true;
+            }
+            else if (hint == INTERRUPT_HINT_STOP)
+            {
+                StopSleepRing();
+            }
         }
         else if (type == INTERRUPT_TYPE_END && isDelayed_)
         {
@@ -533,15 +539,21 @@ namespace OHOS
             StartSleepRing();
             isDelayed_ = false;
         }
-        return;
     }
 
     /* --------------------- SleepRingPlayerCallbackImpl -------------------- */
     void SleepRingPlayerCallbackImpl::OnPlaybackComplete(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnPlaybackComplete");
+        static int countsleep = 0;
         SleepViewEventListener::GetInstance().PopInterCancelMusic();
-        SleepViewEventListener::GetInstance().PopInterPlayMusic();
+        /*达到最大次数不再播放*/
+        if (countsleep <= MAX_SLEEP_RING)
+        {
+            SleepViewEventListener::GetInstance().PopInterPlayMusic();
+            countsleep++;
+            printf("countsleep: %d\n", countsleep);
+        }
     }
 
     void SleepRingPlayerCallbackImpl::OnError(int32_t errorType, int32_t errorCode)