From: Caisking <3449750381@qq.com> Date: Tue, 3 Sep 2024 02:05:07 +0000 (+0800) Subject: 修复睡眠进度条显示异常 X-Git-Tag: release_V1.2.70_20241020_135402~540^2~1 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=58f1fc920d63459431b6e25df7317cb625e3230e;p=mirrors%2FFD230.git 修复睡眠进度条显示异常 --- 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) {