From 81b07ba9f595fe4cdb9a3bd9b4040fa30341b9ef Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E7=BD=97=E6=AD=A3?= <1732036298@qq.com> Date: Wed, 30 Oct 2024 09:20:58 +0000 Subject: [PATCH] Merge #1295 into sdk602patch0911 from refs/changes/1295/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 罗正 * refs/changes/1295/head: (9 commits squashed) - #1109,解决,闹钟,点击编辑区域需要优化bug - 修改音乐存储大小最多为53M - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - #1078,解决,闹钟是关闭状态,还会响起闹铃bug - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 - 1.关机动画开始后关闭翻腕息屏,防止息屏后关机动画不执行 2.关机动画启动禁止一切弹窗,通过设置Slice优先级为最高级实现 - 秒表界面优化 - 秒表界面优化,采用,定时器里更新变量,Notify中更新显示,减少误差 - Merge branch 'sdk602patch0911' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0911 Signed-off-by: 罗正 <1732036298@qq.com> Reviewed-by: Caisking <3449750381@qq.com> Reviewed-by: 罗正 <1732036298@qq.com> Reviewed-by: aliyun8003852482 <1224667075@qq.com> Reviewed-by: snickersun@163.com Reviewed-by: aliyun6865282430 <1624952103@qq.com> Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/1295 --- .../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 fda687ad9..1ddf56cec 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