From: Caisking <3449750381@qq.com> Date: Sat, 21 Sep 2024 02:48:37 +0000 (+0800) Subject: #256 手表,充电满,充电显示100%,充电进度条显示不准 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=c1f2b833d3ca4b4a7fc72e1b34e232278bc411a5;p=mirrors%2FFD230.git #256 手表,充电满,充电显示100%,充电进度条显示不准 --- diff --git a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp index 02af283a8..9c2898bc0 100644 --- a/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/notify/charge_notification.cpp @@ -64,8 +64,7 @@ namespace OHOS std::string powerstr = std::to_string(power) + "%"; // 获取当前时间 - time_t seconds; - time(&seconds); + time_t seconds = time(nullptr); struct tm pTM; localtime_r(&seconds, &pTM); // 使用 localtime_r 以确保线程安全 @@ -74,29 +73,33 @@ namespace OHOS (pTM.tm_hour < 10 ? "0" : "") + std::to_string(pTM.tm_hour) + ":" + (pTM.tm_min < 10 ? "0" : "") + std::to_string(pTM.tm_min); + // 更新充电状态标签 + if (UILabel_Chargeing) { + if (power == 100) { + UILabel_Chargeing->SetText("充电完成"); // TODO: 增加多国语言 + } else { + // UILabel_Chargeing->SetText("Charging"); + UILabel_Chargeing->SetText("正在充电"); + // UILabel_Chargeing->SetTextId(STR_CHARGE); + } + UILabel_Chargeing->Invalidate(); + } + // 刷新时间标签 if (UILabel_time) { UILabel_time->SetText(stringtime.c_str()); + UILabel_time->Invalidate(); } // 刷新电池百分比标签 if (UILabel_power) { UILabel_power->SetText(powerstr.c_str()); + UILabel_power->Invalidate(); } // 刷新进度条 if (batteryprogress) { batteryprogress->SetValue(power); - } - - // 刷新 UI - if (UILabel_time) { - UILabel_time->Invalidate(); - } - if (UILabel_power) { - UILabel_power->Invalidate(); - } - if (batteryprogress) { batteryprogress->Invalidate(); } } @@ -263,8 +266,8 @@ namespace OHOS UILabel_Chargeing->Resize(200, 60); // widget's width and height UILabel_Chargeing->SetViewId("label4");// Set style UILabel_Chargeing->SetStyle(STYLE_TEXT_FONT, 30); - UILabel_Chargeing->SetText("正在充电"); - UILabel_Chargeing->SetTextId(STR_CHARGE); + // UILabel_Chargeing->SetText("正在充电"); + // UILabel_Chargeing->SetTextId(STR_CHARGE); UILabel_Chargeing->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); UILabel_Chargeing->SetTextColor(Color::GetColorFromRGBA(0x4F, 0xC3, 0x4C, 0xff)); UILabel_Chargeing->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);