#include "ui_resource_image.h"
#include "common/image_cache_manager.h"
#include <time.h>
-
+extern uint8_t battery_get_voltage(float *voltage);
namespace OHOS {
}
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);
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