/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2025. All rights reserved. * * Description: TjdUiAppCallView.cpp * * Author: luziquan@ss-tjd.com * * Create: 2025-08-16 *--------------------------------------------------------------------------*/ #include "TjdUiAppCallView.h" #include "TjdUiImageIds.h" #include "TjdUiMemManage.h" #include "TjdUiMultiLanguageExt.h" #include "animator/animator_manager.h" #include "bts_br_gap.h" #include "bts_hfp_hf.h" #include "common/image_cache_manager.h" #include "components/root_view.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 { #define CALL_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_phone.bin" CallViewIndex TjdUiAppCallView::currentViewIndex_ = CallViewIndex::CALL_UNKNOWN; static TjdUiAppCallView *g_TjdUiAppCallView = nullptr; TjdUiAppCallView::TjdUiAppCallView() { g_TjdUiAppCallView = this; } TjdUiAppCallView::~TjdUiAppCallView() { g_TjdUiAppCallView = nullptr; } TjdUiAppCallView *TjdUiAppCallView::GetInstance(void) { return g_TjdUiAppCallView; } void TjdUiAppCallView::OnStart() { OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(CALL_IMAGE_BIN_PATH); if (mainView_ == nullptr) { mainView_ = new OHOS::UIScrollView(); } mainView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); AddViewToRootContainer(mainView_); volumeControlBarView_.SetVisible(false); OHOS::RootView::GetInstance()->AddSystemView(&volumeControlBarView_); volumeControlBarView_.Invalidate(); } void TjdUiAppCallView::OnStop() { OHOS::RootView::GetInstance()->RemoveSystemView(&volumeControlBarView_); mainView_->RemoveAll(); for (int i = 0; i < CallViewIndex::CALL_UNKNOWN; i++) { if (viewManager_[i] != nullptr) { viewManager_[i]->RemoveAll(); delete viewManager_[i]; viewManager_[i] = nullptr; } } OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(CALL_IMAGE_BIN_PATH); } void TjdUiAppCallView::InitTargetView(CallViewIndex index) { if (viewManager_[index] != nullptr) { return; } // clang-format off switch (index) { case CALL_CALL_OUT: viewManager_[index] = new CallOutView(); break; case CALL_CALLING: viewManager_[index] = new CallingView(); break; case CALL_END: viewManager_[index] = new CallEndView(); 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 TjdUiAppCallView::ShowView(CallViewIndex showIndex) { if (showIndex < 0 || showIndex >= CallViewIndex::CALL_UNKNOWN) { return; } InitTargetView(showIndex); if (currentViewIndex_ >= 0 && currentViewIndex_ < CallViewIndex::CALL_UNKNOWN && viewManager_[currentViewIndex_] != nullptr) { viewManager_[currentViewIndex_]->HideView(); } if (viewManager_[showIndex] != nullptr) { viewManager_[showIndex]->ShowView(); } currentViewIndex_ = showIndex; } void TjdUiAppCallView::SetVolumeControlBarVisable(bool visable) { volumeControlBarView_.SetVisible(visable); volumeControlBarView_.Invalidate(); } int TjdUiAppCallView::ChangeVolumeControlBarValue(int volume) { return volumeControlBarView_.SetVolume(volume); } int TjdUiAppCallView::GetVolumeControlBarValue(void) { return volumeControlBarView_.GetVolume(); } void TjdUiAppCallView::SetCallingTime(std::string &time) { InitTargetView(CallViewIndex::CALL_CALLING); static_cast(viewManager_[CallViewIndex::CALL_CALLING])->SetCallTime(time); } #pragma region 电话来电界面 CallInView::CallInView() { auto &image = OHOS::ImageCacheManager::GetInstance(); auto callStopRes = image.LoadOneInMultiRes(IMG_PHONE_REJECT, CALL_IMAGE_BIN_PATH); auto callAnswerRes = image.LoadOneInMultiRes(IMG_PHONE_ANSWER, CALL_IMAGE_BIN_PATH); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); callStop_.SetPosition(98, 295, 90, 90); callStop_.SetTouchable(true); callStop_.SetViewId(BTN_CALL_IN_STOP_VIEW_ID); if (callStopRes != nullptr) { callStop_.SetSrc(callStopRes); } callAnswer_.SetPosition(278, 295, 90, 90); callAnswer_.SetTouchable(true); callAnswer_.SetViewId(BTN_CALL_IN_ANSWER_VIEW_ID); if (callAnswerRes != nullptr) { callAnswer_.SetSrc(callAnswerRes); } name_.SetFont(TJD_VECTOR_FONT_FILENAME, 46); name_.Resize(380, 140); name_.SetX((GetWidth() >> 1) - (name_.GetWidth() >> 1)); name_.SetY(20); name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_BOTTOM); status_.SetTextId(STR_ID_240); status_.SetFont(TJD_VECTOR_FONT_FILENAME, 34); status_.Resize(300, 50); status_.SetY(name_.GetY() + name_.GetHeight()); status_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP); Add(&callStop_); Add(&callAnswer_); Add(&name_); Add(&status_); } void CallInView::SetMsgClickEvent(OHOS::UIView::OnClickListener *listener) { callStop_.SetOnClickListener(listener); callAnswer_.SetOnClickListener(listener); } void CallInView::SetCallName(std::string &name) { name_.SetText(name.c_str()); } #pragma endregion #pragma region 电话拨出界面 CallOutView::CallOutView() { auto &image = OHOS::ImageCacheManager::GetInstance(); auto callStopRes = image.LoadOneInMultiRes(IMG_PHONE_ICON_REJECT, CALL_IMAGE_BIN_PATH); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); callStop_.SetPosition(170, 262, 162, 126); callStop_.SetTouchable(true); callStop_.SetViewId(BTN_DIAL_CALL_END_VIEW_ID); callStop_.SetOnClickListener(TjdUiAppCallPresenter::GetInstance()); SetOnRotateListener(TjdUiAppCallPresenter::GetInstance()); if (callStopRes != nullptr) { callStop_.SetSrc(callStopRes); } name_.SetFont(TJD_VECTOR_FONT_FILENAME, 46); name_.Resize(380, 140); name_.SetX((GetWidth() >> 1) - (name_.GetWidth() >> 1)); name_.SetY(20); name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_BOTTOM); status_.SetTextId(STR_ID_241); status_.SetFont(TJD_VECTOR_FONT_FILENAME, 34); status_.Resize(300, 50); status_.SetX((GetWidth() >> 1) - (status_.GetWidth() >> 1)); status_.SetY(name_.GetY() + name_.GetHeight()); status_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP); status_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.5); Add(&callStop_); Add(&name_); Add(&status_); } void CallOutView::ShowView() { std::string &number = TjdUiAppCallPresenter::GetInstance()->GetCallingNumber(); name_.SetText(number.c_str()); SetVisible(true); RequestFocus(); } #pragma endregion #pragma region 通话中界面 CallingView::CallingView() { auto &image = OHOS::ImageCacheManager::GetInstance(); auto callStopRes = image.LoadOneInMultiRes(IMG_PHONE_ICON_REJECT, CALL_IMAGE_BIN_PATH); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); SetOnRotateListener(TjdUiAppCallPresenter::GetInstance()); callStop_.SetPosition(170, 262, 126, 126); callStop_.SetTouchable(true); callStop_.SetViewId(BTN_DIAL_CALL_END_VIEW_ID); callStop_.SetOnClickListener(TjdUiAppCallPresenter::GetInstance()); if (callStopRes != nullptr) { callStop_.SetSrc(callStopRes); } name_.SetFont(TJD_VECTOR_FONT_FILENAME, 46); name_.Resize(380, 140); name_.SetX((GetWidth() >> 1) - (name_.GetWidth() >> 1)); name_.SetY(20); name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_BOTTOM); time_.SetText("00:00"); time_.SetFont(TJD_VECTOR_FONT_FILENAME, 34); time_.Resize(300, 50); time_.SetX((GetWidth() >> 1) - (time_.GetWidth() >> 1)); time_.SetY(name_.GetY() + name_.GetHeight()); time_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP); time_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.5); Add(&callStop_); Add(&name_); Add(&time_); } void CallingView::ShowView() { std::string &number = TjdUiAppCallPresenter::GetInstance()->GetCallingNumber(); name_.SetText(number.c_str()); SetVisible(true); RequestFocus(); } void CallingView::HideView() { SetVisible(false); ClearFocus(); } void CallingView::SetCallTime(std::string &time) { time_.SetText(time.c_str()); } #pragma endregion #pragma region 电话音量控制界面 VolumeControlBarView::VolumeControlBarView() { auto &image = OHOS::ImageCacheManager::GetInstance(); auto res = image.LoadOneInMultiRes(IMG_PHONE_VOICE_ICON, CALL_IMAGE_BIN_PATH); SetPosition(408, 102, 36, 260); SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0); volumeSlider_.SetPosition(0, 0, 36, 260); volumeSlider_.SetStyle(OHOS::STYLE_BACKGROUND_OPA, 0); volumeSlider_.SetDirection(OHOS::UISlider::Direction::DIR_BOTTOM_TO_TOP); volumeSlider_.SetValidWidth(8); volumeSlider_.SetValidHeight(260); volumeSlider_.SetValue(0); volumeSlider_.SetSliderColor(OHOS::Color::GetColorFromRGBA(0x59, 0x59, 0x59, 0xff), OHOS::Color::GetColorFromRGBA(0xFF, 0xFF, 0xFF, 0xff)); volumeSlider_.SetKnobWidth(36); volumeSlider_.SetKnobStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xff808080); volumeSlider_.SetKnobRadius(36); volumeSlider_.SetForegroundStyle(OHOS::STYLE_BACKGROUND_OPA, 0xff); volumeSlider_.SetKnobImage(res); volumeSlider_.SetSliderRadius(4, 4); volumeSlider_.SetRotateFactor(0.1); Add(&volumeSlider_); } int VolumeControlBarView::SetVolume(int volume) { auto val = volumeSlider_.GetValue(); val += volume; volumeSlider_.SetValue(val); return val; } int VolumeControlBarView::GetVolume(void) { return volumeSlider_.GetValue(); } #pragma endregion #pragma region 电话结束界面 CallEndView::CallEndView() { auto &image = OHOS::ImageCacheManager::GetInstance(); auto callStopRes = image.LoadOneInMultiRes(IMG_PHONE_ICON_REJECT, CALL_IMAGE_BIN_PATH); Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); callStop_.SetPosition(170, 262, 162, 126); callStop_.SetTouchable(true); callStop_.SetViewId(BTN_DIAL_CALL_END_VIEW_ID); callStop_.SetOnClickListener(TjdUiAppCallPresenter::GetInstance()); if (callStopRes != nullptr) { callStop_.SetSrc(callStopRes); } name_.SetFont(TJD_VECTOR_FONT_FILENAME, 46); name_.Resize(380, 140); name_.SetX((GetWidth() >> 1) - (name_.GetWidth() >> 1)); name_.SetY(20); name_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_BOTTOM); status_.SetTextId(STR_ID_242); status_.SetFont(TJD_VECTOR_FONT_FILENAME, 34); status_.Resize(300, 50); status_.SetX((GetWidth() >> 1) - (status_.GetWidth() >> 1)); status_.SetY(name_.GetY() + name_.GetHeight()); status_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_TOP); status_.SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.5); Add(&callStop_); Add(&name_); Add(&status_); } void CallEndView::ShowView() { std::string &number = TjdUiAppCallPresenter::GetInstance()->GetCallingNumber(); name_.SetText(number.c_str()); SetVisible(true); } void CallEndView::SetCallStatus(std::string &status) { status_.SetText(status.c_str()); } #pragma endregion } // namespace TJD