From c1f2b833d3ca4b4a7fc72e1b34e232278bc411a5 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 21 Sep 2024 10:48:37 +0800 Subject: [PATCH] =?utf8?q?#256=20=E6=89=8B=E8=A1=A8=EF=BC=8C=E5=85=85?= =?utf8?q?=E7=94=B5=E6=BB=A1=EF=BC=8C=E5=85=85=E7=94=B5=E6=98=BE=E7=A4=BA1?= =?utf8?q?00%=EF=BC=8C=E5=85=85=E7=94=B5=E8=BF=9B=E5=BA=A6=E6=9D=A1?= =?utf8?q?=E6=98=BE=E7=A4=BA=E4=B8=8D=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../src/notify/charge_notification.cpp | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) 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); -- 2.17.1