修复电池更新
authorCaisking <Casiking@zhihuishixun.com>
Wed, 31 Dec 2025 09:49:43 +0000 (17:49 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Wed, 31 Dec 2025 09:49:43 +0000 (17:49 +0800)
code/sdk/application/wearable/fd272/service/msg_center/src/notify/charge_notification.cpp

index f79291e..8208824 100644 (file)
@@ -17,6 +17,7 @@
 #include "components/ui_circle_progress.h"
 #include "uicomponents/UIComponents.h"
 #include "charge_notification.h"
+#include <service/graphic_service.h>
 
 //#include "ui_resource_string.h"
 
@@ -71,11 +72,13 @@ namespace OHOS
 
     osTimerId_t Chargeing_timer= NULL;
 
-    // 刷新回调
-    void Chargeing_Timer_CallBack(int data) {
-      if (UIViewGroup_charge == nullptr || UILabel_Chargeing == nullptr ||
-          UILabel_power == nullptr || UILabel_time == nullptr ||
-          batteryprogress== nullptr) {
+    // 实际的UI更新逻辑(在图形线程中执行)
+    static void Chargeing_Timer_CallBackProc(int data) {
+      // 检查必要的UI组件是否存在(batteryprogress可能为nullptr,不影响更新)
+      if (UIViewGroup_charge == nullptr || 
+          UILabel_power == nullptr || 
+          UILabel_time == nullptr) {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Chargeing_Timer_CallBackProc: UI组件为空,跳过更新");
         return;
       }
 
@@ -110,6 +113,18 @@ namespace OHOS
         UILabel_power->Invalidate();
       }
 
+      // 如果batteryprogress存在,也更新它的值
+      if (batteryprogress != nullptr) {
+        batteryprogress->SetValue(power);
+        batteryprogress->Invalidate();
+      }
+
+    }
+
+    // 定时器回调函数(通过PostGraphicEvent投递到图形线程)
+    void Chargeing_Timer_CallBack(int data) {
+      GraphicService::GetInstance()->PostGraphicEvent(
+          std::bind(Chargeing_Timer_CallBackProc, data));
     }
 
     bool is_UIViewGroup_charge(void)