From: Caisking Date: Fri, 27 Jun 2025 07:30:49 +0000 (+0800) Subject: 修复aod表盘的显示问题 X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~210^2~39 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=07b7c4942f8a7a5ee3eec8ea3f47a4dbc0c7a36d;p=mirrors%2FFD230.git 修复aod表盘的显示问题 --- diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp index 0a64ad021..9f5fdd285 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/clock/src/AmbientClockView.cpp @@ -15,6 +15,7 @@ #include "ui_resource_image.h" #include #include +#include "custom_runtime.h" namespace OHOS { static constexpr uint16_t POINT_POSITION_X = 202; static constexpr uint16_t POINT_POSITION_Y = 16; @@ -182,8 +183,8 @@ bool AmbientClockView::InitView(void) if (timerlabel == nullptr) { timerlabel = new UILabel(); } - timerlabel->SetPosition(58, 108); // widget's left position and top position - timerlabel->Resize(350, 250); // widget's width and height + timerlabel->SetPosition(33, 108); // widget's left position and top position + timerlabel->Resize(400, 250); // widget's width and height timerlabel->SetViewId("label1");// Set style timerlabel->SetStyle(STYLE_TEXT_FONT, 130); @@ -213,30 +214,25 @@ void AmbientClockView::InitDateTime(void) void AmbientClockView::UpdateTime(void) { - struct timeval tv; - gettimeofday(&tv, nullptr); - uint64_t second = tv.tv_sec; - uint64_t uSecond = tv.tv_usec; - uint64_t minute = second / MIN_TO_HOUR; - uint64_t hour = minute / MIN_TO_HOUR + timezone / (MIN_TO_HOUR * MIN_TO_HOUR); - uint8_t realHour = static_cast(hour % HOURLY_SYSTEM); - uint8_t realMinute = static_cast(minute % MIN_TO_HOUR); - uint16_t realMilliSecond = static_cast((second % MIN_TO_HOUR) * - SEC_TO_MILLI + uSecond / USEC_TO_MILLI); - - // if (timerlabel != nullptr) { - // std::stringstream ss; - // ss.fill('0'); - - // ss << std::setw(2) << realHour << ":"; - // ss << std::setw(2) << realMinute; - - // timerlabel->SetText(ss.str().c_str()); - // } - if(timerlabel == nullptr) - return; - - timerlabel->SetText((std::to_string(realHour) + ":" + std::to_string(realMinute)).c_str()); + /*获取时间*/ + struct timeval tv; + struct tm tblock_; + gettimeofday(&tv, NULL); // 获取当前时间 + localtime_r(&tv.tv_sec, &tblock_); + + std::ostringstream oss; + + //需要判断显示的格式 + if (uapi_dev_runtime_get_time_hour_show_model() == 12) + { + if (tblock_.tm_hour > 12) + tblock_.tm_hour = tblock_.tm_hour - 12 ; + } + + oss << std::setw(2) << std::setfill('0') << tblock_.tm_hour << ":" + << std::setw(2) << std::setfill('0') << tblock_.tm_min; + + timerlabel->SetText(oss.str().c_str()); } }