From 37aa8c8e362b96383779777ec7d1c2ebf76e17db Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Tue, 9 Apr 2024 20:28:39 +0800 Subject: [PATCH] =?utf8?q?=E8=A7=A3=E5=86=B3=E7=A7=92=E8=A1=A8=E8=A7=86?= =?utf8?q?=E5=9B=BE=E5=88=B0=E8=BE=BE=E6=9C=80=E9=AB=98=E8=AE=B0=E5=BD=95?= =?utf8?q?=E6=97=B6=E9=97=B4=E6=9C=AA=E5=87=BA=E7=8E=B0=E5=BC=B9=E7=AA=97?= =?utf8?q?=E8=A7=86=E5=9B=BE=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../stopwatch/include/MainStopWatchView.h | 4 ++- .../stopwatch/src/MainStopWatchView.cpp | 11 ++++++ .../nativeui/stopwatch/src/StopWatchModel.cpp | 35 +++++++------------ 3 files changed, 27 insertions(+), 23 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h index e65e9b7ad..d4b9f0a60 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-04 15:13:51 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-07 10:04:54 + * @LastEditTime: 2024-04-09 20:22:12 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h */ #ifndef MAIN_STOPWATCH_VIEW_H @@ -54,6 +54,8 @@ namespace OHOS bool ChangeStopWatchRecordCycleLimit(int16_t thisView); bool ChangeMainStopWatchRecordTimeLimit(int16_t thisView); UILabelExt *GetShowTimelabel(void); + UICheckBox *GetPlayOrPausecheckBox(void); + void ChangeRecordTimeToLimitView(void); private: void InitMainStopWatchView(void); void ClearAll(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp index abfe10889..b2d8ba4b6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -358,6 +358,17 @@ namespace OHOS return showTimelabel; } + UICheckBox *MainStopWatchView::GetPlayOrPausecheckBox(void) + { + return PlayOrPausecheckBox; + } + + /*切换到记录时间到达上线视图*/ + void MainStopWatchView::ChangeRecordTimeToLimitView(void) + { + ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); + } + void MainStopWatchView::OnStart() { View::OnStart(); 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 0a387957f..3b64f189e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp @@ -19,13 +19,14 @@ namespace OHOS // 声明定时器变量 static osTimerId_t g_timer = NULL; static int g_StopWatchTimes = {0}; - static constexpr int32 NUM_TEN = 10; + 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 uint64_t g_timerStartTimestamp = 0; // 添加一个全局变量来存储定时器开始的时间戳 + static constexpr int32 MAX_NUM_TIME = (99 * 60 * 1000) + (59 * 1000) + 990; // 99分59秒990毫秒 + static uint64_t g_timerStartTimestamp = 0; // 添加一个全局变量来存储定时器开始的时间戳 /* * @brief 显示倒计时(分钟、秒、毫秒),毫秒显示为两位数 */ @@ -101,7 +102,15 @@ namespace OHOS return; } - MainStopWatchView::GetInstance()->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration()); + if ((g_StopWatchTimes) >= MAX_NUM_TIME) // 5999990 = 99分59秒99的毫秒数 + { + MainStopWatchView::GetInstance()->GetPlayOrPausecheckBox()->SetState(UICheckBox::UNSELECTED); + MainStopWatchView::GetInstance()->ChangeRecordTimeToLimitView(); + } + else + { + MainStopWatchView::GetInstance()->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration()); + } } /* @@ -109,24 +118,6 @@ namespace OHOS */ static void StopWatch_TimerCallback(int data) { -#if 0 - uint64_t currentTimestamp = GetCurrentTimestamp(); - if ((currentTimestamp - g_timerStartTimestamp) >= 5999990) // 99分59秒99的毫秒数 - { - if (g_timer != NULL) - { - osTimerStop(g_timer); // 停止定时器 - osTimerDelete(g_timer); // 删除定时器 - g_timer = NULL; - g_timerStartTimestamp = 0; // 重置时间戳 - // 可以在这里添加额外的逻辑,比如更新界面显示等 - } - } - else - { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); - } -#endif GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); } @@ -156,7 +147,7 @@ namespace OHOS int tick = osMs2Tick(interval); /* --------------------------------- 4.启动定时器 -------------------------------- */ - //g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 + // g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 osStatus_t ret = osTimerStart(g_timer, tick); /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ if (ret != osOK) -- 2.17.1