#include "TjdUiAppEbookView.h" #include "TjdUiAppEbookAdapter.h" #include "TjdUiAppEbookModel.h" #include "TjdUiAppEbookPresenter.h" #include "TjdUiImageIds.h" #include "TjdUiMemManage.h" #include "TjdUiMultiLanguageExt.h" #include "common/image_cache_manager.h" #include "sys_config.h" #define ENABLE_PRINT_INFO 1 #define ENABLE_DEBUG 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__) // 错误信息打印一般常开 #if ENABLE_DEBUG #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印 #else #define static_print_debug(...) #endif #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif using namespace OHOS; #define BOOK_LOADING_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_loading.bin" #define BOOK_JSON_PATH TJD_FS_DIR_BOOK "/booklist.json" namespace TJD { #ifndef WAIT_ANIMATOR_COUNT #define WAIT_ANIMATOR_COUNT 11 #endif static OHOS::ImageAnimatorInfo g_pv_waitInfo_[WAIT_ANIMATOR_COUNT]; static void WaitAnimatorImageInfo() { const int waitAnimatorId[WAIT_ANIMATOR_COUNT] = { IMG_LOADING_LOADING_01_06, IMG_LOADING_LOADING_02_06, IMG_LOADING_LOADING_03_06, IMG_LOADING_LOADING_04_06, IMG_LOADING_LOADING_05_06, IMG_LOADING_LOADING_06_06, IMG_LOADING_LOADING_07_06, IMG_LOADING_LOADING_08_06, IMG_LOADING_LOADING_09_06, IMG_LOADING_LOADING_10_06, IMG_LOADING_LOADING_11_06, }; auto &imgManager = OHOS::ImageCacheManager::GetInstance(); imgManager.LoadAllInMultiRes(BOOK_LOADING_IMAGE_BIN_PATH); for (int i = 0; i < WAIT_ANIMATOR_COUNT; i++) { g_pv_waitInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(waitAnimatorId[i], BOOK_LOADING_IMAGE_BIN_PATH); g_pv_waitInfo_[i].pos = {178, 154}; g_pv_waitInfo_[i].width = 121; g_pv_waitInfo_[i].height = 121; g_pv_waitInfo_[i].imageType = OHOS::IMG_SRC_IMAGE_INFO; } } static void WaitAnimatorImageInfoUnload() { OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(BOOK_LOADING_IMAGE_BIN_PATH); } static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; } static inline void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text) { label.SetFont(TJD_VECTOR_FONT_FILENAME, size); label.SetText(text); label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); label.SetPosition(HorizontalCenter(label.GetWidth(), target), y); } /*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/ /*---------------------------- Class EbookBackdropRadioButton ----------------------------*/ /*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/ EbookBackdropRadioButton::EbookBackdropRadioButton() { Resize(163, 123); SetTouchable(true); radio_.SetPosition(0, 0, 160, 120); radio_.SetName("backdropRadio"); radio_.SetStyle(STYLE_BORDER_WIDTH, 2); radio_.SetStyle(STYLE_BORDER_RADIUS, 28); radio_.SetStyle(STYLE_BORDER_COLOR, 0xffffffff); radio_.SetStyle(STYLE_BACKGROUND_OPA, 255); radio_.SetImages(&image, &image); radio_.SetOnChangeListener(this); Add(&radio_); label_.SetPosition(0, (GetHeight() - 33) / 2, 160, 33); label_.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); label_.SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); label_.SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); Add(&label_); } bool EbookBackdropRadioButton::OnChange(OHOS::UICheckBox::UICheckBoxState state) { if (state == OHOS::UICheckBox::UICheckBoxState::SELECTED) { radio_.SetStyle(STYLE_BORDER_COLOR, 0xff00ff00); TjdUiAppEbookView::GetInstance()->SetBackDropID(ID); TjdUiAppEbookView::GetInstance()->SetBackdrop(); } else { radio_.SetStyle(STYLE_BORDER_COLOR, 0xffffffff); } return true; } void EbookBackdropRadioButton::SetRadioColor(uint8_t key, int64_t color) { if (key == STYLE_BACKGROUND_COLOR) { radio_.SetStyle(STYLE_BACKGROUND_COLOR, color); } else if (key == STYLE_BORDER_COLOR) { radio_.SetStyle(STYLE_BORDER_COLOR, color); } } void EbookBackdropRadioButton::SetRadioImage(OHOS::ImageInfo *selected, OHOS::ImageInfo *unselect) { radio_.SetImages(selected, unselect); } /*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/ /*---------------------- ------ Class EbookFilpVFXRadioButton ----------------------------*/ /*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/ EbookFilpVFXRadioButton::EbookFilpVFXRadioButton() { Resize(450, 110); SetStyle(STYLE_BORDER_RADIUS, 55); SetStyle(STYLE_BACKGROUND_COLOR, 0xff262626); SetTouchable(true); SetOnClickListener(this); radio_.SetPosition(382, (GetHeight() - 40) / 2, 40, 40); radio_.SetName("filpVFXRadio"); radio_.SetOnChangeListener(this); radio_.SetImages(ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_ICON_SELECT, BOOK_BIN_PATH), ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_ICON_UNSELECT, BOOK_BIN_PATH)); Add(&radio_); label_.SetPosition(42, 38, 274, 39); label_.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); label_.SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); label_.SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_34); Add(&label_); } bool EbookFilpVFXRadioButton::OnChange(OHOS::UICheckBox::UICheckBoxState state) { if (state == OHOS::UICheckBox::UICheckBoxState::SELECTED) { TjdUiAppEbookView::GetInstance()->SetFilpVFXID(filpVFXID); } return true; } /*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/ /*-------------------------------- Class TjdUiAppEbookView -------------------------------*/ /*----------------------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------------------*/ static TjdUiAppEbookView *g_pv_UiAppEbookView = nullptr; bool EbookUIScrollView::OnDragStartEvent(const OHOS::DragEvent &event) { if (TjdUiAppEbookPresenter::GetInstance()->GetCurrentView() != EBOOK_NONE_VIEW && TjdUiAppEbookPresenter::GetInstance()->GetCurrentView() != EBOOK_LIST_VIEW) { return true; } isOnStart_ = true; return OHOS::UIScrollViewNested::OnDragStartEvent(event); } bool EbookUIScrollView::OnDragEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } if (TjdUiAppEbookPresenter::GetInstance()->GetCurrentView() != EBOOK_NONE_VIEW && TjdUiAppEbookPresenter::GetInstance()->GetCurrentView() != EBOOK_LIST_VIEW) { return true; } return OHOS::UIScrollViewNested::OnDragEvent(event); } bool EbookUIScrollView::OnDragEndEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } isOnStart_ = false; if (TjdUiAppEbookPresenter::GetInstance()->GetCurrentView() != EBOOK_NONE_VIEW && TjdUiAppEbookPresenter::GetInstance()->GetCurrentView() != EBOOK_LIST_VIEW) { return true; } return OHOS::UIScrollViewNested::OnDragEndEvent(event); } TjdUiAppEbookView::TjdUiAppEbookView() { static_print_info("TjdUiAppEbookView::%s", __func__); g_pv_UiAppEbookView = this; } TjdUiAppEbookView::~TjdUiAppEbookView() { static_print_info("TjdUiAppEbookView::%s", __func__); g_pv_UiAppEbookView = nullptr; if (setWaitAnimator_ != nullptr) { delete setWaitAnimator_; setWaitAnimator_ = nullptr; } if (contentList_ != nullptr) { delete contentList_; contentList_ = nullptr; } if (listAdapter_ != nullptr) { delete listAdapter_; listAdapter_ = nullptr; } for (int i = 0; i < 4; i++) { if (backdropButtons[i] != nullptr) { delete backdropButtons[i]; backdropButtons[i] = nullptr; } if (FilpVFXButtons[i] != nullptr) { delete FilpVFXButtons[i]; FilpVFXButtons[i] = nullptr; } } TjdUiMemManage::DeleteChildren(containerAll_); } TjdUiAppEbookView *TjdUiAppEbookView::GetInstance(void) { return g_pv_UiAppEbookView; } void TjdUiAppEbookView::OnStart() { static_print_info("TjdUiAppEbookView::%s", __func__); if (containerAll_ == nullptr) { containerAll_ = new EbookUIScrollView(); containerAll_->SetViewId("containerAll_"); containerAll_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); containerAll_->SetStyle(STYLE_BACKGROUND_OPA, 0); // containerAll_->SetOnDragListener(presenter_); } groupList_[EBOOK_NONE_VIEW] = NoneViewInit(); groupList_[EBOOK_LIST_VIEW] = ListViewInit(); groupList_[EBOOK_MAIN_VIEW] = MainViewInit(); groupList_[EBOOK_DELETE_VIEW] = DeleteViewInit(); groupList_[EBOOK_SETTING_VIEW] = SettingViewInit(); containerAll_->Add(groupList_[EBOOK_NONE_VIEW]); containerAll_->Add(groupList_[EBOOK_LIST_VIEW]); containerAll_->Add(groupList_[EBOOK_MAIN_VIEW]); containerAll_->Add(groupList_[EBOOK_DELETE_VIEW]); containerAll_->Add(groupList_[EBOOK_SETTING_VIEW]); AddViewToRootContainer(containerAll_); } void TjdUiAppEbookView::OnStop() { static_print_info("TjdUiAppEbookView::%s", __func__); OHOS::FocusManager::GetInstance()->ClearFocus(); listContainer_->Remove(contentList_); mainContainer_->Remove(setWaitAnimator_); UIViewGroup *group = dynamic_cast(backdropButtons[0]->GetParent()); for (int i = 0; i < 4; i++) { group->Remove(backdropButtons[i]); group->Remove(FilpVFXButtons[i]); } } OHOS::UIScrollView *TjdUiAppEbookView::NoneViewInit(void) { noneContainer_ = new UIScrollView(); noneContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); noneContainer_->SetVisible(false); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { noneContainer_->SetOnDragListener(TjdUiAppEbookPresenter::GetInstance()); } noneLabel1 = new UILabelExt(); noneLabel1->SetPosition(0, 197, HORIZONTAL_RESOLUTION, 50); // noneLabel1->SetText("暂无电子书");//331 noneLabel1->SetTextId(STR_ID_331); noneLabel1->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); noneLabel1->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); noneLabel1->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_34); noneContainer_->Add(noneLabel1); // noneLabel2 = new UILabel(); // noneLabel2->SetPosition(0, 237, HORIZONTAL_RESOLUTION, 40); // noneLabel2->SetText("请前往APP-电子书设置"); // noneLabel2->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); // noneLabel2->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); // noneLabel2->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_34); // noneContainer_->Add(noneLabel2); return noneContainer_; } OHOS::UIScrollView *TjdUiAppEbookView::ListViewInit(void) { listContainer_ = new UIScrollView(); listContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { listContainer_->SetOnDragListener(TjdUiAppEbookPresenter::GetInstance()); } listLabel = new UILabelExt(); listLabel->SetPosition(0, 16, HORIZONTAL_RESOLUTION, 34); // listLabel->SetText("电子书"); listLabel->SetTextId(STR_ID_21); listLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); listLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); listLabel->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); listAdapter_ = new TjdEbookAdapter(); contentList_ = new UIListNested(UIList::VERTICAL); contentList_->SetViewId("contentList_"); contentList_->SetPosition(0, 0); contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); contentList_->SetScrollBlankSize((VERTICAL_RESOLUTION - EBOOK_ITEM_H) / 2); contentList_->SetSelectPosition((VERTICAL_RESOLUTION / 2) - 50); // middle position contentList_->SetThrowDrag(true); contentList_->EnableAutoAlign(true); contentList_->SetElastic(true); contentList_->SetStartIndex(0); contentList_->SetScrollStateListener(presenter_); contentList_->SetMaxScrollDistance(1000); contentList_->SetYScrollBarVisible(true); contentList_->RequestFocus(); listContainer_->Add(contentList_); listContainer_->Add(listLabel); return listContainer_; } int16_t TjdUiAppEbookView::GetListPosition(void) { return contentList_->GetChildrenHead()->GetY(); } void TjdUiAppEbookView::SetTitleVisible(bool visible) { if (listLabel) listLabel->SetVisible(visible); } OHOS::UIScrollView *TjdUiAppEbookView::MainViewInit(void) { mainContainer_ = new UIScrollView(); mainContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); mainContainer_->SetTouchable(true); mainContainer_->SetVisible(false); mainContainer_->SetOnDragListener(TjdUiAppEbookPresenter::GetInstance()); backdropImage = new UIImageView(); backdropImage->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); backdropImage->SetStyle(STYLE_BACKGROUND_OPA, 255); mainContainer_->Add(backdropImage); txtName = new UILabel(); txtName->SetPosition(0, 42, HORIZONTAL_RESOLUTION, 40); txtName->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); txtName->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); txtName->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_34); mainContainer_->Add(txtName); nextViewText = new TextLabel(); nextViewText->SetPosition(47, 108, 371, 242 + 10); nextViewText->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); nextViewText->SetLineBreakMode(UILabel::LINE_BREAK_TRUNCATE); nextViewText->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); nextViewText->SetVisible(false); mainContainer_->Add(nextViewText); curViewText = new TextLabel(); curViewText->SetPosition(47, 108, 371, 242 + 10); curViewText->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); curViewText->SetLineBreakMode(UILabel::LINE_BREAK_TRUNCATE); curViewText->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); mainContainer_->Add(curViewText); lastViewText = new TextLabel(); lastViewText->SetPosition(47, 108, 371, 242 + 10); lastViewText->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); lastViewText->SetLineBreakMode(UILabel::LINE_BREAK_TRUNCATE); lastViewText->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); lastViewText->SetVisible(false); mainContainer_->Add(lastViewText); setButton = new UIButton(); setButton->SetPosition(193, 373, 80, 80); setButton->SetStyle(STYLE_BORDER_RADIUS, 0); setButton->SetStyle(STYLE_BACKGROUND_OPA, 0); setButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::ButtonState::PRESSED); ImageInfo *imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_SET, BOOK_BIN_PATH); setButton->SetImageSrc(imageinfo, imageinfo); setButton->SetOnClickListener(presenter_); mainContainer_->Add(setButton); lastButton = new UIButton(); lastButton->SetPosition(0, 373, 160, 93); lastButton->SetStyle(STYLE_BORDER_RADIUS, 0); lastButton->SetStyle(STYLE_BACKGROUND_OPA, 0); lastButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::ButtonState::PRESSED); imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_LAST_PAGE, BOOK_BIN_PATH); lastButton->SetImageSrc(imageinfo, imageinfo); lastButton->SetImagePosition(126, 23); lastButton->SetOnClickListener(presenter_); mainContainer_->Add(lastButton); nextButton = new UIButton(); nextButton->SetPosition(306, 373, 160, 93); nextButton->SetStyle(STYLE_BORDER_RADIUS, 0); nextButton->SetStyle(STYLE_BACKGROUND_OPA, 0); nextButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::ButtonState::PRESSED); imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_NEXT_PAGE, BOOK_BIN_PATH); nextButton->SetImageSrc(imageinfo, imageinfo); nextButton->SetImagePosition(7, 23); nextButton->SetOnClickListener(presenter_); mainContainer_->Add(nextButton); setWaitAnimator_ = new EbookWaitView(); mainContainer_->Add(setWaitAnimator_); return mainContainer_; } OHOS::UIScrollView *TjdUiAppEbookView::DeleteViewInit(void) { deleteContainer_ = new UIScrollView(); deleteContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); deleteContainer_->SetVisible(false); deleteContainer_->SetOnDragListener(TjdUiAppEbookPresenter::GetInstance()); deleteLabel = new UILabelExt(); deleteLabel->SetPosition(0, 166, HORIZONTAL_RESOLUTION, 50); // deleteLabel->SetText("删除"); deleteLabel->SetTextId(STR_ID_332); deleteLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); deleteLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); deleteLabel->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_42); deleteContainer_->Add(deleteLabel); deleteNameLabel = new TextLabel(); deleteNameLabel->SetPosition(0, 216, HORIZONTAL_RESOLUTION, 50); deleteNameLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); deleteNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); deleteNameLabel->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_42); deleteContainer_->Add(deleteNameLabel); cancelButton = new UIButton(); cancelButton->SetPosition(103, 326, 92, 92); ImageInfo *imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_CANCEL, BOOK_BIN_PATH); cancelButton->SetImageSrc(imageinfo, imageinfo); cancelButton->SetOnClickListener(presenter_); deleteContainer_->Add(cancelButton); confirmButton = new UIButton(); confirmButton->SetPosition(271, 326, 92, 92); // confirmButton->SetStyle(STYLE_BACKGROUND_COLOR,0xff202020); imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_CONFIRM_1, BOOK_BIN_PATH); confirmButton->SetImageSrc(imageinfo, imageinfo); confirmButton->SetOnClickListener(presenter_); deleteContainer_->Add(confirmButton); return deleteContainer_; } OHOS::UIScrollView *TjdUiAppEbookView::SettingViewInit(void) { settingContainer_ = new UIScrollView(); settingContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); settingContainer_->SetViewId("settingContainer_"); settingContainer_->SetVisible(false); settingContainer_->SetOnDragListener(TjdUiAppEbookPresenter::GetInstance()); UIScrollView *scrollView = new UIScrollView(); scrollView->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); settingContainer_->Add(scrollView); UIView *fillTopView = new UIView(); fillTopView->SetPosition(0, 0, HORIZONTAL_RESOLUTION, 98); scrollView->Add(fillTopView); for (int i = 0; i < 4; i++) { backdropButtons[i] = new EbookBackdropRadioButton(); backdropButtons[i]->SetPosition(58, 98); backdropButtons[i]->SetID(i); // backdropButtons[i]->SetLabelId(STR_ID_646); scrollView->Add(backdropButtons[i]); // FilpVFXButtons[i] = new EbookFilpVFXRadioButton(); // FilpVFXButtons[i]->SetPosition(8, 502 + i * (8 + 110)); // FilpVFXButtons[i]->SetFilpVFXID(i); // scrollView->Add(FilpVFXButtons[i]); if (i == 0) { backdropButtons[0]->SetRadioColor(STYLE_BORDER_COLOR, 0xff00ff00); backdropButtons[0]->SetRadioStatus(UICheckBox::UICheckBoxState::SELECTED); // FilpVFXButtons[i]->SetRadioStatus(UICheckBox::UICheckBoxState::SELECTED); // FilpVFXButtons[i]->SetLabelText("平推"); } else if (i == 1) { backdropButtons[1]->SetPosition(58 + 30 + backdropButtons[1]->GetWidth(), 98, 163, 123); backdropButtons[1]->SetRadioColor(STYLE_BACKGROUND_COLOR, 0xff423930); // FilpVFXButtons[i]->SetLabelText("覆盖"); } else if (i == 2) { backdropButtons[2]->SetPosition(58, 98 + 34 + backdropButtons[2]->GetHeight(), 163, 123); ImageInfo *imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_BREVIARY_BJ_01, BOOK_BIN_PATH); backdropButtons[2]->SetRadioImage(imageinfo, imageinfo); // FilpVFXButtons[i]->SetLabelText("十字折叠"); } else if (i == 3) { backdropButtons[3]->SetPosition(58 + 30 + backdropButtons[3]->GetWidth(), 98 + 34 + backdropButtons[3]->GetHeight(), 163, 123); ImageInfo *imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_BREVIARY_BJ_02, BOOK_BIN_PATH); backdropButtons[3]->SetRadioImage(imageinfo, imageinfo); // FilpVFXButtons[i]->SetLabelText("仿真翻页"); } // std::string str = "背景" + std::to_string(i + 1); std::string str = std::string(FontGlobalManager::GetInstance()->GetText(STR_ID_646)) + std::to_string(i + 1); backdropButtons[i]->SetLabelText(str.c_str()); } // UILabel *label = new UILabel(); // label->SetPosition(50, 453, HORIZONTAL_RESOLUTION - 50, 33); // label->SetText("翻页效果"); // label->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_TOP); // label->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); // label->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); // scrollView->Add(label); setConfirmButton = new UIButton(); // setConfirmButton->SetPosition(52, 1065, 362, 86);//旧版 setConfirmButton->SetPosition(187, 416, 92, 92); setConfirmButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff202020); ImageInfo *imageinfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_CONFIRM_2, BOOK_BIN_PATH); setConfirmButton->SetImageSrc(imageinfo, imageinfo); setConfirmButton->SetOnClickListener(presenter_); scrollView->Add(setConfirmButton); return settingContainer_; } bool TjdUiAppEbookView::ShowNoneView(EbookView hideView) { static_print_info("TjdUiAppEbookView::%s hideView: %d", __func__, hideView); if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[EbookView::EBOOK_NONE_VIEW] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } groupList_[EbookView::EBOOK_NONE_VIEW]->SetVisible(true); presenter_->currentView = EBOOK_NONE_VIEW; return true; } bool TjdUiAppEbookView::ShowListView(EbookView hideView) { static_print_info("TjdUiAppEbookView::%s hideView: %d", __func__, hideView); if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[EbookView::EBOOK_LIST_VIEW] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } if (setWaitAnimator_ != nullptr) { setWaitAnimator_->HideView(); } groupList_[EbookView::EBOOK_LIST_VIEW]->SetVisible(true); presenter_->currentView = EBOOK_LIST_VIEW; if (listAdapter_->GetList().size() == 0) { ShowNoneView(presenter_->currentView); return true; } return true; } bool TjdUiAppEbookView::ShowMainView(EbookView hideView) { static_print_info("TjdUiAppEbookView::%s hideView: %d", __func__, hideView); if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[EbookView::EBOOK_MAIN_VIEW] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } groupList_[EbookView::EBOOK_MAIN_VIEW]->SetVisible(true); presenter_->currentView = EBOOK_MAIN_VIEW; return true; } bool TjdUiAppEbookView::ShowDeleteView(EbookView hideView) { static_print_info("TjdUiAppEbookView::%s hideView: %d", __func__, hideView); if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[EbookView::EBOOK_DELETE_VIEW] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } std::string str = "《" + presenter_->GetSelectedEbookItem()->name + "》?"; deleteNameLabel->SetText(str.c_str()); groupList_[EbookView::EBOOK_DELETE_VIEW]->SetVisible(true); presenter_->currentView = EBOOK_DELETE_VIEW; return true; } bool TjdUiAppEbookView::ShowSettingView(EbookView hideView) { static_print_info("TjdUiAppEbookView::%s hideView: %d", __func__, hideView); if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[EbookView::EBOOK_SETTING_VIEW] == nullptr) { static_print_error("TjdUiAppEbookView::%s: groupList_ is nullptr", __func__); return false; } // printf("view id: %s\n", groupList_[EbookView::EBOOK_SETTING_VIEW]->GetViewId()); groupList_[EbookView::EBOOK_SETTING_VIEW]->SetVisible(true); presenter_->currentView = EBOOK_SETTING_VIEW; return true; } bool TjdUiAppEbookView::ChangeView(EbookView view, EbookView hideView) { static_print_info("TjdUiAppEbookView::%s", __func__); if (view >= EBOOK_VIEW_MAX || hideView >= EBOOK_VIEW_MAX) { return false; } if (viewMapper_[view] == nullptr || viewMapper_[hideView] == nullptr) { return false; } (GetInstance()->*viewMapper_[view])(hideView); return true; } void TjdUiAppEbookView::ResetListPosition(void) { if (contentList_ == nullptr) { return; } auto head = contentList_->GetChildrenHead(); while (head != nullptr) { auto item = dynamic_cast(head); item->GetScrollView()->ScrollBy(EBOOK_DELECT_ICON_INTERVAL + EBOOK_DELECT_ICON_W, 0); head = head->GetNextSibling(); } } void TjdUiAppEbookView::DeleteEbookItemFromList(uint32_t id) { TjdUiAppEbookModel::GetInstance().deleteBookById(BOOK_JSON_PATH, id); presenter_->GetBookListData().clear(); TjdUiAppEbookModel::GetInstance().LoadBooksFromJson(BOOK_JSON_PATH, presenter_->GetBookListData()); UpdateEbookAdapter(presenter_->GetBookListData()); contentList_->SetAdapter(listAdapter_); contentList_->RefreshList(); if (presenter_->GetBookListData().size() == 0) { return; } else if (presenter_->GetBookListData().size() == id) { contentList_->ScrollBy(((VERTICAL_RESOLUTION - EBOOK_ITEM_H) / 2) - (EBOOK_ITEM_H + EBOOK_ITEM_MARGIN_BOTTOM) * (id - 1)); } else { contentList_->ScrollBy(((VERTICAL_RESOLUTION - EBOOK_ITEM_H) / 2) - (EBOOK_ITEM_H + EBOOK_ITEM_MARGIN_BOTTOM) * id); } } void TjdUiAppEbookView::SetBackdrop(void) { ImageInfo *image; switch (selectedBackDropID) { case 0: backdropImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); break; case 1: backdropImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff423930); break; case 2: image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_BJ_01, BOOK_BIN_PATH); backdropImage->SetSrc(image); break; case 3: image = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_EBOOK_BJ_02, BOOK_BIN_PATH); backdropImage->SetSrc(image); break; default: break; } } void TjdUiAppEbookView::UpdateEbookAdapter(std::list &list) { listAdapter_->DeleteListAllItem(); for (auto it = list.begin(); it != list.end(); it++) { listAdapter_->GetList().emplace_back((*it).id, (*it).name, (*it).curChapter, (*it).curPage, (*it).loadOver); } } EbookWaitView::EbookWaitView() { Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); animator_.SetPosition(150, 113, 166, 164); // InitLabelHorCenter(desc_, 34, 287, 466, "加载中,请稍后..."); desc_.SetFont(TJD_VECTOR_FONT_FILENAME, 34); desc_.SetTextId(STR_ID_647); desc_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP); desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); desc_.SetPosition(83, 287, 300, 50); WaitAnimatorImageInfo(); animator_.SetImageAnimatorSrc(g_pv_waitInfo_, 11, 100); animator_.Start(); Add(&animator_); Add(&desc_); } EbookWaitView::~EbookWaitView() { animator_.Stop(); WaitAnimatorImageInfoUnload(); RemoveAll(); } void EbookWaitView::ShowView() { animator_.Start(); SetVisible(true); } void EbookWaitView::HideView() { animator_.Stop(); SetVisible(false); } } // namespace TJD