初始化界面电量获取
authorCaisking <3449750381@qq.com>
Thu, 21 Dec 2023 06:59:00 +0000 (14:59 +0800)
committerCaisking <3449750381@qq.com>
Thu, 21 Dec 2023 06:59:00 +0000 (14:59 +0800)
code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp

index 02e4dd1..cb1e4b5 100755 (executable)
@@ -12,7 +12,7 @@
 #include "ui_resource_image.h"
 #include "common/image_cache_manager.h"
 #include <time.h>
-
+extern uint8_t battery_get_voltage(float *voltage);
 
 
 namespace OHOS {
@@ -423,7 +423,9 @@ bool MainClockView::InitSweepClock(void)
     }
     batteryLabel->SetPosition(228, 52);         // widget's left position and top position
     batteryLabel->Resize(66, 33); 
-    batteryLabel->SetText("2%");
+    float voltage = 0.0F;
+    uint8_t value = battery_get_voltage(&voltage);
+    batteryLabel->SetText((std::to_string(value) + "%").c_str()); // 更新百分比显示
     batteryLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
     batteryLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28);
     batteryLabel->SetStyle(STYLE_BACKGROUND_COLOR, OPA_TRANSPARENT);
@@ -483,7 +485,7 @@ bool MainClockView::InitSweepClock(void)
     progress->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
 
     // Set additional property
-    progress->SetValue(50);
+    progress->SetValue(value);
     // Set BackgroundStyle
     progress->SetBackgroundStyle(STYLE_TEXT_COLOR, 0xff000000);
     // Set ForegroundStyle