From 3d8fa2c8a1a5e0eb723ef81830689a75f8109f39 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 12 Oct 2024 17:06:22 +0800 Subject: [PATCH] =?utf8?q?#969,=E8=A7=A3=E5=86=B3=EF=BC=8C=E9=9F=A9?= =?utf8?q?=E8=AF=AD=EF=BC=8C=E7=A7=92=E8=A1=A8=E8=AE=A1=E6=97=B6=E7=95=8C?= =?utf8?q?=E9=9D=A2=E6=9C=89=E9=81=AE=E6=8C=A1bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/MainStopWatchPresenter.h | 3 +- .../stopwatch/src/MainStopWatchPresenter.cpp | 38 +++++++++------ .../stopwatch/src/MainStopWatchView.cpp | 6 +-- .../nativeui/stopwatch/src/StopWatchModel.cpp | 46 +++++++------------ 4 files changed, 46 insertions(+), 47 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h index dc906baa6..01c4560ef 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-04 15:13:51 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-20 11:25:11 + * @LastEditTime: 2024-10-12 16:05:30 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h */ #ifndef MAIN_STOPWATCH_PRESENTER_H @@ -66,6 +66,7 @@ namespace OHOS uint64_t lastRecordTime = 0; // 上次记录时间 int RecordCycleNumber{0}; // 用来记录计时圈数 bool X_DRAG_FLAG{false}; + bool isStartMark{false}; }; } // namespace OHOS 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 b950eec17..97a5d9ca9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -88,7 +88,7 @@ namespace OHOS label->SetPosition(x, y); label->SetStyle(STYLE_TEXT_FONT, TextFont); label->SetStyle(STYLE_LINE_HEIGHT, LineHeight); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, TextFont); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, TextFont); label->Invalidate(); } @@ -171,7 +171,7 @@ namespace OHOS UNUSED(view); MainStopWatchView *mainStopWatchView = MainStopWatchView::GetInstance(); const char *clickedViewId = view.GetViewId(); - if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0) + if (strcmp(clickedViewId, ResetOrMarkButton_MARK_VIEWID) == 0) // 点击标记按钮 { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RecordCycleNumber:%d\n", RecordCycleNumber); if (RecordCycleNumber >= MAX_RECORD_LOOPS) // 到达最高记录圈数 @@ -184,10 +184,16 @@ namespace OHOS { RecordCycleNumber += 1; } - mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); - SetShowTimeLableStyle(m_showTimelabel, 93, 60, 65, 78); - mainStopWatchView->SetViewIsVisible(m_list, true); - mainStopWatchView->SetViewIsVisible(m_image, true); + + if (isStartMark == false) // 第一次标记 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, false); + SetShowTimeLableStyle(m_showTimelabel, 0, 60, 65, 78); + mainStopWatchView->SetViewIsVisible(m_list, true); + mainStopWatchView->SetViewIsVisible(m_image, true); + isStartMark = true; + } uint64_t currentRecordTime = TimeStrToMilliseconds(MainStopWatchView::GetInstance()->GetShowTimelabel()->GetText()); // 获取当前时间 uint64_t timeDifference = 0; // 时间差值 @@ -219,7 +225,7 @@ namespace OHOS lastRecordTime = currentRecordTime; return true; } - else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0) + else if (strcmp(clickedViewId, ResetOrMarkButton_RESET2_VIEWID) == 0) // 点击重置按钮 { StopWatchModel::GetInstance()->StopWatch_StopTimer(); // 停止定时器 mainStopWatchView->GetShowTimelabel()->SetText("00:00.00"); @@ -229,15 +235,21 @@ namespace OHOS m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); m_button->Invalidate(); - mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true); - SetShowTimeLableStyle(m_showTimelabel, 68, 160, 84, 94); - mainStopWatchView->SetViewIsVisible(m_image, false); - mainStopWatchView->SetViewIsVisible(m_list, false); + if (isStartMark == true) // 重置标记 + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "isStartMark = %d", isStartMark); + mainStopWatchView->SetViewIsVisible(m_stopWatchlabel, true); + SetShowTimeLableStyle(m_showTimelabel, 0, 160, 84, 94); + mainStopWatchView->SetViewIsVisible(m_image, false); + mainStopWatchView->SetViewIsVisible(m_list, false); + isStartMark = false; + } if (m_listdata != nullptr) { for (int i = 0; i < m_listdata->Size(); i++) { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", i); char *p = (char *)(m_listdata->Tail()->data_); free(p); } @@ -250,11 +262,11 @@ namespace OHOS } RecordCycleNumber = 0; } - else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0) + else if (strcmp(clickedViewId, CycleToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 { mainStopWatchView->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); } - else if (strcmp(clickedViewId, TimeToLimitReturnButton_VIEWID) == 0) + else if (strcmp(clickedViewId, TimeToLimitReturnButton_VIEWID) == 0) // 点击返回按钮 { mainStopWatchView->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); } 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 fd4848626..89538ec79 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -273,11 +273,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "showTimelabel new fail!!"); return; } - showTimelabel->SetPosition(68, 160); + showTimelabel->SetPosition(0, 160,466, 94); showTimelabel->SetStyle(STYLE_TEXT_FONT, 84); showTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94); showTimelabel->SetText("00:00.00"); - showTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + showTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_CLIP); showTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); showTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 84); /* -------------------------------- LineImage ------------------------------- */ @@ -316,7 +316,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "listadapter new fail!!"); return; } - listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 28); + listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 28); /* -------------------------------- listdata -------------------------------- */ listdata = new List(); if (listdata == nullptr) 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 0bb93fbc9..b37b7f66e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp @@ -17,7 +17,7 @@ namespace OHOS /* ----------------------------------- 定时器 ---------------------------------- */ // 声明定时器变量 - static osTimerId_t g_timer = NULL; + static osTimerId_t g_timer = nullptr; static int g_StopWatchTimes = {0}; static constexpr int32 NUM_TEN = 10; // 主要用于格式化输出,当小时、分钟或秒小于10时,在其前面添加一个’0’以保持常规时间格式 static constexpr int16 ERROR = 0; @@ -25,7 +25,7 @@ namespace OHOS 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_NUM_TIME = (99 * 60 * 1000) + (59 * 1000) + 990; // 99分59秒990毫秒 + static constexpr int32 MAX_STOPWATCH_TIME = (99 * 60 * 1000) + (59 * 1000) + 990; // 99分59秒990毫秒 static uint64_t g_timerStartTimestamp = 0; // 添加一个全局变量来存储定时器开始的时间戳 /* * @brief 显示倒计时(分钟、秒、毫秒),毫秒显示为两位数 @@ -81,28 +81,13 @@ namespace OHOS */ static void StopWatch_TimerCallbackProc(int data) { - g_StopWatchTimes += 10; // 每次回调增加10毫秒 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_StopWatchTimes:%d\n", g_StopWatchTimes); - - if (MainStopWatchView::GetInstance() == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] GetInstance is NULL"); - return; - } - - if (MainStopWatchView::GetInstance()->GetShowTimelabel() == nullptr) + if (MainStopWatchView::GetInstance() == nullptr || MainStopWatchView::GetInstance()->GetShowTimelabel() == nullptr || StopWatchModel::GetInstance()->DisplayStopWatchDuration() == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] GetInstance()->GetShowTimelabel is NULL"); return; } - if (StopWatchModel::GetInstance()->DisplayStopWatchDuration() == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[StopWatch_TimerCallbackProc] DisplayStopWatchDuration is NULL"); - return; - } + if ((g_StopWatchTimes) >= MAX_STOPWATCH_TIME) // 达到最大时间 - if ((g_StopWatchTimes) >= MAX_NUM_TIME) // 5999990 = 99分59秒99的毫秒数 { MainStopWatchView::GetInstance()->GetPlayOrPausecheckBox()->SetState(UICheckBox::UNSELECTED); MainStopWatchView::GetInstance()->ChangeRecordTimeToLimitView(); @@ -118,6 +103,7 @@ namespace OHOS */ static void StopWatch_TimerCallback(int data) { + g_StopWatchTimes += 10; // 每次回调增加10毫秒 GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); } @@ -128,16 +114,16 @@ namespace OHOS void StopWatchModel::StopWatch_StartTimer(uint32_t interval) { /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != NULL) + if (g_timer != nullptr) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StopWatchModel::StopWatch_StartTimer Timer already exists!!"); return; } /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)StopWatch_TimerCallback, osTimerPeriodic, NULL, NULL); + g_timer = osTimerNew((osTimerFunc_t)StopWatch_TimerCallback, osTimerPeriodic, nullptr, nullptr); // 检查定时器创建是否成功 - if (g_timer == NULL) + if (g_timer == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatchModel::StopWatch_StartTimer Timer create failed!!"); return; @@ -149,15 +135,15 @@ namespace OHOS /* --------------------------------- 4.启动定时器 -------------------------------- */ // g_timerStartTimestamp = GetCurrentTimestamp(); // 假设GetCurrentTimestamp()是获取当前时间戳的函数 osStatus_t ret = osTimerStart(g_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 NULL -------------------- */ + /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ if (ret != osOK) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[StopWatch_StartTimer]osTimerDelete failed, ret = %lx!!", ret); - if (g_timer != NULL) + if (g_timer != nullptr) { ret = osTimerDelete(g_timer); } - g_timer = NULL; + g_timer = nullptr; return; } return; @@ -169,16 +155,16 @@ namespace OHOS void StopWatchModel::StopWatch_StopTimer(void) { // 检查定时器是否存在 - if (g_timer != NULL) + if (g_timer != nullptr) { osTimerStop(g_timer); - // 删除定时器并置为 NULL + // 删除定时器并置为 nullptr osStatus_t ret = osTimerDelete(g_timer); if (ret != osOK) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); } - g_timer = NULL; + g_timer = nullptr; g_StopWatchTimes = 0; } } @@ -188,7 +174,7 @@ namespace OHOS void StopWatchModel::StopWatch_PauseTimer(void) { // 检查定时器是否存在 - if (g_timer != NULL) + if (g_timer != nullptr) { // 暂停定时器,但不删除它 osStatus_t ret = osTimerStop(g_timer); @@ -205,7 +191,7 @@ namespace OHOS void StopWatchModel::StopWatch_ResumeTimer(uint32_t interval) { // 检查定时器是否存在 - if (g_timer != NULL) + if (g_timer != nullptr) { int tick = osMs2Tick(interval); // 恢复定时器 -- 2.17.1