From 8ef1ff24f63deb0c5fac1ecbb3339204fe4b0122 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Wed, 26 Mar 2025 16:19:59 +0800 Subject: [PATCH] =?utf8?q?=E5=A4=A9=E6=B0=94slice=E5=90=88=E5=B9=B6?= =?utf8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../include/FutureWeatherListAdapter.h | 67 +++ .../include/FutureWeatherListitemView.h | 36 ++ .../weather/include/FutureWeatherView.h | 44 ++ .../weather/include/GetWeatherDataErrorView.h | 38 ++ .../weather/include/MainWeatherPresenter.h | 58 +++ .../weather/include/MainWeatherView.h | 64 +++ .../weather/include/WeatherControlView.h | 42 ++ .../nativeui/weather/include/WeatherModel.h | 129 +++++ .../weather/include/WeatherReportView.h | 84 ++++ .../nativeui/weather/include/WeatherView.h | 84 ++++ .../weather/src/FutureWeatherListAdapter.cpp | 98 ++++ .../weather/src/FutureWeatherListitemView.cpp | 87 ++++ .../weather/src/FutureWeatherView.cpp | 151 ++++++ .../weather/src/GetWeatherDataErrorView.cpp | 104 ++++ .../weather/src/MainWeatherPresenter.cpp | 132 +++++ .../nativeui/weather/src/MainWeatherView.cpp | 265 ++++++++++ .../weather/src/WeatherControlView.cpp | 175 +++++++ .../nativeui/weather/src/WeatherModel.cpp | 395 +++++++++++++++ .../weather/src/WeatherReportView.cpp | 461 ++++++++++++++++++ .../nativeui/weather/src/WeatherView.cpp | 451 +++++++++++++++++ 20 files changed, 2965 insertions(+) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListAdapter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListitemView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherControlView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherModel.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherReportView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListAdapter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListitemView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherControlView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherModel.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherReportView.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherView.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListAdapter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListAdapter.h new file mode 100644 index 000000000..771b44a9b --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListAdapter.h @@ -0,0 +1,67 @@ +/*** + * @Date: 2024-04-16 10:24:43 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-07-10 21:13:30 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListAdapter.h + */ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-15 09:25:05 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-15 14:42:55 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListAdapter.h + */ +#ifndef FUTURE_WEATHER_LISTADAPTER_H +#define FUTURE_WEATHER_LISTADAPTER_H + +#include "components/abstract_adapter.h" +#include "languagecode/LanguageInit.h" +#include + +namespace OHOS +{ + struct FutureWeather + { + std::string iconDay; // 白天天气图标 + std::string fxDate; // 日期 + std::string tempMinAndMax; + // std::string tempMin; // 最低温度 + // std::string tempMax; // 最高温度 + }; + + class FutureWeatherListAdapter : public AbstractAdapter + { + public: + explicit FutureWeatherListAdapter(); + virtual ~FutureWeatherListAdapter(); + + /* * + * @brief Sets the UIView adapter data, which is a FutureWeather linked list. + * + * @param data Indicates the FutureWeather linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(std::list &data); + + void ClearData(void); + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + virtual uint16_t GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16_t index) override; + + virtual void AddListItem(const FutureWeather &item); + + private: + std::list listData; + }; + +} + +#endif diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListitemView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListitemView.h new file mode 100644 index 000000000..c965cd71d --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListitemView.h @@ -0,0 +1,36 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-15 09:25:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-15 14:41:57 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListitemView.h + */ +#ifndef FUTURE_WEATHER_LIST_ITEM_VIEW +#define FUTURE_WEATHER_LIST_ITEM_VIEW + +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "weather/include/FutureWeatherListAdapter.h" +namespace OHOS +{ + class FutureWeatherListitemView : public UIViewGroup + { + public: + FutureWeatherListitemView(); + virtual ~FutureWeatherListitemView(); + virtual void SetItemInfo(const FutureWeather itemInfo); + virtual void SetUpChild(); + + private: + FutureWeatherListitemView(const FutureWeatherListitemView &); + UIImageView weatherImg; // 天气图标 + UILabel dateLabel; // 日期 + UILabel minAndmaxTemperatureLabel; // 最高温度 + // UILabel minTemperatureLabel; // 最小温度 + // UILabel maxTemperatureLabel; // 最高温度 + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherView.h new file mode 100644 index 000000000..a9d0eb55f --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherView.h @@ -0,0 +1,44 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-19 09:54:09 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h + */ +#ifndef FUTURE_WEATHER_VIEW_H +#define FUTURE_WEATHER_VIEW_H + + +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_list.h" +#include "components/icon_adapter.h" +#include "AppGroupView.h" +#include "weather/include/FutureWeatherListAdapter.h" + +namespace OHOS +{ + class FutureWeatherView : public AppGroupView + { + + public: + FutureWeatherView(); + virtual ~FutureWeatherView(); + static FutureWeatherView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void AddFutureWeatherItemToList(const FutureWeather &item); + bool UpdateFutureWeatherListData(void); + UIList *GetFutureWeatherList(); + private: + void ClearAll(void); + // UIScrollView *scrollView{nullptr}; + UILabelExt *Title = nullptr; + UIList *FutureWeatherList{nullptr}; + FutureWeatherListAdapter *futureWeatherListAdapter{nullptr}; + bool viewInitStatus{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h new file mode 100644 index 000000000..fa0530e30 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h @@ -0,0 +1,38 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-15 14:21:01 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h + */ +#ifndef Get_WEATHER_DATA_ERROR_VIEW_H +#define Get_WEATHER_DATA_ERROR_VIEW_H + + +#include "View.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +namespace OHOS +{ + + static constexpr const char *GETWEATHERDATAERRORVIEW = "GetWeatherDataErrorView"; + class GetWeatherDataErrorView + { + + public: + GetWeatherDataErrorView(); + virtual ~GetWeatherDataErrorView(); + static GetWeatherDataErrorView *GetInstance(void); + UIScrollView *GetWeatherDataErrorViewInit(void); + + private: + void ClearAll(); + + UIScrollView *scrollView = nullptr; + UILabelExt *label = nullptr; + UIImageView *image = nullptr; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherPresenter.h new file mode 100644 index 000000000..d149d71e5 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherPresenter.h @@ -0,0 +1,58 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-05-10 10:58:31 + * @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 "weather/include/WeatherModel.h" +/*主天气视图*/ +namespace OHOS +{ + static constexpr const char *MAIN_WEATHER_VIEW = "MainWeatherview"; + class WeatherControlViewOnSwipeListener : public UISwipeView::OnSwipeListener + { + public: + WeatherControlViewOnSwipeListener() {} + ~WeatherControlViewOnSwipeListener() {} + void OnSwipe(UISwipeView &view) override; + }; + + class MainWeatherView; + class MainWeatherPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener + { + public: + MainWeatherPresenter(); + virtual ~MainWeatherPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static MainWeatherPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + void OnSwipe(UISwipeView &view) override; + + WeatherModel *weatherModel{nullptr}; + bool X_DRAG_FLAG{false}; + }; +} // namespace OHOS + +#endif // MainWeather_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherView.h new file mode 100644 index 000000000..2469577fd --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherView.h @@ -0,0 +1,64 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2025-02-24 16:52:58 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h + */ +#ifndef MAIN_WEATHER_VIEW_H +#define MAIN_WEATHER_VIEW_H + +#include "View.h" +#include "components/ui_swipe_view.h" + +#include "weather/include/WeatherView.h" +#include "weather/include/WeatherReportView.h" +#include "weather/include/GetWeatherDataErrorView.h" +#include "weather/include/FutureWeatherView.h" +namespace OHOS +{ + typedef enum + { + MAINWEATHERVIEW = 0, // 主天气视图 + WEATHERREPORTVIEW, // 气象报告视图 + FUTUREWEATHERVIEW, // 未来七天天气视图 + MAX_WEATHERVIEW, + } WeatherPageId; + class MainWeatherPresenter; + class MainWeatherView : public View + { + + public: + MainWeatherView(); + virtual ~MainWeatherView(); + static MainWeatherView *GetInstance(void); + UISwipeView *MainWeatherViewInit(void); + void ClearAll(void); + AppGroupView *WeatherViewPageInit(void); + AppGroupView *WeatherReportViewPageInit(void); + AppGroupView *FutureWeatherViewPageInit(void); + UIScrollView *WeatherDataErrorViewPageInit(void); + WeatherView *GetWeatherView(void); + UIView *GetWeatherPageView(void); + WeatherReportView *GetWeatherReportView(void); + FutureWeatherView *GetFutureWeatherView(void); + bool UpdateMainWeatherViewVisibility(void); + + public: + void OnStart() override; + + private: + WeatherView *weatherView{nullptr}; + WeatherReportView *weatherReportView{nullptr}; + FutureWeatherView *futureWeatherView{nullptr}; + GetWeatherDataErrorView *getWeatherDataErrorView{nullptr}; + + private: + int16_t maxPage = MAX_WEATHERVIEW; + UISwipeView *weatherSwipeViewList{nullptr}; // 天气滑动视图列表 + AppGroupView *recordCard[MAX_WEATHERVIEW]{nullptr}; + AppGroupView *CreatePage(int32_t WeatherPageId); + UIScrollView *weatherScrllView{nullptr}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherControlView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherControlView.h new file mode 100644 index 000000000..edad327c3 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherControlView.h @@ -0,0 +1,42 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-03 18:01:53 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherControlView.h + */ +#ifndef WEATHER_CONTROL_VIEW_H +#define WEATHER_CONTROL_VIEW_H +/*该视图主要放在主视图*/ + +#include "components/root_view.h" +#include "components/ui_card_page.h" +#include "wearable_log.h" +#include "weather/include/MainWeatherView.h" +namespace OHOS +{ + class WeatherControlView : public UICardPage + { + public: + WeatherControlView(); + virtual ~WeatherControlView(); + static WeatherControlView *GetInstance(void); + bool InitView(void); + void PreLoad(void) override; + void UnLoad(void) override; + bool UpdateWeatherControlViewVisibility(); + UISwipeView *GetWeatherSwipView(void); + + private: + void ClearAll(void); + bool InitializeWeatherDataErrorView(void); + bool InitializeWeatherSwipeView(void); + bool CreateMainWeatherView(void); + MainWeatherView *mainWeatherView{nullptr}; + UISwipeView *weatherSwipView{nullptr}; + UIScrollView *weatherScrllView{nullptr}; + UISwipeView::OnSwipeListener *weatherOnSwipeListener{nullptr}; + bool viewiInitStatus{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherModel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherModel.h new file mode 100644 index 000000000..c3343153e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherModel.h @@ -0,0 +1,129 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-08 18:40:20 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-09-13 10:25:12 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h + */ +#ifndef WEATHER_MODEL_H +#define WEATHER_MODEL_H + +#include "wearable_log.h" +#include "iostream" +#include +#include "weather/include/FutureWeatherListAdapter.h" +namespace OHOS +{ +#if __cplusplus + extern "C" + { +#endif /* __cplusplus */ +#include "string.h" + #define weather_short_len 32 + #define weather_long_len 64 + + /*天气数据*/ + struct Weather_data + { + int humidity; // 湿度 + char windScale[weather_short_len]; // 风速 + char textNight[weather_short_len]; // 夜间天气文本 + int uvIndex; // 紫外线指数 + int temp; // 温度 + int iconNight; // 夜间天气图标 + }; + //"address": { "lat" : 225737664, "atm" : "1010", "city" : "深圳", "subLocality" : "宝安", "lon" : 1138535138 } + /*天气数据的地址信息*/ + struct Weather_data_address + { + int lat; // 纬度 + char atm[weather_short_len]; // 大气压 + 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[weather_short_len]; // 白天天气文本 + int tempMax; // 最高温度 + }; + + 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_seven_day_data(struct ONE_DAY_DATA t,int count); + +#if __cplusplus + } +#endif /* __cplusplus */ + +#define DAYS_OF_THE_WEEK 7 +#define weather_src "/user/res/weather/weather65x65/" + static const char *weather65x65[] = + { + weather_src "weather_sunny.bin", // 占位或默认 + weather_src "weather_sunny.bin", // 晴(白天) + weather_src "weather_clear_sunny.bin", // 晴(晚上) + weather_src "weather_sunny_cloudy.bin", // 多云(白天) + weather_src "weather_clear_cloudy.bin", // 多云(晚上) + weather_src "weather_overcast.bin", // 阴 + weather_src "weather_rain.bin", // 阵雨 + weather_src "weather_thundershower.bin", // 雷雨 + weather_src "weather_snow.bin", // 雪 + weather_src "weather_foggy.bin", // 雾 + weather_src "weather_haze.bin", // 霾 + weather_src "weather_duststorm.bin", // 沙尘暴 + weather_src "weather_unknown.bin", // 未知 + + }; + /* -------------------------------------------------------------------------- */ + class WeatherModel + { + public: + static WeatherModel &GetInstance(void); + void InitFutureWeatherItem(); + void TimestampToMonthDayString(time_t timestamp, char *buffer); + std::string GetWeatherCurTime(); + std::string GetWeatherImage(); + std::string GetWeatherTemperature(); + std::string GetWeatherDescription(); + std::string GetWeatherArea(); + std::string GetWeatherMaxAndMinTemperature(); + /* -------------------------------------------------------------------------- */ + std::string GetWeather_data_seven_data_iconDay(int date); + 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 GetWeather_data_seven_data_tempMin(int date); + std::string GetWeather_data_seven_data_tempMax(int date); + /* -------------------------------------------------------------------------- */ + std::string GetHumidity(); + std::string GetWindScale(); + std::string GetUVIndex(); + /* -------------------------------------------------------------------------- */ + bool GetWeatherDataIsValid(void); + void SetWeatherDataIsValid(bool value); + /* -------------------------------------------------------------------------- */ + void UpdateMainWeatherData(void); + void UpdateWeatherCurTime(void); + /* -------------------------------------------------------------------------- */ + bool IsNightTime(); + private: + WeatherModel(); + WeatherModel(const WeatherModel &) = delete; + WeatherModel &operator=(const WeatherModel &) = delete; + virtual ~WeatherModel(); + FutureWeather FutureWeatherItem[DAYS_OF_THE_WEEK]; + bool WEATHER_DATA_VALID{false}; // 天气数据是否有效 + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherReportView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherReportView.h new file mode 100644 index 000000000..4e6940fcc --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherReportView.h @@ -0,0 +1,84 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-17 16:20:42 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h + */ +#ifndef WEATHER_REPORT_VIEW_H +#define WEATHER_REPORT_VIEW_H + + +#include "View.h" +#include "AppGroupView.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "ui_resource_string.h" +#include "components/ui_image_animator.h" +#include "ConfigModel.h" +namespace OHOS +{ + class WeatherReportView : public AppGroupView + { + + public: + struct LabelConfig + { + int16_t left; + int16_t top; + int16_t width; + int16_t height; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + std::string text; // 文本 + uint16_t textId; + uint8_t lineBreakMode; // 断行模式。 + }; + WeatherReportView(); + virtual ~WeatherReportView(); + static WeatherReportView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(void); + UIImageAnimatorView *GetUVImageAnimatorView() + { + return UVImageAnimatorView; + } + bool UpdateWeatherReportViewData(void); + + private: + bool SetTextLabel(UILabel *label, const std::string &text); + void DumpWeatherInfo(void); + bool UpdateUVData(void); + bool UpdateWindSpeedData(void); + bool UpdateHumidityData(void); + std::string UVData; // 紫外线强度数据 + std::string WindSpeedData; // 风速数据 + std::string HumidityData; // 湿度数据 + private: + UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签 + UILabelExt *SetUpLabelExt(LabelConfig &labelconfig); + bool WeatherReportViewLabelInit(void); + bool WeatherReportViewImageAnimatorViewInit(void); + UILabelExt *title{nullptr}; // 标题 + UILabelExt *UV{nullptr}; // 紫外线 + UILabelExt *UV_Number{nullptr}; // + UILabelExt *WindSpeed{nullptr}; // 风速 + UILabelExt *WindSpeed_Number{nullptr}; // + UILabelExt *Humidity{nullptr}; // 湿度 + UILabelExt *Humidity_Number{nullptr}; // + + UIImageView *PullUpImage{nullptr}; // 上拉图片 + + UIImageAnimatorView *UVImageAnimatorView{nullptr}; // 紫外线动画 + UIImageAnimatorView *WindSpeedImageAnimatorView{nullptr}; // 风速动画 + UIImageAnimatorView *HumidityImageAnimatorView{nullptr}; // 湿度动画 + + const ImageInfo **UVPathsArray{nullptr}; + const ImageInfo **WindSpeedPathsArray{nullptr}; + const ImageInfo **HumidityPathsArray{nullptr}; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif // WeatherReport_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherView.h new file mode 100644 index 000000000..098bf9338 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherView.h @@ -0,0 +1,84 @@ +/*** + * @Date: 2024-08-19 11:01:42 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 19:24:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h + */ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-08-17 16:03:36 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h + */ +#ifndef WEATHER_VIEW_H +#define WEATHER_VIEW_H + + +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "wearable_log.h" +#include "AppGroupView.h" +#include + +namespace OHOS +{ +#define IS_USE_IMAGEANIMATOR 0 + static constexpr const char *WeatherBackground = "/user/res/weather/WEATHER_BACKGROUND.bin"; // 天气背景 + class WeatherView : public AppGroupView + { + + public: + WeatherView(); + virtual ~WeatherView(); + static WeatherView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool UpdateWeatherViewData(void); + bool UpdateWeatherTime(void); + + private: + UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); + private: + void DumpWeatherInfo(); + bool SetImageSource(UIImageView *image, const std::string &source); + bool SetTextLabel(UILabel *label, const std::string &text); + bool UpdateWeatherImag(void); + bool UpdateWeatherTemperature(void); + bool UpdateWeatherWeatherDescription(void); + bool UpdateWeatherWeatherArea(void); + bool UpdateWeatherMaxandMinTemperature(void); + + std::string WeatherTime; // 天气时间 + std::string WeatherImag; // 天气图片 + std::string Temperature; // 温度 + std::string WeatherDescription; // 天气描述 + std::string WeatherArea; // 天气地区 + std::string MaxandMinTemperature; // 最高与最低气温 + private: + UIImageView *WeatherBackGroundImg{nullptr}; // 天气背景 + UIImageView *showWeatherImage = nullptr; // 显示天气图片 + UILabelExt *showCurrentTimeLabel{nullptr}; // 显示当前时间 + UILabelExt *showTemperatureLabel{nullptr}; // 显示天气温度 + UILabelExt *showWeatherDescriptionLabel{nullptr}; // 显示天气描述 + UILabelExt *showWeatherAreaLabel{nullptr}; // 显示天气地区 + UILabelExt *showMaxandMinTemperatureLabel{nullptr}; // 显示最高与最低气温 +#if IS_USE_IMAGEANIMATOR + UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 + const char **PullUpPathsArray{nullptr}; +#else + + UIImageView *PullUpImage{nullptr}; // 上拉图片 +#endif + bool viewInitStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListAdapter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListAdapter.cpp new file mode 100644 index 000000000..f0ad458cc --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListAdapter.cpp @@ -0,0 +1,98 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-15 09:25:17 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-15 16:41:36 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp + */ +#include "weather/include/FutureWeatherListAdapter.h" +#include "weather/include/FutureWeatherListitemView.h" +#include "wearable_log.h" + +namespace OHOS +{ + + FutureWeatherListAdapter::FutureWeatherListAdapter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::FutureWeatherListAdapter"); + } + + FutureWeatherListAdapter::~FutureWeatherListAdapter() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::~FutureWeatherListAdapter"); + listData.clear(); + } + + uint16_t FutureWeatherListAdapter::GetCount(void) + { + return listData.size(); + } + + void FutureWeatherListAdapter::SetData(std::list &data) + { + if (!listData.empty()) + { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) + { + listData.push_back(*it); + } + } + + void FutureWeatherListAdapter::ClearData(void) + { + if (!listData.empty()) + { + listData.clear(); + } + } + + UIView *FutureWeatherListAdapter::GetView(UIView *inView, int16_t index) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::GetView,index %d", index); + // 1.先检查列表数据是否为空,若为空则返回空指针 + if (listData.empty()) + { + return nullptr; + } + // 2.接着检查索引是否小于0,若小于0则返回空指针 + if (index < 0) + { + return nullptr; + } + // 3.检查是否超出列表数据大小,若超出则返回空指针 + size_t uindex = index; + if (uindex >= listData.size()) + { + return nullptr; + } + // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量 + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) + { + it++; + } + FutureWeather itemData = *it; + FutureWeatherListitemView *item = nullptr; + // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的LanguageSwitchListItemView对象,否则将inView转换成LanguageSwitchListItemView类型的指针 + if (inView == nullptr) + { + item = new FutureWeatherListitemView(); + } + else + { + item = dynamic_cast(inView); + } + item->SetItemInfo(itemData); + return item; + } + + void FutureWeatherListAdapter::AddListItem(const FutureWeather &item) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::AddListItem"); + listData.push_back(item); + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListitemView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListitemView.cpp new file mode 100644 index 000000000..48addec65 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListitemView.cpp @@ -0,0 +1,87 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-15 09:25:53 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-10-05 10:53:08 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp + */ + +#include "weather/include/FutureWeatherListitemView.h" +#include "wearable_log.h" +namespace OHOS +{ + + FutureWeatherListitemView::FutureWeatherListitemView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::FutureWeatherListitemView"); + SetPosition(0, 0, 330, 85); + SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + SetStyle(STYLE_BACKGROUND_OPA, 255); + SetTouchable(true); + SetUpChild(); + Add(&weatherImg); + Add(&dateLabel); + Add(&minAndmaxTemperatureLabel); + // Add(&minTemperatureLabel); + // Add(&maxTemperatureLabel); + } + + FutureWeatherListitemView::~FutureWeatherListitemView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::~FutureWeatherListitemView"); + Remove(&weatherImg); + Remove(&dateLabel); + Remove(&minAndmaxTemperatureLabel); + // Remove(&minTemperatureLabel); + // Remove(&maxTemperatureLabel); + } + + void FutureWeatherListitemView::SetItemInfo(const FutureWeather itemInfo) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::SetItemInfo"); + weatherImg.SetSrc(itemInfo.iconDay.c_str()); + dateLabel.SetText(itemInfo.fxDate.c_str()); + minAndmaxTemperatureLabel.SetText(itemInfo.tempMinAndMax.c_str()); + //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "itemInfo.iconDay.c_str() = %s,itemInfo.fxDate.c_str() = %s,itemInfo.tempMinAndMax.c_str()", itemInfo.iconDay.c_str(), itemInfo.fxDate.c_str(),itemInfo.tempMinAndMax.c_str()); + // minTemperatureLabel.SetText(itemInfo.tempMin.c_str()); + // maxTemperatureLabel.SetText(itemInfo.tempMax.c_str()); + } + + void FutureWeatherListitemView::SetUpChild() + { + /* -------------------------------------------------------------------------- */ + weatherImg.SetPosition(0, 0, 65, 65); + /* -------------------------------------------------------------------------- */ + dateLabel.SetPosition(101, 16); + dateLabel.SetStyle(STYLE_TEXT_FONT, 30); + dateLabel.SetStyle(STYLE_LINE_HEIGHT, 35); + dateLabel.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + dateLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + dateLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + /* -------------------------------------------------------------------------- */ + minAndmaxTemperatureLabel.SetPosition(231, 16, 40, 40); + minAndmaxTemperatureLabel.SetStyle(STYLE_TEXT_FONT, 30); + minAndmaxTemperatureLabel.SetStyle(STYLE_LINE_HEIGHT, 35); + minAndmaxTemperatureLabel.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + minAndmaxTemperatureLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + minAndmaxTemperatureLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); + // /* -------------------------------------------------------------------------- */ + // minTemperatureLabel.SetPosition(231, 16, 40, 40); + // minTemperatureLabel.SetStyle(STYLE_TEXT_FONT, 30); + // minTemperatureLabel.SetStyle(STYLE_LINE_HEIGHT, 35); + // minTemperatureLabel.SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + // minTemperatureLabel.SetLineBreakMode(UILabel::LINE_BREAK_STRETCH); + // minTemperatureLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + // minTemperatureLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // /* -------------------------------------------------------------------------- */ + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::SetUpChild %d %d ", minTemperatureLabel.GetWidth(), minTemperatureLabel.GetTextWidth()); + // maxTemperatureLabel.SetPosition(231 + minTemperatureLabel.GetTextWidth(), 16, 40, 40); + // maxTemperatureLabel.SetStyle(STYLE_TEXT_FONT, 30); + // maxTemperatureLabel.SetStyle(STYLE_LINE_HEIGHT, 35); + // maxTemperatureLabel.SetLineBreakMode(UILabel::LINE_BREAK_STRETCH); + // maxTemperatureLabel.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + // maxTemperatureLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // /* -------------------------------------------------------------------------- */ + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherView.cpp new file mode 100644 index 000000000..a99bd59f2 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherView.cpp @@ -0,0 +1,151 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2025-02-25 15:09:45 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp + */ +#include "weather/include/FutureWeatherView.h" +#include "wearable_log.h" +#include "weather/include/WeatherModel.h" +#include "ui_resource_string.h" +#include "weather/include/WeatherModel.h" +namespace OHOS +{ + + static FutureWeatherView *g_pFutureWeatherView{nullptr}; + + FutureWeatherView::FutureWeatherView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::FutureWeatherView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(2); // 视图索引 + g_pFutureWeatherView = this; + } + + FutureWeatherView::~FutureWeatherView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::~FutureWeatherView"); + ClearAll(); + g_pFutureWeatherView = nullptr; + } + + FutureWeatherView *FutureWeatherView::GetInstance() + { + return g_pFutureWeatherView; + } + + void FutureWeatherView::ClearAll() + { + if (viewInitStatus == true) + { + RemoveAll(); + + delete Title; + Title = nullptr; + + delete futureWeatherListAdapter; + futureWeatherListAdapter = nullptr; + + delete FutureWeatherList; + FutureWeatherList = nullptr; + } + } + + bool FutureWeatherView::InitPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage"); + /* -------------------------------------------------------------------------- */ + Title = new UILabelExt(); + if (Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::Title is new fail!!"); + return false; + } + Title->SetPosition(93, 52, 280, 47); + Title->SetStyle(STYLE_TEXT_FONT, 30); + Title->SetStyle(STYLE_LINE_HEIGHT, 35); + Title->SetTextId(STR_NEXT_7_DAYS); + Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + Add(Title); + /* -------------------------------------------------------------------------- */ + futureWeatherListAdapter = new FutureWeatherListAdapter(); + if (futureWeatherListAdapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FutureWeatherView::InitPage] futureWeatherListAdapter is nullptr"); + return false; + } + /* -------------------------------------------------------------------------- */ + FutureWeatherList = new UIList(UIList::VERTICAL); + if (FutureWeatherList == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::FutureWeatherList is nullptr"); + return false; + } + FutureWeatherList->SetPosition(68, 130, 330, 300); + FutureWeatherList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + FutureWeatherList->SetThrowDrag(true); + FutureWeatherList->SetReboundSize(30); + FutureWeatherList->SetMaxScrollDistance(1000); + FutureWeatherList->SetScrollBlankSize(30); + FutureWeatherList->SetDragACCLevel(5); + FutureWeatherList->SetSwipeACCLevel(200); + WeatherModel::GetInstance().InitFutureWeatherItem(); + FutureWeatherList->SetAdapter(futureWeatherListAdapter); + FutureWeatherList->RequestFocus(); + FutureWeatherList->SetRotateFactor(1.0); + FutureWeatherList->SetIntercept(true); + Add(FutureWeatherList); + viewInitStatus = true; + + return true; + } + + bool FutureWeatherView::InitView(void *caller) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage fail"); + return false; + } + // UpdateFutureWeatherListData(); + SetDraggable(true); + SetTouchable(true); + return true; + } + + void FutureWeatherView::AddFutureWeatherItemToList(const FutureWeather &item) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::AddFutureWeatherItemToList"); + futureWeatherListAdapter->AddListItem(item); + } + + UIList *FutureWeatherView::GetFutureWeatherList() + { + return FutureWeatherList; + } + + // 更新未来七天数据 + bool FutureWeatherView::UpdateFutureWeatherListData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::UpdateFutureWeatherListData"); + if (futureWeatherListAdapter != nullptr) + { + delete futureWeatherListAdapter; + futureWeatherListAdapter = nullptr; + } + futureWeatherListAdapter = new FutureWeatherListAdapter(); + if (futureWeatherListAdapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "futureWeatherListAdapter is nullptr"); + return false; + } + WeatherModel::GetInstance().InitFutureWeatherItem(); + FutureWeatherList->SetAdapter(futureWeatherListAdapter); + FutureWeatherList->RefreshList(); + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp new file mode 100644 index 000000000..c2116553d --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp @@ -0,0 +1,104 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 14:50:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp + */ +#include "weather/include/GetWeatherDataErrorView.h" +#include "wearable_log.h" +#include "weather/include/MainWeatherPresenter.h" +#include "ui_resource_string.h" + +/* 天气获取数据失败后会调用该视图*/ +namespace OHOS +{ + + static GetWeatherDataErrorView *g_pGetWeatherDataErrorView{nullptr}; + + GetWeatherDataErrorView::GetWeatherDataErrorView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetWeatherDataErrorView::GetWeatherDataErrorView"); + g_pGetWeatherDataErrorView = this; + } + + GetWeatherDataErrorView::~GetWeatherDataErrorView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetWeatherDataErrorView::~GetWeatherDataErrorView"); + ClearAll(); + g_pGetWeatherDataErrorView = nullptr; + } + + GetWeatherDataErrorView *GetWeatherDataErrorView::GetInstance() + { + return g_pGetWeatherDataErrorView; + } + + UIScrollView *GetWeatherDataErrorView::GetWeatherDataErrorViewInit() + { + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + if (scrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is new fail!!"); + return nullptr; + } + scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + scrollView->SetViewId(GETWEATHERDATAERRORVIEW); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + /* -------------------------------------------------------------------------- */ + image = new UIImageView(); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image is new fail!!"); + return nullptr; + } + image->SetPosition(168, 127, 130, 130); + const char *ImgSr = "/user/res/weather/weather65x65/weather_unknown.bin"; // 天气数据获取失败 + image->SetAutoEnable(false); + image->SetResizeMode(UIImageView::CONTAIN); + image->SetSrc(ImgSr); + scrollView->Add(image); + /* -------------------------------------------------------------------------- */ + label = new UILabelExt(); + if (label == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is new fail!!"); + return nullptr; + } + label->SetPosition(33, 268, 400, 70); + label->SetStyle(STYLE_TEXT_FONT, 30); + label->SetStyle(STYLE_LINE_HEIGHT, 35); + label->SetTextId(STR_GET_WEATHER_ERROR); + label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + + scrollView->Add(label); + } + return scrollView; + } + + void GetWeatherDataErrorView::ClearAll() + { + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + if (label != nullptr) + { + delete label; + label = nullptr; + } + if (image != nullptr) + { + delete image; + image = nullptr; + } + delete scrollView; + scrollView = nullptr; + } + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp new file mode 100644 index 000000000..a8e28d0e3 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp @@ -0,0 +1,132 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "weather/include/MainWeatherPresenter.h" +#include "common/key_code.h" +#include "common/key_code.h" +#include +#include +#include "UiConfig.h" +#include "gfx_utils/mem_check.h" + +#include "NativeRegisterManager.h" +namespace OHOS +{ + REGIST_MENU_PRO(VIEW_WEATHER, MainWeatherView, MainWeatherPresenter, + PNG_APPLIST_WEATHER_IMAGE_BIG, PNG_APPLIST_WEATHER_IMAGE,PNG_APPLIST_WEATHER_IMAGE, "天气", STR_WEATHER); + + // 当前Presenter属性实例化的内存指针 + static MainWeatherPresenter *g_pMainWeatherPresenter = nullptr; + + MainWeatherPresenter::MainWeatherPresenter() + { + weatherModel = &WeatherModel::GetInstance(); + g_pMainWeatherPresenter = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + MainWeatherPresenter::~MainWeatherPresenter() + { + g_pMainWeatherPresenter = nullptr; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + MainWeatherPresenter *MainWeatherPresenter::GetInstance() + { + + return g_pMainWeatherPresenter; + } + + void MainWeatherPresenter::OnStart() + { + + } + + void MainWeatherPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainWeatherPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void MainWeatherPresenter::OnStop(void) + { + } + + bool MainWeatherPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MainWeatherPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool MainWeatherPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnDragEnd"); + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainWeatherPresenter::X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + X_DRAG_FLAG = false; + } + return true; + } + + bool MainWeatherPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnClick"); + + UNUSED(view); + UNUSED(event); + return true; + } + + // 增加按键事件 + bool MainWeatherPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + } + + void MainWeatherPresenter::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherPresenter::OnSwipe,current tab index = %d", view.GetCurrentPage()); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the view index = %d,dragging direction = %d,current tab index = %d", view.GetViewIndex(), view.GetDirection(), view.GetCurrentPage()); + if (view.GetCurrentPage() == MAINWEATHERVIEW) + { + WeatherModel::GetInstance().UpdateWeatherCurTime(); + } + } + + void WeatherControlViewOnSwipeListener::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlViewOnSwipeListener::OnSwipe,current tab index = %d", view.GetCurrentPage()); + // if (view.GetCurrentPage() == MAINWEATHERVIEW) + // { + // view.SetIntercept(false); + // //MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); + // } + // else + // { + // view.SetIntercept(true); + // } + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp new file mode 100644 index 000000000..caa57f44c --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp @@ -0,0 +1,265 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2025-02-24 16:52:22 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp + */ +#include "weather/include/MainWeatherView.h" +#include "weather/include/MainWeatherPresenter.h" +#include "weather/include/WeatherModel.h" +namespace OHOS +{ + static MainWeatherView *g_pMainWeatherView{nullptr}; + MainWeatherView::MainWeatherView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::MainWeatherView"); + g_pMainWeatherView = this; + } + + MainWeatherView::~MainWeatherView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::~MainWeatherView"); + ClearAll(); + g_pMainWeatherView = nullptr; + } + + MainWeatherView *MainWeatherView::GetInstance(void) + { + return g_pMainWeatherView; + } + + void MainWeatherView::ClearAll(void) + { + if (weatherSwipeViewList != nullptr) + { + weatherSwipeViewList->RemoveAll(); + + delete weatherView; + weatherView = nullptr; + + delete weatherReportView; + weatherReportView = nullptr; + + delete futureWeatherView; + futureWeatherView = nullptr; + + delete weatherSwipeViewList; + weatherSwipeViewList = nullptr; + } + + if (getWeatherDataErrorView != nullptr) + { + delete getWeatherDataErrorView; + getWeatherDataErrorView = nullptr; + } + + for (int32_t i = 0; i < maxPage; i++) + { + recordCard[i] = nullptr; + } + } + + /* + * @brief 主天气页面视图初始化 + */ + UISwipeView *MainWeatherView::MainWeatherViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::MainWeatherViewInit"); + if (nullptr == weatherSwipeViewList) + { + weatherSwipeViewList = new UISwipeView(UISwipeView::VERTICAL); + if (nullptr == weatherSwipeViewList) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherSwipeViewList new fail!!"); + return nullptr; + } + + weatherSwipeViewList->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + weatherSwipeViewList->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); // 0 : X; 0 : Y + weatherSwipeViewList->SetAnimatorTime(50); // 50:animator drag time(ms) + weatherSwipeViewList->SetViewId(MAIN_WEATHER_VIEW); + weatherSwipeViewList->SetDraggable(true); + weatherSwipeViewList->SetTouchable(true); + weatherSwipeViewList->SetVisible(false); + for (uint16_t i = 0; i < maxPage; i++) + { + recordCard[i] = CreatePage(i); + if (nullptr == recordCard[i]) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "recordCard[%d] is nullptr!!", i); + return nullptr; + } + recordCard[i]->InitView(this); + weatherSwipeViewList->Add(recordCard[i]); + } + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView InitPage over!!"); + } + return weatherSwipeViewList; + } + + bool MainWeatherView::UpdateMainWeatherViewVisibility() + { + if (weatherSwipeViewList != nullptr && weatherScrllView != nullptr) + { + if (WeatherModel::GetInstance().GetWeatherDataIsValid()) + { + weatherSwipeViewList->SetVisible(true); + weatherScrllView->SetVisible(false); + } + else + { + weatherScrllView->SetVisible(true); + weatherSwipeViewList->SetVisible(false); + weatherScrllView->SetOnDragListener(presenter_); + } + GetRootContainer()->Invalidate(); + return true; + } + return false; + } + + void MainWeatherView::OnStart() + { + AddViewToRootContainer(MainWeatherViewInit()); + weatherScrllView = WeatherDataErrorViewPageInit(); + AddViewToRootContainer(weatherScrllView); + + if (weatherSwipeViewList != nullptr) + { + UIView::OnClickListener *weatherOnClickListener = (UIView::OnClickListener *)OHOS::MainWeatherPresenter::GetInstance(); + if (weatherOnClickListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnClickListener new fail"); + return; + } + + UIView::OnDragListener *weatherOnDragListener = (UIView::OnDragListener *)OHOS::MainWeatherPresenter::GetInstance(); + if (weatherOnDragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnDragListener new fail"); + return; + } + + UISwipeView::OnSwipeListener *weatherOnSwipeListener = (UISwipeView::OnSwipeListener *)OHOS::MainWeatherPresenter::GetInstance(); + if (weatherOnSwipeListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); + return; + } + weatherSwipeViewList->SetOnClickListener(presenter_); + weatherSwipeViewList->SetOnDragListener(presenter_); + weatherSwipeViewList->SetOnSwipeListener(presenter_); + } + UpdateMainWeatherViewVisibility(); + } + + WeatherView *MainWeatherView::GetWeatherView(void) + { + return weatherView; + } + + WeatherReportView *MainWeatherView::GetWeatherReportView(void) + { + return weatherReportView; + } + + FutureWeatherView *MainWeatherView::GetFutureWeatherView(void) + { + return futureWeatherView; + } + + /* + * @brief 天气页面视图初始化 + */ + AppGroupView *MainWeatherView::WeatherViewPageInit(void) + { + weatherView = new WeatherView(); + if (weatherView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView::new weatherView fail!"); + return nullptr; + } + + return weatherView; + } + + /* + * @brief 气象报告视图初始化 + */ + AppGroupView *MainWeatherView::WeatherReportViewPageInit(void) + { + weatherReportView = new WeatherReportView(); + if (weatherReportView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView::new weatherReportView fail!"); + return nullptr; + } + return weatherReportView; + } + + /* + * @brief 未来天气视图初始化 + */ + AppGroupView *MainWeatherView::FutureWeatherViewPageInit(void) + { + futureWeatherView = new FutureWeatherView(); + if (futureWeatherView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView::new futureWeatherView fail!"); + return nullptr; + } + return futureWeatherView; + } + + /* + * @brief 获取天气数据失败视图初始化 + */ + UIScrollView *MainWeatherView::WeatherDataErrorViewPageInit(void) + { + if (getWeatherDataErrorView == nullptr) + { + getWeatherDataErrorView = new GetWeatherDataErrorView(); + if (getWeatherDataErrorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getWeatherDataErrorView new fail!!"); + return nullptr; + } + } + return getWeatherDataErrorView->GetWeatherDataErrorViewInit(); + } + + struct MainWeatherViewMapper + { + const int16_t viewId; + AppGroupView *(MainWeatherView::*func)(void); + }; + + // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与DisplayBrightnessViewMapper类中的特定成员函数指针进行了绑定。 + static const MainWeatherViewMapper g_pageMapper[] = { + {MAINWEATHERVIEW, &MainWeatherView::WeatherViewPageInit}, + {WEATHERREPORTVIEW, &MainWeatherView::WeatherReportViewPageInit}, + {FUTUREWEATHERVIEW, &MainWeatherView::FutureWeatherViewPageInit}, + }; + + /* + * @brief 根据提供的 WeatherPageId 查找对应的页面ID,然后根据这个页面ID来创建对应的页面视图 + */ + AppGroupView *MainWeatherView::CreatePage(int32_t WeatherPageId) + { + uint16_t i; + AppGroupView *view = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage WeatherPageId:%d", WeatherPageId); + + for (i = 0; i < sizeof(g_pageMapper) / sizeof(g_pageMapper[0]); i++) + { + if (g_pageMapper[i].viewId == WeatherPageId) + { // 正确使用 WeatherPageId 来匹配视图ID + view = (this->*(g_pageMapper[i].func))(); // 如果找到匹配项,则调用相应的函数创建视图 + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage view:%p", view); + return view; // 返回创建的视图 + } + } + return nullptr; // 如果没有找到匹配的视图ID,返回 nullptr + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherControlView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherControlView.cpp new file mode 100644 index 000000000..867efa38b --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherControlView.cpp @@ -0,0 +1,175 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 14:51:13 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherControlView.cpp + */ +#include "weather/include/WeatherControlView.h" +#include "weather/include/MainWeatherPresenter.h" +namespace OHOS +{ + + static WeatherControlView *g_pWeatherControlView{nullptr}; + WeatherControlView::WeatherControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::WeatherControlView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pWeatherControlView = this; + } + + WeatherControlView::~WeatherControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::~WeatherControlView"); + ClearAll(); + g_pWeatherControlView = nullptr; + } + + WeatherControlView *WeatherControlView::GetInstance(void) + { + return g_pWeatherControlView; + } + + void WeatherControlView::ClearAll(void) + { + if (viewiInitStatus == true) + { + RemoveAll(); + delete weatherOnSwipeListener; + weatherOnSwipeListener = nullptr; + + delete mainWeatherView; + mainWeatherView = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::ClearAll success!!"); + } + } + + bool WeatherControlView::CreateMainWeatherView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::InitView"); + if (mainWeatherView == nullptr) + { + mainWeatherView = new MainWeatherView(); + if (mainWeatherView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::new mainWeatherView fail!"); + return false; + } + } + + return true; + } + + // 天气数据有效初始化该视图 + bool WeatherControlView::InitializeWeatherSwipeView() + { + if (weatherSwipView == nullptr) + { + weatherSwipView = mainWeatherView->MainWeatherViewInit(); + if (weatherSwipView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mainWeatherView->MainWeatherViewInit() == nullptr!!"); + return false; + } + } + + if (weatherOnSwipeListener == nullptr) + { + weatherOnSwipeListener = static_cast(new WeatherControlViewOnSwipeListener()); + if (weatherOnSwipeListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); + return false; + } + } + + // weatherSwipView->SetOnSwipeListener(weatherOnSwipeListener); + weatherSwipView->SetVisible(false); + Add(weatherSwipView); + + return true; + } + + // 无天气数据则初始化该视图 + bool WeatherControlView::InitializeWeatherDataErrorView() + { + if (weatherScrllView == nullptr) + { + weatherScrllView = mainWeatherView->WeatherDataErrorViewPageInit(); + if (weatherScrllView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mainWeatherView->WeatherDataErrorViewPageInit() == nullptr!!"); + return false; + } + } + + weatherScrllView->SetVisible(true); // 默认没有天气数据 + Add(weatherScrllView); + + return true; + } + + // 根据天气数据是否有效设置视图可见性: + bool WeatherControlView::UpdateWeatherControlViewVisibility() + { + if (weatherSwipView != nullptr && weatherScrllView != nullptr) + { + if (WeatherModel::GetInstance().GetWeatherDataIsValid()) + { + weatherSwipView->SetVisible(true); + weatherScrllView->SetVisible(false); + } + else + { + weatherScrllView->SetVisible(true); + weatherSwipView->SetVisible(false); + } + Invalidate(); + return true; + } + return false; + } + + bool WeatherControlView::InitView() + { + if (!CreateMainWeatherView()) + { + return false; + } + + if (!InitializeWeatherSwipeView()) + { + return false; + } + + if (!InitializeWeatherDataErrorView()) + { + return false; + } + + UpdateWeatherControlViewVisibility(); + + return true; + } + + void WeatherControlView::PreLoad(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherControlView::PreLoad"); + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + + void WeatherControlView::UnLoad(void) + { + // Weather's usage scenes is complicated, so we do not release it's resources inner slice. + } + + UISwipeView *WeatherControlView::GetWeatherSwipView(void) + { + return weatherSwipView; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherModel.cpp new file mode 100644 index 000000000..cd291e2b0 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherModel.cpp @@ -0,0 +1,395 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-08 18:40:09 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-10-24 15:32:28 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp + */ +#include "weather/include/WeatherModel.h" +#include "weather/include/MainWeatherView.h" +#include "weather/include/WeatherControlView.h" + +#include "ConfigModel.h" +#include "custom_runtime.h" + +#ifdef FD230_650 +#include "DialModelWeather.h" +#include "DialModelWeatherStr.h" +#endif + +namespace OHOS +{ +#if __cplusplus + extern "C" + { +#endif /* __cplusplus */ + static Weather_data Weather_data_t_now; + static Weather_data_address Weather_data_t_address; + static ONE_DAY_DATA Weather_data_seven_data[7]; + uint8_t Weather_data_seven_count = 0; + + /* + * @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, weather_short_len); + strcpy_s(Weather_data_t_now.windScale, weather_short_len, windScale); + memset((void *)Weather_data_t_now.textNight, 0, weather_short_len); + strcpy_s(Weather_data_t_now.textNight, weather_short_len, textNight); + Weather_data_t_now.uvIndex = uvIndex; + Weather_data_t_now.temp = temp; + Weather_data_t_now.iconNight = iconNight; + + WeatherModel::GetInstance().SetWeatherDataIsValid(true); + } + + /* + * @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_t_address.lat = lat; + Weather_data_t_address.lon = lon; + memset((void *)Weather_data_t_address.atm, 0, weather_short_len); + strcpy_s(Weather_data_t_address.atm, weather_short_len, atm); + memset((void *)Weather_data_t_address.city, 0, weather_long_len); + strcpy_s(Weather_data_t_address.city, weather_long_len, city); + memset((void *)Weather_data_t_address.subLocality, 0, weather_long_len); + strcpy_s(Weather_data_t_address.subLocality, weather_long_len, subLocality); + } + + /* + * @brief 设置七天天气数据 + */ + void UI_set_weather_seven_day_data(struct ONE_DAY_DATA t, int count) + { + if (count == 0) + { + Weather_data_seven_count = 0; + } + if (count >= 7) + { + return; + } + Weather_data_seven_data[count].fxDate = t.fxDate; + Weather_data_seven_data[count].iconDay = t.iconDay; + Weather_data_seven_data[count].tempMax = t.tempMax; + Weather_data_seven_data[count].tempMin = t.tempMin; + Weather_data_seven_data[count].fxDate = t.fxDate; + memset((void *)Weather_data_seven_data[count].textDay, 0, weather_short_len); + strcpy_s(Weather_data_seven_data[count].textDay, weather_short_len, t.textDay); + + Weather_data_seven_count++; + } + +#if __cplusplus + } +#endif /* __cplusplus */ + + WeatherModel::WeatherModel() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherModel::WeatherModel"); + } + + WeatherModel::~WeatherModel() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherModel::~WeatherModel"); + } + + WeatherModel &WeatherModel::GetInstance() + { + static WeatherModel instance; + return instance; + } + + void WeatherModel::InitFutureWeatherItem() + { + MainWeatherView *p_MainWeatherView = MainWeatherView::GetInstance(); + if (p_MainWeatherView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::GetInstance fail!!"); + return; + } + for (uint8_t i = 0; i < Weather_data_seven_count; i++) + { + FutureWeatherItem[i].iconDay = GetWeather_data_seven_data_iconDay(i); + FutureWeatherItem[i].fxDate = GetWeather_data_seven_data_fxDate(i); + FutureWeatherItem[i].tempMinAndMax = GetWeather_data_seven_data_tempMinAndtempMax(i); + p_MainWeatherView->GetFutureWeatherView()->AddFutureWeatherItemToList(FutureWeatherItem[i]); + } + } + + void WeatherModel::TimestampToMonthDayString(time_t timestamp, char *buffer) + { + // 将时间戳转换成tm结构 + struct tm timeinfo; + localtime_r(×tamp, &timeinfo); + + // 格式化输出月份和日期 + // 注意: 月份tm_mon从0开始计数,所以显示时需要加1 + sprintf(buffer, "%02d.%02d", timeinfo.tm_mon + 1, timeinfo.tm_mday); + } + + /*获取天气界面的当前时间*/ + std::string WeatherModel::GetWeatherCurTime() + { + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + + int hour = pTM.tm_hour; + // 需要判断显示的格式 + if (uapi_dev_runtime_get_time_hour_show_model() == 12) + { + if (pTM.tm_hour > 12) + hour = pTM.tm_hour - 12; + } + + int minute = pTM.tm_min; + + std::string weatherTime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + (minute < 10 ? "0" : "") + std::to_string(minute); + + return weatherTime; + } + + // 判断当前时间是否在晚上 + bool WeatherModel::IsNightTime() + { + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + + int hour = pTM.tm_hour; + + // 假设晚上是从 18 点到次日 6 点 + return hour >= 18 || hour < 6; + } + + // 获取天气图片 + std::string WeatherModel::GetWeatherImage() + { + // int index = Weather_data_t_now.iconNight;//夜晚天气图标 + int index; + // if (IsNightTime()) + // { + // index = Weather_data_t_now.iconNight; // 夜晚天气图标 + // } + // else + // { + // index = Weather_data_seven_data[0].iconDay; // 白天天气图标 + // } + index = Weather_data_seven_data[0].iconDay; // 白天天气图标 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_t_now.iconNight = %d", index); + return weather65x65[index]; + } + + // 获取温度 + std::string WeatherModel::GetWeatherTemperature() + { + int temperature = Weather_data_t_now.temp; + return std::to_string(temperature) + "°"; + } + + // 获取天气描述 + std::string WeatherModel::GetWeatherDescription() + { + std::string WeatherDescription; + // if (IsNightTime()) + // { + // WeatherDescription = Weather_data_t_now.textNight; + // } + // else + // { + // WeatherDescription = Weather_data_seven_data[0].textDay; + // } + WeatherDescription = Weather_data_seven_data[0].textDay; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherDescription:%s", WeatherDescription.c_str()); + return WeatherDescription; + } + + // 获取天气地区 + std::string WeatherModel::GetWeatherArea() + { + std::string city = Weather_data_t_address.city; + std::string subLocality = Weather_data_t_address.subLocality; + return (city + subLocality); + } + + // 获取最高气温和最低气温 + std::string WeatherModel::GetWeatherMaxAndMinTemperature() + { + int maxtemperature = Weather_data_seven_data[0].tempMax; + int mintemperature = Weather_data_seven_data[0].tempMin; + int language = ConfigModel::GetInstance()->GetLanguage(); + std::string MaxandMinTemperature; + if (language == 0) // 如果系统语言为中文 + { + MaxandMinTemperature = "最高" + std::to_string(maxtemperature) + "°" + " " + "最低" + std::to_string(mintemperature) + "°"; + } + else + { + MaxandMinTemperature = "Max" + std::to_string(maxtemperature) + "°" + " " + "Min" + std::to_string(mintemperature) + "°"; + } + return MaxandMinTemperature; + } + /* -------------------------------------------------------------------------- */ + /*获取未来七天中某一天白天天气图标*/ + std::string WeatherModel::GetWeather_data_seven_data_iconDay(int date) + { + int index = Weather_data_seven_data[date].iconDay; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].iconDay = %d", date, index); + return weather65x65[index]; + } + + /*获取未来七天某一天白天天气文本*/ + std::string WeatherModel::GetWeather_data_seven_data_textDay(int date) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].textDay = %s", date, Weather_data_seven_data[date].textDay); + return Weather_data_seven_data[date].textDay; + } + + /*获取未来七天某一天日期*/ + 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_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].fxDate = %s", date, formattedDate); + return formattedDate; + } + + /*获取未来七天某一天最高和最低气温*/ + std::string WeatherModel::GetWeather_data_seven_data_tempMinAndtempMax(int date) + { + int maxTemp = Weather_data_seven_data[date].tempMax; + int minTemp = Weather_data_seven_data[date].tempMin; + std::string maxandminTemperature = (std::to_string(minTemp) + "°") + "/" + std::to_string(maxTemp) + "°"; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "maxandminTemperature = %s", maxandminTemperature.c_str()); + return maxandminTemperature; + } + + /*获取未来七天某一天最低气温*/ + std::string WeatherModel::GetWeather_data_seven_data_tempMin(int date) + { + int minTemp = Weather_data_seven_data[date].tempMin; + std::string minTemperature = std::to_string(minTemp) + "°"; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].tempMin = %s", date, minTemperature.c_str()); + return minTemperature; + } + + /*获取未来七天某一天最高气温*/ + std::string WeatherModel::GetWeather_data_seven_data_tempMax(int date) + { + int maxTemp = Weather_data_seven_data[date].tempMax; + std::string maxTemperature = "/" + std::to_string(maxTemp) + "°"; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " Weather_data_seven_data[%d].tempMax = %s", date, maxTemperature.c_str()); + return maxTemperature; + } + + /* -------------------------------------------------------------------------- */ + + /*获取湿度*/ + std::string WeatherModel::GetHumidity() + { + std::string humidity = std::to_string(Weather_data_t_now.humidity) + "%"; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "humidity:%s", humidity.c_str()); + return humidity; + } + + /*获取风速*/ + std::string WeatherModel::GetWindScale() + { + std::string windScale = Weather_data_t_now.windScale; + WEARABLE_LOGD(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_LOGD(WEARABLE_LOG_MODULE_APP, "uvIndex:%s", uvIndex.c_str()); + return uvIndex; + } + + // 设置天气数据是否有效 + void WeatherModel::SetWeatherDataIsValid(bool value) + { + WEATHER_DATA_VALID = value; + } + + // 获取天气数据是否有效 + bool WeatherModel::GetWeatherDataIsValid() + { + return WEATHER_DATA_VALID; + } + + /* 更新所有天气数据 */ + void WeatherModel::UpdateMainWeatherData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateMainWeatherData"); + + MainWeatherView *p_MainWeatherView = MainWeatherView::GetInstance(); + if (p_MainWeatherView != nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "p_MainWeatherView"); + p_MainWeatherView->GetWeatherView()->UpdateWeatherViewData(); + p_MainWeatherView->GetWeatherReportView()->UpdateWeatherReportViewData(); + p_MainWeatherView->GetFutureWeatherView()->UpdateFutureWeatherListData(); + + p_MainWeatherView->UpdateMainWeatherViewVisibility(); + } + + WeatherControlView *p_WeatherControlView = WeatherControlView::GetInstance(); + if (p_WeatherControlView != nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "p_WeatherControlView"); + p_WeatherControlView->UpdateWeatherControlViewVisibility(); + } + #ifdef FD230_650 + if (DialModelWeather::GetInstance()) + { + int index; + // if(IsNightTime()) + // { + // index = Weather_data_t_now.iconNight; // 夜晚天气图标 + // } + // else + // { + // index = Weather_data_seven_data[0].iconDay; //白天天气图标 + // } + index = Weather_data_seven_data[0].iconDay; // 白天天气图标 + + DialModelWeather::GetInstance()->UpdateWeather(index); // 更新主界面天气图标 + // const std::string str = GetWeatherTemperature() + " "+GetWeatherDescription(); + const std::string str = GetWeatherTemperature(); + DialModelWeatherStr::GetInstance()->UpdateWeatherStr(str); + } + #endif + } + + /*更新天气界面的时间显示*/ + void WeatherModel::UpdateWeatherCurTime(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateWeatherCurTime"); + MainWeatherView *p_MainWeatherView = MainWeatherView::GetInstance(); + if (p_MainWeatherView != nullptr) + { + p_MainWeatherView->GetWeatherView()->UpdateWeatherTime(); + } + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherReportView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherReportView.cpp new file mode 100644 index 000000000..54e0ba08e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherReportView.cpp @@ -0,0 +1,461 @@ +/*** + * @Date: 2024-08-19 11:01:42 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-30 19:25:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp + */ +#include "weather/include/WeatherReportView.h" +#include "wearable_log.h" +#include "weather/include/WeatherModel.h" +#include "common/image_cache_manager.h" +#include "uicomponents/UIComponents.h" +namespace OHOS +{ + static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_X = 53; + static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_Y = 160; + static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_W = 60; + static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_H = 60; + static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 24; // 图片帧数 + static constexpr int16_t UV_IMAGE_ANIMATOR_TIME = 100; // 图片更新间隔 + static ImageAnimatorInfo UVimageAnimatorInfo[UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; + + static constexpr int16_t WINDSPEED_IMAGE_ANIMATOR_VIEW_X = 203; + static constexpr int16_t WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 24; // 图片帧数 + static ImageAnimatorInfo WindSpeedimageAnimatorInfo[WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; + + static constexpr int16_t HUMIDITY_IMAGE_ANIMATOR_VIEW_X = 353; + static constexpr int16_t HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 20; // 图片帧数 + static ImageAnimatorInfo HumidityimageAnimatorInfo[HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; + + static constexpr const char *UVPaths = "/user/res/weather/weather60x60gif/UV/"; + static constexpr const char *WindSpeedPaths = "/user/res/weather/weather60x60gif/WindSpeed/"; + static constexpr const char *HumidityPaths = "/user/res/weather/weather60x60gif/Humidity/"; + + static WeatherReportView *g_pWeatherReportView{nullptr}; + + WeatherReportView::WeatherReportView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " WeatherReportView::WeatherReportView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(1); + WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); + UVData = p_WeatherModel->GetUVIndex(); // 紫外线强度数据 + WindSpeedData = p_WeatherModel->GetWindScale(); // 风速数据 + HumidityData = p_WeatherModel->GetHumidity(); // 湿度数据 + + g_pWeatherReportView = this; + } + + WeatherReportView::~WeatherReportView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " WeatherReportView::~WeatherReportView"); + ClearAll(); + g_pWeatherReportView = nullptr; + } + + WeatherReportView *WeatherReportView::GetInstance() + { + return g_pWeatherReportView; + } + + void WeatherReportView::ClearAll(void) + { + if (viewInitStatus == true) + { + RemoveAll(); + delete title; + title = nullptr; + + delete UV; + UV = nullptr; + + delete UV_Number; + UV_Number = nullptr; + + delete WindSpeed; + WindSpeed = nullptr; + + delete WindSpeed_Number; + WindSpeed_Number = nullptr; + + delete Humidity; + Humidity = nullptr; + + delete Humidity_Number; + Humidity_Number = nullptr; + + delete PullUpImage; + PullUpImage = nullptr; + + UVImageAnimatorView->Stop(); + delete UVImageAnimatorView; + UVImageAnimatorView = nullptr; + + WindSpeedImageAnimatorView->Stop(); + delete WindSpeedImageAnimatorView; + WindSpeedImageAnimatorView = nullptr; + + HumidityImageAnimatorView->Stop(); + delete HumidityImageAnimatorView; + HumidityImageAnimatorView = nullptr; + + // FreeImagePathsArray(UVPathsArray, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + + // FreeImagePathsArray(WindSpeedPathsArray, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + + // FreeImagePathsArray(HumidityPathsArray, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + + FreeImageInfoArray(UVPathsArray, UVPaths, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + FreeImageInfoArray(WindSpeedPathsArray, WindSpeedPaths, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + FreeImageInfoArray(HumidityPathsArray, HumidityPaths, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + } + } + + // 设置标签 + UILabelExt *WeatherReportView::SetUpLabel(LabelConfig &labelconfig) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + 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.c_str()); // 内容 + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(GILROY_BOLD_FONT, labelconfig.fontSize); + return label; + } + + UILabelExt *WeatherReportView::SetUpLabelExt(LabelConfig &labelconfig) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + 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->SetTextId(labelconfig.textId); // 内容 + label->SetLineBreakMode(labelconfig.lineBreakMode); // 断行模式。 + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); + return label; + } + + bool WeatherReportView::WeatherReportViewLabelInit(void) + { + LabelConfig labelconfig = { + .left = 83, + .top = 52, + .width = 300, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + //.text = "气象报告", + .textId = STR_WEATHER_REPORT, + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + title = SetUpLabelExt(labelconfig); + if (title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::title new fail!"); + return false; + } + /* -------------------------------------------------------------------------- */ + labelconfig = { + .left = 23, + .top = 240, + .width = 120, + .height = 50, + .fontSize = 40, + .lineHeigh = 50, + .text = UVData.c_str(), // 紫外线强度 + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + UV_Number = SetUpLabel(labelconfig); + if (UV_Number == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::UV_Number new fail!"); + return false; + } + + labelconfig.left = 173; + labelconfig.text = WindSpeedData.c_str(); // 风速 + WindSpeed_Number = SetUpLabel(labelconfig); + if (WindSpeed_Number == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WindSpeed_Number new fail!"); + return false; + } + + labelconfig.left = 323; + labelconfig.text = HumidityData.c_str(); // 湿度 + Humidity_Number = SetUpLabel(labelconfig); + if (Humidity_Number == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::Humidity_Number new fail!"); + return false; + } + + /* -------------------------------------------------------------------------- */ + labelconfig = { + .left = 23, + .top = 290, + .width = 120, + .height = 35, + .fontSize = 30, + .lineHeigh = 35, + //.text = "紫外线", + .textId = STR_ULTRAVIOLET, + .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, + }; + UV = SetUpLabelExt(labelconfig); + if (UV == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::UV new fail!"); + return false; + } + UV->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + + labelconfig.left = 173; + // labelconfig.text = "风速"; + labelconfig.textId = STR_WIND_SPEED; + WindSpeed = SetUpLabelExt(labelconfig); + if (WindSpeed == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WindSpeed new fail!"); + return false; + } + WindSpeed->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + + labelconfig.left = 323; + // labelconfig.text = "湿度"; + labelconfig.textId = STR_HUMIDITY; + Humidity = SetUpLabelExt(labelconfig); + if (Humidity == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::Humidity new fail!"); + return false; + } + Humidity->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + /* ----------------------------------- Add ---------------------------------- */ + + Add(title); + Add(UV_Number); + Add(WindSpeed_Number); + Add(Humidity_Number); + Add(UV); + Add(WindSpeed); + Add(Humidity); + + return true; + } + + bool WeatherReportView::WeatherReportViewImageAnimatorViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WeatherReportViewImageAnimatorViewInit"); + + /* ----------------------------- UVImageAnimatorView---------------------------- */ + UVPathsArray = CreateImageInfoArray(UVPaths, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (UVImageAnimatorView == nullptr) + { + UVImageAnimatorView = new UIImageAnimatorView(); + if (UVImageAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UVImageAnimatorView new fail"); + return false; + } + 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 = 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; + UVimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H; + } + UVImageAnimatorView->SetPosition(UV_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H); + UVImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + UVImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + UVImageAnimatorView->SetImageAnimatorSrc(UVimageAnimatorInfo, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME); + UVImageAnimatorView->SetRepeat(true); + UVImageAnimatorView->Start(); + } + /* ----------------------- WindSpeedImageAnimatorView ----------------------- */ + WindSpeedPathsArray = CreateImageInfoArray(WindSpeedPaths, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (WindSpeedImageAnimatorView == nullptr) + { + WindSpeedImageAnimatorView = new UIImageAnimatorView(); + if (WindSpeedImageAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WindSpeedImageAnimatorView new fail"); + return false; + } + 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 = 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; + WindSpeedimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H; + } + WindSpeedImageAnimatorView->SetPosition(WINDSPEED_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H); + WindSpeedImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + WindSpeedImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + WindSpeedImageAnimatorView->SetImageAnimatorSrc(WindSpeedimageAnimatorInfo, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME); + WindSpeedImageAnimatorView->SetRepeat(true); + WindSpeedImageAnimatorView->Start(); + } + /* ------------------------ HumidityImageAnimatorView ----------------------- */ + HumidityPathsArray = CreateImageInfoArray(HumidityPaths, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES); + if (HumidityImageAnimatorView == nullptr) + { + HumidityImageAnimatorView = new UIImageAnimatorView(); + if (HumidityImageAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HumidityImageAnimatorView new fail"); + return false; + } + 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 = 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; + HumidityimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H; + } + HumidityImageAnimatorView->SetPosition(HUMIDITY_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H); + HumidityImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + HumidityImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + HumidityImageAnimatorView->SetImageAnimatorSrc(HumidityimageAnimatorInfo, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME); + HumidityImageAnimatorView->SetRepeat(true); + HumidityImageAnimatorView->Start(); + } + /* -------------------------------------------------------------------------- */ + PullUpImage = new UIImageView(); + if (PullUpImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new PullUpImage fail!"); + return false; + } + PullUpImage->SetPosition(213, 400, 40, 40); + PullUpImage->SetAutoEnable(false); + PullUpImage->SetResizeMode(UIImageView::CONTAIN); + PullUpImage->SetSrc("/user/res/Sleep/up.bin"); + /* ----------------------------------- Add ---------------------------------- */ + Add(UVImageAnimatorView); + Add(WindSpeedImageAnimatorView); + Add(HumidityImageAnimatorView); + Add(PullUpImage); + viewInitStatus = true; + + return true; + } + + bool WeatherReportView::InitPage(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage"); + if (!WeatherReportViewLabelInit() || !WeatherReportViewImageAnimatorViewInit()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage fail!!"); + return false; + } + + return true; + } + + bool WeatherReportView::InitView(void *caller) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherReportView InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage fail"); + return false; + } + // UpdateWeatherReportViewData(); + SetDraggable(true); + SetTouchable(true); + return true; + } + + + // 设置文本标签的通用函数 + bool WeatherReportView::SetTextLabel(UILabel *label, const std::string &text) + { + if (label) + { + label->SetText(text.c_str()); + label->Invalidate(); + return true; + } + return false; + } + + void WeatherReportView::DumpWeatherInfo(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::DumpWeatherInfo"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UVData:%s", UVData.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WindSpeedData:%s", WindSpeedData.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HumidityData:%s", HumidityData.c_str()); + } + + // 更新紫外线数据 + bool WeatherReportView::UpdateUVData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateUVData"); + + std::string uv = WeatherModel::GetInstance().GetUVIndex(); + + return SetTextLabel(UV_Number, uv); + } + + // 更新风速数据 + bool WeatherReportView::UpdateWindSpeedData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWindSpeedData"); + + std::string windscale = WeatherModel::GetInstance().GetWindScale(); + + return SetTextLabel(WindSpeed_Number, windscale); + return true; + } + + // 更新湿度数据 + bool WeatherReportView::UpdateHumidityData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateHumidityData"); + + std::string humidity = WeatherModel::GetInstance().GetHumidity(); + + return SetTextLabel(Humidity_Number, humidity); + } + + // 更新气象报告数据 + bool WeatherReportView::UpdateWeatherReportViewData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherReportViewData"); + bool success = true; + success &= UpdateUVData(); + success &= UpdateWindSpeedData(); + success &= UpdateHumidityData(); + if (!success) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherViewData fail!!"); + } + // DumpWeatherInfo(); + return true; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherView.cpp new file mode 100644 index 000000000..778a62f13 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherView.cpp @@ -0,0 +1,451 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-06-12 11:44:04 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-11-05 14:51:56 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp + */ +#include "weather/include/WeatherView.h" +#include "ConfigModel.h" +#include "weather/include/WeatherModel.h" +#include "graphic_config.h" +/* +当至天气界面时,主动获取最新天气数据。 +(此操作静默将进行,获取到则立刻更新显示,获取不到则重试 +重试3次无果结束更新) +在加载该视图时,需要加载:1时间,2天气图片,3温度,4天气描述,5,地点,6,温度范围 +*/ + +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 = 100; + static constexpr int16_t WEATHER_IMAGE_Y = 168; + static constexpr int16_t WEATHER_IMAGE_W = 130; + static constexpr int16_t WEATHER_IMAGE_H = 130; + + /*当前时间标签*/ + 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 = 240; + static constexpr int16_t TEMPERATURE_LABEL_Y = 170; + 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 = 53; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_Y = 316; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_W = 360; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_H = 35; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_TEXT_FONT = 30; + static constexpr int16_t WEATHER_DESCRIPTION_LABEL_LINE_HEIGHT = 35; + + /*天气地区标签*/ + static constexpr int16_t WEATHER_AREA_LABEL_X = 53; + static constexpr int16_t WEATHER_AREA_LABEL_Y = 110; + static constexpr int16_t WEATHER_AREA_LABEL_W = 360; + static constexpr int16_t WEATHER_AREA_LABEL_H = 35; + static constexpr int16_t WEATHER_AREA_LABEL_TEXT_FONT = 30; + static constexpr int16_t WEATHER_AREA_LABEL_LINE_HEIGHT = 35; + + /*最高与最低气温标签*/ + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_X = 53; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_Y = 361; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_W = 360; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_H = 35; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_TEXT_FONT = 30; + static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_LINE_HEIGHT = 35; + +#if IS_USE_IMAGEANIMATOR + 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; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_H = 40; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_NUM_FRAMES = 70; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_TIME = 100; + ImageAnimatorInfo PullUpimageAnimatorInfo[PULLUP_ANIMATOR_VIEW_NUM_FRAMES]; + static constexpr const char *PullUpPaths = "/user/res/weather/PullUp/PullUp_"; +#else + /*上拉图片*/ + static constexpr int16_t PULLUP_IMAGE_X = 213; + static constexpr int16_t PULLUP_IMAGE_Y = 400; + static constexpr int16_t PULLUP_IMAGE_W = 40; + static constexpr int16_t PULLUP_IMAGE_H = 40; +#endif + + static WeatherView *g_pWeatherView{nullptr}; + WeatherView::WeatherView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::WeatherView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); + WeatherTime = p_WeatherModel->GetWeatherCurTime(); + WeatherImag = p_WeatherModel->GetWeatherImage(); + Temperature = p_WeatherModel->GetWeatherTemperature(); + WeatherDescription = p_WeatherModel->GetWeatherDescription(); + WeatherArea = p_WeatherModel->GetWeatherArea(); + MaxandMinTemperature = p_WeatherModel->GetWeatherMaxAndMinTemperature(); + + g_pWeatherView = this; + } + + WeatherView::~WeatherView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " WeatherView::~WeatherView"); + ClearAll(); + g_pWeatherView = nullptr; + } + + void WeatherView::ClearAll() + { + if (viewInitStatus == true) + { + RemoveAll(); + if (WeatherBackGroundImg != nullptr) + { + delete WeatherBackGroundImg; + WeatherBackGroundImg = nullptr; + } + if (showWeatherImage != nullptr) + { + delete showWeatherImage; + showWeatherImage = nullptr; + } + if (showCurrentTimeLabel != nullptr) + { + delete showCurrentTimeLabel; + showCurrentTimeLabel = nullptr; + } + if (showTemperatureLabel != nullptr) + { + delete showTemperatureLabel; + showTemperatureLabel = nullptr; + } + if (showWeatherDescriptionLabel != nullptr) + { + delete showWeatherDescriptionLabel; + showWeatherDescriptionLabel = nullptr; + } + if (showWeatherAreaLabel != nullptr) + { + delete showWeatherAreaLabel; + showWeatherAreaLabel = nullptr; + } + if (showMaxandMinTemperatureLabel != nullptr) + { + delete showMaxandMinTemperatureLabel; + showMaxandMinTemperatureLabel = nullptr; + } +#if IS_USE_IMAGEANIMATOR + if (PullUpAnimatorView != nullptr) + { + PullUpAnimatorView->Stop(); + delete PullUpAnimatorView; + PullUpAnimatorView = nullptr; + } + FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); +#else + if (PullUpImage != nullptr) + { + delete PullUpImage; + PullUpImage = nullptr; + } +#endif + } + } + + WeatherView *WeatherView::GetInstance() + { + return g_pWeatherView; + } + + UILabelExt *WeatherView::InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + 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_OSCILLATION); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, textfont); + return label; + } + + bool WeatherView::InitPage(void) + { + WEARABLE_LOGD(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(WeatherBackground); + /* -------------------------------------------------------------------------- */ + showWeatherImage = new UIImageView(); + if (showWeatherImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new showWeatherImage fail!"); + return false; + } + showWeatherImage->SetPosition(WEATHER_IMAGE_X, WEATHER_IMAGE_Y, WEATHER_IMAGE_W, WEATHER_IMAGE_W); + showWeatherImage->SetAutoEnable(false); + showWeatherImage->SetResizeMode(UIImageView::CONTAIN); + showWeatherImage->SetSrc(WeatherImag.c_str()); + /* -------------------------------------------------------------------------- */ + showCurrentTimeLabel = InitLabelExt(CURRENT_TIME_LABEL_X, CURRENT_TIME_LABEL_Y, CURRENT_TIME_LABEL_W, CURRENT_TIME_LABEL_H, WeatherTime.c_str(), + 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; + } + showCurrentTimeLabel->SetFont(GILROY_BOLD_FONT, CURRENT_TIME_LABEL_TEXT_FONT); + /* -------------------------------------------------------------------------- */ + 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; + } + // showTemperatureLabel->SetFont(GILROY_REGULAR_FONT, TEMPERATURE_LABEL_TEXT_FONT); + /* -------------------------------------------------------------------------- */ + 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 = 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!"); + return false; + } + showWeatherAreaLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + /* -------------------------------------------------------------------------- */ + 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)); +/* -------------------------------------------------------------------------- */ +#if IS_USE_IMAGEANIMATOR + PullUpPathsArray = CreateImagePathsArray(PullUpPaths, "bin", PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + if (PullUpAnimatorView == nullptr) + { + PullUpAnimatorView = new UIImageAnimatorView(); + if (PullUpAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpAnimatorView new fail"); + return false; + } + 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].pos.x = PULLUP_ANIMATOR_VIEW_X; + PullUpimageAnimatorInfo[i].pos.y = PULLUP_ANIMATOR_VIEW_Y; + PullUpimageAnimatorInfo[i].width = PULLUP_ANIMATOR_VIEW_W; + PullUpimageAnimatorInfo[i].height = PULLUP_ANIMATOR_VIEW_H; + } + PullUpAnimatorView->SetPosition(PULLUP_ANIMATOR_VIEW_X, PULLUP_ANIMATOR_VIEW_Y, PULLUP_ANIMATOR_VIEW_W, PULLUP_ANIMATOR_VIEW_H); + PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + PullUpAnimatorView->SetImageAnimatorSrc(PullUpimageAnimatorInfo, PULLUP_ANIMATOR_VIEW_NUM_FRAMES, PULLUP_ANIMATOR_VIEW_TIME); + PullUpAnimatorView->SetRepeat(true); + PullUpAnimatorView->Start(); + } +#else + PullUpImage = new UIImageView(); + if (PullUpImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new PullUpImage fail!"); + return false; + } + PullUpImage->SetPosition(PULLUP_IMAGE_X, PULLUP_IMAGE_Y, PULLUP_IMAGE_W, PULLUP_IMAGE_H); + PullUpImage->SetAutoEnable(false); + PullUpImage->SetResizeMode(UIImageView::CONTAIN); + PullUpImage->SetSrc("/user/res/Sleep/up.bin"); +#endif + /* -------------------------------- 将组件添加到根视图 ------------------------------- */ + Add(WeatherBackGroundImg); + Add(showWeatherImage); + Add(showCurrentTimeLabel); + Add(showTemperatureLabel); + Add(showWeatherDescriptionLabel); + Add(showWeatherAreaLabel); + Add(showMaxandMinTemperatureLabel); +#if IS_USE_IMAGEANIMATOR + Add(PullUpAnimatorView); +#else + Add(PullUpImage); +#endif + viewInitStatus = true; + + return true; + } + + bool WeatherView::InitView(void *caller) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::InitPage fail"); + return false; + } + // UpdateWeatherViewData(); + SetDraggable(true); + SetTouchable(true); + return true; + } + + + // 设置文本标签的通用函数 + bool WeatherView::SetTextLabel(UILabel *label, const std::string &text) + { + if (label) + { + label->SetText(text.c_str()); + label->Invalidate(); + return true; + } + return false; + } + + // 设置图片资源的通用函数 + bool WeatherView::SetImageSource(UIImageView *image, const std::string &source) + { + if (image) + { + image->SetSrc(source.c_str()); + image->Invalidate(); + return true; + } + return false; + } + + void WeatherView::DumpWeatherInfo() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::DumpWeatherInfo"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherTime:%s", WeatherTime.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherImag:%s", WeatherImag.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Temperature:%s", Temperature.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherDescription:%s", WeatherDescription.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherArea:%s", WeatherArea.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MaxandMinTemperature:%s\n", MaxandMinTemperature.c_str()); + } + + // 更新天气界面的当前时间 + bool WeatherView::UpdateWeatherTime() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherTime"); + + std::string weatherTime = WeatherModel::GetInstance().GetWeatherCurTime(); + + return SetTextLabel(showCurrentTimeLabel, weatherTime); + } + + // 更新天气界面的天气图片 + bool WeatherView::UpdateWeatherImag() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherImag"); + + std::string weatherImag = WeatherModel::GetInstance().GetWeatherImage(); + + return SetImageSource(showWeatherImage, weatherImag); + } + + // 更新天气界面的天气温度 + bool WeatherView::UpdateWeatherTemperature() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherTemperature"); + + std::string temperature = WeatherModel::GetInstance().GetWeatherTemperature(); + + return SetTextLabel(showTemperatureLabel, temperature); + } + + // 更新天气界面的天气描述 + bool WeatherView::UpdateWeatherWeatherDescription() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherWeatherDescription"); + + std::string weatherDescription = WeatherModel::GetInstance().GetWeatherDescription(); + + return SetTextLabel(showWeatherDescriptionLabel, weatherDescription); + } + + // 更新天气界面的天气地区 + bool WeatherView::UpdateWeatherWeatherArea() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherWeatherArea"); + + std::string weatherArea = WeatherModel::GetInstance().GetWeatherArea(); + + return SetTextLabel(showWeatherAreaLabel, weatherArea); + } + + // 更新天气界面的最高与最低气温 + bool WeatherView::UpdateWeatherMaxandMinTemperature() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherMaxandMinTemperature"); + + std::string maxMinTemperature = WeatherModel::GetInstance().GetWeatherMaxAndMinTemperature(); + + return SetTextLabel(showMaxandMinTemperatureLabel, maxMinTemperature); + } + + // 更新天气视图数据 + bool WeatherView::UpdateWeatherViewData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherViewData"); + bool success = true; + success &= UpdateWeatherTime(); + success &= UpdateWeatherImag(); + success &= UpdateWeatherTemperature(); + success &= UpdateWeatherWeatherDescription(); + success &= UpdateWeatherWeatherArea(); + success &= UpdateWeatherMaxandMinTemperature(); + + if (!success) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherViewData fail!!"); + } + + // DumpWeatherInfo(); // 输出天气信息到日志 + + return success; + } + +} \ No newline at end of file -- 2.17.1