/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved. * * Description: TjdUiAppPhoneView.cpp * * Author: luziquan@ss-tjd.com * * Create: 2025-08-16 *--------------------------------------------------------------------------*/ #include "TjdUiAppPhoneView.h" #include "TjdUiImageIds.h" #include "TjdUiMemManage.h" #include "TjdUiMultiLanguageExt.h" #include "TjdUiUtils.h" #include "animator/animator_manager.h" #include "common/image_cache_manager.h" #include "graphic_service.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 TjdUiAppPhoneView *g_phoneView = nullptr; #define PHONE_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_phone.bin" PhoneViewIndex TjdUiAppPhoneView::currentViewIndex_ = PhoneViewIndex::PHONE_MAIN_LIST; bool TjdUiAppPhoneView::isQuickEnter_ = false; bool PhoneUIScrollView::OnDragStartEvent(const OHOS::DragEvent &event) { if (TjdUiAppPhoneView::IsQuickEnter()) { return true; } if (TjdUiAppPhoneView::currentViewIndex_ != PhoneViewIndex::PHONE_UNKNOWN && TjdUiAppPhoneView::currentViewIndex_ != PhoneViewIndex::PHONE_MAIN_LIST) { return true; } isOnStart_ = true; return OHOS::UIScrollViewNested::OnDragStartEvent(event); } bool PhoneUIScrollView::OnDragEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } if (TjdUiAppPhoneView::IsQuickEnter()) { return true; } if (TjdUiAppPhoneView::currentViewIndex_ != PhoneViewIndex::PHONE_UNKNOWN && TjdUiAppPhoneView::currentViewIndex_ != PhoneViewIndex::PHONE_MAIN_LIST) { return true; } return OHOS::UIScrollViewNested::OnDragEvent(event); } bool PhoneUIScrollView::OnDragEndEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } isOnStart_ = false; if (TjdUiAppPhoneView::IsQuickEnter()) { return true; } if (TjdUiAppPhoneView::currentViewIndex_ != PhoneViewIndex::PHONE_UNKNOWN && TjdUiAppPhoneView::currentViewIndex_ != PhoneViewIndex::PHONE_MAIN_LIST) { return true; } return OHOS::UIScrollViewNested::OnDragEndEvent(event); } TjdUiAppPhoneView::TjdUiAppPhoneView() { g_phoneView = this; } TjdUiAppPhoneView::~TjdUiAppPhoneView() { g_phoneView = nullptr; } TjdUiAppPhoneView *TjdUiAppPhoneView::GetInstance(void) { return g_phoneView; } void TjdUiAppPhoneView::OnStart() { OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(PHONE_IMAGE_BIN_PATH); if (mainView_ == nullptr) { mainView_ = new PhoneUIScrollView(); } mainView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); // mainView_->SetOnDragListener(TjdUiAppPhonePresenter::GetInstance()); AddViewToRootContainer(mainView_); } void TjdUiAppPhoneView::OnStop() { currentViewIndex_ = PhoneViewIndex::PHONE_MAIN_LIST; isQuickEnter_ = false; mainView_->RemoveAll(); for (int i = 0; i < PhoneViewIndex::PHONE_UNKNOWN; i++) { if (viewManager_[i] != nullptr) { delete viewManager_[i]; viewManager_[i] = nullptr; } } OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(PHONE_IMAGE_BIN_PATH); } void TjdUiAppPhoneView::InitTargetView(PhoneViewIndex index) { if (viewManager_[index] != nullptr) { return; } // clang-format off switch (index) { case PHONE_MAIN_LIST: viewManager_[index] = new PhoneMainListView(); break; case PHONE_CONTACT: viewManager_[index] = new PhoneContactView(); break; case PHONE_CALL_LOG: viewManager_[index] = new PhoneCallLogView(); break; case PHONE_DIAL: viewManager_[index] = new PhoneDialView(); break; case PHONE_DISCONNECT: viewManager_[index] = new PhoneDisConnectView(); break; default: break; } // clang-format on if (viewManager_[index] == nullptr) { return; } viewManager_[index]->SetPosition(0, 0); viewManager_[index]->SetVisible(false); mainView_->Add(viewManager_[index]); } void TjdUiAppPhoneView::ShowView(PhoneViewIndex showIndex) { if (showIndex < 0 || showIndex >= PhoneViewIndex::PHONE_UNKNOWN) { return; } InitTargetView(showIndex); if (currentViewIndex_ >= 0 && currentViewIndex_ < PhoneViewIndex::PHONE_UNKNOWN && viewManager_[currentViewIndex_] != nullptr) { viewManager_[currentViewIndex_]->HideView(); } if (viewManager_[showIndex] != nullptr) { viewManager_[showIndex]->ShowView(); } currentViewIndex_ = showIndex; } void TjdUiAppPhoneView::SetDialNumber(std::string &number) { InitTargetView(PhoneViewIndex::PHONE_DIAL); static_cast(viewManager_[PhoneViewIndex::PHONE_DIAL])->SetNumber(number); } #pragma region 电话主界面列表选择 PhoneMainListView::PhoneMainListView() { auto &images = OHOS::ImageCacheManager::GetInstance(); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { SetOnDragListener(TjdUiAppPhonePresenter::GetInstance()); } listInfo_.clear(); listInfo_.push_back({PHONE_CALL_LOG, OHOS::FontGlobalManager::GetInstance()->GetText(STR_ID_234), "", images.LoadOneInMultiRes(IMG_PHONE_CALL, PHONE_IMAGE_BIN_PATH)}); listInfo_.push_back({PHONE_CONTACT, OHOS::FontGlobalManager::GetInstance()->GetText(STR_ID_235), "", images.LoadOneInMultiRes(IMG_PHONE_CONTACTS, PHONE_IMAGE_BIN_PATH)}); listInfo_.push_back({PHONE_DIAL, OHOS::FontGlobalManager::GetInstance()->GetText(STR_ID_236), "", images.LoadOneInMultiRes(IMG_PHONE_DIAL, PHONE_IMAGE_BIN_PATH)}); adapter_ = new TjdUITransformListGroupAdapter>( listInfo_); listGroup_ = new TjdUITransformListGroup(adapter_); title_.SetTextId(STR_ID_08); title_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); title_.Resize(200, 100); title_.SetX((listGroup_->GetWidth() >> 1) - (title_.GetWidth() >> 1)); title_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); auto titleOffset_ = ((OHOS::Screen::GetInstance().GetHeight() >> 1) - (128 >> 1) - 17 - title_.GetHeight()); listGroup_->AddCustomView(&title_, TjdUITransformListGroup::CustomViewPos::TITLE); listGroup_->SetTitleOffset(titleOffset_); Add(listGroup_); } void PhoneMainListView::ShowView() { SetVisible(true); TjdUiUtils::ViewRequestFocus(*listGroup_); } void PhoneMainListView::HideView() { listGroup_->ClearFocus(); SetVisible(false); } #pragma endregion #pragma region 联系人界面 PhoneContactView::PhoneContactView() { auto &image = OHOS::ImageCacheManager::GetInstance(); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); SetOnDragListener(TjdUiAppPhonePresenter::GetInstance()); errorView_.SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); errorViewTitle_.SetTextId(STR_ID_235); errorViewTitle_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); errorViewTitle_.Resize(200, 100); errorViewTitle_.SetX((errorView_.GetWidth() >> 1) - (errorViewTitle_.GetWidth() >> 1)); errorViewTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); bg_.SetPosition(162, 127, 141, 165); bg_.SetSrc(image.LoadOneInMultiRes(IMG_PHONE_ICON_NOCONTACT, PHONE_IMAGE_BIN_PATH)); desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); desc_.SetTextId(STR_ID_238); desc_.Resize(300, 140); desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP); desc_.SetPosition(((GetWidth() - desc_.GetWidth()) >> 1), bg_.GetY() + bg_.GetHeight() + 20); errorView_.Add(&errorViewTitle_); errorView_.Add(&bg_); errorView_.Add(&desc_); adapter_ = new TjdUITransformListGroupAdapter>( listInfo_); listGroup_ = new TjdUITransformListGroup(adapter_); title_.SetTextId(STR_ID_235); title_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); title_.Resize(200, 100); title_.SetX((listGroup_->GetWidth() >> 1) - (title_.GetWidth() >> 1)); title_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); auto titleOffset_ = ((OHOS::Screen::GetInstance().GetHeight() >> 1) - (128 >> 1) - 17 - title_.GetHeight()); listGroup_->AddCustomView(&title_, TjdUITransformListGroup::CustomViewPos::TITLE); listGroup_->SetTitleOffset(titleOffset_); Add(&errorView_); Add(listGroup_); } PhoneContactView::~PhoneContactView() { errorView_.RemoveAll(); RemoveAll(); if (adapter_ != nullptr) { delete adapter_; adapter_ = nullptr; } if (listGroup_ != nullptr) { listGroup_->RemoveAll(); delete listGroup_; listGroup_ = nullptr; } } void PhoneContactView::ShowView() { TjdUiAppPhonePresenter *presenter = TjdUiAppPhonePresenter::GetInstance(); if (presenter->GetNeedRefreshContact()) { RefreshContactList(); auto transformItemList_ = listGroup_->GetTransformList(); transformItemList_->RefreshList(); transformItemList_->ScrollTo(0); presenter->SetNeedRefreshContact(false); } SetVisible(true); auto list = TjdUiAppPhonePresenter::GetInstance()->GetContactListCase(); if (list.empty()) { errorView_.SetVisible(true); listGroup_->SetVisible(false); } else { errorView_.SetVisible(false); listGroup_->SetVisible(true); TjdUiUtils::ViewRequestFocus(*listGroup_); } } void PhoneContactView::HideView() { SetVisible(false); listGroup_->ClearFocus(); } void PhoneContactView::RefreshContactList() { auto &image = OHOS::ImageCacheManager::GetInstance(); int index = 0; const int resId[] = {IMG_PHONE_ICON01, IMG_PHONE_ICON02, IMG_PHONE_ICON03, IMG_PHONE_ICON04}; listInfo_.clear(); auto list = TjdUiAppPhonePresenter::GetInstance()->GetContactListCase(); for (auto &item : list) { auto iconRes = image.LoadOneInMultiRes(resId[(index++) % 4], PHONE_IMAGE_BIN_PATH); listInfo_.push_back({item.index, item.name, item.number, iconRes}); } } #pragma endregion #pragma region 通话记录界面 PhoneCallLogView::PhoneCallLogView() { auto &image = OHOS::ImageCacheManager::GetInstance(); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); SetOnDragListener(TjdUiAppPhonePresenter::GetInstance()); callLogStatusResId[CALL_LOG_STATUS_OUT] = IMG_PHONE_INCOMING_CAL; callLogStatusResId[CALL_LOG_STATUS_IN] = IMG_PHONE_OUTGOING_CALL; callLogStatusResId[CALL_LOG_STATUS_MISS] = IMG_PHONE_MISSED_CALL; errorView_.SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); errorViewTitle_.SetTextId(STR_ID_234); errorViewTitle_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); errorViewTitle_.Resize(200, 100); errorViewTitle_.SetX((errorView_.GetWidth() >> 1) - (errorViewTitle_.GetWidth() >> 1)); errorViewTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); bg_.SetPosition(162, 127, 141, 165); bg_.SetSrc(image.LoadOneInMultiRes(IMG_PHONE_ICON_NOCALL, PHONE_IMAGE_BIN_PATH)); desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); desc_.SetTextId(STR_ID_237); desc_.Resize(300, 140); desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP); desc_.SetPosition(((GetWidth() - desc_.GetWidth()) >> 1), bg_.GetY() + bg_.GetHeight() + 20); errorView_.Add(&errorViewTitle_); errorView_.Add(&bg_); errorView_.Add(&desc_); listInfo_.clear(); adapter_ = new TjdUITransformListGroupAdapter>( listInfo_); listGroup_ = new TjdUITransformListGroup(adapter_); title_.SetTextId(STR_ID_234); title_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); title_.Resize(200, 100); title_.SetX((listGroup_->GetWidth() >> 1) - (title_.GetWidth() >> 1)); title_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); auto titleOffset_ = ((OHOS::Screen::GetInstance().GetHeight() >> 1) - (128 >> 1) - 17 - title_.GetHeight()); listGroup_->AddCustomView(&title_, TjdUITransformListGroup::CustomViewPos::TITLE); listGroup_->SetTitleOffset(titleOffset_); Add(&errorView_); Add(listGroup_); } PhoneCallLogView::~PhoneCallLogView() { errorView_.RemoveAll(); RemoveAll(); if (adapter_ != nullptr) { delete adapter_; adapter_ = nullptr; } if (listGroup_ != nullptr) { listGroup_->RemoveAll(); delete listGroup_; listGroup_ = nullptr; } } void PhoneCallLogView::ShowView() { TjdUiAppPhonePresenter *presenter = TjdUiAppPhonePresenter::GetInstance(); if (presenter->GetNeedRefreshCallLog()) { RefreshCallLogList(); auto transformItemList_ = listGroup_->GetTransformList(); transformItemList_->RefreshList(); transformItemList_->SetReboundSize(0); transformItemList_->ScrollBy(transformItemList_->GetHeight()); transformItemList_->SetReboundSize(transformItemList_->GetHeight() >> 1); presenter->SetNeedRefreshCallLog(false); } SetVisible(true); std::list &list = presenter->GetCallLogListCase(); if (list.empty()) { errorView_.SetVisible(true); listGroup_->SetVisible(false); } else { errorView_.SetVisible(false); listGroup_->SetVisible(true); TjdUiUtils::ViewRequestFocus(*listGroup_); } } void PhoneCallLogView::HideView() { SetVisible(false); listGroup_->ClearFocus(); } void PhoneCallLogView::RefreshCallLogList() { auto &image = OHOS::ImageCacheManager::GetInstance(); int index = 0; listInfo_.clear(); auto list = TjdUiAppPhonePresenter::GetInstance()->GetCallLogListCase(); for (auto &item : list) { auto iconRes = image.LoadOneInMultiRes(callLogStatusResId[item.status], PHONE_IMAGE_BIN_PATH); listInfo_.push_back({item.index, item.name, item.number, iconRes}); } } #pragma endregion #pragma region 拨号界面 PhoneDialView::PhoneDialView() { auto &image = OHOS::ImageCacheManager::GetInstance(); SetOnDragListener(TjdUiAppPhonePresenter::GetInstance()); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); int defaultResId[12] = {IMG_PHONE_DEFAULT_01, IMG_PHONE_DEFAULT_02, IMG_PHONE_DEFAULT_03, IMG_PHONE_DEFAULT_04, IMG_PHONE_DEFAULT_05, IMG_PHONE_DEFAULT_06, IMG_PHONE_DEFAULT_07, IMG_PHONE_DEFAULT_08, IMG_PHONE_DEFAULT_09, IMG_PHONE_DEFAULT_10, IMG_PHONE_DEFAULT_11, IMG_PHONE_DEFAULT_12}; int triggeredResId[12] = {IMG_PHONE_DEFAULT_01_PRESS, IMG_PHONE_DEFAULT_02_PRESS, IMG_PHONE_DEFAULT_03_PRESS, IMG_PHONE_DEFAULT_04_PRESS, IMG_PHONE_DEFAULT_05_PRESS, IMG_PHONE_DEFAULT_06_PRESS, IMG_PHONE_DEFAULT_07_PRESS, IMG_PHONE_DEFAULT_08_PRESS, IMG_PHONE_DEFAULT_09_PRESS, IMG_PHONE_DEFAULT_10_PRESS, IMG_PHONE_DEFAULT_11_PRESS, IMG_PHONE_DEFAULT_12_PRESS}; dialEdit_.SetPosition(75, 69, 315, 50); dialEdit_.SetFont(TJD_VECTOR_FONT_FILENAME, 46); dialEdit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_CLIP); dialEdit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); int16_t startX = 35; int16_t startY = 129; int16_t width = 128; int16_t height = 66; for (int i = 0; i < 12; i++) { dialBtn_[i].SetViewId(dialId_[i].c_str()); dialBtn_[i].SetOnTouchListener(TjdUiAppPhonePresenter::GetInstance()); dialBtn_[i].SetOnLongPressListener(TjdUiAppPhonePresenter::GetInstance()); dialBtn_[i].SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0); dialBtn_[i].SetStyleForState(OHOS::STYLE_BACKGROUND_OPA, 0, OHOS::UIButton::ButtonState::PRESSED); dialBtn_[i].SetPosition(startX + (width + 6) * (i % 3), startY + (height + 9) * (i / 3), width, height); auto defaultRes = image.LoadOneInMultiRes(defaultResId[i], PHONE_IMAGE_BIN_PATH); auto triggeredRes = image.LoadOneInMultiRes(triggeredResId[i], PHONE_IMAGE_BIN_PATH); if (defaultRes != nullptr && triggeredRes != nullptr) { dialBtn_[i].SetImageSrc(defaultRes, triggeredRes); } Add(&dialBtn_[i]); } Add(&dialEdit_); } PhoneDialView::~PhoneDialView() { RemoveAll(); } void PhoneDialView::SetNumber(std::string &number) { auto it = fontSizeMap.find(number.size()); if (it != fontSizeMap.end()) { dialEdit_.SetFont(TJD_VECTOR_FONT_FILENAME, it->second); } else if (number.size() <= 12) { dialEdit_.SetFont(TJD_VECTOR_FONT_FILENAME, 46); } dialEdit_.SetText(number.c_str()); } #pragma endregion #pragma region 尚未连接App界面 PhoneDisConnectView::PhoneDisConnectView() { auto &image = OHOS::ImageCacheManager::GetInstance(); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); SetOnDragListener(TjdUiAppPhonePresenter::GetInstance()); bg_.SetPosition(160, 126, 146, 146); bg_.SetSrc(image.LoadOneInMultiRes(IMG_PHONE_PROMPT_FAIL, PHONE_IMAGE_BIN_PATH)); desc_.SetTextId(STR_ID_239); desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); desc_.Resize(300, 140); desc_.SetX((GetWidth() >> 1) - (desc_.GetWidth() >> 1)); desc_.SetY(bg_.GetY() + bg_.GetHeight() + 10); desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP); Add(&bg_); Add(&desc_); } #pragma endregion } // namespace TJD