#include "TjdUiAppFindPhoneView.h" #include "TjdUiImageIds.h" #include "TjdUiMultiLanguageExt.h" #include "TjdUiScreenManage.h" #include "common/image_cache_manager.h" #include "gfx_utils/mem_check.h" #include "style.h" namespace TJD { using namespace OHOS; #define IF_MEM_CHECK 0 #define FINDPHONE_ANIMATOR_COUNT 9 #define FINDPHONE_NOCONNECT_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_no_connect.bin" #define FINDPHONE_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_findphone.bin" int FindPhoneAnimatorId[FINDPHONE_ANIMATOR_COUNT] = { IMG_FINDPHONE_DT_FIND_01, IMG_FINDPHONE_DT_FIND_02, IMG_FINDPHONE_DT_FIND_03, IMG_FINDPHONE_DT_FIND_04, IMG_FINDPHONE_DT_FIND_05, IMG_FINDPHONE_DT_FIND_06, IMG_FINDPHONE_DT_FIND_07, IMG_FINDPHONE_DT_FIND_08, IMG_FINDPHONE_DT_FIND_09}; enum FindPhoneImageInfoIndex { FINDPHONE_INFO_START, FINDPHONE_INFO_PAUSE, FINDPHONE_INFO_FAIL, FINDPHONE_INFO_COVER, FINDPHONE_INFO_COUNT }; // static OHOS::GraphicTimer *findPhoneTimer_ = nullptr; // breathing timer static OHOS::ImageInfo *g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_COUNT]{nullptr}; static OHOS::ImageAnimatorInfo g_pv_animatorInfo_[FINDPHONE_ANIMATOR_COUNT]; static TjdUiAppFindPhoneView *g_pv_AppFindPhoneView = nullptr; TjdUiAppFindPhoneView::TjdUiAppFindPhoneView() { if (IF_MEM_CHECK) OHOS::MemCheck::GetInstance()->EnableLeakCheck(true); g_pv_AppFindPhoneView = this; } TjdUiAppFindPhoneView::~TjdUiAppFindPhoneView() { g_pv_AppFindPhoneView = nullptr; if (IF_MEM_CHECK) OHOS::MemCheck::GetInstance()->EnableLeakCheck(false); } TjdUiAppFindPhoneView *TjdUiAppFindPhoneView::GetInstance(void) { return g_pv_AppFindPhoneView; } void TjdUiAppFindPhoneView::OnStart() { View::OnStart(); InitFindPhoneImage(); if (containerAll_ == nullptr) { containerAll_ = new UIViewGroup(); } containerAll_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); findphoneView[FindPhoneViewIndex::FIND_PHONE_VIEW] = InitFindPhoneView(); findphoneView[FindPhoneViewIndex::FIND_PHONE_FAIL_VIEW] = InitBleNotConnectedView(); containerAll_->Add(findphoneView[FindPhoneViewIndex::FIND_PHONE_VIEW]); containerAll_->Add(findphoneView[FindPhoneViewIndex::FIND_PHONE_FAIL_VIEW]); AddViewToRootContainer(containerAll_); } void TjdUiAppFindPhoneView::OnStop() { // if(findPhoneTimer_ != nullptr) { // findPhoneTimer_->Stop(); // delete findPhoneTimer_; // findPhoneTimer_ = nullptr; // } ImageCacheManager::GetInstance().UnloadAllInMultiRes(FINDPHONE_IMAGE_BIN_PATH); ImageCacheManager::GetInstance().UnloadAllInMultiRes(FINDPHONE_NOCONNECT_IMAGE_BIN_PATH); TjdUiMemManage::DeleteChildren(containerAll_); } void TjdUiAppFindPhoneView::ShowView(FindPhoneViewIndex hideView, FindPhoneViewIndex showView) { if (findphoneView[hideView] != nullptr) { findphoneView[hideView]->SetVisible(false); } if (findphoneView[showView] != nullptr) { findphoneView[showView]->SetVisible(true); currentView_ = showView; } } void TjdUiAppFindPhoneView::InitFindPhoneImage() { g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_START] = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FINDPHONE_FIND_PHONE_START, FINDPHONE_IMAGE_BIN_PATH); g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_PAUSE] = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FINDPHONE_FIND_PHONE_PAUSE, FINDPHONE_IMAGE_BIN_PATH); g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_FAIL] = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_NO_CONNECT_NO_CONNECT, FINDPHONE_NOCONNECT_IMAGE_BIN_PATH); g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_COVER] = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_FINDPHONE_DT_FIND_01, FINDPHONE_IMAGE_BIN_PATH); ImageCacheManager &imgManager = ImageCacheManager::GetInstance(); for (int i = 0; i < FINDPHONE_ANIMATOR_COUNT; i++) { g_pv_animatorInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(FindPhoneAnimatorId[i], FINDPHONE_IMAGE_BIN_PATH); g_pv_animatorInfo_[i].pos = {0, 0}; g_pv_animatorInfo_[i].width = 466; g_pv_animatorInfo_[i].height = 466; g_pv_animatorInfo_[i].imageType = IMG_SRC_IMAGE_INFO; } } void TjdUiAppFindPhoneView::Changestatus1() { fdPhoneStart_->SetVisible(false); fdPhonePause_->SetVisible(true); fdPhoneCover_->SetVisible(false); imageAnimatorfindphone_->Start(); lblFindPhone_->SetTextId(STR_ID_76); // lblFindPhone_->SetVisible(true); // OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN); } void TjdUiAppFindPhoneView::Changestatus2() { TjdUiScreenManage::ResetScreenKeepOnTimeout(); fdPhoneStart_->SetVisible(true); fdPhonePause_->SetVisible(false); imageAnimatorfindphone_->Stop(); lblFindPhone_->SetTextId(STR_ID_587); } OHOS::UIScrollView *TjdUiAppFindPhoneView::InitFindPhoneView() { OHOS::UIScrollView *findPhoneView = new OHOS::UIScrollView(); findPhoneView->SetPosition(0, 0, 466, 466); findPhoneView->SetOnDragListener(TjdUiAppFindPhonePresenter::GetInstance()); imageAnimatorfindphone_ = new OHOS::UIImageAnimatorView(); imageAnimatorfindphone_->SetPosition(0, 0, 466, 466); imageAnimatorfindphone_->SetImageAnimatorSrc(g_pv_animatorInfo_, FINDPHONE_ANIMATOR_COUNT, 200); imageAnimatorfindphone_->SetVisible(true); if (lblFindPhone_ == nullptr) { lblFindPhone_ = new UILabelExt(); } lblFindPhone_->SetFont(TJD_VECTOR_FONT_FILENAME, 28); // lblFindPhone_->SetText("查找手机"); lblFindPhone_->SetTextId(STR_ID_587); // lblFindPhone_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); lblFindPhone_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); lblFindPhone_->SetPosition(0, 317,466,42); if (fdPhoneStart_ == nullptr) { fdPhoneStart_ = new OHOS::UIImageView(); } fdPhoneStart_->SetPosition(77, 378, 312, 88); fdPhoneStart_->SetViewId(FINDPHONE_START_ID); fdPhoneStart_->SetTouchable(true); fdPhoneStart_->SetStyle(STYLE_IMAGE_OPA, 0xff); fdPhoneStart_->SetOnClickListener(TjdUiAppFindPhonePresenter::GetInstance()); if (g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_START] != nullptr) { fdPhoneStart_->SetSrc(g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_START]); } if (fdPhonePause_ == nullptr) { fdPhonePause_ = new OHOS::UIImageView(); } fdPhonePause_->SetPosition(77, 378, 312, 88); fdPhonePause_->SetViewId(FINDPHONE_PAUSE_ID); fdPhonePause_->SetTouchable(true); fdPhonePause_->SetOnClickListener(TjdUiAppFindPhonePresenter::GetInstance()); fdPhonePause_->SetVisible(false); if (g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_PAUSE] != nullptr) { fdPhonePause_->SetSrc(g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_PAUSE]); } if (fdPhoneCover_ == nullptr) { fdPhoneCover_ = new OHOS::UIImageView(); } fdPhoneCover_->SetPosition(0, 0, 466, 466); fdPhoneCover_->SetViewId(FINDPHONE_COVER_ID); fdPhoneCover_->SetTouchable(true); fdPhoneCover_->SetOnClickListener(TjdUiAppFindPhonePresenter::GetInstance()); if (g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_COVER] != nullptr) { fdPhoneCover_->SetSrc(g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_COVER]); } // if (findPhoneTimer_ == nullptr) { // findPhoneTimer_ = new OHOS::GraphicTimer(1000, FindPhoneTimerCallback, nullptr, true); // } findPhoneView->Add(imageAnimatorfindphone_); findPhoneView->Add(fdPhoneCover_); findPhoneView->Add(fdPhoneStart_); findPhoneView->Add(fdPhonePause_); findPhoneView->Add(lblFindPhone_); findPhoneView->SetVisible(true); return findPhoneView; } OHOS::UIScrollView *TjdUiAppFindPhoneView::InitBleNotConnectedView() { OHOS::UIScrollView *findPhoneBleNotConnectedView = new OHOS::UIScrollView(); findPhoneBleNotConnectedView->SetPosition(0, 0, 466, 466); findPhoneBleNotConnectedView->SetOnDragListener(TjdUiAppFindPhonePresenter::GetInstance()); if (lblFindPhoneNotConnected_ == nullptr) { lblFindPhoneNotConnected_ = new UILabelExt(); } lblFindPhoneNotConnected_->SetFont(TJD_VECTOR_FONT_FILENAME, 28); // lblFindPhoneNotConnected_->SetText("请连接APP"); lblFindPhoneNotConnected_->SetTextId(STR_ID_557); lblFindPhoneNotConnected_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); lblFindPhoneNotConnected_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); lblFindPhoneNotConnected_->SetPosition(0, 305,466,40); if (fdPhoneFail_ == nullptr) { fdPhoneFail_ = new OHOS::UIImageView(); } fdPhoneFail_->SetPosition(80, 145, 297, 136); fdPhoneFail_->SetViewId(FINDPHONE_FAIL_ID); fdPhoneFail_->SetTouchable(true); fdPhoneFail_->SetOnClickListener(TjdUiAppFindPhonePresenter::GetInstance()); if (g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_FAIL] != nullptr) { fdPhoneFail_->SetSrc(g_pv_findphoneimageInfo[FindPhoneImageInfoIndex::FINDPHONE_INFO_FAIL]); } findPhoneBleNotConnectedView->Add(lblFindPhoneNotConnected_); findPhoneBleNotConnectedView->Add(fdPhoneFail_); findPhoneBleNotConnectedView->SetVisible(false); return findPhoneBleNotConnectedView; } } // namespace TJD