From: luozheng <1732036298@qq.com> Date: Sat, 13 Apr 2024 10:54:50 +0000 (+0800) Subject: 天气界面优化,采用imagecash管理图片 X-Git-Tag: release_V1.2.70_20241020_135402~1189^2~6 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=fa33189e98d29bf6eccbcbae7dbe851873983540;p=mirrors%2FFD230.git 天气界面优化,采用imagecash管理图片 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h index 4e1a2a16a..1c72c64c6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:20 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-13 16:53:26 + * @LastEditTime: 2024-04-13 18:23:57 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h */ #ifndef WEATHER_MODEL_H @@ -20,7 +20,6 @@ namespace OHOS #endif /* __cplusplus */ #include "string.h" - static uint8_t WEATHER_DATA_VALID = 0; // 天气数据是否有效 /*天气数据*/ struct Weather_data { @@ -62,11 +61,10 @@ namespace OHOS } #endif /* __cplusplus */ - static constexpr const char *WeatherBackground = "WEATHER_BACKGROUND.bin"; // 天气背景 static constexpr const char *weather130x130[] = { "/user/res/weather/weather130x130/WEATHER_CLEAR-CLOUDY.bin", - "/user/res/weather/weather130x130/WEATHER_CLEAR-SUNNY.bin", //晴 + "/user/res/weather/weather130x130/WEATHER_CLEAR-SUNNY.bin", // 晴 "/user/res/weather/weather130x130/WEATHER_DUSTSTORM.bin", "/user/res/weather/weather130x130/WEATHER_FOGGY.bin", "/user/res/weather/weather130x130/WEATHER_HAZE.bin", @@ -94,6 +92,11 @@ namespace OHOS std::string GetWeather_data_seven_data_textDay(int date); std::string GetWeather_data_seven_data_fxDate(int date); std::string GetWeather_data_seven_data_tempMinAndtempMax(int date); + /* -------------------------------------------------------------------------- */ + std::string GetHumidity(); + std::string GetWindScale(); + std::string GetUVIndex(); + static uint8_t WEATHER_DATA_VALID; // 天气数据是否有效 private: WeatherModel(); WeatherModel(const WeatherModel &) = delete; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h index a06a92a72..553edbf14 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-12 16:41:27 + * @LastEditTime: 2024-04-13 18:01:59 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h */ #ifndef WEATHER_REPORT_VIEW_H @@ -31,7 +31,7 @@ namespace OHOS int16_t height; int16_t fontSize; // 字体大小 int16_t lineHeigh; // 行高 - const char *text; // 文本 + std::string text; // 文本 uint8_t lineBreakMode; // 断行模式。 }; WeatherReportView(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h index 331cbcfba..c86b93323 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-12 15:06:35 + * @LastEditTime: 2024-04-13 18:34:25 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h */ #ifndef WEATHER_VIEW_H @@ -23,6 +23,7 @@ namespace OHOS { + static constexpr const char *WeatherBackground = "/user/res/weather/WEATHER_BACKGROUND.bin"; // 天气背景 class WeatherView : public AppGroupView { @@ -49,6 +50,7 @@ namespace OHOS std::string WeatherArea; // 天气地区 std::string MaxandMinTemperature; // 最高与最低气温 private: + UIImageView *WeatherBackGroundImg{nullptr}; // 天气背景 UIImageView *showWeatherImage = nullptr; // 显示天气图片 UILabelExt *showCurrentTimeLabel{nullptr}; // 显示当前时间 UILabelExt *showTemperatureLabel{nullptr}; // 显示天气温度 diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp index 7539595a2..191b1a06a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp @@ -1,7 +1,7 @@ #include "weather/include/FutureWeatherView.h" #include "wearable_log.h" #include "weather/include/WeatherModel.h" - +#include "common/image_cache_manager.h" namespace OHOS { @@ -108,8 +108,8 @@ namespace OHOS { weatherImg[i] = new UIImageView(); } - weatherImg[i]->SetPosition(68, 130 + i * yImg, 65, 65); // SetPosition的参数分别是x, y, width, height - weatherImg[i]->SetSrc(weather65x65[p_WeatherModel->GetWeather_data_seven_data_iconDay(i)]); // 请设置实际的图片源 + weatherImg[i]->SetPosition(68, 130 + i * yImg, 65, 65); // SetPosition的参数分别是x, y, width, height + weatherImg[i]->SetSrc(ImageCacheManager::GetInstance().LoadSingleRes(weather65x65[p_WeatherModel->GetWeather_data_seven_data_iconDay(i)])); // 请设置实际的图片源 // 创建日期标签 if (dateLabel[i] == nullptr) diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp index 18fd11412..0433e80ba 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-13 17:31:05 + * @LastEditTime: 2024-04-13 17:51:01 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp */ #include "weather/include/MainWeatherView.h" @@ -125,7 +125,7 @@ namespace OHOS void MainWeatherView::OnStart() { View::OnStart(); - if (WEATHER_DATA_VALID) + if (WeatherModel::WEATHER_DATA_VALID) { MainWeatherViewInit(); RootView::GetInstance()->Add(weatherSwipeViewList); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp index b5a27dd4f..b9c182e67 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:09 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-13 17:07:14 + * @LastEditTime: 2024-04-13 18:00:02 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp */ #include "weather/include/WeatherModel.h" @@ -36,7 +36,7 @@ namespace OHOS Weather_data_t_now.temp = temp; Weather_data_t_now.iconNight = iconNight; - WEATHER_DATA_VALID = 1; + WeatherModel::WEATHER_DATA_VALID = 1; } /* @@ -94,6 +94,7 @@ namespace OHOS "\"code\":1}"; /* -------------------------------------------------------------------------- */ + uint8_t WeatherModel::WEATHER_DATA_VALID = 0; WeatherModel::WeatherModel() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherModel::WeatherModel"); @@ -176,8 +177,7 @@ namespace OHOS std::string WeatherModel::GetWeather_data_seven_data_fxDate(int date) { static char formattedDate[6]; // 5字符加上终结符'\0' - TimestampToMonthDayString(Weather_data_seven_data[date].fxDate,formattedDate); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "formattedDate:%s",formattedDate); + TimestampToMonthDayString(Weather_data_seven_data[date].fxDate, formattedDate); return formattedDate; } @@ -190,4 +190,29 @@ namespace OHOS return maxandminTemperature; } + /* -------------------------------------------------------------------------- */ + + /*获取湿度*/ + std::string WeatherModel::GetHumidity() + { + int humidity = Weather_data_t_now.humidity; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "humidity:%d", humidity); + return std::to_string(humidity); + } + + /*获取风速*/ + std::string WeatherModel::GetWindScale() + { + std::string windScale = Weather_data_t_now.windScale; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "windScale:%s", windScale.c_str()); + return windScale; + } + + /*获取紫外线指数*/ + std::string WeatherModel::GetUVIndex() + { + std::string uvIndex = std::to_string(Weather_data_t_now.uvIndex) + "%"; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uvIndex:%s", uvIndex.c_str()); + return uvIndex; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp index 702037ee5..58cf2a37f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp @@ -1,6 +1,7 @@ #include "weather/include/WeatherReportView.h" #include "wearable_log.h" #include "weather/include/WeatherModel.h" +#include "common/image_cache_manager.h" namespace OHOS { static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_X = 53; @@ -102,7 +103,7 @@ namespace OHOS label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小 label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小 label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 - label->SetText(labelconfig.text); // 内容 + label->SetText(labelconfig.text.c_str()); // 内容 label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 label->SetRollSpeed(40); label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); @@ -128,6 +129,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::title new fail!"); return false; } + WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); /* -------------------------------------------------------------------------- */ labelconfig = { .left = 23, @@ -136,7 +138,7 @@ namespace OHOS .height = 50, .fontSize = 40, .lineHeigh = 50, - .text = "7", + .text = p_WeatherModel->GetHumidity().c_str(), .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, }; UV_Number = SetUpLabel(labelconfig); @@ -147,7 +149,7 @@ namespace OHOS } labelconfig.left = 173; - labelconfig.text = "1-2"; + labelconfig.text = p_WeatherModel->GetWindScale(); WindSpeed_Number = SetUpLabel(labelconfig); if (WindSpeed_Number == nullptr) { @@ -156,7 +158,7 @@ namespace OHOS } labelconfig.left = 323; - labelconfig.text = "75%"; + labelconfig.text = p_WeatherModel->GetUVIndex(); Humidity_Number = SetUpLabel(labelconfig); if (Humidity_Number == nullptr) { @@ -231,8 +233,8 @@ namespace OHOS } for (uint8_t i = 0; i < UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) { - UVimageAnimatorInfo[i].imagePath = (UVPathsArray[i]); - UVimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + UVimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(UVPathsArray[i]); + UVimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; UVimageAnimatorInfo[i].pos.x = UV_IMAGE_ANIMATOR_VIEW_X; UVimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y; UVimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W; @@ -257,8 +259,8 @@ namespace OHOS } for (uint8_t i = 0; i < WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) { - WindSpeedimageAnimatorInfo[i].imagePath = (WindSpeedPathsArray[i]); - WindSpeedimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + WindSpeedimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(WindSpeedPathsArray[i]); + WindSpeedimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; WindSpeedimageAnimatorInfo[i].pos.x = WINDSPEED_IMAGE_ANIMATOR_VIEW_X; WindSpeedimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y; WindSpeedimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W; @@ -283,8 +285,8 @@ namespace OHOS } for (uint8_t i = 0; i < HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) { - HumidityimageAnimatorInfo[i].imagePath = (HumidityPathsArray[i]); - HumidityimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + HumidityimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(HumidityPathsArray[i]); + HumidityimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; HumidityimageAnimatorInfo[i].pos.x = HUMIDITY_IMAGE_ANIMATOR_VIEW_X; HumidityimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y; HumidityimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp index c1399bff9..adec552f9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp @@ -1,6 +1,7 @@ #include "weather/include/WeatherView.h" #include "config/include/ConfigModel.h" #include "weather/include/WeatherModel.h" +#include "common/image_cache_manager.h" /* 当至天气界面时,主动获取最新天气数据。 (此操作静默将进行,获取到则立刻更新显示,获取不到则重试 @@ -10,6 +11,12 @@ namespace OHOS { + /*主天气背景图片*/ + static constexpr int16_t WEATHER_BACKGROUND_IMAGE_X = 0; + static constexpr int16_t WEATHER_BACKGROUND_IMAGE_Y = 0; + static constexpr int16_t WEATHER_BACKGROUND_IMAGE_W = 466; + static constexpr int16_t WEATHER_BACKGROUND_IMAGE_H = 466; + /*天气图片*/ static constexpr int16_t WEATHER_IMAGE_X = 77; static constexpr int16_t WEATHER_IMAGE_Y = 124; @@ -71,15 +78,14 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::WeatherView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); SetViewIndex(0); // 视图索引 - if (1) - { - WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); - WeatherImag = p_WeatherModel->GetWeatherImage(); - Temperature = p_WeatherModel->GetWeatherTemperature(); - WeatherDescription = p_WeatherModel->GetWeatherDescription(); - WeatherArea = p_WeatherModel->GetWeatherArea(); - MaxandMinTemperature = p_WeatherModel->GetWeatherMaxAndMinTemperature(); - } + + WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); + WeatherImag = p_WeatherModel->GetWeatherImage(); + Temperature = p_WeatherModel->GetWeatherTemperature(); + WeatherDescription = p_WeatherModel->GetWeatherDescription(); + WeatherArea = p_WeatherModel->GetWeatherArea(); + MaxandMinTemperature = p_WeatherModel->GetWeatherMaxAndMinTemperature(); + g_pWeatherView = this; } @@ -95,6 +101,11 @@ namespace OHOS if (viewInitStatus == true) { RemoveAll(); + if (WeatherBackGroundImg != nullptr) + { + delete WeatherBackGroundImg; + WeatherBackGroundImg = nullptr; + } if (showWeatherImage != nullptr) { delete showWeatherImage; @@ -165,6 +176,15 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " WeatherView::InitPage"); /* -------------------------------------------------------------------------- */ + WeatherBackGroundImg = new UIImageView(); + if (WeatherBackGroundImg == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new WeatherBackGroundImg fail!"); + return false; + } + WeatherBackGroundImg->SetPosition(WEATHER_BACKGROUND_IMAGE_X, WEATHER_BACKGROUND_IMAGE_Y, WEATHER_BACKGROUND_IMAGE_W, WEATHER_BACKGROUND_IMAGE_H); + WeatherBackGroundImg->SetSrc(ImageCacheManager::GetInstance().LoadSingleRes(WeatherBackground)); + /* -------------------------------------------------------------------------- */ showWeatherImage = new UIImageView(); if (showWeatherImage == nullptr) { @@ -172,7 +192,7 @@ namespace OHOS return false; } showWeatherImage->SetPosition(WEATHER_IMAGE_X, WEATHER_IMAGE_Y, WEATHER_IMAGE_W, WEATHER_IMAGE_W); - showWeatherImage->SetSrc(WeatherImag.c_str()); + showWeatherImage->SetSrc(ImageCacheManager::GetInstance().LoadSingleRes(WeatherImag)); /* -------------------------------------------------------------------------- */ showCurrentTimeLabel = InitLabelExt(CURRENT_TIME_LABEL_X, CURRENT_TIME_LABEL_Y, CURRENT_TIME_LABEL_W, CURRENT_TIME_LABEL_H, "", CURRENT_TIME_LABEL_TEXT_FONT, CURRENT_TIME_LABEL_LINE_HEIGHT); @@ -227,8 +247,8 @@ namespace OHOS } for (uint8_t i = 0; i < PULLUP_ANIMATOR_VIEW_NUM_FRAMES; i++) { - PullUpimageAnimatorInfo[i].imagePath = (PullUpPathsArray[i]); - PullUpimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + PullUpimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(PullUpPathsArray[i]); + PullUpimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; PullUpimageAnimatorInfo[i].pos.x = PULLUP_ANIMATOR_VIEW_X; PullUpimageAnimatorInfo[i].pos.y = PULLUP_ANIMATOR_VIEW_Y; PullUpimageAnimatorInfo[i].width = PULLUP_ANIMATOR_VIEW_W; @@ -242,6 +262,7 @@ namespace OHOS PullUpAnimatorView->Start(); } /* -------------------------------- 将组件添加到根视图 ------------------------------- */ + Add(WeatherBackGroundImg); Add(showWeatherImage); Add(showCurrentTimeLabel); Add(showTemperatureLabel);