/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: TjdUiWatchFaceCommonView.cpp * * Author: liuguanwu * * Create: 2024-10 *--------------------------------------------------------------------------*/ #include "TjdUiWatchFaceCommonView.h" #include "DialViewGroup.h" #include "TjdUiAppAlipayModel.h" #include "TjdUiAppMainView.h" #include "TjdUiAppSportView.h" #include "TjdUiMsgCenter.h" #include "TjdUiWFCustomParse.h" #include "TjdUiWFPageCustom.h" #include "TjdUiWatchFaceCtrl.h" #include "View.h" #include "common/image_cache_manager.h" #include "common/key_code.h" #include "graphic_service.h" #include "service_charger.h" #include "sql_setting.h" #include "sys_config.h" #include "ui_screennotify.h" #if ENABLE_MEMORY_CHECK #include "gfx_utils/mem_check.h" #endif extern "C" { #include "input_app.h" } using namespace OHOS; namespace TJD { #define ENABLE_PRINT_INFO 0 #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 #define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_main_wf.bin" #define WF_BIN_PATH TJD_FS_DIR_WF /********************************************************************************************************************** * PUBLIC FUNCTIONS */ static TjdUiWatchFaceCommonView *g_watchFaceCommonView = nullptr; TjdUiWatchFaceCommonView::TjdUiWatchFaceCommonView() { g_watchFaceCommonView = this; } TjdUiWatchFaceCommonView::~TjdUiWatchFaceCommonView() { UnLoadWFAfter(); g_watchFaceCommonView = nullptr; } static void FloatWindowScreenStatusNotifyCallback(ScreenStatus status) { if (status == SCREEN_STATUS_ON) { GraphicService::GetInstance()->PostGraphicEvent([]() { TjdUiAppMainView *mainView = TjdUiAppMainView::GetInstance(); if (mainView) { mainView->HideFloatWindow(); } }); } } static void ChargePlugInCb(void) { static_print_debug("ChargePlugInCb"); GraphicService::GetInstance()->PostGraphicEvent([] { if (g_watchFaceCommonView) { g_watchFaceCommonView->CreateChargingIcon(); } }); } static void ChargePlugOutCb(void) { static_print_debug("ChargePlugInCb"); GraphicService::GetInstance()->PostGraphicEvent([] { if (g_watchFaceCommonView) { g_watchFaceCommonView->DeleteChargingIcon(); } }); } static void PopInPageCb(void) { static_print_debug("PopInPageCb"); GraphicService::GetInstance()->PostGraphicEvent([] { if (g_watchFaceCommonView) { g_watchFaceCommonView->HideSystemViewIcon(); } TjdUiAppMainView *mainView = TjdUiAppMainView::GetInstance(); if (mainView) { mainView->HideFloatWindow(); } }); } static void PopOutPageCb(void) { static_print_debug("PopOutPageCb"); GraphicService::GetInstance()->PostGraphicEvent([] { if (g_watchFaceCommonView) { g_watchFaceCommonView->ShowSystemViewIcon(); } }); } void TjdUiWatchFaceCommonView::CreateChargingIcon(void) { if (img_charging) { return; } ImageInfo *imgInfo{nullptr}; if (img_charging == nullptr) { img_charging = new UIImageView(); img_charging->SetViewId("img_message_charge"); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_MAIN_WF_CHARGING, IMAGE_BIN_PATH); img_charging->SetSrc(imgInfo); img_charging->SetPosition((Screen::GetInstance().GetWidth() - img_charging->GetWidth()) / 2, 20); OHOS::RootView::GetInstance()->AddSystemView(img_charging); if (GetCurTopic() == TJDUI_TOPIC_EVENT_CHARING) { HideSystemViewIcon(); } } else { static_print_error("TjdUiWatchFaceCommonView::CreateChargingIcon:img_charging:%p", img_charging); } } void TjdUiWatchFaceCommonView::DeleteChargingIcon(void) { if (img_charging) { OHOS::RootView::GetInstance()->RemoveSystemView(img_charging); delete img_charging; img_charging = nullptr; } } void TjdUiWatchFaceCommonView::ShowSystemViewIcon(void) { TjdUiAppMainView *mainView = TjdUiAppMainView::GetInstance(); if (mainView == nullptr) { DeleteChargingIcon(); return; } if (mainView->IsMainClockPage()) { if (img_sport) { img_sport->SetVisible(true); return; } if (img_charging) { img_charging->SetVisible(true); return; } if (img_message_dot) { img_message_dot->SetVisible(true); } } } void TjdUiWatchFaceCommonView::HideSystemViewIcon(void) { TjdUiAppMainView *mainView = TjdUiAppMainView::GetInstance(); if (mainView == nullptr) { DeleteChargingIcon(); return; } if (mainView->IsMainClockPage()) { if (img_charging) { img_charging->SetVisible(false); } if (img_message_dot) { img_message_dot->SetVisible(false); } if (img_sport) { img_sport->SetVisible(false); } } } //基础监听器的重写 bool TjdUiWatchFaceCommonView::OnClick(UIView &view, const ClickEvent &event) { if (&view == img_sport) { OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_SPORT); } else if (&view == wfCard_) { uint32_t currentTime = OHOS::HALTick::GetInstance().GetTime(); if (currentTime - lastClickTime_ < 300) { TjdUiAppAlipayModel::GetInstance().SetQuickEnterFlag(true); OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_ALIPAY, TransitionType::TJD_TRANSITION_ZOOM); } lastClickTime_ = currentTime; } return true; } //主表盘公共内容 void TjdUiWatchFaceCommonView::LoadWFAfter(TjdUiWfBase *Page) { Page->RegisterCardPageEvent( std::bind(&TjdUiWatchFaceCommonView::CardPageEvent, this, std::placeholders::_1, std::placeholders::_2)); wfCard_ = Page; wfCard_->SetTouchable(true); wfCard_->SetCoverable(true); wfCard_->SetOnClickListener(this); ImageInfo *imgInfo{nullptr}; GetIfReturnToDial(&imgInfo); if (imgInfo && img_sport == nullptr) { img_sport = new UIImageView(); img_sport->SetViewId("img_sport"); img_sport->SetSrc(imgInfo); img_sport->SetAutoEnable(false); img_sport->Resize(60, 60); img_sport->SetResizeMode(UIImageView::ImageResizeMode::FILL); img_sport->SetPosition((Screen::GetInstance().GetWidth() - img_sport->GetWidth()) / 2, 20); OHOS::RootView::GetInstance()->AddSystemView(img_sport); img_sport->SetOnClickListener(this); img_sport->SetTouchable(true); img_sport->SetVisible(false); } else { static_print_error("TjdUiWatchFaceCommonView::LoadWFAfter:imgInfo:%p img_sport:%p", imgInfo, img_sport); } if (TjdUiAppMainView::GetInstance()->GetMessageRead() == 1 && img_message_dot == nullptr) { img_message_dot = new UIImageView(); img_message_dot->SetViewId("img_message_dot"); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_MAIN_WF_RED_DOT, IMAGE_BIN_PATH); img_message_dot->SetSrc(imgInfo); img_message_dot->SetPosition((Screen::GetInstance().GetWidth() - img_message_dot->GetWidth()) / 2, 20); OHOS::RootView::GetInstance()->AddSystemView(img_message_dot); img_message_dot->SetVisible(false); } else { static_print_error("TjdUiWatchFaceCommonView::LoadWFAfter:iimg_message_dot:%p", img_message_dot); } if (tjd_service_charger_get_charger_status() == CHARGER_STATUS_CHARGING) { CreateChargingIcon(); } HideSystemViewIcon(); registerNotifyScreenStatus(FloatWindowScreenStatusNotifyCallback); tjd_driver_button_register_insert_vbus_cb(ChargePlugInCb); tjd_driver_button_register_unplug_vbus_cb(ChargePlugOutCb); RegisterNotifyPopOutPage(PopOutPageCb); RegisterNotifyPopInPage(PopInPageCb); } void TjdUiWatchFaceCommonView::UnLoadWFAfter(void) { static_print_debug("TjdUiWatchFaceCommonView::UnLoadWFAfter"); if (img_sport) { OHOS::RootView::GetInstance()->RemoveSystemView(img_sport); delete img_sport; img_sport = nullptr; } if (img_message_dot) { OHOS::RootView::GetInstance()->RemoveSystemView(img_message_dot); delete img_message_dot; img_message_dot = nullptr; } if (img_charging) { OHOS::RootView::GetInstance()->RemoveSystemView(img_charging); delete img_charging; img_charging = nullptr; } deregisterNotifyScreenStatus(FloatWindowScreenStatusNotifyCallback); tjd_driver_button_unregister_insert_vbus_cb(ChargePlugInCb); tjd_driver_button_unregister_unplug_vbus_cb(ChargePlugOutCb); DeRegisterNotifyPopOutPage(PopOutPageCb); DeRegisterNotifyPopInPage(PopInPageCb); wfCard_ = nullptr; } void TjdUiWatchFaceCommonView::CardPageEvent(TjdUiWfBase::CardPageEvent event, bool eventValue) { if (event == TjdUiWfBase::CardPageEvent::CARD_PAGE_EVENT_SCROLLBEGIN) { if (eventValue) { HideSystemViewIcon(); } } else if (event == TjdUiWfBase::CardPageEvent::CARD_PAGE_EVENT_SCROLLEND) { if (eventValue) { ShowSystemViewIcon(); } } else if (event == TjdUiWfBase::CardPageEvent::CARD_PAGE_EVENT_COVERBEGIN) { if (!eventValue) { HideSystemViewIcon(); } } else if (event == TjdUiWfBase::CardPageEvent::CARD_PAGE_EVENT_COVEREND) { if (!eventValue) { ShowSystemViewIcon(); } } else if (event == TjdUiWfBase::CardPageEvent::CARD_PAGE_EVENT_ONACTIVE) { ShowSystemViewIcon(); } else if (event == TjdUiWfBase::CardPageEvent::CARD_PAGE_EVENT_ONINACTIVE) { HideSystemViewIcon(); } } } // namespace TJD