/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: * * Author: huangshuyi * * Create: 2024-8 *--------------------------------------------------------------------------*/ #include "components/ui_label.h" #include "wearable_log.h" #include "common/image_cache_manager.h" #include #include #include "gfx_utils/image_info.h" #include "gfx_utils/heap_base.h" #include "TjdUiImageIds.h" #include "ui_label.h" #include "TjdUiMultiLanguageExt.h" #include "sys_config.h" #include "components/ui_view.h" #include "components/ui_view_group.h" #include "components/root_view.h" #include "components/ui_scroll_view.h" #include "components/ui_image_view.h" #include "ui_label_ext.h" #include "notification_manager.h" #include "msg_center.h" #include "TjdUiMsgCenter.h" #include "sql_message.h" #include "TjdUiMessageCommon.h" #include "TjdUiMemManage.h" #include "NativeAbility.h" #include "TjdUiAppIds.h" #include "TransitionType.h" #include "sql_setting.h" #include "power_display_service.h" #include "TjdUiAppMainView.h" #include "ui_screennotify.h" #include "systick.h" #include "common/key_code.h" #include "dock/input_device.h" #include "TjdUiLauncher.h" #include "TjdUiScreenDrag.h" using namespace OHOS; using namespace TJD; #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 #define IMAGE_BIN_PATH TJD_IMAGE_PATH"img_main_message.bin" static uint8_t newestIndex; static uint64_t g_message_time_start_stamp = 0; static uint8_t clickFlag = 0; static uint8_t isTimeOutFlag = 0; //class TjdUiMessagePopUpPage : public OHOS::UIView::OnClickListener, public OHOS::UIView::OnDragListener, public OHOS::RootView::OnKeyActListener class TjdUiMessagePopUpPage : public OHOS::UIView::OnClickListener, TjdUiScreenDragListener, public OHOS::RootView::OnKeyActListener { public: TjdUiMessagePopUpPage(){} virtual ~TjdUiMessagePopUpPage(); bool OnClick(OHOS::UIView& view, const OHOS::ClickEvent& event) override { NotificationManager::GetInstance()->StopNotify(); clickFlag = 1; isTimeOutFlag = 0; return true; } void ScreenDragEventCallback (OHOS::UIView &view, const OHOS::DragEvent &event) override { NotificationManager::GetInstance()->StopNotify(); isTimeOutFlag = 0; } bool OnKeyAct(UIView& view, const KeyEvent& event) override { if(!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } NotificationManager::GetInstance()->StopNotify(); isTimeOutFlag = 0; return true; } UIViewGroup* PageInit(void); UIViewGroup* Page{nullptr}; private: int16_t dragStartX_{0}; int16_t dragCurrentX_{0}; int32_t dragDistance_{0}; }; static TjdUiMessagePopUpPage*MessagePopUpPage = nullptr; TjdUiMessagePopUpPage::~TjdUiMessagePopUpPage() { Page = nullptr; } static bool ScreenStatusNotify(ScreenStatus status) { static_print_debug("message pop page ScreenStatusNotify:%d..............", status); uint64_t timeNow = uapi_systick_get_ms(); if (status == SCREEN_STATUS_ON) { if (timeNow - g_message_time_start_stamp > 5000) { NotificationManager::GetInstance()->StopNotify(); isTimeOutFlag = 1; } } else { g_message_time_start_stamp = uapi_systick_get_ms(); } return false; } static void PageFree(void) { OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST); if (MessagePopUpPage != nullptr) { RootView::GetInstance()->Remove(MessagePopUpPage->Page); TjdUiMemManage::DeleteChildren(MessagePopUpPage->Page); TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::SYS_KEY_TYPE); } delete MessagePopUpPage; static_print_debug("MessagePopUpPage PageFree"); RunPopOutPageCallback(); deregisterPopPageNotifyScreenStatus(ScreenStatusNotify); if (clickFlag == 1) { #if 0 OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MESSAGE_DETAILS, OHOS::TransitionType::TRANSITION_INVALID, gSliceDefaultPriority, &newestIndex); #else OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MESSAGE_DETAILS, OHOS::TransitionType::TRANSITION_INVALID, gSliceDefaultPriority); TjdUiLauncher::GetInstance().SetExtraData(&newestIndex); #endif } if (sql_setting_get_notification()) { //使能了红点通知 TjdUiAppMainView::SetMessageRead(1); } else { TjdUiAppMainView::SetMessageRead(0); } if (isTimeOutFlag == 0) { TjdUiAppMainView::SetMessageRead(0); } //printf("=========================================:%d\n", TjdUiAppMainView::GetMessageRead()); } static int16_t CreateMessageItem(UIViewGroup*& cont, const uint8_t& index, const int16_t& x, const int16_t& y) { static_print_debug("CreateMessageItem,index:%d", index); //sql_message_print_all(); time_t timesample = sql_message_get_timestamp(index); struct tm *timeinfo = std::localtime(×ample); uint16_t year = timeinfo->tm_year + 1900; uint8_t month = timeinfo->tm_mon + 1; uint8_t day = timeinfo->tm_mday; uint8_t hour = timeinfo->tm_hour; uint8_t minute = timeinfo->tm_min; char strTime[30]; snprintf(strTime, sizeof(strTime), "%d-%d-%d %d:%d", year, month, day, hour, minute); //std::string strTime = "2024-5-21"; UILabel *labelTime = new UILabel(); cont->Add(labelTime); //labelTime->SetText(strTime.c_str()); labelTime->SetText(strTime); labelTime->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); labelTime->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); labelTime->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); labelTime->SetX(cont->GetWidth() / 2 - labelTime->GetWidth() / 2); labelTime->SetY(y); labelTime->SetViewId("labelTime"); // std::string strText = "nnoodsfofdjojglfdjlgjfdslkjlkgjfdlkjnnodsfljglkjelkrjglkkndsnvsalkfkjaljlgkjrkejlkglkalkgj"; char* strText; sql_message_get_detail_info(index, &strText); UILabel *labelText = new UILabel(); cont->Add(labelText); //labelText->SetText(strText.c_str()); labelText->SetText(strText); labelText->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); labelText->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); labelText->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); labelText->SetWidth(cont->GetWidth() - 100); labelText->SetX((cont->GetWidth() - labelText->GetWidth()) / 2); labelText->SetY(labelTime->GetY() + labelTime->GetHeight() + 20); labelText->SetHeight(cont->GetHeight() - labelText->GetY() - 40); labelText->SetTouchable(true); labelText->SetOnClickListener(MessagePopUpPage); // labelText->LayoutBottomToSibling(labelTime->GetViewId(), 3); int16_t labelTextH = labelText->GetHeight(); int16_t labelTextY = labelText->GetY(); //printf("text width:%d,height:%d,y:%d,cont width:%d,height:%d,y:%d\n", labelText->GetWidth(), labelText->GetHeight(), labelTextY, cont->GetWidth(), cont->GetHeight(), cont->GetY()); return labelTextH + labelTextY; } UIViewGroup* TjdUiMessagePopUpPage::PageInit(void) { //NotificationManager::GetInstance()->StopNotify(); Page = new UIViewGroup(); if (Page == nullptr) { static_print_error("CreateAlarmView g_alarmView null!"); return nullptr; } clickFlag = 0; isTimeOutFlag = 0; Page->SetDraggable(true); Page->SetTouchable(true); Page->SetOnDragListener(this); Page->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); //Page->SetStyle(STYLE_BACKGROUND_COLOR, Color::Red().full); uint8_t* index_list = new uint8_t[sql_message_get_max_number()]; uint8_t count = sql_message_get_message_index_list(index_list); if (count == 0) { static_print_info("No message"); return nullptr; } if (sql_setting_get_screen_wakes()) { //使能了来信亮屏 const power_display_svr_api_t *display_api = power_display_svr_get_api(); display_api->turn_on_screen(); } newestIndex = index_list[0]; static_print_debug("message pop index:%d", newestIndex); message_enum newestType = sql_message_get_type(newestIndex); delete []index_list; TjdUiMessage* messageRes = TjdUiMessageResGet(sql_message_get_type(newestIndex)); //TjdUiMessage* messageRes = TjdUiMessageResGet(MESSAGE_WECHAT2); ImageInfo* imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(messageRes->imageId, IMAGE_BIN_PATH); //ImageInfo* imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(messageRes->imageId, IMAGE_BIN_PATH); UIImageView* imageType = new UIImageView(); Page->Add(imageType); imageType->SetSrc(imgInfo); imageType->SetAutoEnable(false); imageType->Resize(60, 60); imageType->SetResizeMode(UIImageView::ImageResizeMode::FILL); int16_t imageWidth = imageType->GetRect().GetWidth(); imageType->LayoutLeftOfParent(Screen::GetInstance().GetWidth()/2 - imageWidth/2); imageType->LayoutTopOfParent(20); imageType->SetViewId("imageType"); UILabelExt *labelName = new UILabelExt(); Page->Add(labelName); labelName->SetTextId(messageRes->nameId);//需要换成多语言 labelName->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_30); labelName->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); labelName->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); labelName->LayoutTopOfParent(20); int16_t labelNameW = labelName->GetWidth(); labelName->LayoutLeftOfParent((Page->GetWidth() - labelNameW) / 2); labelName->LayoutBottomToSibling(imageType->GetViewId(), 4); int16_t y = labelName->GetY() + labelName->GetHeight() + 20; CreateMessageItem(Page, newestIndex, 60, y); //CreateMessageItem(Page, 0, 60, y); NotificationManager::GetInstance()->RegisterNotifyCleanupFunction(PageFree); registerPopPageNotifyScreenStatus(ScreenStatusNotify); g_message_time_start_stamp = uapi_systick_get_ms(); TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::SYS_KEY_TYPE); return Page; } static UIViewGroup* TjdUiMessagePopUpPageCreate(void) { MessagePopUpPage = new TjdUiMessagePopUpPage(); return MessagePopUpPage->PageInit(); } ////////////////////////////下面两个是对外的接口//////////////////////////// void TjdUiMsgCenterMessageProc(const Topic topic, Request* req) { OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic)); NotificationManager::GetInstance()->ShowNotify(TjdUiMessagePopUpPageCreate, static_cast(topic), true); } extern "C" { void TjdUiMsgCenterMessagePopUpTrigger(void) { GraphicService::GetInstance()->PostGraphicEvent( std::bind(TjdUiMsgEventPublish, TJDUI_TOPIC_EVENT_MSG, nullptr, 0)); } }