* @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
#endif /* __cplusplus */
#include "string.h"
- static uint8_t WEATHER_DATA_VALID = 0; // 天气数据是否有效
/*天气数据*/
struct Weather_data
{
}
#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",
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;
* @Author: luozheng 1732036298@qq.com\r
* @Date: 2024-03-30 09:14:38\r
* @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-12 16:41:27\r
+ * @LastEditTime: 2024-04-13 18:01:59\r
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h\r
*/\r
#ifndef WEATHER_REPORT_VIEW_H\r
int16_t height;\r
int16_t fontSize; // 字体大小\r
int16_t lineHeigh; // 行高\r
- const char *text; // 文本\r
+ std::string text; // 文本\r
uint8_t lineBreakMode; // 断行模式。\r
};\r
WeatherReportView();\r
* @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
namespace OHOS
{
+ static constexpr const char *WeatherBackground = "/user/res/weather/WEATHER_BACKGROUND.bin"; // 天气背景
class WeatherView : public AppGroupView
{
std::string WeatherArea; // 天气地区
std::string MaxandMinTemperature; // 最高与最低气温
private:
+ UIImageView *WeatherBackGroundImg{nullptr}; // 天气背景
UIImageView *showWeatherImage = nullptr; // 显示天气图片
UILabelExt *showCurrentTimeLabel{nullptr}; // 显示当前时间
UILabelExt *showTemperatureLabel{nullptr}; // 显示天气温度
#include "weather/include/FutureWeatherView.h"\r
#include "wearable_log.h"\r
#include "weather/include/WeatherModel.h"\r
-\r
+#include "common/image_cache_manager.h"\r
namespace OHOS\r
{\r
\r
{\r
weatherImg[i] = new UIImageView();\r
}\r
- weatherImg[i]->SetPosition(68, 130 + i * yImg, 65, 65); // SetPosition的参数分别是x, y, width, height\r
- weatherImg[i]->SetSrc(weather65x65[p_WeatherModel->GetWeather_data_seven_data_iconDay(i)]); // 请设置实际的图片源\r
+ weatherImg[i]->SetPosition(68, 130 + i * yImg, 65, 65); // SetPosition的参数分别是x, y, width, height\r
+ weatherImg[i]->SetSrc(ImageCacheManager::GetInstance().LoadSingleRes(weather65x65[p_WeatherModel->GetWeather_data_seven_data_iconDay(i)])); // 请设置实际的图片源\r
\r
// 创建日期标签\r
if (dateLabel[i] == nullptr)\r
* @Author: luozheng 1732036298@qq.com\r
* @Date: 2024-01-29 15:37:44\r
* @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-13 17:31:05\r
+ * @LastEditTime: 2024-04-13 17:51:01\r
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp\r
*/\r
#include "weather/include/MainWeatherView.h"\r
void MainWeatherView::OnStart()\r
{\r
View<MainWeatherPresenter>::OnStart();\r
- if (WEATHER_DATA_VALID)\r
+ if (WeatherModel::WEATHER_DATA_VALID)\r
{\r
MainWeatherViewInit();\r
RootView::GetInstance()->Add(weatherSwipeViewList);\r
* @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"
Weather_data_t_now.temp = temp;
Weather_data_t_now.iconNight = iconNight;
- WEATHER_DATA_VALID = 1;
+ WeatherModel::WEATHER_DATA_VALID = 1;
}
/*
"\"code\":1}";
/* -------------------------------------------------------------------------- */
+ uint8_t WeatherModel::WEATHER_DATA_VALID = 0;
WeatherModel::WeatherModel()
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherModel::WeatherModel");
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;
}
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
#include "weather/include/WeatherReportView.h"\r
#include "wearable_log.h"\r
#include "weather/include/WeatherModel.h"\r
+#include "common/image_cache_manager.h"\r
namespace OHOS\r
{\r
static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_X = 53;\r
label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小\r
label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); // 字体大小\r
label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高\r
- label->SetText(labelconfig.text); // 内容\r
+ label->SetText(labelconfig.text.c_str()); // 内容\r
label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。\r
label->SetRollSpeed(40);\r
label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::title new fail!");\r
return false;\r
}\r
+ WeatherModel *p_WeatherModel = &WeatherModel::GetInstance();\r
/* -------------------------------------------------------------------------- */\r
labelconfig = {\r
.left = 23,\r
.height = 50,\r
.fontSize = 40,\r
.lineHeigh = 50,\r
- .text = "7",\r
+ .text = p_WeatherModel->GetHumidity().c_str(),\r
.lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS,\r
};\r
UV_Number = SetUpLabel(labelconfig);\r
}\r
\r
labelconfig.left = 173;\r
- labelconfig.text = "1-2";\r
+ labelconfig.text = p_WeatherModel->GetWindScale();\r
WindSpeed_Number = SetUpLabel(labelconfig);\r
if (WindSpeed_Number == nullptr)\r
{\r
}\r
\r
labelconfig.left = 323;\r
- labelconfig.text = "75%";\r
+ labelconfig.text = p_WeatherModel->GetUVIndex();\r
Humidity_Number = SetUpLabel(labelconfig);\r
if (Humidity_Number == nullptr)\r
{\r
}\r
for (uint8_t i = 0; i < UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)\r
{\r
- UVimageAnimatorInfo[i].imagePath = (UVPathsArray[i]);\r
- UVimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;\r
+ UVimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(UVPathsArray[i]);\r
+ UVimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;\r
UVimageAnimatorInfo[i].pos.x = UV_IMAGE_ANIMATOR_VIEW_X;\r
UVimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y;\r
UVimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W;\r
}\r
for (uint8_t i = 0; i < WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)\r
{\r
- WindSpeedimageAnimatorInfo[i].imagePath = (WindSpeedPathsArray[i]);\r
- WindSpeedimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;\r
+ WindSpeedimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(WindSpeedPathsArray[i]);\r
+ WindSpeedimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;\r
WindSpeedimageAnimatorInfo[i].pos.x = WINDSPEED_IMAGE_ANIMATOR_VIEW_X;\r
WindSpeedimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y;\r
WindSpeedimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W;\r
}\r
for (uint8_t i = 0; i < HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)\r
{\r
- HumidityimageAnimatorInfo[i].imagePath = (HumidityPathsArray[i]);\r
- HumidityimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;\r
+ HumidityimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(HumidityPathsArray[i]);\r
+ HumidityimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;\r
HumidityimageAnimatorInfo[i].pos.x = HUMIDITY_IMAGE_ANIMATOR_VIEW_X;\r
HumidityimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y;\r
HumidityimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W;\r
#include "weather/include/WeatherView.h"
#include "config/include/ConfigModel.h"
#include "weather/include/WeatherModel.h"
+#include "common/image_cache_manager.h"
/*
当至天气界面时,主动获取最新天气数据。
(此操作静默将进行,获取到则立刻更新显示,获取不到则重试
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;
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;
}
if (viewInitStatus == true)
{
RemoveAll();
+ if (WeatherBackGroundImg != nullptr)
+ {
+ delete WeatherBackGroundImg;
+ WeatherBackGroundImg = nullptr;
+ }
if (showWeatherImage != nullptr)
{
delete showWeatherImage;
{
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)
{
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);
}
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;
PullUpAnimatorView->Start();
}
/* -------------------------------- 将组件添加到根视图 ------------------------------- */
+ Add(WeatherBackGroundImg);
Add(showWeatherImage);
Add(showCurrentTimeLabel);
Add(showTemperatureLabel);