From 58f1fc920d63459431b6e25df7317cb625e3230e Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Tue, 3 Sep 2024 10:05:07 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E5=A4=8D=E7=9D=A1=E7=9C=A0=E8=BF=9B?= =?utf8?q?=E5=BA=A6=E6=9D=A1=E6=98=BE=E7=A4=BA=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../fd230app/nativeui/sleep/src/SleepView.cpp | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp index 68270ce63..1256ec558 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/sleep/src/SleepView.cpp @@ -36,33 +36,39 @@ namespace OHOS int total_sleep = sleepModel.get_sleep_total(); int sleep_goal = sleepModel.get_sleep_goal(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepDataRefresh %d %d sleep_goal:%d total_sleep:%d", sleep_hour, sleep_min, sleep_goal, total_sleep); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SleepDataRefresh %d %d sleep_goal:%d total_sleep:%d", sleep_hour, sleep_min, sleep_goal * 60, total_sleep); // 补零操作 std::string hour_str = (sleep_hour < 10) ? "0" + std::to_string(sleep_hour) : std::to_string(sleep_hour); std::string min_str = (sleep_min < 10) ? "0" + std::to_string(sleep_min) : std::to_string(sleep_min); - // 有数据则刷新 + // 有数据才刷新 if (sleep_hour != 0 || sleep_min != 0) { - if (time_hour != nullptr && time_minute != nullptr) + // 更新时间显示 + if (time_hour != nullptr) { time_hour->SetText(hour_str.c_str()); + } + if (time_minute != nullptr) + { time_minute->SetText(min_str.c_str()); } // 计算进度百分比,确保目标睡眠时间不为零 - float value = 0.0f; + float progress_value = 0.0f; if (sleep_goal > 0) { - value = static_cast(total_sleep) / sleep_goal; // 计算进度 - // value = std::clamp(value, 0.0f, 1.0f); // 确保在 0 到 1 之间 + progress_value = static_cast(total_sleep) / (sleep_goal * 60); // 计算进度 } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Progress value: %.2f%%", value * 100); // 显示为百分比 - circleProgress_->SetValue(value); + + // 日志输出进度百分比 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Progress value: %.2f%%", progress_value * 100); // 显示为百分比 + + // 更新进度条 + circleProgress_->SetValue(progress_value * 100); // 更新进度条值,范围为 0 到 100 circleProgress_->SetCapType(CAP_ROUND); } - // 更新目标时间 if (goaltime != nullptr) { -- 2.17.1