/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: * * Author: huangshuyi * * Create: 2024-4 *--------------------------------------------------------------------------*/ #include "TjdUiAppMainPresenter.h" #include "DialViewGroup.h" #include "NativeAbility.h" #include "TjdUiAppIds.h" #include "TjdUiAppMainPageFavorite.h" #include "TjdUiAppMainPageHealth.h" #include "TjdUiAppMainPageMakeFriend.h" #include "TjdUiAppMainPageMusic.h" #include "TjdUiAppMainPageShortCut.h" #include "TjdUiAppMainView.h" #include "TjdUiDoubleClickListencer.h" #include "TjdUiEditShortcutPresenter.h" #include "TjdUiRegisterManager.h" #include "TjdUiScreenEvent.h" #include "TjdUiScreenManage.h" #include "TjdUiWatchFaceBase.h" #include "common/key_code.h" #include "dock/input_device.h" #include "sql_setting.h" #include "sys_config.h" #include "transition/TjdPreZoomTransition.h" #if ENABLE_MEMORY_CHECK #include "gfx_utils/mem_check.h" #endif using namespace OHOS; namespace TJD { TJD_REGIST_SLICE(TJD_APP_VIEW_MAIN, TjdUiAppMainView, TjdUiAppMainPresenter); #define ENABLE_PRINT_INFO 1 #if ENABLE_PRINT_INFO #define static_print_info(...) sys_ui_log_i(__VA_ARGS__) //一般信息打印宏控制 #define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) //警告信息打印一般常开 #define static_print_error(...) sys_ui_log_e(__VA_ARGS__) //错误信息打印一般常开 #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif static constexpr uint16_t MAX_PERIOD = 1000; static TjdUiAppMainPresenter *g_pMainClockPresenter = nullptr; TjdUiAppMainPresenter::TjdUiAppMainPresenter() { // MemCheck::GetInstance()->EnableLeakCheck(true); g_pMainClockPresenter = this; } TjdUiAppMainPresenter::~TjdUiAppMainPresenter() { g_pMainClockPresenter = nullptr; // MemCheck::GetInstance()->EnableLeakCheck(false); } TjdUiAppMainPresenter *TjdUiAppMainPresenter::GetInstance(void) { return g_pMainClockPresenter; } void TjdUiAppMainPresenter::OnStart() { mainPresenterState_ = MainPresenterState::RESUME; TjdUiDoubleClickListencer::GetInstance().RegisterClickEvent( std::bind(&TjdUiAppMainPresenter::OnKeyClickAct, this, std::placeholders::_1, std::placeholders::_2), std::bind(&TjdUiAppMainPresenter::OnKeyDoubleClickAct, this, std::placeholders::_1, std::placeholders::_2)); TjdUiDoubleClickListencer::GetInstance().DoubleKeyCode(OHOS::ZliteKeyCode::ZLITE_KEY_TJD_RIGHTDOWN); TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE); TjdUiScreenManage::ResetScreenKeepOnTimeout(); /* 用作开机第一次判断锁屏或密码是否存在 */ // TjdUiScreenEventInitEvent(); } void TjdUiAppMainPresenter::OnSwipe(UISwipeView &view) { UNUSED(view); TjdCardId cardId = view_->GetHorCurrentCard(); SetTaskPeroid(cardId); if (cardId == TjdCardId::TJD_CARD_HEALTH) { if (!isHearthRateSensorOpened_) { // CompassModel::GetInstance()->OpenCompassSensor(); isHearthRateSensorOpened_ = true; } } else if (isHearthRateSensorOpened_) { // CompassModel::GetInstance()->CloseCompassSensor(); isHearthRateSensorOpened_ = false; } } void TjdUiAppMainPresenter::OnStop() { mainPresenterState_ = MainPresenterState::STOP; TjdUiDoubleClickListencer::GetInstance().UnRegisterClickEvent(); if (isHearthRateSensorOpened_) { // CompassModel::GetInstance()->CloseCompassSensor(); } // TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE); } void TjdUiAppMainPresenter::OnResume() { Presenter::OnResume(); mainPresenterState_ = MainPresenterState::RESUME; // Set current page again to invoke OnActive method. uint8_t curCardId = view_->GetHorCurrentCard(); view_->SwitchToCard(curCardId); // if (lastBlurView_ != nullptr) { // OHOS::RootView::GetInstance()->SetBlurView(lastBlurView_); // lastBlurView_ = nullptr; // } } void TjdUiAppMainPresenter::OnPause() { Presenter::OnPause(); // Save watchface content for slide back OHOS::UIView *watchFace = view_->GetViewById(TjdCardId::TJD_CARD_WATCH_FACE)->GetParent(); uint8_t opaScale = watchFace->GetOpaScale(); watchFace->SetOpaScale(OPA_OPAQUE); PageTransitionMgr::GetInstance().SaveSlideBackSnapShotIfNecessary(watchFace); watchFace->SetOpaScale(opaScale); uint8_t curCardId = view_->GetHorCurrentCard(); OHOS::UICardPage *card = view_->GetViewById(curCardId); if (card != nullptr) { card->OnPause(); } mainPresenterState_ = MainPresenterState::PAUSE; // if (lastBlurView_ == nullptr) { // lastBlurView_ = OHOS::RootView::GetInstance()->GetBlurView(); // OHOS::RootView::GetInstance()->ClearBlurView(lastBlurView_); // } } bool TjdUiAppMainPresenter::OnClick(UIView &view, const ClickEvent &event) { TjdCardId horCardId = view_->GetHorCurrentCard(); TjdVerCardId verCardId = view_->GetVerCurrentCard(); if (horCardId != TjdCardId::TJD_CARD_WATCH_FACE) { return true; } switch (verCardId) { case TjdVerCardId::TJD_VER_CARD_SHORTCUT: //位于快捷栏界面,分发到快捷栏界面处理 TjdUiAppMainPageShortcut::GetInstance()->OnClick(view, event); break; case TjdVerCardId::TJD_VER_CARD_WATCH_FACE: //位于主页面,分发到主页面处理 view_->GetWfCommon()->OnClick(view, event); break; case TjdVerCardId::TJD_VER_CARD_MESSAGE: break; } return true; } bool TjdUiAppMainPresenter::OnLongPress(UIView &view, const LongPressEvent &event) { UNUSED(event); UNUSED(view); static_print_debug("TjdUiAppMainPresenter OnLongPress"); TjdCardId horCardId = view_->GetHorCurrentCard(); TjdVerCardId verCardId = view_->GetVerCurrentCard(); if (verCardId != TjdVerCardId::TJD_VER_CARD_WATCH_FACE) { // 位于上下拉页面,直接返回 return true; } if (horCardId != TjdCardId::TJD_CARD_WATCH_FACE) { TjdSetPreZoomParams(20, 258); OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN_PREVIEW_COMPONENT, TransitionType::TJD_TRANSITION_PRE_ZOOM); } else { TjdSetPreZoomParams(0, 246); OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_WF_SELECT, TransitionType::TJD_TRANSITION_PRE_ZOOM); } return true; } bool TjdUiAppMainPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { UNUSED(event); UNUSED(view); uint8_t cardId = view_->GetHorCurrentCard(); if (cardId == TjdCardId::TJD_CARD_FAVORITE) { auto favoritePage = dynamic_cast(view_->GetViewById(TjdCardId::TJD_CARD_FAVORITE)); if (favoritePage && favoritePage->OnKeyEvent(event)) { return true; } } TjdUiDoubleClickListencer::GetInstance().OnKeyAct(view, event); return true; } bool TjdUiAppMainPresenter::OnKeyClickAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { UNUSED(event); UNUSED(view); OHOS::ZliteKeyCode keyId = (ZliteKeyCode)event.GetKeyId(); uint8_t cardId = view_->GetHorCurrentCard(); TjdVerCardId verCardId = view_->GetVerCurrentCard(); if (verCardId == TjdVerCardId::TJD_VER_CARD_WATCH_FACE) { //位于表盘界面没有被上下界面覆盖 if (cardId == TjdCardId::TJD_CARD_WATCH_FACE) { view_->GetWfCommon()->KeyHandler(view, event); return true; } // 没有位于主表盘界面且也不是在上下拉页面 if (keyId == ZliteKeyCode::ZLITE_KEY_TJD_RIGHTUP) { GraphicService::GetInstance()->PostGraphicEvent([]() { TjdUiAppMainView *mainView = TjdUiAppMainView::GetInstance(); if (mainView == nullptr) { return; } mainView->SwitchToClockPage(); }); } else if (keyId == ZliteKeyCode::ZLITE_KEY_TJD_LEFT) { GraphicService::GetInstance()->PostGraphicEvent([]() { uint16_t sliceId = (uint16_t)sql_setting_get_switch_downkey_app(); if (TJD_APP_VIEW_INVALID == sliceId) { sliceId = TJD_APP_VIEW_SPORT; } OHOS::NativeAbility::GetInstance().ChangeSlice(sliceId, TransitionType::TJD_TRANSITION_ZOOM); }); } } else { if (keyId != ZliteKeyCode::ZLITE_KEY_TJD_RIGHTUP) { return true; } GraphicService::GetInstance()->PostGraphicEvent([verCardId]() { TjdUiAppMainView *mainView = TjdUiAppMainView::GetInstance(); if (mainView == nullptr) { return; } if (verCardId == TjdVerCardId::TJD_VER_CARD_SHORTCUT && TjdUiAppMainPageShortcut::currentViewIndex_ == ShortcutView::SHORTCUT_EDIT) { TjdUiEditShortcutPresenter::GetInstance()->ViewExitEvent(); } else { TjdUiAppMainPageShortcut::GetInstance()->ReturnToTop(); // 按键退出复位快捷栏位置 mainView->SwitchToClockPage(); OHOS::RootView::GetInstance()->ClearBlurView(OHOS::RootView::GetInstance()->GetBlurView()); } }); } return true; } bool TjdUiAppMainPresenter::OnKeyDoubleClickAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { UNUSED(event); UNUSED(view); OHOS::ZliteKeyCode keyId = (ZliteKeyCode)event.GetKeyId(); uint8_t cardId = view_->GetHorCurrentCard(); uint8_t curVerPageId = view_->GetMainViewGroup()->GetCurrentPageId(1); if (view_->GetWfCommon()->IsShowFloatWindow() || curVerPageId == 2 || curVerPageId == 0) { return true; } GraphicService::GetInstance()->PostGraphicEvent([]() { OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_DOCK, TransitionType::TJD_TRANSITION_ZOOM); }); return true; } void TjdUiAppMainPresenter::SetTaskPeroid(TjdCardId cardId) { SetLastRun(0); // refresh entering card in time if (cardId == TjdCardId::TJD_CARD_FAVORITE) { SetPeriod(DEFAULT_TASK_PERIOD); } else if (cardId == TjdCardId::TJD_CARD_WATCH_FACE) { uint32_t time; // OHOS::DialSetting &setting = GetDialSetting(); // if (setting.dialFlag) { // time = dynamic_cast(view_->GetViewById(WATCH_FACE))->GetPeriod(); // } else { time = DEFAULT_TASK_PERIOD; // } SetPeriod(time); } else if (cardId == TjdCardId::TJD_CARD_MUSIC) { SetPeriod(500); } else { SetPeriod(MAX_PERIOD); } } bool TjdUiAppMainPresenter::IsFromSetCardView(void) const { return TjdUiAppMainModel::GetInstance().IsFromSetCardView(); } void TjdUiAppMainPresenter::SetFromSetCardView(bool isFrom) { TjdUiAppMainModel::GetInstance().SetFromSetCardView(isFrom); } uint8_t TjdUiAppMainPresenter::GetFromCardId(void) { return TjdUiAppMainModel::GetInstance().GetFromCardId(); } const std::vector &TjdUiAppMainPresenter::GetCardSettings(void) { return TjdUiAppMainModel::GetInstance().GetCardSettings(); } void TjdUiAppMainPresenter::Notify(void) { TjdCardId horPageId = view_->GetHorCurrentCard(); if (horPageId == TjdCardId::TJD_CARD_WATCH_FACE) { TjdVerCardId verPageId = view_->GetVerCurrentCard(); TjdUiWfBase *pTempWfBase = dynamic_cast(view_->GetViewById(TJD_CARD_WATCH_FACE)); if (pTempWfBase) { pTempWfBase->Update(); } if (verPageId == TjdVerCardId::TJD_VER_CARD_SHORTCUT) { TjdUiAppMainPageShortcut::GetInstance()->UpdateView(); } } if (horPageId == TjdCardId::TJD_CARD_FAVORITE) { auto *tmpView = dynamic_cast(view_->GetViewById(TJD_CARD_FAVORITE)); if (tmpView) { tmpView->FavoriteClockTick(); } } else if (horPageId == TjdCardId::TJD_CARD_HEALTH) { auto *tmpView = dynamic_cast(view_->GetViewById(TJD_CARD_FAVORITE)); if (tmpView) { tmpView->NotifyTick(); } } else if (horPageId == TjdCardId::TJD_CARD_MAKE_FRIEND) { auto *tmpView = dynamic_cast(view_->GetViewById(TJD_CARD_FAVORITE)); if (tmpView) { tmpView->NotifyTick(); } } else if (horPageId == TjdCardId::TJD_CARD_MUSIC) { auto *tmpView = dynamic_cast(view_->GetViewById(TJD_CARD_FAVORITE)); if (tmpView) { tmpView->NotifyTick(); } } } } // namespace TJD