/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved. * * Description: TjdUiAppShutdownPresenter.cpp * * Author: luziquan@ss-tjd.com * * Create: 2024-06-13 *--------------------------------------------------------------------------*/ #include "TjdUiAppShutdownPresenter.h" #include "NativeAbility.h" #include "TjdUiAppIds.h" #include "TjdUiAppShutdownView.h" #include "TjdUiMsgCenter.h" #include "TjdUiSettingCenter.h" #include "broadcast_feature.h" #include "common/key_code.h" #include "dock/input_device.h" #include "notification_manager.h" #include "sys_config.h" #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 namespace TJD { static constexpr int16_t SLIDER_MIN = 13; static constexpr int16_t SLIDER_MAX = 87; static TjdUiAppShutdownPresenter *g_shutdownPresenter = nullptr; TjdUiAppShutdownPresenter::TjdUiAppShutdownPresenter() { g_shutdownPresenter = this; } TjdUiAppShutdownPresenter::~TjdUiAppShutdownPresenter() { g_shutdownPresenter = nullptr; } static TjdUiAppShutdownView *g_messageShutdownView = nullptr; void TjdUiShutdownMsgCenterMessageProc(const Topic topic, Request *req) { const uint16_t notifyId = OHOS::NotificationManager::GetInstance()->GetShowingNotifyId(); if (OHOS::NotificationManager::GetInstance()->HasNotifyShowing() && (notifyId == TJDUI_TOPIC_EVENT_SHUTDOWN)) { return; } if (g_messageShutdownView != nullptr) { static_print_debug("TjdUiShutdownMsgCenterMessageProc g_messageShutdownView != nullptr"); return; } OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic)); OHOS::NotificationManager::GetInstance()->ShowNotify( []() -> OHOS::UIViewGroup * { if (g_messageShutdownView == nullptr) { static_print_debug("TjdUiShutdownMsgCenterMessageProc"); g_shutdownPresenter = new TjdUiAppShutdownPresenter(); g_messageShutdownView = new TjdUiAppShutdownView(); TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(g_shutdownPresenter, KeyModelType::SYS_KEY_TYPE); } OHOS::NotificationManager::GetInstance()->RegisterNotifyCleanupFunction([]() { OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST); static_print_debug("TjdUiShutdownMsgCenterMessageProc RegisterNotifyCleanupFunction"); TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::SYS_KEY_TYPE); delete g_messageShutdownView; delete g_shutdownPresenter; g_messageShutdownView = nullptr; g_shutdownPresenter = nullptr; RunPopOutPageCallback(); }); return g_messageShutdownView->InitView(); }, static_cast(topic), true); } TjdUiAppShutdownPresenter *TjdUiAppShutdownPresenter::GetInstance(void) { return g_shutdownPresenter; } bool TjdUiAppShutdownPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { TjdUiAppShutdownView *shutdownView = TjdUiAppShutdownView::GetInstance(); std::string viewId = view.GetViewId(); if (viewId.empty()) { return false; } if (viewId == BTN_RESTART_VIEW_ID) { shutdownView->ShowView(ShutdownViewIndex::RESTART_VIEW); } else if (viewId == BTN_SHUTDOWN_VIEW_ID) { shutdownView->ShowView(ShutdownViewIndex::SHUTDOWN_VIEW); } else if (viewId == BTN_RESTART_ENTER_VIEW_ID) { TjdUiSettingCenter::GetInstance().ResetSystem(); } else if (viewId == BTN_SHUTDOWN_ENTER_VIEW_ID) { TjdUiSettingCenter::GetInstance().ShutdownSystem(); } return false; } static void StopShutdownMsg() { const uint16_t notifyId = OHOS::NotificationManager::GetInstance()->GetShowingNotifyId(); if (OHOS::NotificationManager::GetInstance()->HasNotifyShowing() && (notifyId == TJDUI_TOPIC_EVENT_SHUTDOWN)) { OHOS::NotificationManager::GetInstance()->StopNotify(); } } bool TjdUiAppShutdownPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } ViewExitEvent(false); return true; } void TjdUiAppShutdownPresenter::ViewExitEvent(bool isSwipe) { TjdUiAppShutdownView *shutdownView = TjdUiAppShutdownView::GetInstance(); if (shutdownView == nullptr) { return; } auto currentView = TjdUiAppShutdownView::currentViewIndex_; if (currentView == ShutdownViewIndex::RESTART_VIEW) { shutdownView->ShowView(ShutdownViewIndex::CHOOSE_SHUTDOWN_VIEW); } else if (currentView == ShutdownViewIndex::SHUTDOWN_VIEW) { shutdownView->ShowView(ShutdownViewIndex::CHOOSE_SHUTDOWN_VIEW); } else if (currentView == ShutdownViewIndex::CHOOSE_SHUTDOWN_VIEW) { StopShutdownMsg(); } } } // namespace TJD