From: Caisking <3449750381@qq.com> Date: Thu, 21 Dec 2023 06:59:00 +0000 (+0800) Subject: 初始化界面电量获取 X-Git-Tag: release_V1.2.70_20241020_135402~1376 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=cace467c5e671b75be41856de3421cf876917750;p=mirrors%2FFD230.git 初始化界面电量获取 --- diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp index 02e4dd151..cb1e4b55b 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/MainClockView.cpp @@ -12,7 +12,7 @@ #include "ui_resource_image.h" #include "common/image_cache_manager.h" #include - +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