#include "TjdUiAppAlbumView.h" #include "NativeAbility.h" #include "TjdUiAppAlbumPresenter.h" #include "TjdUiAppMainView.h" #include "TjdUiMemManage.h" #include "TjdUiMultiLanguageExt.h" #include "TjdUiScreenManage.h" #include "common/image_cache_manager.h" #include "graphic_service.h" #include "mem_api.h" #include "sys_config.h" #include #include #include #include #define ENABLE_PRINT_INFO 1 #define ENABLE_DEBUG 0 #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; static constexpr int16_t VIDEO_WIDTH = HORIZONTAL_RESOLUTION; static constexpr int16_t VIDEO_HEIGHT = VERTICAL_RESOLUTION; static constexpr int16_t STRIDE_ALIGNMENT_VALUE = 128; static constexpr int16_t BUFFER_QUEUE_SIZE = 3; static constexpr int16_t JPEG_HEIGHT_DIVISOR = 2; static constexpr int16_t JPEG_WIDTH_BYTE_ALIGNMENT = 128; static constexpr int16_t JPEG_HEIGHT_BYTE_ALIGNMENT = 16; static constexpr int16_t USEC_TO_MILLI = 1000; static constexpr int16_t TIME_CONVERT = 60; // sec to min, and min to hor static constexpr int16_t TEXT_BUFFER_SIEZ = 20; static constexpr int16_t TEXT_FONT_SIEZ = 40; static constexpr int16_t MAX_SCROLL_DIS = 1000; static constexpr int16_t VIDEO_FORWARD_BACKWARD_TIME = 5000; namespace TJD { #define ALBUM_LOADING_IMAGE_BIN_PATH TJD_IMAGE_PATH "img_loading.bin" #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(ALBUM_LOADING_IMAGE_BIN_PATH); for (int i = 0; i < WAIT_ANIMATOR_COUNT; i++) { g_pv_waitInfo_[i].imageInfo = imgManager.LoadOneInMultiRes(waitAnimatorId[i], ALBUM_LOADING_IMAGE_BIN_PATH); g_pv_waitInfo_[i].pos = {174, 135}; 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(ALBUM_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); } static std::string millisecondsToTimeString(long milliseconds) { int seconds = milliseconds / 1000; // 毫秒转换为秒 int hours = seconds / 3600; // 秒转换为小时 int minutes = (seconds % 3600) / 60; // 秒中剩余的部分转换为分钟 int secs = seconds % 60; // 剩余的就是秒 // 使用std::ostringstream来构建字符串 std::ostringstream oss; oss << std::setfill('0') << std::setw(2) << hours << ":" << std::setfill('0') << std::setw(2) << minutes << ":" << std::setfill('0') << std::setw(2) << secs; return oss.str(); // 返回构建好的字符串 } static void WaitAlbumVideoStart(void *param) { AlbumVideoOnClickListener *listener = static_cast(param); listener->LoadVideoStart(); } static void AlbumVideoTimerCallback(void *param) { AlbumVideoOnClickListener *listener = static_cast(param); GraphicService::GetInstance()->PostGraphicEvent(std::bind(WaitAlbumVideoStart, listener)); } static void SettingTimerCallback(void *param) { GraphicService::GetInstance()->PostGraphicEvent(std::bind( [](void *param) { auto presenter = static_cast(param); presenter->isSetSucc = false; NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN); }, param)); } AlbumVideoOnClickListener::AlbumVideoOnClickListener(AlbumVideoPlayer *player, OHOS::UILabel *totalTime, OHOS::Animator *animator) : player_(player), totalTime_(totalTime), animator_(animator) { timer_ = new GraphicTimer(100, AlbumVideoTimerCallback, this, true); } AlbumVideoOnClickListener::~AlbumVideoOnClickListener() { player_ = nullptr; totalTime_ = nullptr; animator_ = nullptr; if (timer_ != nullptr) { delete timer_; timer_ = nullptr; } } void AlbumVideoOnClickListener::PauseResumeButtonSwitch(AlbumIconType icon) { for (int i = 0; i < ALBUM_BUTTON_NUM; i++) { if (player_->buttonArray_[i]->GetViewId() == std::string(PAUSE_RESUME_BUTTON)) { ImageInfo *imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(icon); player_->buttonArray_[i]->SetImageSrc(imageinfo, imageinfo); player_->buttonArray_[i]->Invalidate(); break; } } } void AlbumVideoOnClickListener::VideoForward(void) { if (player_->isPlayed_ || player_->isPause_) { int64_t time = 0; player_->GetCurrentPosition(&time); static_print_debug("player_->GetCurrentPosition: %d\n", time); time += VIDEO_FORWARD_BACKWARD_TIME; time = time > player_->GetDurationTime() ? player_->GetDurationTime() : time; player_->SeekVideoPlay(time); animator_->SetRunTime(time); } } void AlbumVideoOnClickListener::VideoBackward(void) { if (player_->isPlayed_ || player_->isPause_) { int64_t time = 0; player_->GetCurrentPosition(&time); static_print_debug("player_->GetCurrentPosition: %d\n", time); time -= VIDEO_FORWARD_BACKWARD_TIME; time = time < 0 ? 0 : time; player_->SeekVideoPlay(time); animator_->SetRunTime(time); } } void AlbumVideoOnClickListener::LoadVideoStart(void) { static_print_debug("AlbumVideoOnClickListener::LoadVideoStart\n"); if (player_->isPlayed_) { int64_t time = player_->GetDurationTime(); animator_->SetTime(time); totalTime_->SetText(millisecondsToTimeString(time).c_str()); animator_->Start(); timer_->Stop(); } } void AlbumVideoOnClickListener::SetVideoWallPaper(void) { player_->PauseVideoPlay(); animator_->Pause(); PauseResumeButtonSwitch(ALBUM_RESUME); TjdUiAppAlbumView::GetInstance()->isEnterFromVideo_ = true; TjdUiAppAlbumView::GetInstance()->ShowPhotoView(TjdUiAppAlbumPresenter::GetInstance()->currentView); } #define SCREEN_AUTO_OFF_TIME (1000 * 60 * 60) bool AlbumVideoOnClickListener::OnClick(UIView &view, const ClickEvent &event) { int32_t ret = 0; if (player_ == nullptr) { static_print_error("AlbumVideoOnClickListener::%s player_ is nullptr!", __func__); return true; } if (animator_ == nullptr) { static_print_error("AlbumVideoOnClickListener::%s animator_ is nullptr!", __func__); return true; } static_print_info("AlbumVideoOnClickListener::%s viewid: %s", __func__, view.GetViewId()); if (view.GetViewId() == std::string(PAUSE_RESUME_BUTTON)) { if (player_->isExited_ || !player_->isEntered_) { ret = player_->StartVideoPlay(); timer_->Start(); PauseResumeButtonSwitch(ALBUM_PAUSE); TjdUiScreenManage::SetScreenKeepOnTimeout(SCREEN_AUTO_OFF_TIME); return true; } if (player_->isPause_) { ret = player_->ResumeVideoPlay(); animator_->Resume(); if (ret == 0) { PauseResumeButtonSwitch(ALBUM_PAUSE); } } else { ret = player_->PauseVideoPlay(); animator_->Pause(); if (ret == 0) { PauseResumeButtonSwitch(ALBUM_RESUME); } } } else if (view.GetViewId() == std::string(FORWARD_BUTTON)) { VideoForward(); } else if (view.GetViewId() == std::string(BACKWARD_BUTTON)) { VideoBackward(); } else if (view.GetViewId() == std::string(WALLPAPER_BUTTON)) { SetVideoWallPaper(); } return true; } void AlbumVideoAnimatorCallback::Callback(OHOS::UIView *view) { UNUSED(view); if (videoAnimator_ == nullptr) { static_print_error("AlbumVideoAnimatorCallback::%s animator is nullptr, please call SetAnimator first"); return; } // uint32_t runTime = videoAnimator_->GetRunTime(); int64_t runTime = 0; TjdUiAppAlbumView::GetInstance()->GetVideoPlayer()->GetCurrentPosition(&runTime); if (abs(runTime - lastTime) < 1000) { return; } static_print_debug("TjdUiAppAlbumView::GetInstance()->GetVideoPlayer()->GetCurrentPosition %d\n", runTime); lastTime = runTime; curlabel_->SetText(millisecondsToTimeString(runTime).c_str()); uint8_t present = ((float)runTime / videoAnimator_->GetTime()) * 100; static_print_debug("present: %d%%", present); present = present > 98 ? 98 : present; slider_->SetValue(present); } void AlbumVideoAnimatorCallback::OnStop(OHOS::UIView &view) { UNUSED(view); ImageInfo *imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_RESUME); button_->SetImageSrc(imageinfo, imageinfo); button_->Invalidate(); curlabel_->SetText(millisecondsToTimeString(0).c_str()); totallabel_->SetText(millisecondsToTimeString(0).c_str()); slider_->SetValue(2); lastTime = 0; TjdUiScreenManage::ResetScreenKeepOnTimeout(); } bool AlbumVideoAnimatorCallback::SetAnimator(OHOS::Animator *animator) { if (animator == nullptr) { static_print_error("AlbumVideoAnimatorCallback::%s animator is nullptr", __func__); return false; } videoAnimator_ = animator; return true; } bool AlbumUIScrollView::OnDragStartEvent(const OHOS::DragEvent &event) { if (TjdUiAppAlbumPresenter::GetInstance()->GetCurrentView() != ALBUM_LIST_VIEW) { return true; } isOnStart_ = true; return OHOS::UIScrollViewNested::OnDragStartEvent(event); } bool AlbumUIScrollView::OnDragEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } if (TjdUiAppAlbumPresenter::GetInstance()->GetCurrentView() != ALBUM_LIST_VIEW) { return true; } return OHOS::UIScrollViewNested::OnDragEvent(event); } bool AlbumUIScrollView::OnDragEndEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } isOnStart_ = false; if (TjdUiAppAlbumPresenter::GetInstance()->GetCurrentView() != ALBUM_LIST_VIEW) { return true; } return OHOS::UIScrollViewNested::OnDragEndEvent(event); } static TjdUiAppAlbumView *g_pv_UiAppAlbumView = nullptr; TjdUiAppAlbumView::TjdUiAppAlbumView() { g_pv_UiAppAlbumView = this; static_print_info("TjdUiAppAlbumView::%s", __func__); } TjdUiAppAlbumView::~TjdUiAppAlbumView() { static_print_info("TjdUiAppAlbumView::%s", __func__); g_pv_UiAppAlbumView = nullptr; if (setTimer_ != nullptr) { setTimer_->Stop(); delete setTimer_; setTimer_ = nullptr; } if (jumpTimerId_ != nullptr) { osTimerDelete(jumpTimerId_); jumpTimerId_ = nullptr; } if (contentList_ != nullptr) { contentList_->ClearFocus(); delete contentList_; contentList_ = nullptr; } if (listAdapter_ != nullptr) { delete listAdapter_; listAdapter_ = nullptr; } if (videoPlay_ != nullptr) { delete videoPlay_; videoPlay_ = nullptr; } if (clickListener != nullptr) { delete clickListener; clickListener = nullptr; } if (videoAnimator_ != nullptr) { videoAnimator_->Stop(); delete videoAnimator_; videoAnimator_ = nullptr; } if (animatorCallback_ != nullptr) { delete animatorCallback_; animatorCallback_ = nullptr; } if (setWaitAnimator_ != nullptr) { delete setWaitAnimator_; setWaitAnimator_ = nullptr; } TjdUiMemManage::DeleteChildren(containerAll_); } TjdUiAppAlbumView *TjdUiAppAlbumView::GetInstance(void) { return g_pv_UiAppAlbumView; } void TjdUiAppAlbumView::OnStart() { static_print_info("TjdUiAppAlbumView::%s", __func__); if (containerAll_ == nullptr) { containerAll_ = new AlbumUIScrollView(); containerAll_->SetViewId("containerAll_"); containerAll_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); containerAll_->SetStyle(STYLE_BACKGROUND_OPA, 0); // containerAll_->SetOnDragListener(presenter_); } groupList_[ALBUM_LIST_VIEW] = ListViewInit(); groupList_[ALBUM_PHOTO_VIEW] = PhotoViewInit(); groupList_[ALBUM_VIDEO_VIEW] = VideoViewInit(); groupList_[ALBUM_SETTING_VIEW] = SettingViewInit(); containerAll_->Add(groupList_[ALBUM_LIST_VIEW]); containerAll_->Add(groupList_[ALBUM_PHOTO_VIEW]); containerAll_->Add(groupList_[ALBUM_VIDEO_VIEW]); containerAll_->Add(groupList_[ALBUM_SETTING_VIEW]); ShowListView(presenter_->currentView); AddViewToRootContainer(containerAll_); } void TjdUiAppAlbumView::OnStop() { static_print_info("TjdUiAppAlbumView::%s", __func__); listContainer_->Remove(contentList_); settingContainer_->Remove(setWaitAnimator_); } OHOS::UIScrollViewNested *TjdUiAppAlbumView::ListViewInit(void) { static_print_debug("TjdUiAppAlbumView::%s", __func__); listContainer_ = new UIScrollViewNested(); listContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { listContainer_->SetOnDragListener(TjdUiAppAlbumPresenter::GetInstance()); } UILabelExt *noneLabel = new UILabelExt(); noneLabel->SetPosition(99, 192, 267, 50); noneLabel->SetViewId(NONE_ALBUM_LABEL); // noneLabel->SetText("请前往APP\n相册同步"); noneLabel->SetTextId(STR_ID_325); noneLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); noneLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); noneLabel->SetFont(TJD_VECTOR_FONT_FILENAME, 36); listContainer_->Add(noneLabel); listAdapter_ = new TjdAlbumAdapter(); presenter_->GetAlbumModel()->GetAllFiles(&GetAdapterList()); contentList_ = new UIListNested(UIList::VERTICAL); contentList_->SetViewId("contentList_"); contentList_->SetPosition(0, 0); contentList_->Resize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); contentList_->SetScrollBlankSize((VERTICAL_RESOLUTION - ALBUM_ITEM_H) / 2); contentList_->SetSelectPosition((VERTICAL_RESOLUTION / 2)); // middle position contentList_->SetThrowDrag(true); contentList_->EnableAutoAlign(true); contentList_->SetElastic(true); contentList_->SetStartIndex(0); contentList_->SetSwipeACCLevel(10); // 0-255 contentList_->SetDragACCLevel(8); // 5: drag acceleration contentList_->SetReboundSize(contentList_->GetHeight() >> 1); contentList_->SetScrollStateListener(presenter_); contentList_->SetMaxScrollDistance(MAX_SCROLL_DIS); contentList_->SetYScrollBarVisible(true); listContainer_->Add(contentList_); return listContainer_; } OHOS::UIScrollView *TjdUiAppAlbumView::PhotoViewInit(void) { static_print_debug("TjdUiAppAlbumView::%s", __func__); photoContainer_ = new UIScrollView(); photoContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); photoContainer_->SetVisible(false); photoContainer_->SetOnDragListener(TjdUiAppAlbumPresenter::GetInstance()); selectedPhoto_ = new UIImageView(); selectedPhoto_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); selectedPhoto_->SetViewId(SELECTED_PHOTO_IMAGE); selectedPhoto_->SetAutoEnable(false); selectedPhoto_->SetResizeMode(UIImageView::FILL); photoContainer_->Add(selectedPhoto_); UIImageView *settingButton = new UIImageView(); settingButton->SetPosition(77, 378, 312, 88); settingButton->SetViewId(SET_WALLPAPER_BUTTON); settingButton->SetTouchable(true); settingButton->SetSrc( ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_ALBUM_Z_SETTING_BG, ALBUM_IMAGE_BIN_PATH)); settingButton->SetOnClickListener(presenter_); photoContainer_->Add(settingButton); UILabelExt *lbSetDial = new UILabelExt(); lbSetDial->SetFont(TJD_VECTOR_FONT_FILENAME, 30); lbSetDial->SetTextId(STR_ID_565); lbSetDial->SetViewId("lbSetDial"); // lbSetDial->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); lbSetDial->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); lbSetDial->SetPosition(0, 407, 466, 40); photoContainer_->Add(lbSetDial); UIButton *button1 = new UIButton(); button1->SetPosition(103, 326, 92, 92); button1->SetViewId(SET_CANCEL_BUTTON); ImageInfo *imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_CANCEL); button1->SetImageSrc(imageinfo, imageinfo); button1->SetVisible(false); button1->SetStyle(STYLE_BACKGROUND_OPA, 0); button1->SetOnClickListener(presenter_); photoContainer_->Add(button1); UIButton *button2 = new UIButton(); button2->SetPosition(271, 326, 92, 92); button2->SetViewId(SET_CONFIRM_BUTTON); button2->SetStyle(STYLE_BACKGROUND_OPA, 0); imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_CONFIRM); button2->SetImageSrc(imageinfo, imageinfo); button2->SetVisible(false); button2->SetOnClickListener(presenter_); photoContainer_->Add(button2); UILabelExt *label = new UILabelExt(); label->SetPosition(0, 214, 466, 50); label->SetViewId(SET_WALLPAPER_LABEL); // label->SetText("是否设置为表盘?");//409 label->SetTextId(STR_ID_409); // label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label->SetFont(TJD_VECTOR_FONT_FILENAME, 36); label->SetVisible(false); photoContainer_->Add(label); return photoContainer_; } OHOS::UIScrollView *TjdUiAppAlbumView::VideoViewInit(void) { static_print_debug("TjdUiAppAlbumView::%s", __func__); videoContainer_ = new UIScrollView(); videoContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); videoContainer_->SetVisible(false); videoContainer_->SetOnDragListener(TjdUiAppAlbumPresenter::GetInstance()); surfaceView_ = new AlbumSurfaceView(); surfaceView_->SetViewId("sur"); surfaceView_->SetPosition(0, 0, VIDEO_WIDTH, VIDEO_HEIGHT); surfaceView_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); colorKey_.full = 0xff3184d7; surfaceView_->SetSurfaceColorkey(colorKey_); videoContainer_->Add(surfaceView_); playContainer_ = new UIScrollView(); playContainer_->SetPosition(0, 271, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION - 271); playContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); videoContainer_->Add(playContainer_); int screenWidth = 466; int buttonWidth = 100; int spacing = 10; int totalWidth = 4 * buttonWidth + 3 * spacing; int startX = (screenWidth - totalWidth) / 2; for (int i = 0; i < ALBUM_BUTTON_NUM; i++) { buttonArray_[i] = new UIButton(); int buttonX = startX + i * (buttonWidth + spacing); buttonArray_[i]->SetPosition(buttonX, 0, 100, 70); buttonArray_[i]->SetStyle(STYLE_BACKGROUND_OPA, 0); buttonArray_[i]->SetStyleForState(STYLE_BACKGROUND_OPA, 0, UIButton::PRESSED); buttonArray_[i]->SetImagePosition((buttonArray_[i]->GetWidth() - 50) / 2, (buttonArray_[i]->GetHeight() - 50) / 2); } buttonArray_[0]->SetViewId(BACKWARD_BUTTON); ImageInfo *imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_BACKWARD); buttonArray_[0]->SetImageSrc(imageinfo, imageinfo); buttonArray_[1]->SetViewId(PAUSE_RESUME_BUTTON); imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_RESUME); buttonArray_[1]->SetImageSrc(imageinfo, imageinfo); buttonArray_[2]->SetViewId(FORWARD_BUTTON); imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_FORWARD); buttonArray_[2]->SetImageSrc(imageinfo, imageinfo); buttonArray_[3]->SetViewId(WALLPAPER_BUTTON); imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_WALLPAPER); buttonArray_[3]->SetImageSrc(imageinfo, imageinfo); videoSlider_ = new UISlider(); videoSlider_->SetPosition(73, 367 - 271, 320, 20); videoSlider_->SetStyle(STYLE_BORDER_RADIUS, 29); videoSlider_->SetValidWidth(320); videoSlider_->SetValidHeight(14); videoSlider_->SetValue(2); videoSlider_->SetKnobWidth(14); videoSlider_->SetKnobRadius(7); videoSlider_->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); videoSlider_->SetCapType(CAP_ROUND); videoSlider_->SetKnobStyle(STYLE_BACKGROUND_COLOR, 0xff00E345); videoSlider_->SetSliderColor(Color::GetColorFromRGBA(0, 45, 14, 0xff), Color::GetColorFromRGBA(0, 227, 29, 0xff)); playContainer_->Add(videoSlider_); UILabel *slashLabel = new UILabel(); slashLabel->SetPosition(234, 407 - 271); slashLabel->SetText("/"); slashLabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); slashLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); slashLabel->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_24); playContainer_->Add(slashLabel); videoTotalTime_ = new UILabel(); videoTotalTime_->SetPosition(244, 407 - 271); videoTotalTime_->SetText("00:00:00"); videoTotalTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); videoTotalTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); videoTotalTime_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_24); playContainer_->Add(videoTotalTime_); videoCurTime_ = new UILabel(); videoCurTime_->SetPosition(141, 407 - 271, 93, 23); videoCurTime_->SetText("00:00:00"); videoCurTime_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); videoCurTime_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); videoCurTime_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_24); playContainer_->Add(videoCurTime_); Surface *surface = surfaceView_->GetSurface(); surface->SetStrideAlignment(STRIDE_ALIGNMENT_VALUE); surface->SetWidthAndHeight(VIDEO_WIDTH, VIDEO_HEIGHT); surface->SetQueueSize(BUFFER_QUEUE_SIZE); surface->SetFormat(PIXEL_FMT_YCBCR_420_SP); // jpeg decoder output buffer size calculation formula int32_t ySize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * VIDEO_HEIGHT; int32_t uvSize = ALIGN_BYTE(VIDEO_WIDTH, JPEG_WIDTH_BYTE_ALIGNMENT) * ALIGN_BYTE(VIDEO_HEIGHT, JPEG_HEIGHT_BYTE_ALIGNMENT) / JPEG_HEIGHT_DIVISOR; int32_t bufferSize = ySize + uvSize; surface->SetSize(bufferSize); videoPlay_ = new AlbumVideoPlayer(surface, buttonArray_, "", false); videoPlay_->SetVideoPlayLoop(false); videoPlay_->SetSyncExitMode(true); animatorCallback_ = new AlbumVideoAnimatorCallback(videoCurTime_, videoTotalTime_, videoSlider_, buttonArray_[1]); videoAnimator_ = new Animator(animatorCallback_, nullptr, 0, false); animatorCallback_->SetAnimator(videoAnimator_); clickListener = new AlbumVideoOnClickListener(videoPlay_, videoTotalTime_, videoAnimator_); for (int i = 0; i < ALBUM_BUTTON_NUM; i++) { buttonArray_[i]->SetOnClickListener(clickListener); playContainer_->Add(buttonArray_[i]); } return videoContainer_; } OHOS::UIScrollView *TjdUiAppAlbumView::SettingViewInit(void) { static_print_debug("TjdUiAppAlbumView::%s", __func__); isSetWallPaperFail_ = false; if (settingContainer_ != nullptr) { settingContainer_->SetVisible(false); settingContainer_->GetChildById(SET_SUCC_IMAGE)->SetVisible(false); settingContainer_->GetChildById(SET_FAIL_IMAGE)->SetVisible(false); settingContainer_->GetChildById(SET_SUCC_LABEL)->SetVisible(false); settingContainer_->GetChildById(SET_FAIL_LABEL)->SetVisible(false); settingContainer_->GetChildById(SET_RESET_BUTTON)->SetVisible(false); return settingContainer_; } settingContainer_ = new UIScrollView(); settingContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); settingContainer_->SetVisible(false); settingContainer_->SetOnDragListener(TjdUiAppAlbumPresenter::GetInstance()); setWaitAnimator_ = new AlbumWaitView(); settingContainer_->Add(setWaitAnimator_); UIImageView *imageView1 = new UIImageView(); imageView1->SetPosition(151, 118, 166, 164); imageView1->SetViewId(SET_SUCC_IMAGE); ImageInfo *imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_SET_SUCC); imageView1->SetSrc(imageinfo); imageView1->SetVisible(false); settingContainer_->Add(imageView1); UIImageView *imageView2 = new UIImageView(); imageView2->SetPosition(153, 119, 170, 168); imageView2->SetViewId(SET_FAIL_IMAGE); imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_SET_FALSE); imageView2->SetSrc(imageinfo); imageView2->SetVisible(false); settingContainer_->Add(imageView2); UILabelExt *setSucc = new UILabelExt(); setSucc->SetPosition(161, 310, 127, 31); setSucc->SetViewId(SET_SUCC_LABEL); // setSucc->SetText("设置成功"); setSucc->SetTextId(STR_ID_327); setSucc->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); setSucc->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_TOP); setSucc->SetFont(TJD_VECTOR_FONT_FILENAME, 36); setSucc->SetVisible(false); settingContainer_->Add(setSucc); UILabelExt *setFail = new UILabelExt(); setFail->SetPosition(0, 310, 466, 47); setFail->SetViewId(SET_FAIL_LABEL); // setFail->SetText("设置失败"); setFail->SetTextId(STR_ID_566); // setFail->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); setFail->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); setFail->SetFont(TJD_VECTOR_FONT_FILENAME, 36); setFail->SetVisible(false); settingContainer_->Add(setFail); UIButton *resetButton = new UIButton(); resetButton->SetPosition(187, 352, 92, 92); resetButton->SetStyle(STYLE_BACKGROUND_OPA, 0); resetButton->SetViewId(SET_RESET_BUTTON); resetButton->SetStyle(STYLE_BORDER_RADIUS, 0); imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_RESET); resetButton->SetImageSrc(imageinfo, imageinfo); resetButton->SetVisible(false); resetButton->SetOnClickListener(presenter_); settingContainer_->Add(resetButton); setTimer_ = new GraphicTimer(2000, SettingTimerCallback, presenter_); return settingContainer_; } bool TjdUiAppAlbumView::ChangeView(AlbumView view, AlbumView hideView) { if (view >= ALBUM_VIEW_MAX || hideView >= ALBUM_VIEW_MAX) { return false; } if (viewMapper_[view] == nullptr || viewMapper_[hideView] == nullptr) { return false; } (GetInstance()->*viewMapper_[view])(hideView); return true; } void TjdUiAppAlbumView::ResetListPosition() { if (contentList_ == nullptr) { return; } auto head = contentList_->GetChildrenHead(); while (head != nullptr) { auto item = dynamic_cast(head); item->GetScrollView().ScrollBy(DELECT_ICON_INTERVAL + DELECT_ICON_W, 0); head = head->GetNextSibling(); } RefreshListView(); } void TjdUiAppAlbumView::RefreshListView(void) { if (GetAdapterList().size() > 0) { contentList_->SetVisible(true); listContainer_->GetChildById(NONE_ALBUM_LABEL)->SetVisible(false); } else { contentList_->SetVisible(false); listContainer_->GetChildById(NONE_ALBUM_LABEL)->SetVisible(true); } } void TjdUiAppAlbumView::EnterWallPaperSet(bool value) { if (value) { isEnterWallPaperSet_ = true; photoContainer_->GetChildById(SELECTED_PHOTO_IMAGE)->SetStyle(STYLE_IMAGE_OPA, 102); photoContainer_->GetChildById(SET_WALLPAPER_BUTTON)->SetVisible(false); photoContainer_->GetChildById("lbSetDial")->SetVisible(false); photoContainer_->GetChildById(SET_CONFIRM_BUTTON)->SetVisible(true); photoContainer_->GetChildById(SET_CANCEL_BUTTON)->SetVisible(true); photoContainer_->GetChildById(SET_WALLPAPER_LABEL)->SetVisible(true); } else { isEnterWallPaperSet_ = false; photoContainer_->GetChildById(SELECTED_PHOTO_IMAGE)->SetStyle(STYLE_IMAGE_OPA, 255); photoContainer_->GetChildById(SET_WALLPAPER_BUTTON)->SetVisible(true); photoContainer_->GetChildById("lbSetDial")->SetVisible(true); photoContainer_->GetChildById(SET_CONFIRM_BUTTON)->SetVisible(false); photoContainer_->GetChildById(SET_CANCEL_BUTTON)->SetVisible(false); photoContainer_->GetChildById(SET_WALLPAPER_LABEL)->SetVisible(false); } RootView::GetInstance()->Invalidate(); } void TjdUiAppAlbumView::EnterSetFail(bool value) { if (value) { isSetWallPaperFail_ = true; setWaitAnimator_->HideView(); settingContainer_->GetChildById(SET_FAIL_IMAGE)->SetVisible(true); settingContainer_->GetChildById(SET_FAIL_LABEL)->SetVisible(true); settingContainer_->GetChildById(SET_RESET_BUTTON)->SetVisible(true); } else { isSetWallPaperFail_ = false; setWaitAnimator_->ShowView(); StartJumpTimer(); AlbumItem *itemPtr = listAdapter_->GetListItem(presenter_->GetSelectedListId()); presenter_->TaskProcess(itemPtr); settingContainer_->GetChildById(SET_FAIL_IMAGE)->SetVisible(false); settingContainer_->GetChildById(SET_FAIL_LABEL)->SetVisible(false); settingContainer_->GetChildById(SET_RESET_BUTTON)->SetVisible(false); } settingContainer_->Invalidate(); } void TjdUiAppAlbumView::EnterSetSucc(void) { setWaitAnimator_->HideView(); settingContainer_->GetChildById(SET_SUCC_IMAGE)->SetVisible(true); settingContainer_->GetChildById(SET_SUCC_LABEL)->SetVisible(true); settingContainer_->Invalidate(); setTimer_->Start(); } void TjdUiAppAlbumView::StartJumpTimer() { if (jumpTimerId_ == nullptr) { jumpTimerId_ = osTimerNew( [](void *arg) { GraphicService::GetInstance()->PostGraphicEvent( []() { TjdUiAppAlbumView::GetInstance()->JumpTimerCallback(); }); }, osTimerPeriodic, nullptr, nullptr); if (jumpTimerId_ == nullptr) { return; } } else { static_print_error("StartJumpTimer: jumpTimerId_ is not null"); } int32_t ret = osTimerStart(jumpTimerId_, 500); if (ret != 0) { return; } } void TjdUiAppAlbumView::StopJumpTimer() { if (jumpTimerId_ == nullptr) { return; } int32_t ret = osTimerStop(jumpTimerId_); if (ret != 0) { static_print_error("TjdUiAppAlbumView::StopJumpTimer timer fail"); return; } } void TjdUiAppAlbumView::JumpTimerCallback() { static_print_debug("TjdUiAppAlbumView::JumpTimerCallback count:%d", jumpTimerCount_); if (++jumpTimerCount_ > 20) { // 10s后都没有收到设置成功,设置失败 jumpTimerCount_ = 0; EnterSetFail(true); StopJumpTimer(); return; } else if (presenter_->isSetSucc) { jumpTimerCount_ = 0; EnterSetSucc(); StopJumpTimer(); return; } } void TjdUiAppAlbumView::DeleteAlbumItemFromList(uint8_t index) { TjdUiAppAlbumModel::GetInstance().DeleteFile(listAdapter_->GetListItem(index)->type, listAdapter_->GetListItem(index)->path); listAdapter_->DeleteListItem(index); contentList_->RefreshList(); ResetListPosition(); } bool TjdUiAppAlbumView::ShowListView(AlbumView hideView) { if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (hideView == ALBUM_VIDEO_VIEW) { if (!videoPlay_->isEntered_) { static_print_debug("TjdUiAppAlbumView::%s video is not played", __func__); } else { for (int i = 0; i < ALBUM_BUTTON_NUM; i++) { if (videoPlay_->buttonArray_[i]->GetViewId() == std::string(PAUSE_RESUME_BUTTON)) { ImageInfo *imageinfo = TjdUiAppAlbumPresenter::GetInstance()->GetAlbumIcon(ALBUM_RESUME); videoPlay_->buttonArray_[i]->SetImageSrc(imageinfo, imageinfo); videoPlay_->buttonArray_[i]->Invalidate(); break; } } videoTotalTime_->SetText("00:00:00"); videoAnimator_->Stop(); videoPlay_->StopVideoPlay(); } } if (groupList_[AlbumView::ALBUM_LIST_VIEW] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } RefreshListView(); if (contentList_ != nullptr && presenter_->firstEnter_) { contentList_->RequestFocus(); contentList_->SetRotateFactor(1.0); } groupList_[AlbumView::ALBUM_LIST_VIEW]->SetVisible(true); groupList_[AlbumView::ALBUM_LIST_VIEW]->Invalidate(); presenter_->currentView = ALBUM_LIST_VIEW; return true; } bool TjdUiAppAlbumView::ShowPhotoView(AlbumView hideView) { if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (hideView == ALBUM_LIST_VIEW) { contentList_->ClearFocus(); } if (groupList_[AlbumView::ALBUM_PHOTO_VIEW] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } AlbumItem *itemPtr = listAdapter_->GetListItem(presenter_->GetSelectedListId()); selectedPhoto_->SetSrc(itemPtr->path); groupList_[AlbumView::ALBUM_PHOTO_VIEW]->SetVisible(true); groupList_[AlbumView::ALBUM_PHOTO_VIEW]->Invalidate(); presenter_->currentView = ALBUM_PHOTO_VIEW; return true; } bool TjdUiAppAlbumView::ShowVideoView(AlbumView hideView) { if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (hideView == ALBUM_LIST_VIEW) { contentList_->ClearFocus(); } AlbumItem *itemPtr = listAdapter_->GetListItem(presenter_->GetSelectedListId()); std::string uri = itemPtr->path; surfaceView_->SetPreview(uri); uri = uri.substr(0, uri.rfind('.') + 1) + "mp4"; videoPlay_->SetUri(uri); if (groupList_[AlbumView::ALBUM_VIDEO_VIEW] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } groupList_[AlbumView::ALBUM_VIDEO_VIEW]->SetVisible(true); groupList_[AlbumView::ALBUM_VIDEO_VIEW]->Invalidate(); presenter_->currentView = ALBUM_VIDEO_VIEW; return true; } bool TjdUiAppAlbumView::ShowSettingView(AlbumView hideView) { if (groupList_[hideView] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[AlbumView::ALBUM_SETTING_VIEW] == nullptr) { static_print_error("TjdUiAppAlbumView::%s: groupList_ is nullptr", __func__); return false; } setWaitAnimator_->ShowView(); AlbumItem *itemPtr = listAdapter_->GetListItem(presenter_->GetSelectedListId()); StartJumpTimer(); presenter_->TaskProcess(itemPtr); groupList_[AlbumView::ALBUM_SETTING_VIEW]->SetVisible(true); groupList_[AlbumView::ALBUM_SETTING_VIEW]->Invalidate(); presenter_->currentView = ALBUM_SETTING_VIEW; return true; } AlbumWaitView::AlbumWaitView() { 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_330); desc_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); desc_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); desc_.SetPosition(HorizontalCenter(desc_.GetWidth(), 466), 287); WaitAnimatorImageInfo(); animator_.SetImageAnimatorSrc(g_pv_waitInfo_, 11, 100); // animator_.Start(); Add(&animator_); Add(&desc_); } AlbumWaitView::~AlbumWaitView() { animator_.Stop(); WaitAnimatorImageInfoUnload(); RemoveAll(); } void AlbumWaitView::ShowView() { animator_.Start(); SetVisible(true); } void AlbumWaitView::HideView() { animator_.Stop(); SetVisible(false); } void AlbumSurfaceView::SetPreview(std::string res) { ImageInfo *imgInfo; if (lastRes_ == "") { imgInfo = ImageCacheManager::GetInstance().LoadSingleRes(res); UILiteSurfaceView::SetPreview(imgInfo); lastRes_ = res; } else { ImageCacheManager::GetInstance().UnloadSingleRes(lastRes_); imgInfo = ImageCacheManager::GetInstance().LoadSingleRes(res); UILiteSurfaceView::SetPreview(imgInfo); lastRes_ = res; } } void AlbumSurfaceView::UnsetPreview() { ImageCacheManager::GetInstance().UnloadSingleRes(lastRes_); lastRes_ = ""; } } // namespace TJD