From db37e0732eb0442ea43b3c15fb7dceeb76cbabdb Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Wed, 18 Mar 2026 19:44:51 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E7=94=B5=E9=87=8F=E6=98=BE?= =?utf8?q?=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/main/include/PullUpDownView.h | 2 ++ .../nativeui/main/src/MainPresenterSample.cpp | 14 ++++++--- .../nativeui/main/src/PullUpDownView.cpp | 30 ++++++++++++++++++- 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/PullUpDownView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/PullUpDownView.h index 9732fd5cd..e2e6d61db 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/PullUpDownView.h +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/include/PullUpDownView.h @@ -87,6 +87,7 @@ namespace OHOS UILabel *GetDateAndWeekLabel(void); void UpdateSignalStrengthStatusAndBatteryPosition(); void UpdateBatteryProcess(); + UILabel *GetBatteryPercentLabel(void); private: void InitBaseData(); @@ -102,6 +103,7 @@ namespace OHOS UIViewGroup *group1{nullptr}; UIImageView *batteryimage{nullptr}; // 电池图片 UIBoxProgress *progress{nullptr}; // 电池进度条 + UILabel *batteryPercentLabel{nullptr}; // 电量百分比文本 UILabel *showDateAndWeekLabel{nullptr}; // 显示日期和星期 UIImageView *chargeBatteryicon{nullptr}; //充电图标 bool isChargeBatteryIconVisible{false}; // 充电图标是否可见 diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp index fb1192cb7..55f9c9e0d 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/MainPresenterSample.cpp @@ -693,10 +693,16 @@ #endif WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value); std::string dateAndweek = std::string(dateStr) + " " + std::string(weekStr); - if (PullUpDownView::GetInstance() != nullptr) - { - PullUpDownView::GetInstance()->GetProgress()->SetValue(value); - PullUpDownView::GetInstance()->GetDateAndWeekLabel()->SetText(dateAndweek.c_str()); + if (PullUpDownView::GetInstance() != nullptr) + { + PullUpDownView::GetInstance()->GetProgress()->SetValue(value); + PullUpDownView::GetInstance()->GetDateAndWeekLabel()->SetText(dateAndweek.c_str()); + UILabel *batLabel = PullUpDownView::GetInstance()->GetBatteryPercentLabel(); + if (batLabel != nullptr) + { + std::string percentStr = std::to_string(static_cast(value)) + "%"; + batLabel->SetText(percentStr.c_str()); + } } // 释放动态分配的内存 diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/PullUpDownView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/PullUpDownView.cpp index 6162ebeac..1f375489d 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/PullUpDownView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/main/src/PullUpDownView.cpp @@ -272,13 +272,15 @@ namespace OHOS group1->SetStyle(STYLE_BACKGROUND_OPA, 0); group[DROPDOWNVIEW]->Add(group1); /* ----------------------------------- 电池 ----------------------------------- */ + const int BATTERY_LEFT_OFFSET = 30; /* 电池图标整体左移 */ + int batteryAreaWidth = 48; /* 图标+间距+电量文本 */ batteryimage = new UIImageView(); if (batteryimage == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryimage new fail"); return; } - batteryimage->SetPosition((group1->GetWidth() - 48) / 2, (group1->GetHeight() - 30) / 2, 48, 30); + batteryimage->SetPosition((group1->GetWidth() - batteryAreaWidth) / 2 - BATTERY_LEFT_OFFSET, (group1->GetHeight() - 30) / 2, 48, 30); std::string batteryimagesPath = "/user/res/Battery/Battery_White.bin"; batteryimage->SetSrc(batteryimagesPath.c_str()); group1->Add(batteryimage); @@ -313,6 +315,22 @@ namespace OHOS chargeBatteryicon->SetResizeMode(UIImageView::CONTAIN); chargeBatteryicon->SetVisible(false); group1->Add(chargeBatteryicon); + /* ----------------------------------- 电量百分比文本 ----------------------------------- */ + batteryPercentLabel = new UILabel(); + if (batteryPercentLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "batteryPercentLabel new fail"); + return; + } + batteryPercentLabel->SetPosition(batteryimage->GetX() + 48 + 8, (group1->GetHeight() - 28) / 2, 50, 28); + batteryPercentLabel->SetStyle(STYLE_TEXT_FONT, 24); + batteryPercentLabel->SetStyle(STYLE_LINE_HEIGHT, 28); + batteryPercentLabel->SetTextColor(Color::White()); + batteryPercentLabel->SetText("0%"); + batteryPercentLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + batteryPercentLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + batteryPercentLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 26); + group1->Add(batteryPercentLabel); /* --------------------------------- 显示日期和星期 -------------------------------- */ showDateAndWeekLabel = new UILabel(); if (showDateAndWeekLabel == nullptr) @@ -353,6 +371,11 @@ namespace OHOS delete chargeBatteryicon; chargeBatteryicon = nullptr; } + if (batteryPercentLabel != nullptr) + { + delete batteryPercentLabel; + batteryPercentLabel = nullptr; + } delete group1; group1 = nullptr; } @@ -415,6 +438,11 @@ namespace OHOS { return showDateAndWeekLabel; } + + UILabel *PullUpDownView::GetBatteryPercentLabel(void) + { + return batteryPercentLabel; + } /* -------------------------------------------------------------------------- */ AppGroupView *PullUpDownView::DropDownCardPage1Init(void) { -- 2.17.1