screennotify 文件夹更新
authorluozheng <1732036298@qq.com>
Tue, 28 May 2024 12:30:14 +0000 (20:30 +0800)
committerluozheng <1732036298@qq.com>
Tue, 28 May 2024 12:30:14 +0000 (20:30 +0800)
code/sdk/application/wearable/fd230app/nativeui/screennotify/include/ui_screennotify.h
code/sdk/application/wearable/fd230app/nativeui/screennotify/src/ui_screennotify.cpp

index fa29ba8..5644098 100644 (file)
@@ -1,5 +1,5 @@
 #include <list>
-#include "stdio.h"
+#include <cstdio>
 #include "ability_state.h"
 #include "cmsis_os2.h"
 #include "common_def.h"
 #include "power_display_service.h"
 #include "NativeAbility.h"
 #include "AppViewIDs.h"
-#include "components/ui_label_ext.h"
-#include "language/font/ui_resource_string.h"
 #include "MainViewSample.h"
 #include "ui_screennotify.h"
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
-    static uint32_t g_back_to_home_interval = 5;
+static uint32_t g_back_to_home_interval = 5;
 
     // 需要屏蔽掉的slice,ignore_slice_ids数组中的slice灭屏超时后不会调转到默认界面
-    uint16_t ignore_slice_ids[] = {
-        VIEW_INVALID,
-        VIEW_SETTING,
-        VIEW_UISAMPLE,
-        VIEW_BLOODOXY, // 血氧功能
-        VIEW_HEART,    // 心率检测
-        VIEW_SAVEBAT,  // 省电模式
-        VIEW_TEST,
+uint16_t ignore_slice_ids[] = {
+VIEW_INVALID,
+VIEW_SETTING,
+VIEW_UISAMPLE,
+VIEW_BLOODOXY, // 血氧功能
+VIEW_HEART,    // 心率检测
+VIEW_SAVEBAT,  // 省电模式
+VIEW_TEST,
 #ifdef SUPPORT_ALIPAY_SEC
-        VIEW_MAIN_ALIPAY,
+    VIEW_MAIN_ALIPAY,
 #endif
     };
 
-    static std::list<ScreenStatusNotifyCallback> g_callback;
+static std::list<ScreenStatusNotifyCallback> g_callback;
 
-    static void ChangeToHomeView(void)
-    {
+static void ChangeToHomeView(void)
+{
 #if 0
-        screen_context_t *sc = power_display_get_screen_context();
-        uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId();
-        for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++)
-        {
-            if (ignore_slice_ids[i] == current_slice_id)
-            {
-                return;
-            }
+    screen_context_t *sc = power_display_get_screen_context();
+    uint16_t current_slice_id = OHOS::NativeAbility::GetInstance().GetCurSliceId();
+    for (uint16_t i = 0; i < sizeof(ignore_slice_ids) / sizeof(uint16_t); i++) {
+        if (ignore_slice_ids[i] == current_slice_id) {
+            return;
         }
-        if (sc->screen_off_time_interval > g_back_to_home_interval)
-        {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u",
-                          sc->screen_off_time_interval);
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u",
-                          OHOS::NativeAbility::GetInstance().GetNativeAbilityState());
-            if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE)
-            {
-                if (current_slice_id != VIEW_MAIN)
-                { // 主表盘
-                    OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN);
-                }
-                else
-                {
-                    // if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage()) {
+    }
+    if (sc->screen_off_time_interval > g_back_to_home_interval) {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "screen off time = %u",
+                      sc->screen_off_time_interval);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetNativeAbilityState = %u",
+                      OHOS::NativeAbility::GetInstance().GetNativeAbilityState());
+        if (OHOS::NativeAbility::GetInstance().GetNativeAbilityState() == STATE_ACTIVE) {
+            if (current_slice_id != VIEW_MAIN_SAMPLE) { // 主表盘
+                OHOS::NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_SAMPLE);
+            } else {
+                if (!OHOS::MainViewSample::GetInstance()->IsMainClockPage()) {
                     // 当前页面为主表盘的其他页面时,切换回主表盘页面
-                    // OHOS::MainViewSample::GetInstance()->SwitchToClockPage();
-                    // }
+                    OHOS::MainViewSample::GetInstance()->SwitchToClockPage();
                 }
             }
         }
-#endif
     }
+#endif
+}
 
-    void notify_screen_on_event(void)
-    {
-        for (auto callback : g_callback)
-        {
-            callback(SCREEN_STATUS_ON);
-        }
-        GraphicService::GetInstance()->PostGraphicEvent(ChangeToHomeView);
-    }
+void notify_screen_on_event(void)
+{
+    GraphicService::GetInstance()->PostGraphicEvent(
+        [&] {
+            for (auto callback : g_callback) {
+                callback(SCREEN_STATUS_ON);
+            }
+            ChangeToHomeView();
+        });
+}
 
-    void notify_screen_off_event(void)
-    {
-        for (auto callback : g_callback)
-        {
-            callback(SCREEN_STATUS_OFF);
-        }
-    }
+void notify_screen_off_event(void)
+{
+    GraphicService::GetInstance()->PostGraphicEvent(
+        [&] {
+            for (auto callback : g_callback) {
+                callback(SCREEN_STATUS_OFF);
+            }
+        });
+}
 
-    void set_back_to_home_interval(uint32_t time_sec)
-    {
-        g_back_to_home_interval = time_sec;
-    }
+void set_back_to_home_interval(uint32_t time_sec)
+{
+    g_back_to_home_interval = time_sec;
+}
 
-    uint32_t get_back_to_home_interval(void)
-    {
-        return g_back_to_home_interval;
-    }
+uint32_t get_back_to_home_interval(void)
+{
+    return g_back_to_home_interval;
+}
 
-    void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-    {
-        if (callback != nullptr)
-        {
-            g_callback.push_back(callback);
-        }
+void registerNotifyScreenStatus(ScreenStatusNotifyCallback callback)
+{
+    if (callback != nullptr) {
+        g_callback.push_back(callback);
     }
+}
 
-    void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback)
-    {
-        if (callback != nullptr)
-        {
-            g_callback.remove(callback);
-        }
+void deregisterNotifyScreenStatus(ScreenStatusNotifyCallback callback)
+{
+    if (callback != nullptr) {
+        g_callback.remove(callback);
     }
+}
 
 #ifdef __cplusplus
 }