From: luozheng <1732036298@qq.com> Date: Fri, 11 Oct 2024 08:51:34 +0000 (+0800) Subject: #29,解决,手表,秒表和计时器退出后台后就会停止,需要支持后台运行(需求) X-Git-Tag: release_V1.2.70_20241020_135402~84 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=ed771982322b06d179dd0c76d01f2c79e173bbec;p=mirrors%2FFD230.git #29,解决,手表,秒表和计时器退出后台后就会停止,需要支持后台运行(需求) --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h index 45220fba0..0642536b5 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-03 18:44:50 + * @LastEditTime: 2024-10-11 16:08:37 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/include/CountDownModel.h */ #ifndef COUNTDOWN_MODEL_H @@ -68,6 +68,14 @@ namespace OHOS public: static CountDownModel *GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存 + bool CountDownTimerIsEnd(); // 计时器是否结束 + bool GetChanageToStartCountDownView(); + void SetChanageToStartCountDownView(bool val); + bool CountDownViewIsExit(); // 计时器界面是否退出 + void HandCountDownEndOperator(void); + bool GetCountDownTimerIsPause(); + void SetCountDownTimerIsPause(bool val); + void SetCountDownTime(const std::string &countdowntime); // 设置倒计时时间 std::string GetCountDownTime(void); // 获取倒计时时间 std::string GetBackupCountDownTime(void); @@ -114,6 +122,8 @@ namespace OHOS std::string RingTime{"00:00:00"}; // 响铃时间 std::string CountTime{"00:00:00"}; // 倒计时时间 std::string CountTimeBackup{"00:00:00"}; + bool IsChanageToStartCountDownViewFlag{false};//是否需要切换到开始倒计时界面标志 + bool CountDownTimerIsPauseFlag{false}; }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownView.h b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownView.h index 0b43fbb59..3d3234fec 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-20 10:48:28 + * @LastEditTime: 2024-10-11 10:08:56 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/include/MainCountDownView.h */ #ifndef MAIN_COUNTDOWN_VIEW_H @@ -46,6 +46,7 @@ namespace OHOS virtual ~MainCountDownView(); static MainCountDownView *GetInstance(void); bool ClickFunc(int16_t interface); + bool CheckViewParam(int16_t hideView, int16_t showView); void ChangeView(int16_t hideView, int16_t showView); bool ChangeMainCountDown(int16_t thisView); bool ChangeTimeConfigCountdown(int16_t thisView); @@ -65,10 +66,9 @@ namespace OHOS StartCountDownView *p_StartCountDownView{nullptr}; private: - void MainCountDownViewInit(void); + UIScrollView * MainCountDownViewInit(void); void ClearAll(void); UILabelButtonExt *SetUILabelButton(int x, int y, int w, int h, const char *id, const char *text,int textId); - UIViewGroup *group = nullptr; UIScrollView *scrollView[COUNTDOWN_MAX_VIEW]{nullptr}; UILabelExt *Title{nullptr}; UILabelExt *QuickStart{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp index 887603109..7518ec048 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-07 18:15:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-28 17:51:27 + * @LastEditTime: 2024-10-11 16:17:52 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/countdown/src/CountDownModel.cpp */ #include "countdown/include/CountDownModel.h" @@ -16,11 +16,13 @@ #include "ui_resource_string.h" #include "custom_runtime.h" #include "uiservice/include/ui_service.h" +#include "AppViewIDs.h" +#include "NativeAbility.h" namespace OHOS { /* -------------------------------------------------------------------------- */ // 声明定时器变量 - static osTimerId_t g_timer = NULL; + static osTimerId_t g_timer = nullptr; int CountDownModel::g_CountDownTimes = {0}; static constexpr int32 NUM_TEN = 10; // 主要用于格式化输出,当小时、分钟或秒小于10时,在其前面添加一个’0’以保持常规时间格式,例如“09:05:03”。 static constexpr int16 NUM_TIME_MIN = 60; @@ -310,7 +312,7 @@ namespace OHOS /*触发铃声的开始*/ void CountDownModel::RequestStartRingtone(void) { - if(uapi_sleep_mode_flag_get()) + if (uapi_sleep_mode_flag_get()) { return; } @@ -326,6 +328,62 @@ namespace OHOS PostRingtoneEvent(&CountDownModel::StopRingtonePlaybackAndReleaseResources); } + // 判断计时器是否结束 + bool CountDownModel::CountDownTimerIsEnd() // 计时器是否结束 + { + if (g_timer == nullptr) + { + return true; + } + return false; + } + //获取是否需要跳转到开始到计时界面 + bool CountDownModel::GetChanageToStartCountDownView() + { + return IsChanageToStartCountDownViewFlag; + } + + //设置是否需要跳转到开始到计时界面 + void CountDownModel::SetChanageToStartCountDownView(bool val) + { + IsChanageToStartCountDownViewFlag = val; + } + + bool CountDownModel::CountDownViewIsExit() // 计时器界面是否退出 + { + MainCountDownView *g_CountDownView = MainCountDownView::GetInstance(); + if (g_CountDownView == nullptr) + { + return true; + } + return false; + } + + //处理倒计时到期时的一些操作 + void CountDownModel::HandCountDownEndOperator(void) + { + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); + if (p_StartCountDownView) + { + CountDown_StopTimer(); // 停止定时器 + ScreenTurnOn(5 * 1000); // 亮屏5s + CountDownModel::GetInstance()->RequestStartRingtone(); // 播放铃声 + + StartCountDownView::GetInstance()->GetPlayOrPauseToggleButton()->SetVisible(false); + p_StartCountDownView->GetRepeatButton()->SetVisible(true); + /*倒计时结束 显示大图标 */ + p_StartCountDownView->ShowEndView(true); + } + } + + bool CountDownModel::GetCountDownTimerIsPause() + { + return CountDownTimerIsPauseFlag; + } + void CountDownModel::SetCountDownTimerIsPause(bool val) + { + CountDownTimerIsPauseFlag = val; + } /* ----------------------------------- 定时器 ---------------------------------- */ /* @@ -359,52 +417,32 @@ namespace OHOS */ static void CountDown_TimerCallbackProc(int data) { - // CountDownModel::g_CountDownTimes--; // 每次回调减少1秒 - // WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_CountDownTimes:%d\n", CountDownModel::g_CountDownTimes); - - if (MainCountDownView::GetInstance() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_TimerCallbackProc] GetInstance is NULL"); - return; - } - - if (MainCountDownView::GetInstance()->GetStartCountDownView()->GetShowCountDownTimelabel() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_TimerCallbackProc] GetShowCountDownTimelabel is NULL"); - return; - } - - if (MainCountDownView::GetInstance()->GetStartCountDownView()->GetPlayOrPauseToggleButton() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_TimerCallbackProc] GetPlayOrPauseToggleButton is NULL"); - return; - } - - if (CountDownModel::GetInstance()->DisplayCountDownDuration() == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CountDown_TimerCallbackProc] DisplayCountDownDuration is NULL"); - return; - } - + StartCountDownView *p_StartCountDownView = StartCountDownView::GetInstance(); // 检查倒计时是否结束 if (CountDownModel::g_CountDownTimes <= 0) { - ScreenTurnOn(5*1000);//亮屏5s - - MainCountDownView::GetInstance()->GetStartCountDownView()->GetPlayOrPauseToggleButton()->SetVisible(false); - MainCountDownView::GetInstance()->GetStartCountDownView()->GetRepeatButton()->SetVisible(true); - CountDownModel::GetInstance()->CountDown_StopTimer(); // 停止定时器 - - /*倒计时结束 显示大图标 */ - MainCountDownView::GetInstance()->GetStartCountDownView()->ShowEndView(true); - - // 进行倒计时结束时的额外操作,播放声音等 - CountDownModel::GetInstance()->RequestStartRingtone(); + if (CountDownModel::GetInstance()->CountDownViewIsExit()) // 如果已经退出了界面定时器还在跑,就先跳转Slice + { + CountDownModel::GetInstance()->CountDown_StopTimer(); // 停止定时器 + CountDownModel::GetInstance()->SetChanageToStartCountDownView(true); + NativeAbility::GetInstance().EnterSlice(VIEW_MAIN_COUNTDOWN); + return; + } + else + { + if (p_StartCountDownView) + { + CountDownModel::GetInstance()->HandCountDownEndOperator(); + } + } } else { - // 更新显示 - MainCountDownView::GetInstance()->GetStartCountDownView()->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); + if (p_StartCountDownView) + { + // 更新显示 + p_StartCountDownView->GetShowCountDownTimelabel()->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); + } } return; @@ -426,16 +464,16 @@ namespace OHOS void CountDownModel::CountDown_StartTimer(uint32_t interval) { /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != NULL) + if (g_timer != nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer already exists!!"); return; } /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)CountDown_TimerCallback, osTimerPeriodic, NULL, NULL); + g_timer = osTimerNew((osTimerFunc_t)CountDown_TimerCallback, osTimerPeriodic, nullptr, nullptr); // 检查定时器创建是否成功 - if (g_timer == NULL) + if (g_timer == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CountDownModel::CountDown_StartTimer Timer create failed!!"); return; @@ -447,15 +485,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, "[CountDown_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; @@ -467,17 +505,18 @@ namespace OHOS void CountDownModel::CountDown_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_CountDownTimes = 0; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop timer success!!"); } } /* @@ -486,7 +525,7 @@ namespace OHOS void CountDownModel::CountDown_PauseTimer(void) { // 检查定时器是否存在 - if (g_timer != NULL) + if (g_timer != nullptr) { // 暂停定时器,但不删除它 osStatus_t ret = osTimerStop(g_timer); @@ -503,7 +542,7 @@ namespace OHOS void CountDownModel::CountDown_ResumeTimer(uint32_t interval) { // 检查定时器是否存在 - if (g_timer != NULL) + if (g_timer != nullptr) { int tick = osMs2Tick(interval); // 恢复定时器 diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp index 037a75f45..134887383 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownPresenter.cpp @@ -28,8 +28,6 @@ namespace OHOS MainCountDownPresenter::~MainCountDownPresenter() { - CountDownModel::GetInstance()->CountDown_StopTimer(); // 清理定时器资源 - CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); // 清理播放器资源 g_pMainCountDownPresenter = nullptr; #ifdef MEM_CHECK MemCheck::GetInstance()->EnableLeakCheck(false); @@ -64,6 +62,7 @@ namespace OHOS { Presenter::OnStop(); // ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消长亮屏 + CountDownModel::GetInstance()->StopRingtonePlaybackAndReleaseResources(); // 清理播放器资源 } bool MainCountDownPresenter::OnDrag(UIView &view, const DragEvent &event) @@ -271,6 +270,7 @@ namespace OHOS switch (state) { case UICheckBox::SELECTED: + p_CountDownModel->SetCountDownTimerIsPause(false); p_CountDownModel->CountDown_StartTimer(COUNTDOWN_TIMER_DURATION); p_CountDownModel->CountDown_ResumeTimer(COUNTDOWN_TIMER_DURATION); /*视图恢复*/ @@ -278,6 +278,7 @@ namespace OHOS p_StartCountDownView->ShowEndView(false); break; case UICheckBox::UNSELECTED: + p_CountDownModel->SetCountDownTimerIsPause(true); p_CountDownModel->CountDown_PauseTimer(); /*进行视图隐藏*/ p_StartCountDownView->SetImageAndLabel(false); diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownView.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownView.cpp index 749f3fcc9..c3f485cd6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/MainCountDownView.cpp @@ -2,6 +2,7 @@ #include "countdown/include/MainCountDownPresenter.h" #include "wearable_log.h" #include "common/image_cache_manager.h" +#include "countdown/include/CountDownModel.h" /*倒计时的主界面*/ namespace OHOS { @@ -18,7 +19,6 @@ namespace OHOS MainCountDownView::~MainCountDownView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownView::~MainCountDownView"); - ClearAll(); g_pMainCountDownView = nullptr; } @@ -29,98 +29,75 @@ namespace OHOS void MainCountDownView::ClearAll() { - group->RemoveAll(); - scrollView[MAIN_COUNTDOWN]->RemoveAll(); - ImageCacheManager::GetInstance().UnloadSingleRes(COUNTDOWM_TIMER_ICON); - - if (Title != nullptr) - { - delete Title; - Title = nullptr; - } - - if (QuickStart != nullptr) - { - delete QuickStart; - QuickStart = nullptr; - } - - if (CUSTOM_COUNTDOWN != nullptr) - { - delete CUSTOM_COUNTDOWN; - CUSTOM_COUNTDOWN = nullptr; - } - - if (COUNTDOWN_ONE_MINUTE_BUTTON != nullptr) - { - delete COUNTDOWN_ONE_MINUTE_BUTTON; - COUNTDOWN_ONE_MINUTE_BUTTON = nullptr; - } - - if (COUNTDOWN_FIVE_MINUTE_BUTTON != nullptr) - { - delete COUNTDOWN_FIVE_MINUTE_BUTTON; - COUNTDOWN_FIVE_MINUTE_BUTTON = nullptr; - } - - if (COUNTDOWN_TEN_MINUTE_BUTTON != nullptr) - { - delete COUNTDOWN_TEN_MINUTE_BUTTON; - COUNTDOWN_TEN_MINUTE_BUTTON = nullptr; - } - - if (COUNTDOWN_THIRTY_MINUTE_BUTTON != nullptr) + if (scrollView[MAIN_COUNTDOWN] != nullptr) { - delete COUNTDOWN_THIRTY_MINUTE_BUTTON; - COUNTDOWN_THIRTY_MINUTE_BUTTON = nullptr; + scrollView[MAIN_COUNTDOWN]->RemoveAll(); + if (Title != nullptr) + { + delete Title; + Title = nullptr; + } + if (QuickStart != nullptr) + { + delete QuickStart; + QuickStart = nullptr; + } + ImageCacheManager::GetInstance().UnloadSingleRes(COUNTDOWM_TIMER_ICON); + if (CUSTOM_COUNTDOWN != nullptr) + { + delete CUSTOM_COUNTDOWN; + CUSTOM_COUNTDOWN = nullptr; + } + if (COUNTDOWN_ONE_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_ONE_MINUTE_BUTTON; + COUNTDOWN_ONE_MINUTE_BUTTON = nullptr; + } + if (COUNTDOWN_FIVE_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_FIVE_MINUTE_BUTTON; + COUNTDOWN_FIVE_MINUTE_BUTTON = nullptr; + } + if (COUNTDOWN_TEN_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_TEN_MINUTE_BUTTON; + COUNTDOWN_TEN_MINUTE_BUTTON = nullptr; + } + if (COUNTDOWN_THIRTY_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_THIRTY_MINUTE_BUTTON; + COUNTDOWN_THIRTY_MINUTE_BUTTON = nullptr; + } + delete scrollView[MAIN_COUNTDOWN]; + scrollView[MAIN_COUNTDOWN] = nullptr; } - if (p_CountDownTimeConfigView != nullptr) { delete p_CountDownTimeConfigView; p_CountDownTimeConfigView = nullptr; } - if (p_CountDownTimeNotNullView != nullptr) { delete p_CountDownTimeNotNullView; p_CountDownTimeNotNullView = nullptr; } - if (p_StartCountDownView != nullptr) { delete p_StartCountDownView; p_StartCountDownView = nullptr; } - - if (scrollView[MAIN_COUNTDOWN] != nullptr) - { - delete scrollView[MAIN_COUNTDOWN]; - scrollView[MAIN_COUNTDOWN] = nullptr; - } - - if (group != nullptr) - { - delete group; - group = nullptr; - } } - void MainCountDownView::MainCountDownViewInit() + UIScrollView *MainCountDownView::MainCountDownViewInit() { - if (group == nullptr) + if (scrollView[MAIN_COUNTDOWN] == nullptr) { - /* ---------------------------------- group --------------------------------- */ - group = new UIViewGroup(); - group->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - group->SetTouchable(true); - group->SetDraggable(true); /* ----------------------- scrollView[MAIN_COUNTDOWN] ----------------------- */ scrollView[MAIN_COUNTDOWN] = new UIScrollView(); if (scrollView[MAIN_COUNTDOWN] == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView[MAIN_COUNTDOWN] is new fail!!"); - return; + return nullptr; } scrollView[MAIN_COUNTDOWN]->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); scrollView[MAIN_COUNTDOWN]->SetStyle(STYLE_BACKGROUND_OPA, 0xff); @@ -129,7 +106,7 @@ namespace OHOS if (draglistener == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "draglistener is nullptr!!"); - return; + return nullptr; } scrollView[MAIN_COUNTDOWN]->SetOnDragListener(draglistener); scrollView[MAIN_COUNTDOWN]->SetReboundSize(50); // 设置回弹大小 @@ -146,7 +123,7 @@ namespace OHOS if (Title == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Title is new fail!!"); - return; + return nullptr; } Title->SetPosition(83, 50, 300, 35); Title->SetStyle(STYLE_TEXT_FONT, 30); @@ -161,7 +138,7 @@ namespace OHOS if (CUSTOM_COUNTDOWN == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CUSTOM_COUNTDOWN is new fail!!"); - return; + return nullptr; } CUSTOM_COUNTDOWN->SetPosition(43, 130, 380, 100); CUSTOM_COUNTDOWN->SetViewId(COUNTDOWN_LABELBUTTON_VIEWID); @@ -176,7 +153,7 @@ namespace OHOS if (QuickStart == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QuickStart is new fail!!"); - return; + return nullptr; } QuickStart->SetPosition(83, 270, 300, 35); QuickStart->SetStyle(STYLE_TEXT_FONT, 30); @@ -191,28 +168,28 @@ namespace OHOS if (COUNTDOWN_ONE_MINUTE_BUTTON == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_ONE_MINUTE_BUTTON is new fail!!"); - return; + return nullptr; } /* ---------------------- COUNTDOWN_FIVE_MINUTE_BUTTON ---------------------- */ COUNTDOWN_FIVE_MINUTE_BUTTON = SetUILabelButton(243, 345, 180, 150, COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID, "5分钟", STR_5_MIN); if (COUNTDOWN_FIVE_MINUTE_BUTTON == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_FIVE_MINUTE_BUTTON is new fail!!"); - return; + return nullptr; } /* ----------------------- COUNTDOWN_TEN_MINUTE_BUTTON ---------------------- */ COUNTDOWN_TEN_MINUTE_BUTTON = SetUILabelButton(43, 515, 180, 150, COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID, "10分钟", STR_10_MIN); if (COUNTDOWN_TEN_MINUTE_BUTTON == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_TEN_MINUTE_BUTTON is new fail!!"); - return; + return nullptr; } /* --------------------- COUNTDOWN_THIRTY_MINUTE_BUTTON --------------------- */ COUNTDOWN_THIRTY_MINUTE_BUTTON = SetUILabelButton(243, 515, 180, 150, COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID, "30分钟", STR_30_MIN); if (COUNTDOWN_THIRTY_MINUTE_BUTTON == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "COUNTDOWN_THIRTY_MINUTE_BUTTON is new fail!!"); - return; + return nullptr; } /* -------------------------------------------------------------------------- */ UIView::OnClickListener *ButtonOnClick = static_cast(MainCountDownPresenter::GetInstance()); @@ -221,7 +198,16 @@ namespace OHOS COUNTDOWN_FIVE_MINUTE_BUTTON->SetOnClickListener(ButtonOnClick); COUNTDOWN_TEN_MINUTE_BUTTON->SetOnClickListener(ButtonOnClick); COUNTDOWN_THIRTY_MINUTE_BUTTON->SetOnClickListener(ButtonOnClick); + /* -------------------------------------------------------------------------- */ + scrollView[MAIN_COUNTDOWN]->Add(Title); + scrollView[MAIN_COUNTDOWN]->Add(CUSTOM_COUNTDOWN); + scrollView[MAIN_COUNTDOWN]->Add(QuickStart); + scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_ONE_MINUTE_BUTTON); + scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_FIVE_MINUTE_BUTTON); + scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_TEN_MINUTE_BUTTON); + scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_THIRTY_MINUTE_BUTTON); } + return scrollView[MAIN_COUNTDOWN]; } UILabelButtonExt *MainCountDownView::SetUILabelButton(int x, int y, int w, int h, const char *id, const char *text, int textId) @@ -249,7 +235,7 @@ namespace OHOS return button; } - //获取开始倒计时视图 + // 获取开始倒计时视图 StartCountDownView *MainCountDownView::GetStartCountDownView(void) { return p_StartCountDownView; @@ -258,11 +244,15 @@ namespace OHOS /*1.切换到主倒计时视图*/ bool MainCountDownView::ChangeMainCountDown(int16_t thisView) { - if (scrollView[thisView] == nullptr) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownView::ChangeMainCountDown"); + UIScrollView *view = MainCountDownViewInit(); + if (view == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownView::ChangeMainCountDown"); - group->Add(scrollView[thisView]); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view nullptr fail"); + return false; } + scrollView[thisView] = view; + container_->Add(scrollView[thisView]); return true; } @@ -278,8 +268,14 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCountDownView:: new scrollView[%d] fail", thisView); return false; } - scrollView[thisView] = p_CountDownTimeConfigView->CountDownTimeConfigViewInit(); - group->Add(scrollView[thisView]); + UIScrollView *view = p_CountDownTimeConfigView->CountDownTimeConfigViewInit(); + if (view == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view nullptr fail"); + return false; + } + scrollView[thisView] = view; + container_->Add(scrollView[thisView]); } return true; } @@ -296,12 +292,23 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCountDownView:: new scrollView[%d] fail", thisView); return false; } - scrollView[thisView] = p_StartCountDownView->StartCountDownViewInit(); - group->Add(scrollView[thisView]); + UIScrollView *view = p_StartCountDownView->StartCountDownViewInit(); + if (view == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view nullptr fail"); + return false; + } + scrollView[thisView] = view; + container_->Add(scrollView[thisView]); } if (p_StartCountDownView) { p_StartCountDownView->UpdateimageAndLabelPosition(); + if(CountDownModel::GetInstance()->GetChanageToStartCountDownView() == true) + { + CountDownModel::GetInstance()->SetChanageToStartCountDownView(false); + CountDownModel::GetInstance()->HandCountDownEndOperator(); + } } return true; } @@ -318,8 +325,14 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCountDownView:: new scrollView[%d] fail", thisView); return false; } - scrollView[thisView] = p_CountDownTimeNotNullView->CountDownTimeNotNullViewInit(); - group->Add(scrollView[thisView]); + UIScrollView *view = p_CountDownTimeNotNullView->CountDownTimeNotNullViewInit(); + if (view == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "view nullptr fail"); + return false; + } + scrollView[thisView] = view; + container_->Add(scrollView[thisView]); } return true; } @@ -359,17 +372,43 @@ namespace OHOS return false; } + bool MainCountDownView::CheckViewParam(int16_t hideView, int16_t showView) + { + if (showView < 0 || showView >= COUNTDOWN_MAX) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootView::CheckViewParam showView err."); + return false; + } + + if (hideView < 0 || hideView > COUNTDOWN_MAX) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootView::CheckViewParam hideView err."); + return false; + } + + return true; + } + // 4.切换视图 void MainCountDownView::ChangeView(int16_t hideView, int16_t showView) { - if (hideView > COUNTDOWN_MAX) + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownView::ChangeView %d, %d", hideView, showView); + if (!CheckViewParam(hideView, showView)) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCountDownView:: CountDownViewId Overstep ones bounds"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainCountDownView::CheckViewParam failed."); return; } - scrollView[hideView]->SetVisible(false); + if (hideView != COUNTDOWN_MAX) + { + if (scrollView[hideView] == nullptr) + { + return; + } + scrollView[hideView]->SetVisible(false); + } ClickFunc(showView); scrollView[showView]->SetVisible(true); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainCountDownView:: ChangeView end!!!%d", showView); Draw(); } /* -------------------------------------------------------------------------- */ @@ -377,7 +416,26 @@ namespace OHOS void MainCountDownView::OnStart() { View::OnStart(); - MainCountDownViewInit(); + SetContainerView(new UIViewGroup()); + if (GetContainer() == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail!!"); + return; + } + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetTouchable(true); + container_->SetDraggable(true); + /* -------------------------------------------------------------------------- */ + if (CountDownModel::GetInstance()->CountDownTimerIsEnd() == false || + CountDownModel::GetInstance()->GetChanageToStartCountDownView() == true) + { + ChangeView(COUNTDOWN_MAX, START_COUNTDOWN); // 如果倒计时的timer没有结束或需要跳转到开始倒计时界面,则跳转到开始倒计时界面 + } + else + { + ChangeView(COUNTDOWN_MAX, MAIN_COUNTDOWN); // 如果倒计时的timer已经结束,则跳转到主界面 + } + /* -------------------------------------------------------------------------- */ // 增加按键监听 RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainCountDownPresenter::GetInstance(); RootView::GetInstance()->SetOnKeyActListener(keyactListener); @@ -386,16 +444,6 @@ namespace OHOS void MainCountDownView::OnSetUpView() { View::OnSetUpView(); - scrollView[MAIN_COUNTDOWN]->Add(Title); - scrollView[MAIN_COUNTDOWN]->Add(CUSTOM_COUNTDOWN); - scrollView[MAIN_COUNTDOWN]->Add(QuickStart); - scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_ONE_MINUTE_BUTTON); - scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_FIVE_MINUTE_BUTTON); - scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_TEN_MINUTE_BUTTON); - scrollView[MAIN_COUNTDOWN]->Add(COUNTDOWN_THIRTY_MINUTE_BUTTON); - group->Add(scrollView[MAIN_COUNTDOWN]); - RootView::GetInstance()->Add(group); - container_ = group; Draw(); } @@ -409,7 +457,13 @@ namespace OHOS { View::OnStop(); RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + ClearAll(); return; } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/StartCountDownView.cpp b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/StartCountDownView.cpp index cd34de099..7a04500ef 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/countdown/src/StartCountDownView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/countdown/src/StartCountDownView.cpp @@ -136,7 +136,10 @@ namespace OHOS showCountDownTimelabel->SetPosition(33, 138, 400, 94); showCountDownTimelabel->SetStyle(STYLE_TEXT_FONT, 80); showCountDownTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94); - showCountDownTimelabel->SetText(CountDownModel::GetInstance()->GetCountDownTime().c_str()); + if (CountDownModel::GetInstance()->CountDownTimerIsEnd()) // 如果定时器是停的,显示设置的倒计时时间 + showCountDownTimelabel->SetText(CountDownModel::GetInstance()->GetCountDownTime().c_str()); + else + showCountDownTimelabel->SetText(CountDownModel::GetInstance()->DisplayCountDownDuration()); showCountDownTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); showCountDownTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); showCountDownTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 80); @@ -176,6 +179,10 @@ namespace OHOS play_or_pause_toggleButton->SetViewId(PlayOrPauseToggleButton_ViewID); play_or_pause_toggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); play_or_pause_toggleButton->SetStyle(STYLE_BORDER_RADIUS, 100); + if (CountDownModel::GetInstance()->CountDownTimerIsEnd() || CountDownModel::GetInstance()->GetCountDownTimerIsPause()) // 如果定时器是停的 + play_or_pause_toggleButton->SetState(false); + else + play_or_pause_toggleButton->SetState(true); play_or_pause_toggleButton->SetImages(CountDown_Play_ImagePath, CountDown_PAUSE_ImagePath); UICheckBox::OnChangeListener *ToggleButtonChange = static_cast(MainCountDownPresenter::GetInstance()); play_or_pause_toggleButton->SetOnChangeListener(ToggleButtonChange);