From 64236e670dad0963e40f92c21912a3c9576edb59 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 28 Nov 2024 10:37:33 +0800 Subject: [PATCH] =?utf8?q?=E4=BC=98=E5=8C=96=E7=A7=92=E8=A1=A8=EF=BC=9A?= =?utf8?q?=E4=BF=AE=E5=A4=8D=E4=BA=86=E7=A7=92=E8=A1=A8=E5=AE=9A=E6=97=B6?= =?utf8?q?=E5=99=A8=E5=B7=B2=E5=88=B0=E8=BE=BE=E6=9C=80=E9=AB=98=E6=97=B6?= =?utf8?q?=E9=97=B4=E4=BD=86=E6=98=BE=E7=A4=BA=E6=97=B6=E9=97=B4=E7=9A=84?= =?utf8?q?=E6=A0=87=E7=AD=BE=E6=9C=AA=E5=90=8C=E6=AD=A5=E6=9B=B4=E6=96=B0b?= =?utf8?q?ug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../stopwatch/include/StopWatchModel.h | 4 ++-- .../stopwatch/src/MainStopWatchPresenter.cpp | 21 ++++++++++++------- .../nativeui/stopwatch/src/StopWatchModel.cpp | 11 ++++++---- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h index 228a8ca30..b2d2a770c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-04 15:13:51 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-30 11:47:14 + * @LastEditTime: 2024-11-27 17:45:02 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h */ #ifndef STOP_WATCH_MODEL_H @@ -20,7 +20,7 @@ namespace OHOS public: static std::shared_ptr GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存 ~StopWatchModel() {} - char *DisplayStopWatchDuration(); + std::string DisplayStopWatchDuration(); void StopWatch_StartTimer(uint32_t interval); void StopWatch_StopTimer(void); void StopWatch_PauseTimer(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp index 998137d93..229cc5178 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -85,10 +85,12 @@ namespace OHOS /// @param LineHeight void MainStopWatchPresenter::SetShowTimeLableStyle(UILabel *label, int x, int y, int TextFont, int LineHeight) { - label->SetPosition(x, y); + label->SetPosition(x, y,466,LineHeight); label->SetStyle(STYLE_TEXT_FONT, TextFont); label->SetStyle(STYLE_LINE_HEIGHT, LineHeight); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, TextFont); + label->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label->Invalidate(); } @@ -258,11 +260,16 @@ namespace OHOS if (m_listdata != nullptr) { - for (int i = 0; i < m_listdata->Size(); i++) + // 遍历列表,释放每个元素所占用的内存 + ListNode *node = m_listdata->Head(); + int cnt = 0; + while (node!= m_listdata->End()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", i); - char *p = (char *)(m_listdata->Tail()->data_); - free(p); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d",++cnt); + const char *p = node->data_; + free(const_cast(p)); + + node = m_listdata->Remove(node); } m_listdata->Clear(); } @@ -333,9 +340,9 @@ namespace OHOS { if (view_->GetScrollView(MAIN_STOPWATCH) && view_->GetScrollView(MAIN_STOPWATCH)->IsVisible()) { - if (view_->GetPlayOrPausecheckBox() && view_->GetPlayOrPausecheckBox() && TimerIsRunning) + if (TimerIsRunning) { - view_->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration()); + view_->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration().c_str()); view_->GetShowTimelabel()->Invalidate(); } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp index fa746c248..ff9d68503 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp @@ -18,19 +18,19 @@ namespace OHOS /* ----------------------------------- 定时器 ---------------------------------- */ // 声明定时器变量 static osTimerId_t g_timer = nullptr; - static int g_StopWatchTimes = {0}; + static uint32_t g_StopWatchTimes = {0}; static constexpr int32 NUM_TEN = 10; // 主要用于格式化输出,当小时、分钟或秒小于10时,在其前面添加一个’0’以保持常规时间格式 static constexpr int16 ERROR = 0; static constexpr int16 SUCCESS = 1; static constexpr int16 NUM_TIME_MIN = 60; static constexpr int16 NUM_TIME_HOUR = 3600; static constexpr int32 NUM_TIME_DAY = 86400; - static constexpr int32 MAX_STOPWATCH_TIME = (99 * 60 * 1000) + (59 * 1000) + 990; // 99分59秒990毫秒 + static constexpr uint32_t MAX_STOPWATCH_TIME = (99 * 60 * 1000) + (59 * 1000) + 990; // 99分59秒990毫秒 static uint64_t g_timerStartTimestamp = 0; // 添加一个全局变量来存储定时器开始的时间戳 /* * @brief 显示倒计时(分钟、秒、毫秒),毫秒显示为两位数 */ - char *StopWatchModel::DisplayStopWatchDuration() + std::string StopWatchModel::DisplayStopWatchDuration() { stopwatchDuration.erase(); std::string minute; @@ -73,7 +73,7 @@ namespace OHOS // 拼接分钟、秒和毫秒 stopwatchDuration = minute + ":" + seconds + "." + milliseconds; - return (char *)stopwatchDuration.c_str(); + return stopwatchDuration.c_str(); } // 检查是否达到最大记录时间 @@ -94,6 +94,9 @@ namespace OHOS } MainStopWatchView::GetInstance()->GetPlayOrPausecheckBox()->SetState(UICheckBox::UNSELECTED); MainStopWatchView::GetInstance()->ChangeRecordTimeToLimitView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "已到达记录最高时间:%d",g_StopWatchTimes); + g_StopWatchTimes = MAX_STOPWATCH_TIME; + MainStopWatchView::GetInstance()->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration().c_str()); uapi_set_screen_on_api(); } -- 2.17.1