From: luozheng <1732036298@qq.com> Date: Thu, 11 Apr 2024 11:10:32 +0000 (+0800) Subject: 修改天气视图UI,将UILabel改为UILabelExt X-Git-Tag: release_V1.2.70_20241020_135402~1189^2~16 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=f65df8130dd6a483bad7d1fccb4939059111cef2;p=mirrors%2FFD230.git 修改天气视图UI,将UILabel改为UILabelExt --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h index 4ca98759e..09a8021ab 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h @@ -1,9 +1,16 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-11 17:00:59 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h + */ #ifndef MAIN_WEATHER_PRESENTER_H #define MAIN_WEATHER_PRESENTER_H #include "Presenter.h" +#include "View.h" #include "MainWeatherView.h" -#include "KeyInputListener.h" /*主天气视图*/ namespace OHOS { @@ -11,8 +18,8 @@ namespace OHOS class WeatherControlViewOnSwipeListener : public UISwipeView::OnSwipeListener { public: - WeatherControlViewOnSwipeListener(){} - ~WeatherControlViewOnSwipeListener(){} + WeatherControlViewOnSwipeListener() {} + ~WeatherControlViewOnSwipeListener() {} void OnSwipe(UISwipeView &view) override; }; 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 90e56719f..2ed852656 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-08 18:43:28 + * @LastEditTime: 2024-04-11 15:51:19 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h */ #ifndef WEATHER_MODEL_H @@ -10,56 +10,58 @@ #include "wearable_log.h" #if __cplusplus -extern "C" { +extern "C" +{ #endif /* __cplusplus */ #include "string.h" -struct Weather_data -{ - int humidity; - char windScale[16]; - char textNight[16]; - int uvIndex; - int temp; - int iconNight; -}; -// "address": -// {"lat":225737664, -// "atm":"1010", -// "city":"深圳", -// "subLocality":"宝安", -// "lon":1138535138}, -struct Weather_data_address -{ - int lat; - char atm[16]; - char city[32]; - char subLocality[32]; - int lon; -}; + static int WEATHER_DATA_VALID = 0; //天气数据是否有效 + /*天气数据*/ + struct Weather_data + { + int humidity; // 湿度 + char windScale[16]; // 风速 + char textNight[16]; // 夜间天气文本 + int uvIndex; // 紫外线指数 + int temp; // 温度 + int iconNight; // 夜间天气图标 + }; + //"address": { "lat" : 225737664, "atm" : "1010", "city" : "深圳", "subLocality" : "宝安", "lon" : 1138535138 } + /*天气数据的地址信息*/ + struct Weather_data_address + { + int lat; // 纬度 + char atm[16]; // 大气压 + char city[32]; // 城市 + char subLocality[32]; // 子地区 + int lon; // 经纬度 + }; -//{"tempMin":22,"iconDay":6,"fxDate":1712505600,"textDay":"阵雨","tempMax":29}, -struct ONE_DAY_DATA -{ - int tempMin; - int iconDay; - int fxDate; - char textDay[16]; - int tempMax; -}; + //{"tempMin":22,"iconDay":6,"fxDate":1712505600,"textDay":"阵雨","tempMax":29}, + /*一天内天气数据*/ + struct ONE_DAY_DATA + { + int tempMin; // 最低温度 + int iconDay; // 白天天气图标 + int fxDate; // 日期 + char textDay[16]; // 白天天气文本 + int tempMax; // 最高温度 + }; + + extern Weather_data Weather_data_t_now; + extern Weather_data_address Weather_data_t_address; + extern ONE_DAY_DATA Weather_data_seven_data[]; -void UI_set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight); + void UI_set_weather_now_data(int humidity, char *windScale, char *textNight, int uvIndex, int temp, int iconNight); -void UI_set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon); + void UI_set_weather_address_data(int lat, char *atm, char *city, char *subLocality, int lon); -void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t); + void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t); #if __cplusplus } #endif /* __cplusplus */ namespace OHOS { - - class WeatherModel { public: 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 f0e2d9988..6f6931cf7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h @@ -7,7 +7,6 @@ #include "components/root_view.h" #include "components/ui_view_group.h" #include "components/ui_scroll_view.h" -#include "components/ui_label.h" #include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "components/ui_image_animator.h" @@ -19,7 +18,7 @@ namespace OHOS { static constexpr char *WeatherBackground = "WEATHER_BACKGROUND.bin"; // 天气背景 - static constexpr char *weather130x130[] = + static constexpr const char *weather130x130[] = { "/user/res/weather/weather130x130/WEATHER_CLEAR-CLOUDY.bin", "/user/res/weather/weather130x130/WEATHER_CLEAR-SUNNY.bin", @@ -48,9 +47,10 @@ namespace OHOS virtual bool InitView(void *caller) override; void ClearAll(); bool GetInitViewState(void); + void UpdataTime(); private: - UILabel *InitLabel(int x, int y, const char *text, const char *id, int textfont, int lineheight); + UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); private: std::string GetTime(); @@ -60,20 +60,19 @@ namespace OHOS std::string GetWeatherArea(); std::string GetWeatherMaxAndMinTemperature(); - std::string Time; // 时间 std::string WeatherImag; // 天气图片 std::string Temperature; // 温度 std::string WeatherDescription; // 天气描述 std::string WeatherArea; // 天气地区 std::string MaxandMinTemperature; // 最高与最低气温 private: - UIImageView *showWeatherImage = nullptr; // 显示天气图片 - UILabel *showCurrentTimeLabel{nullptr}; // 显示当前时间 - UILabel *showTemperatureLabel{nullptr}; // 显示天气温度 - UILabel *showWeatherDescriptionLabel{nullptr}; // 显示天气描述 - UILabel *showWeatherAreaLabel{nullptr}; // 显示天气地区 - UILabel *showMaxandMinTemperatureLabel{nullptr}; // 显示最高与最低气温 - UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 + UIImageView *showWeatherImage = nullptr; // 显示天气图片 + UILabelExt *showCurrentTimeLabel{nullptr}; // 显示当前时间 + UILabelExt *showTemperatureLabel{nullptr}; // 显示天气温度 + UILabelExt *showWeatherDescriptionLabel{nullptr}; // 显示天气描述 + UILabelExt *showWeatherAreaLabel{nullptr}; // 显示天气地区 + UILabelExt *showMaxandMinTemperatureLabel{nullptr}; // 显示最高与最低气温 + UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 ImageAnimator *p_ImageAnimator{nullptr}; ImageAnimatorInfo *PullUpimageAnimatorInfo{nullptr}; const char **PullUpPathsArray{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp index 6d0b00d87..69311be7d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp @@ -6,6 +6,7 @@ #include "common/key_code.h" #include "common/key_code.h" #include +#include namespace OHOS { @@ -56,12 +57,15 @@ namespace OHOS bool MainWeatherPresenter::OnDrag(UIView &view, const DragEvent &event) { + UNUSED(view); + UNUSED(event); return true; } bool MainWeatherPresenter::OnDragEnd(UIView &view, const DragEvent &event) { + UNUSED(view); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { 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 94b9e33c9..f4039746f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -2,55 +2,81 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:09 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-08 18:44:06 + * @LastEditTime: 2024-04-11 15:51:28 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp */ #include "weather/include/WeatherModel.h" #if __cplusplus -extern "C" { -#endif /* __cplusplus */ -Weather_data Weather_data_t_now; -Weather_data_address Weather_data_t_address; -ONE_DAY_DATA Weather_data_seven_data[7]; -void UI_set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight) +extern "C" { - Weather_data_t_now.humidity=humidity; - memset((void*)Weather_data_t_now.windScale,0,16); - strcpy(Weather_data_t_now.windScale,windScale); - memset((void*)Weather_data_t_now.textNight,0,16); - strcpy(Weather_data_t_now.textNight,textNight); - Weather_data_t_now.uvIndex=uvIndex; - Weather_data_t_now.temp=temp; - Weather_data_t_now.iconNight=iconNight; -} +#endif /* __cplusplus */ + Weather_data Weather_data_t_now; + Weather_data_address Weather_data_t_address; + ONE_DAY_DATA Weather_data_seven_data[7]; -void UI_set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon) -{ - Weather_data_t_address.lat=lat; - Weather_data_t_address.lon=lon; - memset((void*)Weather_data_t_address.atm,0,16); - strcpy(Weather_data_t_address.atm,atm); - memset((void*)Weather_data_t_address.city,0,32); - strcpy(Weather_data_t_address.city,city); - memset((void*)Weather_data_t_address.subLocality,0,32); - strcpy(Weather_data_t_address.subLocality,subLocality); -} + /* + * @brief 设置当前天气数据 + * @param {int} humidity 湿度 + * @param {char} *windScale 风力 + * @param {char} *textNight 夜间天气文本 + * @param {int} uvIndex 紫外线指数 + * @param {int} temp 温度 + * @param {int} iconNight 夜间天气图标 + */ + void UI_set_weather_now_data(int humidity, char *windScale, char *textNight, int uvIndex, int temp, int iconNight) + { + Weather_data_t_now.humidity = humidity; + memset((void *)Weather_data_t_now.windScale, 0, 16); + strcpy(Weather_data_t_now.windScale, windScale); + memset((void *)Weather_data_t_now.textNight, 0, 16); + strcpy(Weather_data_t_now.textNight, textNight); + Weather_data_t_now.uvIndex = uvIndex; + Weather_data_t_now.temp = temp; + Weather_data_t_now.iconNight = iconNight; -void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t) -{ - for(int i=0;i<7;i++) + WEATHER_DATA_VALID = 1; + } + + /* + * @brief 设置天气地址信息 + * @param {int} lat 纬度 + * @param {char} *atm 大气压 + * @param {char} *city 城市 + * @param {char} *subLocality 子地区 + * @param {int} lon 经度 + */ + void UI_set_weather_address_data(int lat, char *atm, char *city, char *subLocality, int lon) { - Weather_data_seven_data[i].fxDate=t[i].fxDate; - Weather_data_seven_data[i].iconDay=t[i].iconDay; - Weather_data_seven_data[i].tempMax=t[i].tempMax; - Weather_data_seven_data[i].tempMin=t[i].tempMin; - Weather_data_seven_data[i].fxDate=t[i].fxDate; - memset((void*)Weather_data_seven_data[i].textDay,0,16); - strcpy(Weather_data_seven_data[i].textDay,t[i].textDay); + Weather_data_t_address.lat = lat; + Weather_data_t_address.lon = lon; + memset((void *)Weather_data_t_address.atm, 0, 16); + strcpy(Weather_data_t_address.atm, atm); + memset((void *)Weather_data_t_address.city, 0, 32); + strcpy(Weather_data_t_address.city, city); + memset((void *)Weather_data_t_address.subLocality, 0, 32); + strcpy(Weather_data_t_address.subLocality, subLocality); + + WEATHER_DATA_VALID = 1; } -} + /* + * @brief 设置七天天气数据 + */ + void UI_set_weather_seven_day_data(struct ONE_DAY_DATA *t) + { + for (int i = 0; i < 7; i++) + { + Weather_data_seven_data[i].fxDate = t[i].fxDate; + Weather_data_seven_data[i].iconDay = t[i].iconDay; + Weather_data_seven_data[i].tempMax = t[i].tempMax; + Weather_data_seven_data[i].tempMin = t[i].tempMin; + Weather_data_seven_data[i].fxDate = t[i].fxDate; + memset((void *)Weather_data_seven_data[i].textDay, 0, 16); + strcpy(Weather_data_seven_data[i].textDay, t[i].textDay); + } + WEATHER_DATA_VALID = 1; + } #if __cplusplus } 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 80cdec067..b0ade2c4a 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,6 @@ #include "weather/include/WeatherReportView.h" #include "wearable_log.h" - +#include "weather/include/WeatherModel.h" namespace OHOS { static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_X = 53; @@ -110,6 +110,7 @@ namespace OHOS label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); // 字体行高 label->SetText(labelconfig.text); // 内容 label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetRollSpeed(40); label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); return label; @@ -118,14 +119,14 @@ namespace OHOS bool WeatherReportView::WeatherReportViewLabelInit(void) { LabelConfig labelconfig = { - .left = 173, + .left = 93, .top = 52, - .width = 120, - .height = 40, + .width = 280, + .height = 47, .fontSize = 30, .lineHeigh = 35, .text = "气象报告", - .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, }; title = SetUpLabel(labelconfig); if (title == nullptr) @@ -174,11 +175,11 @@ namespace OHOS .left = 23, .top = 290, .width = 120, - .height = 30, + .height = 35, .fontSize = 26, .lineHeigh = 35, .text = "紫外线", - .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, + .lineBreakMode = UILabel::LINE_BREAK_MARQUEE, }; UV = SetUpLabel(labelconfig); if (UV == nullptr) 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 f7d4721e2..2e6692871 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp @@ -1,5 +1,6 @@ #include "weather/include/WeatherView.h" #include "config/include/ConfigModel.h" +#include "weather/include/WeatherModel.h" /* 当至天气界面时,主动获取最新天气数据。 (此操作静默将进行,获取到则立刻更新显示,获取不到则重试 @@ -9,6 +10,52 @@ namespace OHOS { + /*天气图片*/ + static constexpr int16_t WEATHER_IMAGE_X = 77; + static constexpr int16_t WEATHER_IMAGE_Y = 124; + static constexpr int16_t WEATHER_IMAGE_W = 100; + static constexpr int16_t WEATHER_IMAGE_H = 100; + + /*当前时间标签*/ + static constexpr int16_t CURRENT_TIME_LABEL_X = 133; + static constexpr int16_t CURRENT_TIME_LABEL_Y = 52; + static constexpr int16_t CURRENT_TIME_LABEL_W = 200; + static constexpr int16_t CURRENT_TIME_LABEL_H = 47; + static constexpr int16_t CURRENT_TIME_LABEL_TEXT_FONT = 40; + static constexpr int16_t CURRENT_TIME_LABEL_LINE_HEIGHT = 47; + + /*温度标签*/ + static constexpr int16_t TEMPERATURE_LABEL_X = 211; + static constexpr int16_t TEMPERATURE_LABEL_Y = 126; + static constexpr int16_t TEMPERATURE_LABEL_W = 178; + static constexpr int16_t TEMPERATURE_LABEL_H = 125; + static constexpr int16_t TEMPERATURE_LABEL_TEXT_FONT = 100; + static constexpr int16_t TEMPERATURE_LABEL_LINE_HEIGHT = 125; + + /*天气描述标签*/ + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_X = 33; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_Y = 264; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_W = 400; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_H = 43; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_TEXT_FONT = 35; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_LINE_HEIGHT = 41; + + /*天气地区标签*/ + static constexpr int16_t WEATHER_AREA_LABEL_X = 43; + static constexpr int16_t WEATHER_AREA_LABEL_Y = 330; + static constexpr int16_t WEATHER_AREA_LABEL_W = 380; + static constexpr int16_t WEATHER_AREA_LABEL_H = 33; + static constexpr int16_t WEATHER_AREA_LABEL_TEXT_FONT = 26; + static constexpr int16_t WEATHER_AREA_LABEL_LINE_HEIGHT = 30; + + /*最高与最低气温标签*/ + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_X = 83; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_Y = 368; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_W = 300; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_H = 33; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_TEXT_FONT = 20; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_LINE_HEIGHT = 23; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_X = 213; static constexpr int16_t PULLUP_ANIMATOR_VIEW_Y = 400; static constexpr int16_t PULLUP_ANIMATOR_VIEW_W = 40; @@ -22,8 +69,7 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::WeatherView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); - SetViewIndex(0); - Time = GetTime(); + SetViewIndex(0); // 视图索引 WeatherImag = GetWeatherImage(); Temperature = GetWeatherTemperature(); WeatherDescription = GetWeatherDescription(); @@ -96,15 +142,6 @@ namespace OHOS return g_pWeatherView; } - // 获取时间 - std::string WeatherView::GetTime() - { - srand(time(0)); - std::string area[] = {"23:54", "12:00", "7:25"}; - int num = rand() % (sizeof(area) / sizeof(area[0])); - return area[1]; - } - // 获取天气图片 std::string WeatherView::GetWeatherImage() { @@ -152,24 +189,21 @@ namespace OHOS } // 初始化标签 - UILabel *WeatherView::InitLabel(int x, int y, const char *text, const char *id, int textfont, int lineheight) + UILabelExt *WeatherView::InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight) { - UILabel *label = new UILabel(); + UILabelExt *label = new UILabelExt(); if (label == nullptr) { return nullptr; } - label->SetPosition(x, y); - label->Resize(200, 30); - label->SetViewId(id); + label->SetPosition(x, y, w, h); label->SetStyle(STYLE_TEXT_FONT, textfont); label->SetStyle(STYLE_LINE_HEIGHT, lineheight); label->SetText(text); - label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetRollSpeed(0); + label->SetRollSpeed(40); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, textfont); - label->SetVisible(true); return label; } @@ -184,39 +218,35 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new showWeatherImage fail!"); return false; } - showWeatherImage->SetPosition(109, 124, 100, 100); + showWeatherImage->SetPosition(WEATHER_IMAGE_X, WEATHER_IMAGE_Y, WEATHER_IMAGE_W, WEATHER_IMAGE_W); showWeatherImage->SetSrc(WeatherImag.c_str()); /* -------------------------------------------------------------------------- */ - showCurrentTimeLabel = InitLabel(185, 52, Time.c_str(), "showCurrentTimeLabel", 40, 47); + 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); if (showCurrentTimeLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new showCurrentTimeLabel fail!"); return false; } /* -------------------------------------------------------------------------- */ - showTemperatureLabel = InitLabel(249, 126, Temperature.c_str(), "showTemperatureLabel", 100, 125); + showTemperatureLabel = InitLabelExt(TEMPERATURE_LABEL_X, TEMPERATURE_LABEL_Y, TEMPERATURE_LABEL_W, TEMPERATURE_LABEL_H, Temperature.c_str(), + TEMPERATURE_LABEL_TEXT_FONT, TEMPERATURE_LABEL_LINE_HEIGHT); if (showTemperatureLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new showTemperatureLabel fail!"); return false; } /* -------------------------------------------------------------------------- */ - showWeatherDescriptionLabel = new UILabel(); - showWeatherDescriptionLabel->SetPosition(83, 264, 300, 40); - showWeatherDescriptionLabel->SetViewId("showWeatherDescriptionLabel"); - showWeatherDescriptionLabel->SetStyle(STYLE_TEXT_FONT, 35); - showWeatherDescriptionLabel->SetStyle(STYLE_LINE_HEIGHT, 41); - showWeatherDescriptionLabel->SetText(WeatherDescription.c_str()); - showWeatherDescriptionLabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); - showWeatherDescriptionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - showWeatherDescriptionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35); + showWeatherDescriptionLabel = InitLabelExt(WEATHER_DESCRIPTION_LABEL_X, WEATHER_DESCRIPTION_LABEL_Y, WEATHER_DESCRIPTION_LABEL_W, WEATHER_DESCRIPTION_LABEL_H, WeatherDescription.c_str(), + WEATHER_DESCRIPTION_LABEL_TEXT_FONT, WEATHER_DESCRIPTION_LABEL_LINE_HEIGHT); if (showWeatherDescriptionLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new showWeatherDescriptionLabel fail!"); return false; } /* -------------------------------------------------------------------------- */ - showWeatherAreaLabel = InitLabel(155, 330, WeatherArea.c_str(), "showWeatherAreaLabel", 26, 30); + showWeatherAreaLabel = InitLabelExt(WEATHER_AREA_LABEL_X, WEATHER_AREA_LABEL_Y, WEATHER_AREA_LABEL_W, WEATHER_AREA_LABEL_H, WeatherArea.c_str(), + WEATHER_AREA_LABEL_TEXT_FONT, WEATHER_AREA_LABEL_LINE_HEIGHT); if (showWeatherAreaLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new showWeatherAreaLabel fail!"); @@ -224,13 +254,15 @@ namespace OHOS } showWeatherAreaLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); /* -------------------------------------------------------------------------- */ - showMaxandMinTemperatureLabel = InitLabel(158, 368, MaxandMinTemperature.c_str(), "showMaxandMinTemperatureLabel", 20, 23); + showMaxandMinTemperatureLabel = InitLabelExt(MAXANDMIN_TEMPERATURE_LABEL_X, MAXANDMIN_TEMPERATURE_LABEL_Y, MAXANDMIN_TEMPERATURE_LABEL_W, MAXANDMIN_TEMPERATURE_LABEL_H, MaxandMinTemperature.c_str(), + MAXANDMIN_TEMPERATURE_LABEL_TEXT_FONT, MAXANDMIN_TEMPERATURE_LABEL_LINE_HEIGHT); if (showMaxandMinTemperatureLabel == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new showMaxandMinTemperatureLabel fail!"); return false; } showMaxandMinTemperatureLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + /* -------------------------------------------------------------------------- */ p_ImageAnimator = new ImageAnimator(); if (p_ImageAnimator == nullptr) @@ -269,6 +301,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::InitPage fail"); return false; } + UpdataTime(); SetDraggable(true); SetTouchable(true); return true; @@ -279,4 +312,25 @@ namespace OHOS { return viewInitStatus; } + + /*更新当前时间*/ + void WeatherView::UpdataTime() + { + // 获取当前时间 + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + + // 解析时间 + int hour = pTM.tm_hour; + int minute = pTM.tm_min; + + // 将时间和日期转换为字符串 + std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); + if (showCurrentTimeLabel != nullptr) + { + showCurrentTimeLabel->SetText(stringtime.c_str()); + } + } } \ No newline at end of file