From bb47003b9192d8a3a2c8789c5ce86a0ab11a5e7b Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 30 Oct 2024 16:24:48 +0800 Subject: [PATCH] =?utf8?q?=E7=A7=92=E8=A1=A8=E7=95=8C=E9=9D=A2=E4=BC=98?= =?utf8?q?=E5=8C=96=EF=BC=8C=E9=87=87=E7=94=A8=EF=BC=8C=E5=AE=9A=E6=97=B6?= =?utf8?q?=E5=99=A8=E9=87=8C=E6=9B=B4=E6=96=B0=E5=8F=98=E9=87=8F=EF=BC=8CN?= =?utf8?q?otify=E4=B8=AD=E6=9B=B4=E6=96=B0=E6=98=BE=E7=A4=BA=EF=BC=8C?= =?utf8?q?=E5=87=8F=E5=B0=91=E8=AF=AF=E5=B7=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/MainStopWatchPresenter.h | 8 +++-- .../stopwatch/include/MainStopWatchView.h | 3 +- .../stopwatch/include/StopWatchModel.h | 3 +- .../stopwatch/src/MainStopWatchPresenter.cpp | 35 +++++++++++++++++-- .../stopwatch/src/MainStopWatchView.cpp | 9 +++++ .../nativeui/stopwatch/src/StopWatchModel.cpp | 32 +++++++++-------- .../src/StopWatchRecordCycleToLimitView.cpp | 9 ++++- .../src/StopWatchRecordTimeToLimitView.cpp | 8 +++++ 8 files changed, 85 insertions(+), 22 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 01c4560ef..1152b15bd 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-10-12 16:05:30 + * @LastEditTime: 2024-10-30 14:51:08 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchPresenter.h */ #ifndef MAIN_STOPWATCH_PRESENTER_H @@ -13,6 +13,7 @@ #include "MainStopWatchView.h" #include #include "ui_resource_string.h" +#include "ModelListenerSample.h" /*秒表主视图*/ namespace OHOS { @@ -31,7 +32,8 @@ namespace OHOS public UIView::OnClickListener, public UIView::OnDragListener, public RootView::OnKeyActListener, - public UICheckBox::OnChangeListener + public UICheckBox::OnChangeListener, + public ModelListenerSample { public: MainStopWatchPresenter(); @@ -54,6 +56,7 @@ namespace OHOS bool OnDragEnd(UIView &view, const DragEvent &event) override; bool OnChange(UICheckBox::UICheckBoxState state) override; bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + void Notify() override; private: UICheckBox *m_checkbox{nullptr}; UIButton *m_button{nullptr}; @@ -67,6 +70,7 @@ namespace OHOS int RecordCycleNumber{0}; // 用来记录计时圈数 bool X_DRAG_FLAG{false}; bool isStartMark{false}; + bool TimerIsRunning{false}; }; } // namespace OHOS 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 d4b9f0a60..ccae6dbf0 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-09 20:22:12 + * @LastEditTime: 2024-10-30 14:28:49 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/MainStopWatchView.h */ #ifndef MAIN_STOPWATCH_VIEW_H @@ -56,6 +56,7 @@ namespace OHOS UILabelExt *GetShowTimelabel(void); UICheckBox *GetPlayOrPausecheckBox(void); void ChangeRecordTimeToLimitView(void); + UIScrollView *GetScrollView(int16_t index); private: void InitMainStopWatchView(void); void ClearAll(void); 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 2eb3ba26f..228a8ca30 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-04-07 10:35:43 + * @LastEditTime: 2024-10-30 11:47:14 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/stopwatch/include/StopWatchModel.h */ #ifndef STOP_WATCH_MODEL_H @@ -25,6 +25,7 @@ namespace OHOS void StopWatch_StopTimer(void); void StopWatch_PauseTimer(); void StopWatch_ResumeTimer(uint32_t interval); + bool isReachMaxRecordTime(void); private: 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 97a5d9ca9..db51cfc72 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -121,7 +121,18 @@ namespace OHOS UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainStopWatchPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + if (&view == view_->GetScrollView(MAIN_STOPWATCH)) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + else if(&view == view_->GetScrollView(STOPWATCH_RECORD_CYCLE_TO_LIMIT)) + { + view_->ChangeView(STOPWATCH_RECORD_CYCLE_TO_LIMIT, MAIN_STOPWATCH); + } + else if(&view == view_->GetScrollView(STOPWATCH_RECORD_TIME_TO_LIMIT)) + { + view_->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); + } X_DRAG_FLAG = false; } return true; @@ -270,12 +281,19 @@ namespace OHOS { mainStopWatchView->ChangeView(STOPWATCH_RECORD_TIME_TO_LIMIT, MAIN_STOPWATCH); } + else if (strcmp(clickedViewId, PlayOrPausecheckBoxVIEWID) == 0) // 点击播放和暂停按钮 + { + if (StopWatchModel::GetInstance()->isReachMaxRecordTime()) // 到达最大时间不能再计时 + { + mainStopWatchView->ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); + } + } return true; } bool MainStopWatchPresenter::OnChange(UICheckBox::UICheckBoxState state) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnChange"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainStopWatchPresenter::OnChange,state = %d",state); if (state == UICheckBox::UICheckBoxState::SELECTED) { StopWatchModel::GetInstance()->StopWatch_StartTimer(STOPWATCH_TIMER_DURATION); // 开启定时器,如果定时器存在会直接返回 @@ -284,6 +302,7 @@ namespace OHOS m_button->SetViewId(ResetOrMarkButton_MARK_VIEWID); m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, ResetOrMarkButtonImg_Mark); m_button->Invalidate(); // 图片重新赋值要刷新该区域 + TimerIsRunning = true; } else { @@ -291,6 +310,7 @@ namespace OHOS m_button->SetViewId(ResetOrMarkButton_RESET2_VIEWID); m_button->SetImageSrc(ResetOrMarkButtonImg_Reset2, ResetOrMarkButtonImg_Reset2); m_button->Invalidate(); + TimerIsRunning = false; } return true; } @@ -309,4 +329,15 @@ namespace OHOS return false; } + void MainStopWatchPresenter::Notify() + { + if (view_->GetScrollView(MAIN_STOPWATCH) && view_->GetScrollView(MAIN_STOPWATCH)->IsVisible()) + { + if (view_->GetPlayOrPausecheckBox() && view_->GetPlayOrPausecheckBox() && TimerIsRunning) + { + view_->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration()); + view_->GetShowTimelabel()->Invalidate(); + } + } + } } \ No newline at end of file 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 0e117fb00..7811e2960 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -250,6 +250,9 @@ namespace OHOS } scrollView[MAIN_STOPWATCH]->SetPosition(0, 0, 466, 466); scrollView[MAIN_STOPWATCH]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView[MAIN_STOPWATCH]->SetTouchable(true); + scrollView[MAIN_STOPWATCH]->SetDraggable(true); + scrollView[MAIN_STOPWATCH]->SetOnDragListener(presenter_); /* ----------------------------- stopWatchlabel ----------------------------- */ stopWatchlabel = new UILabelExt(); if (stopWatchlabel == nullptr) @@ -364,6 +367,7 @@ namespace OHOS // Add the CallBack about events UICheckBox::OnChangeListener *PlayOrPausecheckBoxChangeListener = static_cast(MainStopWatchPresenter::GetInstance()); PlayOrPausecheckBox->SetOnChangeListener(PlayOrPausecheckBoxChangeListener); + PlayOrPausecheckBox->SetOnClickListener(presenter_); UIView::OnClickListener *ResetOrMarkbuttonClick = static_cast(MainStopWatchPresenter::GetInstance()); ResetOrMarkbutton->SetOnClickListener(ResetOrMarkbuttonClick); } @@ -385,6 +389,11 @@ namespace OHOS ChangeView(MAIN_STOPWATCH, STOPWATCH_RECORD_TIME_TO_LIMIT); } + UIScrollView *MainStopWatchView::GetScrollView(int16_t index) + { + return scrollView[index]; + } + 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 b37b7f66e..fa746c248 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchModel.cpp @@ -76,26 +76,25 @@ namespace OHOS return (char *)stopwatchDuration.c_str(); } - /* - * @brief 在这里添加定时器到期后的处理逻辑 - */ - static void StopWatch_TimerCallbackProc(int data) + // 检查是否达到最大记录时间 + bool StopWatchModel::isReachMaxRecordTime(void) { - if (MainStopWatchView::GetInstance() == nullptr || MainStopWatchView::GetInstance()->GetShowTimelabel() == nullptr || StopWatchModel::GetInstance()->DisplayStopWatchDuration() == nullptr) + if (g_StopWatchTimes >= MAX_STOPWATCH_TIME) { - return; + return true; } + return false; + } - if ((g_StopWatchTimes) >= MAX_STOPWATCH_TIME) // 达到最大时间 - - { - MainStopWatchView::GetInstance()->GetPlayOrPausecheckBox()->SetState(UICheckBox::UNSELECTED); - MainStopWatchView::GetInstance()->ChangeRecordTimeToLimitView(); - } - else + static void StopWatch_TimerCallbackProc(int data) + { + if (MainStopWatchView::GetInstance() == nullptr) { - MainStopWatchView::GetInstance()->GetShowTimelabel()->SetText(StopWatchModel::GetInstance()->DisplayStopWatchDuration()); + return; } + MainStopWatchView::GetInstance()->GetPlayOrPausecheckBox()->SetState(UICheckBox::UNSELECTED); + MainStopWatchView::GetInstance()->ChangeRecordTimeToLimitView(); + uapi_set_screen_on_api(); } /* @@ -104,7 +103,10 @@ namespace OHOS static void StopWatch_TimerCallback(int data) { g_StopWatchTimes += 10; // 每次回调增加10毫秒 - GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); + if(StopWatchModel::GetInstance()->isReachMaxRecordTime()) //达到最大时间 + { + GraphicService::GetInstance()->PostGraphicEvent(std::bind(StopWatch_TimerCallbackProc, data)); + } } /* diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp index 276d7f90c..879ddac78 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp @@ -31,9 +31,16 @@ namespace OHOS if (scrollView == nullptr) { scrollView = new UIScrollView(); - scrollView->SetPosition(0, 0, 466, 466); scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + UIView::OnDragListener *draglistener = static_cast(MainStopWatchPresenter::GetInstance()); + if (draglistener == nullptr) + { + return nullptr; + } + scrollView->SetOnDragListener(draglistener); /* -------------------------------------------------------------------------- */ if (Title == nullptr) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp index 8df7a038a..5173de461 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp @@ -34,6 +34,14 @@ namespace OHOS scrollView = new UIScrollView(); scrollView->SetPosition(0, 0, 466, 466); scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetTouchable(true); + scrollView->SetDraggable(true); + UIView::OnDragListener *draglistener = static_cast(MainStopWatchPresenter::GetInstance()); + if (draglistener == nullptr) + { + return nullptr; + } + scrollView->SetOnDragListener(draglistener); /* -------------------------------------------------------------------------- */ if (Title == nullptr) { -- 2.17.1