/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: * * Author: liangjianfei * * Create: 2024-6 *--------------------------------------------------------------------------*/ #include "TjdUiAppWeatherView.h" #include "TjdUiAppMainPresenter.h" #include "TjdUiImageIds.h" #include "TjdUiMemManage.h" #include "TjdUiMultiLanguageExt.h" #include "common/image_cache_manager.h" #include "common_view/tjd_ui_no_connect.h" #include "graphic_service.h" #include "hal_tick.h" #include "sql_weather.h" #include "sys_config.h" #include "ui_screennotify.h" #include extern "C" { #include "task_ancillary.h" } using namespace OHOS; #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 #define WEATHER_BJ_CLOUDY_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_cloudy.bin" #define WEATHER_BJ_FOG_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_fog.bin" #define WEATHER_BJ_RAIN_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_rain.bin" #define WEATHER_BJ_SANDSTORM_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_sandstorm.bin" #define WEATHER_BJ_SNOW_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_snow.bin" #define WEATHER_BJ_SUNNY_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_sunny.bin" #define WEATHER_BJ_THUNDERSTORM_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_thunderstorm.bin" #define WEATHER_BJ_TYPHOON_BIN_PATH TJD_IMAGE_PATH "img_weather_bj_typhoon.bin" #define MAIN_WEATHER_BJ_BIN_PATH TJD_IMAGE_PATH "img_weather_bj.bin" #define MAIN_WEATHER_COMMON_BIN_PATH TJD_IMAGE_PATH "img_weather_common.bin" namespace TJD { static std::string g_loadAllPath = ""; static constexpr int16_t VIDEO_WIDTH = HORIZONTAL_RESOLUTION; static constexpr int16_t VIDEO_HEIGHT = VERTICAL_RESOLUTION; static constexpr int16_t NUM_2 = 2; static constexpr int16_t MAX_SCROLL_DIS = 1000; 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 STRIDE_ALIGNMENT_VALUE = 128; static constexpr int16_t BUFFER_QUEUE_SIZE = 3; static TjdUiAppWeatherView *g_pWeatherView = nullptr; static std::function g_postEventCallback = nullptr; struct EventInfo { signed int (*func_event_handler)(void *param); // 事件处理函数 void *param; // 事件处理函数入参 void (*func_event_debug)(char *str, ...); // 打印 void *payload; }; static signed int EventHandler(void *param) { if (g_postEventCallback != nullptr) { g_postEventCallback(); } return 0; } static void PostEventHandle(std::function event) { EventInfo g_msg_data = { .func_event_handler = EventHandler, .param = NULL, .func_event_debug = NULL, .payload = NULL, }; g_postEventCallback = event; static unsigned int g_msg_size = sizeof(EventInfo); osal_msg_queue_write_copy(tjd_task_ancillary_get_queue_id(), &g_msg_data, g_msg_size, 0); } static inline int LoadInfo(std::unique_ptr &refInfo, int resId, int size, const std::string &path) { auto &image = OHOS::ImageCacheManager::GetInstance(); OHOS::ImageInfo *imageInfo = nullptr; refInfo.reset(new OHOS::ImageAnimatorInfo[size]); for (int i = 0; i < size; ++i) { imageInfo = image.LoadOneInMultiRes(resId + i, path); refInfo[i].imageInfo = imageInfo; refInfo[i].pos = {0, 0}; refInfo[i].width = imageInfo->header.width; refInfo[i].height = imageInfo->header.height; refInfo[i].imageType = OHOS::IMG_SRC_IMAGE_INFO; } return size; } uint16_t GetWeekStr(uint8_t index) { switch (index) { case 0: return STR_ID_62; case 1: return STR_ID_56; case 2: return STR_ID_57; case 3: return STR_ID_58; case 4: return STR_ID_59; case 5: return STR_ID_60; case 6: return STR_ID_61; default: return STR_ID_645; } } WeatherInfoRes TjdUiAppWeatherView::GetWeatherInfoRes(const WeatherInfo &type) { int size = 0; int startRes = 0; std::string path = ""; // clang-format off switch (type) { case WeatherInfo::SQL_SUNNY: size = 20; startRes = IMG_WEATHER_BJ_SUNNY_CLEAR_01; path = WEATHER_BJ_SUNNY_BIN_PATH; break; case WeatherInfo::SQL_PARTLY_CLOUDY: case WeatherInfo::SQL_CLOUDY: size = 20; startRes = IMG_WEATHER_BJ_CLOUDY_CLOUDY_DT_01; path = WEATHER_BJ_CLOUDY_BIN_PATH; break; case WeatherInfo::SQL_SHOWER: case WeatherInfo::SQL_LIGHT_RAIN: case WeatherInfo::SQL_MODERATE_RAIN: case WeatherInfo::SQL_HEAVY_RAIN: size = 4; startRes = IMG_WEATHER_BJ_RAIN_RAIN_DT_01; path = WEATHER_BJ_RAIN_BIN_PATH; break; case WeatherInfo::SQL_THUNDERSTORM: size = 8; startRes = IMG_WEATHER_BJ_THUNDERSTORM_THUNDERSTORM_DT_01; path = WEATHER_BJ_THUNDERSTORM_BIN_PATH; break; case WeatherInfo::SQL_SNOWY: size = 10; startRes = IMG_WEATHER_BJ_SNOW_SNOW_DT_01; path = WEATHER_BJ_SNOW_BIN_PATH; break; case WeatherInfo::SQL_FOGGY: size = 20; startRes = IMG_WEATHER_BJ_FOG_FOG_DT_01; path = WEATHER_BJ_FOG_BIN_PATH; break; case WeatherInfo::SQL_DUSTSTORM: size = 6; startRes = IMG_WEATHER_BJ_SANDSTORM_SANDSTORM_DT_01; path = WEATHER_BJ_SANDSTORM_BIN_PATH; break; case WeatherInfo::SQL_TYPHOON: size = 5; startRes = IMG_WEATHER_BJ_TYPHOON_TYPHOON_DT_01; path = WEATHER_BJ_TYPHOON_BIN_PATH; break; default: break; } // clang-format on return {startRes, size, path}; } TjdUiAppWeatherView::TjdUiAppWeatherView() { g_pWeatherView = this; } TjdUiAppWeatherView *TjdUiAppWeatherView::GetInstance(void) { return g_pWeatherView; } // static void ScreenStatusNotify(ScreenStatus status) // { // if (TjdUiAppWeatherPresenter::GetInstance()->GetCurSwipePage() != 0) // return; // } void TjdUiAppWeatherView::OnStart() { static_print_info("[TjdUiAppWeatherView]::%s", __func__); // View::OnStart(); TjdUiAppWeatherModel::GetInstance().LoadCurWeatherData(); presenter_->SetCurWeather(SetCurWeather(TjdUiAppWeatherModel::GetInstance().GetWeather())); presenter_->validWeatherLen = TjdUiAppWeatherModel::GetInstance().LoadWeekWeatherInfo(presenter_->preWeekWeather); if (containerAll_ == nullptr) { containerAll_ = new UIViewGroup(); containerAll_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); containerAll_->SetStyle(STYLE_BACKGROUND_OPA, 0); } bgStatic_ = new OHOS::UIImageView(); bgStatic_->SetPosition(0, 0, OHOS::Screen::GetInstance().GetWidth(), OHOS::Screen::GetInstance().GetHeight()); // ImageInfo *imgInfo = // ImageCacheManager::GetInstance().LoadOneInMultiRes(curInfo_.startResId, curInfo_.startResId.path); containerAll_->Add(bgStatic_); bgAnimator_ = new OHOS::UIImageAnimatorView(); bgAnimator_->SetPosition(0, 0, OHOS::Screen::GetInstance().GetWidth(), OHOS::Screen::GetInstance().GetHeight()); bgAnimator_->SetVisible(false); containerAll_->Add(bgAnimator_); if (swipeContainer_ == nullptr) { swipeContainer_ = new UISwipeViewNested(UISwipeView::VERTICAL); swipeContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); swipeContainer_->SetViewId(WEATHER_SWIPEVIEW_ID); swipeContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { swipeContainer_->SetOnDragListener(presenter_); } swipeContainer_->SetOnSwipeListener(presenter_); swipeContainer_->SetVisible(true); } swipeContainer_->Add(FirstPageViewInit()); swipeContainer_->Add(SecondPageViewInit()); swipeContainer_->Add(ThirdPageViewInit()); if (presenter_->validWeatherLen > 4) { swipeContainer_->Add(FourthPageViewInit()); } printf("UpdateCurWeatherInfo pre time:%lld", HALTick::GetInstance().GetTime()); UpdateCurWeatherInfo(); printf("UpdateCurWeatherInfo after time:%lld", HALTick::GetInstance().GetTime()); groupList_[SWIPEPAGE] = swipeContainer_; groupList_[MINDPAGE] = MindPageViewInit(); groupList_[NO_CONNECT_PAGE] = new TjdUINoConnectView(); groupList_[NO_CONNECT_PAGE]->SetDraggable(true); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { groupList_[NO_CONNECT_PAGE]->SetOnDragListener(presenter_); } groupList_[NO_CONNECT_PAGE]->SetVisible(false); for (int i = 0; i < WEATHERSLICEPAGE_MAX; i++) { containerAll_->Add(groupList_[i]); } AddViewToRootContainer(containerAll_); // registerNotifyScreenStatus(ScreenStatusNotify); } void TjdUiAppWeatherView::OnStop() { static_print_info("[TjdUiAppWeatherView]::%s", __func__); } TjdUiAppWeatherView::~TjdUiAppWeatherView() { static_print_info("[TjdUiAppWeatherView]::%s", __func__); // deregisterNotifyScreenStatus(ScreenStatusNotify); g_pWeatherView = nullptr; if (bgAnimator_) { bgAnimator_->Stop(); containerAll_->Remove(bgAnimator_); delete bgAnimator_; bgAnimator_ = nullptr; } if (!g_loadAllPath.empty()) { OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(g_loadAllPath.c_str()); g_loadAllPath.clear(); } ImageCacheManager::GetInstance().UnloadAllInMultiRes(MAIN_WEATHER_COMMON_BIN_PATH); TjdUiMemManage::DeleteChildren(containerAll_); } UIViewGroup *TjdUiAppWeatherView::FirstPageViewInit(void) { firstPageContainer_ = new UIViewGroup(); if (firstPageContainer_ == nullptr) { static_print_error("%s: firstPageContainer_ is nullptr", __func__); return nullptr; } firstPageContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); firstPageContainer_->SetViewId("firstPageContainer_"); firstPageContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); ImageInfo *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_DINGWEI_ICON, WEATHER_COMMON_BIN_PATH); UIImageView *localPosIcon_ = new UIImageView(); localPosIcon_->SetPosition(140, 150); localPosIcon_->Resize(24, 28); localPosIcon_->SetViewId("localPosIcon_"); if (imgInfo != nullptr) { localPosIcon_->SetSrc(imgInfo); } firstPageContainer_->Add(localPosIcon_); /*-----------------------------Add localPos_ to App------------------------------*/ UILabel *localPos_ = new UILabel(); if (localPos_ != nullptr) { localPos_->SetPosition(180, 148, 230, 24); localPos_->SetViewId(WEATHER_LOCATION); localPos_->SetStyle(STYLE_TEXT_FONT, 24); localPos_->SetText(presenter_->GetWeatherModel()->GetLocation()); localPos_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); localPos_->SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER); localPos_->SetFont(TJD_VECTOR_FONT_FILENAME, 24); firstPageContainer_->Add(localPos_); } else { static_print_error("%s: localPos_ is nullptr", __func__); } /*-----------------------------Add label2_ to App------------------------------*/ UILabel *currentTemp_ = new UILabel(); if (currentTemp_ != nullptr) { currentTemp_->SetPosition(55, 200, 160, 58); currentTemp_->SetViewId(WEATHER_CUR_TEMP); currentTemp_->SetText(std::to_string(presenter_->GetWeatherModel()->GetCurTemperature()).c_str()); currentTemp_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); currentTemp_->SetAlign(OHOS::TEXT_ALIGNMENT_RIGHT, OHOS::TEXT_ALIGNMENT_CENTER); currentTemp_->SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 82); firstPageContainer_->Add(currentTemp_); } else { static_print_error("%s: currentTemp_ is nullptr", __func__); } UILabel *currentTempUnit_ = new UILabel(); if (currentTempUnit_ != nullptr) { currentTempUnit_ = new UILabel(); currentTempUnit_->SetPosition(currentTemp_->GetX() + currentTemp_->GetWidth() + 4, 198, 22, 22); currentTempUnit_->SetText("°"); currentTempUnit_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); currentTempUnit_->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); currentTempUnit_->SetFont(TJD_VECTOR_FONT_FILENAME, 60); firstPageContainer_->Add(currentTempUnit_); } else { static_print_error("%s: currentTempUnit_ is nullptr", __func__); } UIImageView *minTempIcon_ = new OHOS::UIImageView(); minTempIcon_->SetPosition(258, 209, 15, 22); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_LOW, WEATHER_COMMON_BIN_PATH); minTempIcon_->SetSrc(imgInfo); firstPageContainer_->Add(minTempIcon_); /*-----------------------------Add minTemp_ to App------------------------------*/ UILabel *minTemp_ = new UILabel(); if (minTemp_ != nullptr) { minTemp_ = new UILabel(); minTemp_->SetPosition(286, 206, 80, 22); minTemp_->SetViewId(WEATHER_MIN_TEMP); minTemp_->SetText(std::to_string(presenter_->GetWeatherModel()->GetTemperatureMin()).c_str()); minTemp_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); minTemp_->SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER); minTemp_->SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30); minTemp_->SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.6); firstPageContainer_->Add(minTemp_); } else { static_print_error("%s: minTemp_ is nullptr", __func__); } /*-----------------------------Add minUnit_ to App------------------------------*/ UILabel *minUnit_ = new UILabel(); if (minUnit_ != nullptr) { minUnit_->SetPosition(236 + minTemp_->GetWidth() + 4, 203); minUnit_->Resize(23, 21); minUnit_->SetViewId("minUnit_"); minUnit_->SetStyle(STYLE_TEXT_FONT, 24); minUnit_->SetText("℃"); minUnit_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); minUnit_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); minUnit_->SetFont(TJD_VECTOR_FONT_FILENAME, 24); minUnit_->SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.6); firstPageContainer_->Add(minUnit_); } else { static_print_error("%s: minUnit_ is nullptr", __func__); } UIImageView *maxTempIcon_ = new OHOS::UIImageView(); maxTempIcon_->SetPosition(258, 246, 15, 22); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_HIGH, WEATHER_COMMON_BIN_PATH); maxTempIcon_->SetSrc(imgInfo); firstPageContainer_->Add(maxTempIcon_); /*-----------------------------Add label5_ to App------------------------------*/ UILabel *maxTemp_ = new UILabel(); if (maxTemp_ != nullptr) { maxTemp_->SetPosition(286, 243, 80, 22); maxTemp_->SetViewId(WEATHER_MAX_TEMP); maxTemp_->SetText(std::to_string(presenter_->GetWeatherModel()->GetTemperatureMax()).c_str()); maxTemp_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); maxTemp_->SetAlign(OHOS::TEXT_ALIGNMENT_LEFT, OHOS::TEXT_ALIGNMENT_CENTER); maxTemp_->SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 30); maxTemp_->SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.6); firstPageContainer_->Add(maxTemp_); } else { static_print_error("%s: maxTemp_ is nullptr", __func__); } /*-----------------------------Add maxUnit_ to App------------------------------*/ UILabel *maxUnit_ = new UILabel(); if (maxUnit_ != nullptr) { maxUnit_->SetPosition(236 + maxTemp_->GetWidth() + 4, 240); maxUnit_->Resize(26, 22); maxUnit_->SetViewId("maxUnit_"); maxUnit_->SetStyle(STYLE_TEXT_FONT, 24); maxUnit_->SetText("℃"); maxUnit_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); maxUnit_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); maxUnit_->SetFont(TJD_VECTOR_FONT_FILENAME, 24); maxUnit_->SetStyle(OHOS::STYLE_TEXT_OPA, OHOS::OPA_OPAQUE * 0.6); firstPageContainer_->Add(maxUnit_); } else { static_print_error("%s: maxUnit_ is nullptr", __func__); } UIImageView *windIcon_ = new OHOS::UIImageView(); windIcon_->SetPosition(130, 338, 32, 34); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_WIND_ICON, WEATHER_COMMON_BIN_PATH); windIcon_->SetSrc(imgInfo); firstPageContainer_->Add(windIcon_); UILabel *wind_ = new OHOS::UILabel(); wind_->SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 24); wind_->SetText(std::to_string(presenter_->GetWeatherModel()->GetWindSpeed()).c_str()); wind_->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP); wind_->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); wind_->SetPosition(107, 385, 74, 18); firstPageContainer_->Add(wind_); UIView *leftLine_ = new OHOS::UIView(); leftLine_->SetPosition(188, 327, 1, 85); leftLine_->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFFF0F1F3); leftLine_->SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE * 0.3); firstPageContainer_->Add(leftLine_); /*-----------------------------Add image1_ to App------------------------------*/ UIImageView *weatherICon_ = new UIImageView(); if (weatherICon_ != nullptr) { weatherICon_->SetPosition(210, 330); weatherICon_->Resize(47, 47); weatherICon_->SetViewId(WEATHER_ICON); ImageInfo *imgInfo = nullptr; if (presenter_->GetCurWeather() == UNKNOW_WEATHER) imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_W_ICON_UNKNOW, MAIN_WEATHER_COMMON_BIN_PATH); else imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes( (TjdUiAppWeatherModel::GetInstance().weartherTypeRes_[static_cast( TjdUiAppWeatherModel::GetInstance().GetCurWeatherType())]), MAIN_WEATHER_COMMON_BIN_PATH); if (imgInfo != nullptr) { weatherICon_->SetSrc(imgInfo); } OHOS::Vector2 scale = {47.0 / imgInfo->header.width, 47.0 / imgInfo->header.height}; weatherICon_->Scale(scale, {0, 0}); firstPageContainer_->Add(weatherICon_); } else { static_print_error("%s: weatherICon_ is nullptr", __func__); } weather_ = new OHOS::UILabelExt(); weather_->SetFont(TJD_VECTOR_FONT_FILENAME, 20); // weather_->SetText("晴天"); weather_->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP); weather_->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); weather_->SetPosition(190, 383, 85, 19); firstPageContainer_->Add(weather_); UIView *rightLine_ = new OHOS::UIView(); rightLine_->SetPosition(274, 327, 1, 85); rightLine_->SetStyle(OHOS::STYLE_BACKGROUND_COLOR, 0xFFF0F1F3); rightLine_->SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE * 0.3); firstPageContainer_->Add(rightLine_); UIImageView *humidityIcon_ = new OHOS::UIImageView(); humidityIcon_->SetPosition(311, 340, 29, 29); imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_HUMIDITY_ICON, WEATHER_COMMON_BIN_PATH); humidityIcon_->SetSrc(imgInfo); firstPageContainer_->Add(humidityIcon_); UILabel *humidity_ = new OHOS::UILabel(); humidity_->SetFont(TJD_D_DIN_PRO_REGULAR_FONT_FILENAME, 24); humidity_->SetText(std::to_string(presenter_->GetWeatherModel()->GetHumidity()).c_str()); humidity_->SetLineBreakMode(OHOS::UILabel::LINE_BREAK_WRAP); humidity_->SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); humidity_->SetPosition(290, 385, 70, 18); firstPageContainer_->Add(humidity_); return firstPageContainer_; } UIViewGroup *TjdUiAppWeatherView::SecondPageViewInit(void) { UIViewGroup *secondPageContainer_ = new UIViewGroup(); if (secondPageContainer_ == nullptr) { static_print_error("%s: secondPageContainer_ is nullptr", __func__); return nullptr; } secondPageContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); secondPageContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); secondPageContainer_->SetViewId("secondPageContainer_"); /*-----------------------------Add image2_ to App------------------------------*/ UIImageView *image2_ = new UIImageView(); if (image2_ != nullptr) { image2_->SetPosition(sunX, sunY); image2_->Resize(48, 48); image2_->SetViewId("sun"); ImageInfo *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_APP_SUN, WEATHER_APP_BIN_PATH); if (imgInfo != nullptr) { image2_->SetSrc(imgInfo); } secondPageContainer_->Add(image2_); } else { static_print_error("%s: image2_ is nullptr", __func__); } /*-----------------------------Add image3_ to App------------------------------*/ UIImageView *image3_ = new UIImageView(); if (image3_ != nullptr) { image3_->SetPosition(32, 117); image3_->Resize(402, 188); image3_->SetViewId("sun bj"); ImageInfo *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_APP_SUNSET, WEATHER_APP_BIN_PATH); if (imgInfo != nullptr) { image3_->SetSrc(imgInfo); } secondPageContainer_->Add(image3_); } else { static_print_error("%s: image3_ is nullptr", __func__); } /*-----------------------------Add label1_ to App------------------------------*/ UILabelExt *label1_ = new UILabelExt(); if (label1_ != nullptr) { label1_->SetPosition(143, 38, 180, 42); label1_->SetViewId("label1_"); label1_->SetStyle(STYLE_TEXT_FONT, 30); // label1_->SetText("日出日落"); label1_->SetTextId(STR_ID_252); label1_->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label1_->SetFont(TJD_VECTOR_FONT_FILENAME, 30); secondPageContainer_->Add(label1_); } else { static_print_error("%s: label1_ is nullptr", __func__); } /*-----------------------------Add label2_ to App------------------------------*/ UILabel *label2_ = new UILabel(); if (label2_ != nullptr) { label2_->SetPosition(46, 317); label2_->SetViewId("sunrise time"); label2_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_24); std::string text = presenter_->GetWeatherModel()->GetSunRiseTime() + "am"; static_print_debug("sunrise time: %s", text.c_str()); // label2_->SetText((std::string("日出") + text).c_str()); label2_->SetText((std::string(FontGlobalManager::GetInstance()->GetText(STR_ID_249)) + text).c_str()); label2_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); label2_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label2_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_24); secondPageContainer_->Add(label2_); } else { static_print_error("%s: label2_ is nullptr", __func__); } /*-----------------------------Add label3_ to App------------------------------*/ UILabel *label3_ = new UILabel(); if (label3_ != nullptr) { label3_->SetPosition(272, 317); label3_->SetViewId("sunset time"); label3_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_24); std::string text = presenter_->GetWeatherModel()->GetSunSetTime() + "pm"; static_print_debug("sunset time: %s", text.c_str()); // label3_->SetText((std::string("日落") + text).c_str()); label3_->SetText((std::string(FontGlobalManager::GetInstance()->GetText(STR_ID_250)) + text).c_str()); label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label3_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_24); secondPageContainer_->Add(label3_); } else { static_print_error("%s: label3_ is nullptr", __func__); } return secondPageContainer_; } UIViewGroup *TjdUiAppWeatherView::ThirdPageViewInit(void) { UIViewGroup *thirdPageContainer_ = new UIViewGroup(); if (thirdPageContainer_ == nullptr) { static_print_error("%s: thirdPageContainer_ is nullptr", __func__); return nullptr; } thirdPageContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); thirdPageContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); thirdPageContainer_->SetViewId("thirdPageContainer_"); for (int i = 0; (i < 4 && i < presenter_->validWeatherLen); i++) { WeekWeather tempWeather; tempWeather.weekLabel_ = new UILabelExt(); tempWeather.tempLabel_ = new UILabel(); tempWeather.CLabel_ = new UILabel(); tempWeather.icon_ = new UIImageView(); if (tempWeather.weekLabel_ != nullptr) { std::string prefix = "week"; std::string suffix = "Label_"; std::string result = prefix + std::to_string(i) + suffix; tempWeather.weekLabel_->SetPosition(69, 79 + i * 90); tempWeather.weekLabel_->SetViewId(result.c_str()); tempWeather.weekLabel_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_34); rtc_time time = presenter_->GetWeatherModel()->GetRTCTime(); tempWeather.weekLabel_->SetTextId(GetWeekStr((time.tm_wday + i) % 7)); tempWeather.weekLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); tempWeather.weekLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); tempWeather.weekLabel_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_34); thirdPageContainer_->Add(tempWeather.weekLabel_); } else { static_print_error("%s: weekWeather[%d].weekLabel_ is nullptr", __func__, i); } if (tempWeather.tempLabel_ != nullptr) { std::string prefix = "temp"; std::string suffix = "Label_"; std::string result = prefix + std::to_string(i) + suffix; tempWeather.tempLabel_->SetPosition(177 - 5, 82 + i * 95, 95, 34); tempWeather.tempLabel_->SetViewId(result.c_str()); tempWeather.tempLabel_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_28); tempWeather.tempLabel_->SetText("11/30"); tempWeather.tempLabel_->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); tempWeather.tempLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_TOP); tempWeather.tempLabel_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); // tempWeather.tempLabel_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffC0C0C0); // tempWeather.tempLabel_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); thirdPageContainer_->Add(tempWeather.tempLabel_); } else { static_print_error("%s: weekWeather[%d].tempLabel_ is nullptr", __func__, i); } if (tempWeather.CLabel_ != nullptr) { tempWeather.CLabel_->SetPosition(273 - 5, 83 + i * 95); tempWeather.CLabel_->SetText("℃"); tempWeather.CLabel_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_27); tempWeather.CLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); tempWeather.CLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); tempWeather.CLabel_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_27); thirdPageContainer_->Add(tempWeather.CLabel_); } else { static_print_error("%s: weekWeather[%d].CLabel_ is nullptr", __func__, i); } if (tempWeather.icon_ != nullptr) { std::string prefix = "icon"; std::string suffix = "_"; std::string result = prefix + std::to_string(i) + suffix; tempWeather.icon_->SetPosition(351 - 5, 72 + i * 95); tempWeather.icon_->Resize(43, 43); tempWeather.icon_->SetViewId(result.c_str()); ImageInfo *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_W_ICON_UNKNOW, MAIN_WEATHER_COMMON_BIN_PATH); tempWeather.icon_->Scale(Vector2{0.7, 0.7}, Vector2{0, 0}); tempWeather.icon_->SetSrc(imgInfo); thirdPageContainer_->Add(tempWeather.icon_); } else { static_print_error("%s: weekWeather[%d].icon_ is nullptr", __func__, i); } weekWeather.push_back(tempWeather); } return thirdPageContainer_; } UIViewGroup *TjdUiAppWeatherView::FourthPageViewInit(void) { UIViewGroup *FourthPageContainer_ = new UIViewGroup(); if (FourthPageContainer_ == nullptr) { static_print_error("%s: FourthPageContainer_ is nullptr", __func__); return nullptr; } FourthPageContainer_->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); FourthPageContainer_->SetStyle(STYLE_BACKGROUND_OPA, 0); FourthPageContainer_->SetViewId("FourthPageContainer_"); // for (int i=4; (i<7 && ivalidWeatherLen); i++) { for (int i = 4; i < 7; i++) { WeekWeather tempWeather; tempWeather.weekLabel_ = new UILabelExt(); tempWeather.tempLabel_ = new UILabel(); tempWeather.CLabel_ = new UILabel(); tempWeather.icon_ = new UIImageView(); if (tempWeather.weekLabel_ != nullptr) { std::string prefix = "week"; std::string suffix = "Label_"; std::string result = prefix + std::to_string(i) + suffix; tempWeather.weekLabel_->SetPosition(69, 79 + (i - 4) * 90); tempWeather.weekLabel_->SetViewId(result.c_str()); rtc_time time = presenter_->GetWeatherModel()->GetRTCTime(); tempWeather.weekLabel_->SetTextId(GetWeekStr((time.tm_wday + i) % 7)); tempWeather.weekLabel_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_34); tempWeather.weekLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); tempWeather.weekLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); tempWeather.weekLabel_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_34); FourthPageContainer_->Add(tempWeather.weekLabel_); } else { static_print_error("%s: weekWeather[%d].weekLabel_ is nullptr", __func__, i); } if (tempWeather.tempLabel_ != nullptr) { std::string prefix = "temp"; std::string suffix = "Label_"; std::string result = prefix + std::to_string(i) + suffix; tempWeather.tempLabel_->SetPosition(177 - 5, 82 + (i - 4) * 95, 95, 34); tempWeather.tempLabel_->SetViewId(result.c_str()); tempWeather.tempLabel_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_28); tempWeather.tempLabel_->SetText("11/30"); tempWeather.tempLabel_->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); tempWeather.tempLabel_->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_TOP); tempWeather.tempLabel_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_28); // tempWeather.tempLabel_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffC0C0C0); // tempWeather.tempLabel_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); FourthPageContainer_->Add(tempWeather.tempLabel_); } else { static_print_error("%s: weekWeather[%d].tempLabel_ is nullptr", __func__, i); } if (tempWeather.CLabel_ != nullptr) { tempWeather.CLabel_->SetPosition(273, 83 + (i - 4) * 95); tempWeather.CLabel_->SetText("℃"); tempWeather.CLabel_->SetStyle(STYLE_TEXT_FONT, TJD_FONT_SIZE_27); tempWeather.CLabel_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); tempWeather.CLabel_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); tempWeather.CLabel_->SetFont(TJD_VECTOR_FONT_FILENAME, TJD_FONT_SIZE_27); FourthPageContainer_->Add(tempWeather.CLabel_); } else { static_print_error("%s: weekWeather[%d].CLabel_ is nullptr", __func__, i); } if (tempWeather.icon_ != nullptr) { std::string prefix = "icon"; std::string suffix = "_"; std::string result = prefix + std::to_string(i) + suffix; tempWeather.icon_->SetPosition(351, 72 + (i - 4) * 95); tempWeather.icon_->Resize(43, 43); ImageInfo *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_COMMON_W_ICON_UNKNOW, MAIN_WEATHER_COMMON_BIN_PATH); tempWeather.icon_->Scale(Vector2{0.7, 0.7}, Vector2{0, 0}); tempWeather.icon_->SetSrc(imgInfo); tempWeather.icon_->SetViewId(result.c_str()); FourthPageContainer_->Add(tempWeather.icon_); } else { static_print_error("%s: weekWeather[%d].icon_ is nullptr", __func__, i); } weekWeather.push_back(tempWeather); } return FourthPageContainer_; } UIScrollViewNested *TjdUiAppWeatherView::MindPageViewInit(void) { UIScrollViewNested *MindPageView = new UIScrollViewNested(); if (MindPageView == nullptr) { static_print_error("%s: MindPageView is nullptr", __func__); return nullptr; } MindPageView->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); MindPageView->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { MindPageView->SetOnDragListener(presenter_); } MindPageView->SetVisible(false); /*-----------------------------Add label1_ to App------------------------------*/ UILabelExt *label1_ = new UILabelExt(); if (label1_ != nullptr) { label1_->SetPosition(66, 214, 334, 42); label1_->SetViewId("label1_"); label1_->SetStyle(STYLE_TEXT_FONT, 30); // label1_->SetText("请前往APP同步天气"); label1_->SetTextId(STR_ID_247); label1_->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label1_->SetFont(TJD_VECTOR_FONT_FILENAME, 30); MindPageView->Add(label1_); } else { static_print_error("%s: label1_ is nullptr", __func__); } MindPageView->SetVisible(false); return MindPageView; } void TjdUiAppWeatherView::ChangedView(WeatherSlicePage view, WeatherSlicePage hideView) { if (view >= WEATHERSLICEPAGE_MAX || viewMapper_[view] == nullptr) { return; } (GetInstance()->*viewMapper_[view])(hideView); } bool TjdUiAppWeatherView::ShowSwipeView(WeatherSlicePage hideView) { if (groupList_[hideView] == nullptr) { static_print_error("%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (groupList_[WeatherSlicePage::SWIPEPAGE] == nullptr) { static_print_error("%s: groupList_ is nullptr", __func__); return false; } groupList_[WeatherSlicePage::SWIPEPAGE]->SetVisible(true); groupList_[WeatherSlicePage::SWIPEPAGE]->Invalidate(); if (swipeContainer_) { swipeContainer_->RequestFocus(); swipeContainer_->SetRotateFactor(1.0); } return true; } bool TjdUiAppWeatherView::ShowMindView(WeatherSlicePage hideView) { if (groupList_[hideView] == nullptr) { static_print_error("%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (hideView == SWIPEPAGE && swipeContainer_) { swipeContainer_->ClearFocus(); } if (groupList_[WeatherSlicePage::SWIPEPAGE] == nullptr) { static_print_error("%s: groupList_ is nullptr", __func__); return false; } groupList_[WeatherSlicePage::MINDPAGE]->SetVisible(true); groupList_[WeatherSlicePage::MINDPAGE]->Invalidate(); return true; } bool TjdUiAppWeatherView::ShowNoConnectView(WeatherSlicePage hideView) { if (groupList_[hideView] == nullptr) { static_print_error("%s: groupList_ is nullptr", __func__); return false; } groupList_[hideView]->SetVisible(false); if (hideView == SWIPEPAGE && swipeContainer_) { swipeContainer_->ClearFocus(); } if (groupList_[WeatherSlicePage::NO_CONNECT_PAGE] == nullptr) { static_print_error("%s: groupList_ is nullptr", __func__); return false; } static_cast(groupList_[WeatherSlicePage::NO_CONNECT_PAGE])->ShowView(); return true; } void TjdUiAppWeatherView::UpdateSunPosition(void) { int16_t index = presenter_->GetCurTimeIndex(); static_print_debug("GetCurTimeIndex: %d", index); // Point testpoint1 = presenter_->GetPointOnSemicircle(9); // static_print_debug("testpoint x:%d y:%d", testpoint1.x, testpoint1.y); // Point testpoint2 = presenter_->GetPointOnSemicircle(15); // static_print_debug("testpoint x:%d y:%d", testpoint2.x, testpoint2.y); Point point = presenter_->GetPointOnSemicircle(index); UIImageView *tempImage = static_cast(swipeContainer_->GetChildById("secondPageContainer_")->GetChildById("sun")); if (tempImage != nullptr) { tempImage->SetPosition(point.x - (73 / 2), point.y - (73 / 2)); tempImage->Invalidate(); } else { static_print_error("%s: sunImage is nullptr", __func__); } tempImage = static_cast(swipeContainer_->GetChildById("secondPageContainer_")->GetChildById("sun bj")); if (tempImage != nullptr) { if (index <= 6) { return; } ImageInfo *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_WEATHER_APP_SUNSET, WEATHER_APP_BIN_PATH); tempImage->SetSrc(imgInfo); tempImage->Invalidate(); } else { static_print_error("%s: sun bjImage is nullptr", __func__); } } void TjdUiAppWeatherView::UpdateWeekWeatherInfo(void) { std::list::iterator viewIt = this->weekWeather.begin(); for (int i = 0; i < presenter_->validWeatherLen; i++, viewIt++) { PreWeekWeather tempPre = presenter_->preWeekWeather[i]; (*viewIt).weekLabel_->SetTextId(tempPre.weekId); (*viewIt).tempLabel_->SetText(tempPre.tempStr.c_str()); (*viewIt).icon_->SetSrc(tempPre.iconSrc); } UIViewGroup *tempSubContainer = static_cast(containerAll_->GetChildById("thirdPageContainer_")); if (tempSubContainer != nullptr) { tempSubContainer->Invalidate(); } else { static_print_error("%s: thirdPageContainer_ is nullptr", __func__); } if (presenter_->validWeatherLen > 4) { if (tempSubContainer != nullptr) { tempSubContainer = static_cast(containerAll_->GetChildById("FourthPageContainer_")); tempSubContainer->Invalidate(); } else { static_print_error("%s: FourthPageContainer_ is nullptr", __func__); } } } void TjdUiAppWeatherView::UpdateCurWeatherInfo(void) { if (swipeContainer_ == nullptr) { static_print_error("%s: swipeContainer_ is nullptr", __func__); return; } auto &image = OHOS::ImageCacheManager::GetInstance(); auto type = static_cast(TjdUiAppWeatherModel::GetInstance().GetWeather()); TjdUiAppWeatherModel &model = TjdUiAppWeatherModel::GetInstance(); // clang-format off switch (type) { case WeatherInfo::SQL_SUNNY: weartherType_ = STR_ID_633;break; case WeatherInfo::SQL_PARTLY_CLOUDY: weartherType_ = STR_ID_634;break; case WeatherInfo::SQL_CLOUDY: weartherType_ = STR_ID_635;break; case WeatherInfo::SQL_LIGHT_RAIN: weartherType_ = STR_ID_636;break; case WeatherInfo::SQL_MODERATE_RAIN: weartherType_ = STR_ID_637;break; case WeatherInfo::SQL_HEAVY_RAIN: weartherType_ = STR_ID_638;break; case WeatherInfo::SQL_SHOWER: weartherType_ = STR_ID_639;break; case WeatherInfo::SQL_THUNDERSTORM: weartherType_ = STR_ID_640;break; case WeatherInfo::SQL_SNOWY: weartherType_ = STR_ID_641;break; case WeatherInfo::SQL_FOGGY: weartherType_ = STR_ID_642;break; case WeatherInfo::SQL_DUSTSTORM: weartherType_ = STR_ID_643;break; case WeatherInfo::SQL_TYPHOON: weartherType_ = STR_ID_644;break; default: weartherType_ = STR_ID_645;break; } // clang-format on if (bgStatic_) { curInfo_ = GetWeatherInfoRes(type); if (curInfo_.size != 0) { // 先加载静态图片,防止加载动画时间过久导致黑屏 auto imageRes = image.LoadOneInMultiRes(curInfo_.startResId, curInfo_.path); bgStatic_->SetSrc(imageRes); } } if (bgAnimator_) { OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(curInfo_.path); // g_loadAllPath = curInfo_.path; // AnimatorResLoadSuccess(); PostEventHandle([this]() { uint32_t startTime = OHOS::HALTick::GetInstance().GetTime(); OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(curInfo_.path); g_loadAllPath = curInfo_.path; uint32_t endTime = OHOS::HALTick::GetInstance().GetElapseTime(startTime); GraphicService::GetInstance()->PostGraphicEvent([this]() { AnimatorResLoadSuccess(); }); static_print_info("weather LoadAllInMultiRes time:%d", endTime); }); } if (weather_) { weather_->SetTextId(weartherType_); } } void TjdUiAppWeatherView::AnimatorResLoadSuccess(void) { LoadInfo(animatorInfoArray_, curInfo_.startResId, curInfo_.size, curInfo_.path); if (bgAnimator_) { bgAnimator_->SetImageAnimatorSrc(animatorInfoArray_.get(), curInfo_.size, 75); if (bgAnimator_->GetState() == OHOS::Animator::STOP) { bgStatic_->SetVisible(false); bgAnimator_->SetVisible(true); bgAnimator_->Start(); } } } } // namespace TJD