天气slice合并提交
authorluozheng <1732036298@qq.com>
Wed, 26 Mar 2025 08:19:59 +0000 (16:19 +0800)
committerluozheng <1732036298@qq.com>
Wed, 26 Mar 2025 08:19:59 +0000 (16:19 +0800)
20 files changed:
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListAdapter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherListitemView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/FutureWeatherView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherPresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/MainWeatherView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherControlView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherModel.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherReportView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/include/WeatherView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListAdapter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherListitemView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/FutureWeatherView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/MainWeatherView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherControlView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherModel.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherReportView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/weather/src/WeatherView.cpp [new file with mode: 0644]

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 (file)
index 0000000..771b44a
--- /dev/null
@@ -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 <list>
+
+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<FutureWeather> &data);
+
+        void ClearData(void);
+        /* *
+         * @brief Obtains the <b>data</b> size of the UILabel adapter.
+         *
+         * @return Returns the <b>data</b> 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<FutureWeather> 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 (file)
index 0000000..c965cd7
--- /dev/null
@@ -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 (file)
index 0000000..a9d0eb5
--- /dev/null
@@ -0,0 +1,44 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-03-30 09:14:38\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-06-19 09:54:09\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h\r
+ */\r
+#ifndef FUTURE_WEATHER_VIEW_H\r
+#define FUTURE_WEATHER_VIEW_H\r
+\r
+\r
+#include "View.h"\r
+#include "components/ui_view_group.h"\r
+#include "components/ui_scroll_view.h"\r
+#include "components/ui_label_ext.h"\r
+#include "components/ui_list.h"\r
+#include "components/icon_adapter.h"\r
+#include "AppGroupView.h"\r
+#include "weather/include/FutureWeatherListAdapter.h"\r
+\r
+namespace OHOS\r
+{\r
+    class FutureWeatherView : public AppGroupView\r
+    {\r
+\r
+    public:\r
+        FutureWeatherView();\r
+        virtual ~FutureWeatherView();\r
+        static FutureWeatherView *GetInstance(void);\r
+        bool InitPage(void);\r
+        virtual bool InitView(void *caller) override;\r
+        void AddFutureWeatherItemToList(const FutureWeather &item);\r
+        bool UpdateFutureWeatherListData(void);\r
+        UIList *GetFutureWeatherList();\r
+    private:\r
+        void ClearAll(void);\r
+        // UIScrollView *scrollView{nullptr};\r
+        UILabelExt *Title = nullptr;\r
+        UIList *FutureWeatherList{nullptr};\r
+        FutureWeatherListAdapter *futureWeatherListAdapter{nullptr};\r
+        bool viewInitStatus{false};\r
+    };\r
+}\r
+#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 (file)
index 0000000..fa0530e
--- /dev/null
@@ -0,0 +1,38 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-03-30 09:14:38\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-06-15 14:21:01\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h\r
+ */\r
+#ifndef Get_WEATHER_DATA_ERROR_VIEW_H\r
+#define Get_WEATHER_DATA_ERROR_VIEW_H\r
+\r
+\r
+#include "View.h"\r
+#include "components/ui_scroll_view.h"\r
+#include "components/ui_label.h"\r
+#include "components/ui_label_ext.h"\r
+#include "components/ui_image_view.h"\r
+namespace OHOS\r
+{\r
+\r
+    static constexpr const char *GETWEATHERDATAERRORVIEW = "GetWeatherDataErrorView";\r
+    class GetWeatherDataErrorView\r
+    {\r
+\r
+    public:\r
+        GetWeatherDataErrorView();\r
+        virtual ~GetWeatherDataErrorView();\r
+        static GetWeatherDataErrorView *GetInstance(void);\r
+        UIScrollView *GetWeatherDataErrorViewInit(void);\r
+\r
+    private:\r
+        void ClearAll();\r
+\r
+        UIScrollView *scrollView = nullptr;\r
+        UILabelExt *label = nullptr;\r
+        UIImageView *image = nullptr;\r
+    };\r
+} \r
+#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 (file)
index 0000000..d149d71
--- /dev/null
@@ -0,0 +1,58 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-01-29 15:37:44\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-05-10 10:58:31\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h\r
+ */\r
+#ifndef MAIN_WEATHER_PRESENTER_H\r
+#define MAIN_WEATHER_PRESENTER_H\r
+\r
+#include "Presenter.h"\r
+#include "View.h"\r
+#include "MainWeatherView.h"\r
+#include "weather/include/WeatherModel.h"\r
+/*主天气视图*/\r
+namespace OHOS\r
+{\r
+    static constexpr const char *MAIN_WEATHER_VIEW = "MainWeatherview";\r
+    class WeatherControlViewOnSwipeListener : public UISwipeView::OnSwipeListener\r
+    {\r
+    public:\r
+        WeatherControlViewOnSwipeListener() {}\r
+        ~WeatherControlViewOnSwipeListener() {}\r
+        void OnSwipe(UISwipeView &view) override;\r
+    };\r
+\r
+    class MainWeatherView;\r
+    class MainWeatherPresenter : public Presenter<MainWeatherView>,\r
+                                 public UIView::OnClickListener,\r
+                                 public RootView::OnKeyActListener,\r
+                                 public UIView::OnDragListener,\r
+                                 public UISwipeView::OnSwipeListener\r
+    {\r
+    public:\r
+        MainWeatherPresenter();\r
+        virtual ~MainWeatherPresenter();\r
+\r
+        void OnStart() override;\r
+        void OnPause() override;\r
+        void OnResume() override;\r
+        void OnStop() override;\r
+\r
+        static MainWeatherPresenter *GetInstance();\r
+\r
+    private:\r
+        // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
+        bool OnClick(UIView &view, const ClickEvent &event) override;\r
+        bool OnDrag(UIView &view, const DragEvent &event) override;\r
+        bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
+        void OnSwipe(UISwipeView &view) override;\r
+\r
+        WeatherModel *weatherModel{nullptr};\r
+        bool X_DRAG_FLAG{false};\r
+    };\r
+} // namespace OHOS\r
+\r
+#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 (file)
index 0000000..2469577
--- /dev/null
@@ -0,0 +1,64 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-01-29 15:37:44\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2025-02-24 16:52:58\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h\r
+ */\r
+#ifndef MAIN_WEATHER_VIEW_H\r
+#define MAIN_WEATHER_VIEW_H\r
+\r
+#include "View.h"\r
+#include "components/ui_swipe_view.h"\r
+\r
+#include "weather/include/WeatherView.h"\r
+#include "weather/include/WeatherReportView.h"\r
+#include "weather/include/GetWeatherDataErrorView.h"\r
+#include "weather/include/FutureWeatherView.h"\r
+namespace OHOS\r
+{\r
+    typedef enum\r
+    {\r
+        MAINWEATHERVIEW = 0, // 主天气视图\r
+        WEATHERREPORTVIEW,   // 气象报告视图\r
+        FUTUREWEATHERVIEW,   // 未来七天天气视图\r
+        MAX_WEATHERVIEW,\r
+    } WeatherPageId;\r
+    class MainWeatherPresenter;\r
+    class MainWeatherView : public View<MainWeatherPresenter>\r
+    {\r
+\r
+    public:\r
+        MainWeatherView();\r
+        virtual ~MainWeatherView();\r
+        static MainWeatherView *GetInstance(void);\r
+        UISwipeView *MainWeatherViewInit(void);\r
+        void ClearAll(void);\r
+        AppGroupView *WeatherViewPageInit(void);\r
+        AppGroupView *WeatherReportViewPageInit(void);\r
+        AppGroupView *FutureWeatherViewPageInit(void);\r
+        UIScrollView *WeatherDataErrorViewPageInit(void);\r
+        WeatherView *GetWeatherView(void);\r
+        UIView *GetWeatherPageView(void);\r
+        WeatherReportView *GetWeatherReportView(void);\r
+        FutureWeatherView *GetFutureWeatherView(void);\r
+        bool UpdateMainWeatherViewVisibility(void);\r
+\r
+    public:\r
+        void OnStart() override;\r
+\r
+    private:\r
+        WeatherView *weatherView{nullptr};\r
+        WeatherReportView *weatherReportView{nullptr};\r
+        FutureWeatherView *futureWeatherView{nullptr};\r
+        GetWeatherDataErrorView *getWeatherDataErrorView{nullptr};\r
+\r
+    private:\r
+        int16_t maxPage = MAX_WEATHERVIEW;\r
+        UISwipeView *weatherSwipeViewList{nullptr}; // 天气滑动视图列表\r
+        AppGroupView *recordCard[MAX_WEATHERVIEW]{nullptr};\r
+        AppGroupView *CreatePage(int32_t WeatherPageId);\r
+        UIScrollView *weatherScrllView{nullptr};\r
+    };\r
+} // namespace OHOS\r
+#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 (file)
index 0000000..edad327
--- /dev/null
@@ -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 (file)
index 0000000..c334315
--- /dev/null
@@ -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 <time.h>
+#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 (file)
index 0000000..4e6940f
--- /dev/null
@@ -0,0 +1,84 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-03-30 09:14:38\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-08-17 16:20:42\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h\r
+ */\r
+#ifndef WEATHER_REPORT_VIEW_H\r
+#define WEATHER_REPORT_VIEW_H\r
+\r
+\r
+#include "View.h"\r
+#include "AppGroupView.h"\r
+#include "components/ui_view_group.h"\r
+#include "components/ui_scroll_view.h"\r
+#include "components/ui_label_ext.h"\r
+#include "ui_resource_string.h"\r
+#include "components/ui_image_animator.h"\r
+#include "ConfigModel.h"\r
+namespace OHOS\r
+{\r
+    class WeatherReportView : public AppGroupView\r
+    {\r
+\r
+    public:\r
+        struct LabelConfig\r
+        {\r
+            int16_t left;\r
+            int16_t top;\r
+            int16_t width;\r
+            int16_t height;\r
+            int16_t fontSize;  // 字体大小\r
+            int16_t lineHeigh; // 行高\r
+            std::string text;  // 文本\r
+            uint16_t textId;\r
+            uint8_t lineBreakMode; // 断行模式。\r
+        };\r
+        WeatherReportView();\r
+        virtual ~WeatherReportView();\r
+        static WeatherReportView *GetInstance(void);\r
+        bool InitPage(void);\r
+        virtual bool InitView(void *caller) override;\r
+        void ClearAll(void);\r
+        UIImageAnimatorView *GetUVImageAnimatorView()\r
+        {\r
+            return UVImageAnimatorView;\r
+        }\r
+        bool UpdateWeatherReportViewData(void);\r
+\r
+    private:\r
+        bool SetTextLabel(UILabel *label, const std::string &text);\r
+        void DumpWeatherInfo(void);\r
+        bool UpdateUVData(void);\r
+        bool UpdateWindSpeedData(void);\r
+        bool UpdateHumidityData(void);\r
+        std::string UVData;        // 紫外线强度数据\r
+        std::string WindSpeedData; // 风速数据\r
+        std::string HumidityData;  // 湿度数据\r
+    private:\r
+        UILabelExt *SetUpLabel(LabelConfig &labelconfig); // 设置标签\r
+        UILabelExt *SetUpLabelExt(LabelConfig &labelconfig);\r
+        bool WeatherReportViewLabelInit(void);\r
+        bool WeatherReportViewImageAnimatorViewInit(void);\r
+        UILabelExt *title{nullptr};                               // 标题\r
+        UILabelExt *UV{nullptr};                                  // 紫外线\r
+        UILabelExt *UV_Number{nullptr};                           //\r
+        UILabelExt *WindSpeed{nullptr};                           // 风速\r
+        UILabelExt *WindSpeed_Number{nullptr};                    //\r
+        UILabelExt *Humidity{nullptr};                            // 湿度\r
+        UILabelExt *Humidity_Number{nullptr};                     //\r
+\r
+        UIImageView *PullUpImage{nullptr}; // 上拉图片\r
+        \r
+        UIImageAnimatorView *UVImageAnimatorView{nullptr};        // 紫外线动画\r
+        UIImageAnimatorView *WindSpeedImageAnimatorView{nullptr}; // 风速动画\r
+        UIImageAnimatorView *HumidityImageAnimatorView{nullptr};  // 湿度动画\r
+\r
+        const ImageInfo **UVPathsArray{nullptr};\r
+        const ImageInfo **WindSpeedPathsArray{nullptr};\r
+        const ImageInfo **HumidityPathsArray{nullptr};\r
+        bool viewInitStatus{false};\r
+    };\r
+} // namespace OHOS\r
+#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 (file)
index 0000000..098bf93
--- /dev/null
@@ -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 <iostream>
+
+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 (file)
index 0000000..f0ad458
--- /dev/null
@@ -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<FutureWeather> &data)
+    {
+        if (!listData.empty())
+        {
+            listData.clear();
+        }
+        std::list<FutureWeather>::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<FutureWeather>::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<FutureWeatherListitemView *>(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 (file)
index 0000000..48addec
--- /dev/null
@@ -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 (file)
index 0000000..a99bd59
--- /dev/null
@@ -0,0 +1,151 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-01-29 15:37:44\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2025-02-25 15:09:45\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp\r
+ */\r
+#include "weather/include/FutureWeatherView.h"\r
+#include "wearable_log.h"\r
+#include "weather/include/WeatherModel.h"\r
+#include "ui_resource_string.h"\r
+#include "weather/include/WeatherModel.h"\r
+namespace OHOS\r
+{\r
+\r
+    static FutureWeatherView *g_pFutureWeatherView{nullptr};\r
+\r
+    FutureWeatherView::FutureWeatherView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::FutureWeatherView");\r
+        SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);\r
+        SetViewIndex(2); // 视图索引\r
+        g_pFutureWeatherView = this;\r
+    }\r
+\r
+    FutureWeatherView::~FutureWeatherView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::~FutureWeatherView");\r
+        ClearAll();\r
+        g_pFutureWeatherView = nullptr;\r
+    }\r
+\r
+    FutureWeatherView *FutureWeatherView::GetInstance()\r
+    {\r
+        return g_pFutureWeatherView;\r
+    }\r
+\r
+    void FutureWeatherView::ClearAll()\r
+    {\r
+        if (viewInitStatus == true)\r
+        {\r
+            RemoveAll();\r
+\r
+            delete Title;\r
+            Title = nullptr;\r
+\r
+            delete futureWeatherListAdapter;\r
+            futureWeatherListAdapter = nullptr;\r
+\r
+            delete FutureWeatherList;\r
+            FutureWeatherList = nullptr;\r
+        }\r
+    }\r
+\r
+    bool FutureWeatherView::InitPage(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage");\r
+        /* -------------------------------------------------------------------------- */\r
+        Title = new UILabelExt();\r
+        if (Title == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::Title is new fail!!");\r
+            return false;\r
+        }\r
+        Title->SetPosition(93, 52, 280, 47);\r
+        Title->SetStyle(STYLE_TEXT_FONT, 30);\r
+        Title->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+        Title->SetTextId(STR_NEXT_7_DAYS);\r
+        Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+        Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+        Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+        Add(Title);\r
+        /* -------------------------------------------------------------------------- */\r
+        futureWeatherListAdapter = new FutureWeatherListAdapter();\r
+        if (futureWeatherListAdapter == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FutureWeatherView::InitPage] futureWeatherListAdapter is nullptr");\r
+            return false;\r
+        }\r
+        /* -------------------------------------------------------------------------- */\r
+        FutureWeatherList = new UIList(UIList::VERTICAL);\r
+        if (FutureWeatherList == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::FutureWeatherList is nullptr");\r
+            return false;\r
+        }\r
+        FutureWeatherList->SetPosition(68, 130, 330, 300);\r
+        FutureWeatherList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);\r
+        FutureWeatherList->SetThrowDrag(true);\r
+        FutureWeatherList->SetReboundSize(30);\r
+        FutureWeatherList->SetMaxScrollDistance(1000);\r
+        FutureWeatherList->SetScrollBlankSize(30);\r
+        FutureWeatherList->SetDragACCLevel(5);\r
+        FutureWeatherList->SetSwipeACCLevel(200);\r
+        WeatherModel::GetInstance().InitFutureWeatherItem();\r
+        FutureWeatherList->SetAdapter(futureWeatherListAdapter);\r
+        FutureWeatherList->RequestFocus();\r
+        FutureWeatherList->SetRotateFactor(1.0);\r
+        FutureWeatherList->SetIntercept(true);\r
+        Add(FutureWeatherList);\r
+        viewInitStatus = true;\r
+\r
+        return true;\r
+    }\r
+\r
+    bool FutureWeatherView::InitView(void *caller)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitView %p", caller);\r
+        if (InitPage() == false)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage fail");\r
+            return false;\r
+        }\r
+        // UpdateFutureWeatherListData();\r
+        SetDraggable(true);\r
+        SetTouchable(true);\r
+        return true;\r
+    }\r
+\r
+    void FutureWeatherView::AddFutureWeatherItemToList(const FutureWeather &item)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::AddFutureWeatherItemToList");\r
+        futureWeatherListAdapter->AddListItem(item);\r
+    }\r
+\r
+    UIList *FutureWeatherView::GetFutureWeatherList()\r
+    {\r
+        return FutureWeatherList;\r
+    }\r
+\r
+    // 更新未来七天数据\r
+    bool FutureWeatherView::UpdateFutureWeatherListData(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::UpdateFutureWeatherListData");\r
+        if (futureWeatherListAdapter != nullptr)\r
+        {\r
+            delete futureWeatherListAdapter;\r
+            futureWeatherListAdapter = nullptr;\r
+        }\r
+        futureWeatherListAdapter = new FutureWeatherListAdapter();\r
+        if (futureWeatherListAdapter == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "futureWeatherListAdapter is nullptr");\r
+            return false;\r
+        }\r
+        WeatherModel::GetInstance().InitFutureWeatherItem();\r
+        FutureWeatherList->SetAdapter(futureWeatherListAdapter);\r
+        FutureWeatherList->RefreshList();\r
+        return true;\r
+    }\r
+}
\ 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 (file)
index 0000000..c211655
--- /dev/null
@@ -0,0 +1,104 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-01-29 15:37:44\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-11-05 14:50:56\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp\r
+ */\r
+#include "weather/include/GetWeatherDataErrorView.h"\r
+#include "wearable_log.h"\r
+#include "weather/include/MainWeatherPresenter.h"\r
+#include "ui_resource_string.h"\r
+\r
+/* 天气获取数据失败后会调用该视图*/\r
+namespace OHOS\r
+{\r
+\r
+    static GetWeatherDataErrorView *g_pGetWeatherDataErrorView{nullptr};\r
+\r
+    GetWeatherDataErrorView::GetWeatherDataErrorView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetWeatherDataErrorView::GetWeatherDataErrorView");\r
+        g_pGetWeatherDataErrorView = this;\r
+    }\r
+\r
+    GetWeatherDataErrorView::~GetWeatherDataErrorView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetWeatherDataErrorView::~GetWeatherDataErrorView");\r
+        ClearAll();\r
+        g_pGetWeatherDataErrorView = nullptr;\r
+    }\r
+\r
+    GetWeatherDataErrorView *GetWeatherDataErrorView::GetInstance()\r
+    {\r
+        return g_pGetWeatherDataErrorView;\r
+    }\r
+\r
+    UIScrollView *GetWeatherDataErrorView::GetWeatherDataErrorViewInit()\r
+    {\r
+        if (scrollView == nullptr)\r
+        {\r
+            scrollView = new UIScrollView();\r
+            if (scrollView == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is new fail!!");\r
+                return nullptr;\r
+            }\r
+            scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());\r
+            scrollView->SetViewId(GETWEATHERDATAERRORVIEW);\r
+            scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
+            /* -------------------------------------------------------------------------- */\r
+            image = new UIImageView();\r
+            if (image == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "image is new fail!!");\r
+                return nullptr;\r
+            }\r
+            image->SetPosition(168, 127, 130, 130);\r
+            const char *ImgSr = "/user/res/weather/weather65x65/weather_unknown.bin"; // 天气数据获取失败\r
+            image->SetAutoEnable(false);\r
+            image->SetResizeMode(UIImageView::CONTAIN);\r
+            image->SetSrc(ImgSr);\r
+            scrollView->Add(image);\r
+            /* -------------------------------------------------------------------------- */\r
+            label = new UILabelExt();\r
+            if (label == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is new fail!!");\r
+                return nullptr;\r
+            }\r
+            label->SetPosition(33, 268, 400, 70);\r
+            label->SetStyle(STYLE_TEXT_FONT, 30);\r
+            label->SetStyle(STYLE_LINE_HEIGHT, 35);\r
+            label->SetTextId(STR_GET_WEATHER_ERROR);\r
+            label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP);\r
+            label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+            label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+\r
+            \r
+            scrollView->Add(label);\r
+        }\r
+        return scrollView;\r
+    }\r
+\r
+    void GetWeatherDataErrorView::ClearAll()\r
+    {\r
+        if (scrollView != nullptr)\r
+        {\r
+            scrollView->RemoveAll();\r
+            if (label != nullptr)\r
+            {\r
+                delete label;\r
+                label = nullptr;\r
+            }\r
+            if (image != nullptr)\r
+            {\r
+                delete image;\r
+                image = nullptr;\r
+            }\r
+            delete scrollView;\r
+            scrollView = nullptr;\r
+        }\r
+    }\r
+\r
+}
\ 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 (file)
index 0000000..a8e28d0
--- /dev/null
@@ -0,0 +1,132 @@
+#include "AppViewIDs.h"\r
+#include "NativeAbility.h"\r
+#include "weather/include/MainWeatherPresenter.h"\r
+#include "common/key_code.h"\r
+#include "common/key_code.h"\r
+#include <custom_utils.h>\r
+#include <ohos_types.h>\r
+#include "UiConfig.h"\r
+#include "gfx_utils/mem_check.h"\r
+\r
+#include "NativeRegisterManager.h"\r
+namespace OHOS\r
+{\r
+    REGIST_MENU_PRO(VIEW_WEATHER, MainWeatherView, MainWeatherPresenter,\r
+        PNG_APPLIST_WEATHER_IMAGE_BIG, PNG_APPLIST_WEATHER_IMAGE,PNG_APPLIST_WEATHER_IMAGE, "天气", STR_WEATHER);\r
+\r
+    // 当前Presenter属性实例化的内存指针\r
+    static MainWeatherPresenter *g_pMainWeatherPresenter = nullptr;\r
+\r
+    MainWeatherPresenter::MainWeatherPresenter()\r
+    {\r
+        weatherModel = &WeatherModel::GetInstance();\r
+        g_pMainWeatherPresenter = this;\r
+#ifdef MEM_CHECK\r
+        MemCheck::GetInstance()->EnableLeakCheck(true);\r
+#endif\r
+    }\r
+\r
+    MainWeatherPresenter::~MainWeatherPresenter()\r
+    {\r
+        g_pMainWeatherPresenter = nullptr;\r
+#ifdef MEM_CHECK\r
+        MemCheck::GetInstance()->EnableLeakCheck(false);\r
+#endif\r
+    }\r
+\r
+    MainWeatherPresenter *MainWeatherPresenter::GetInstance()\r
+    {\r
+\r
+        return g_pMainWeatherPresenter;\r
+    }\r
+\r
+    void MainWeatherPresenter::OnStart()\r
+    {\r
+\r
+    }\r
+\r
+    void MainWeatherPresenter::OnPause(void)\r
+    {\r
+\r
+        Presenter<MainWeatherView>::OnPause();\r
+    }\r
+\r
+    void MainWeatherPresenter::OnResume(void)\r
+    {\r
+        Presenter<MainWeatherView>::OnResume();\r
+    }\r
+\r
+    void MainWeatherPresenter::OnStop(void)\r
+    {\r
+    }\r
+\r
+    bool MainWeatherPresenter::OnDrag(UIView &view, const DragEvent &event)\r
+    {\r
+        UNUSED(view);\r
+        if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动\r
+        {\r
+            MainWeatherPresenter::X_DRAG_FLAG = true;\r
+        }\r
+        return true;\r
+    }\r
+\r
+    bool MainWeatherPresenter::OnDragEnd(UIView &view, const DragEvent &event)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnDragEnd");\r
+        UNUSED(view);\r
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainWeatherPresenter::X_DRAG_FLAG)\r
+        {\r
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);\r
+            X_DRAG_FLAG = false;\r
+        }\r
+        return true;\r
+    }\r
+\r
+    bool MainWeatherPresenter::OnClick(UIView &view, const ClickEvent &event)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MainWeatherPresenter::OnClick");\r
+\r
+        UNUSED(view);\r
+        UNUSED(event);\r
+        return true;\r
+    }\r
+\r
+    // 增加按键事件\r
+    bool MainWeatherPresenter::OnKeyAct(UIView &view, const KeyEvent &event)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct");\r
+        uint16 keyID = event.GetKeyId();\r
+        uint16_t keyState = event.GetState();\r
+        // 如果是power键就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)\r
+        {\r
+            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);\r
+        }\r
+        return true;\r
+    }\r
+\r
+    void MainWeatherPresenter::OnSwipe(UISwipeView &view)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherPresenter::OnSwipe,current tab index = %d", view.GetCurrentPage());\r
+        // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the view index = %d,dragging direction = %d,current tab index = %d", view.GetViewIndex(), view.GetDirection(), view.GetCurrentPage());\r
+        if (view.GetCurrentPage() == MAINWEATHERVIEW)\r
+        {\r
+            WeatherModel::GetInstance().UpdateWeatherCurTime();\r
+        }\r
+    }\r
+\r
+    void WeatherControlViewOnSwipeListener::OnSwipe(UISwipeView &view)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlViewOnSwipeListener::OnSwipe,current tab index = %d", view.GetCurrentPage());\r
+        // if (view.GetCurrentPage() == MAINWEATHERVIEW)\r
+        // {\r
+        //     view.SetIntercept(false);\r
+        //     //MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList();\r
+        // }\r
+        // else\r
+        // {\r
+        //     view.SetIntercept(true);\r
+        // }\r
+        return;\r
+    }\r
+}
\ 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 (file)
index 0000000..caa57f4
--- /dev/null
@@ -0,0 +1,265 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-01-29 15:37:44\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2025-02-24 16:52:22\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp\r
+ */\r
+#include "weather/include/MainWeatherView.h"\r
+#include "weather/include/MainWeatherPresenter.h"\r
+#include "weather/include/WeatherModel.h"\r
+namespace OHOS\r
+{\r
+    static MainWeatherView *g_pMainWeatherView{nullptr};\r
+    MainWeatherView::MainWeatherView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::MainWeatherView");\r
+        g_pMainWeatherView = this;\r
+    }\r
+\r
+    MainWeatherView::~MainWeatherView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::~MainWeatherView");\r
+        ClearAll();\r
+        g_pMainWeatherView = nullptr;\r
+    }\r
+\r
+    MainWeatherView *MainWeatherView::GetInstance(void)\r
+    {\r
+        return g_pMainWeatherView;\r
+    }\r
+\r
+    void MainWeatherView::ClearAll(void)\r
+    {\r
+        if (weatherSwipeViewList != nullptr)\r
+        {\r
+            weatherSwipeViewList->RemoveAll();\r
+\r
+            delete weatherView;\r
+            weatherView = nullptr;\r
+\r
+            delete weatherReportView;\r
+            weatherReportView = nullptr;\r
+\r
+            delete futureWeatherView;\r
+            futureWeatherView = nullptr;\r
+\r
+            delete weatherSwipeViewList;\r
+            weatherSwipeViewList = nullptr;\r
+        }\r
+\r
+        if (getWeatherDataErrorView != nullptr)\r
+        {\r
+            delete getWeatherDataErrorView;\r
+            getWeatherDataErrorView = nullptr;\r
+        }\r
+\r
+        for (int32_t i = 0; i < maxPage; i++)\r
+        {\r
+            recordCard[i] = nullptr;\r
+        }\r
+    }\r
+\r
+    /*\r
+     * @brief 主天气页面视图初始化\r
+     */\r
+    UISwipeView *MainWeatherView::MainWeatherViewInit(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::MainWeatherViewInit");\r
+        if (nullptr == weatherSwipeViewList)\r
+        {\r
+            weatherSwipeViewList = new UISwipeView(UISwipeView::VERTICAL);\r
+            if (nullptr == weatherSwipeViewList)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherSwipeViewList new fail!!");\r
+                return nullptr;\r
+            }\r
+\r
+            weatherSwipeViewList->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full);\r
+            weatherSwipeViewList->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); // 0 : X; 0 : Y\r
+            weatherSwipeViewList->SetAnimatorTime(50);                                           // 50:animator drag time(ms)\r
+            weatherSwipeViewList->SetViewId(MAIN_WEATHER_VIEW);\r
+            weatherSwipeViewList->SetDraggable(true);\r
+            weatherSwipeViewList->SetTouchable(true);\r
+            weatherSwipeViewList->SetVisible(false);\r
+            for (uint16_t i = 0; i < maxPage; i++)\r
+            {\r
+                recordCard[i] = CreatePage(i);\r
+                if (nullptr == recordCard[i])\r
+                {\r
+                    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "recordCard[%d] is nullptr!!", i);\r
+                    return nullptr;\r
+                }\r
+                recordCard[i]->InitView(this);\r
+                weatherSwipeViewList->Add(recordCard[i]);\r
+            }\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView InitPage over!!");\r
+        }\r
+        return weatherSwipeViewList;\r
+    }\r
+\r
+    bool MainWeatherView::UpdateMainWeatherViewVisibility()\r
+    {\r
+        if (weatherSwipeViewList != nullptr && weatherScrllView != nullptr)\r
+        {\r
+            if (WeatherModel::GetInstance().GetWeatherDataIsValid())\r
+            {\r
+                weatherSwipeViewList->SetVisible(true);\r
+                weatherScrllView->SetVisible(false);\r
+            }\r
+            else\r
+            {\r
+                weatherScrllView->SetVisible(true);\r
+                weatherSwipeViewList->SetVisible(false);\r
+                weatherScrllView->SetOnDragListener(presenter_);\r
+            }\r
+            GetRootContainer()->Invalidate();\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
+    void MainWeatherView::OnStart()\r
+    {\r
+        AddViewToRootContainer(MainWeatherViewInit());\r
+        weatherScrllView = WeatherDataErrorViewPageInit();\r
+        AddViewToRootContainer(weatherScrllView);\r
+\r
+        if (weatherSwipeViewList != nullptr)\r
+        {\r
+            UIView::OnClickListener *weatherOnClickListener = (UIView::OnClickListener *)OHOS::MainWeatherPresenter::GetInstance();\r
+            if (weatherOnClickListener == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnClickListener new fail");\r
+                return;\r
+            }\r
+\r
+            UIView::OnDragListener *weatherOnDragListener = (UIView::OnDragListener *)OHOS::MainWeatherPresenter::GetInstance();\r
+            if (weatherOnDragListener == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnDragListener new fail");\r
+                return;\r
+            }\r
+\r
+            UISwipeView::OnSwipeListener *weatherOnSwipeListener = (UISwipeView::OnSwipeListener *)OHOS::MainWeatherPresenter::GetInstance();\r
+            if (weatherOnSwipeListener == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail");\r
+                return;\r
+            }\r
+            weatherSwipeViewList->SetOnClickListener(presenter_);\r
+            weatherSwipeViewList->SetOnDragListener(presenter_);\r
+            weatherSwipeViewList->SetOnSwipeListener(presenter_);\r
+        }\r
+        UpdateMainWeatherViewVisibility();\r
+    }\r
+\r
+    WeatherView *MainWeatherView::GetWeatherView(void)\r
+    {\r
+        return weatherView;\r
+    }\r
+\r
+    WeatherReportView *MainWeatherView::GetWeatherReportView(void)\r
+    {\r
+        return weatherReportView;\r
+    }\r
+\r
+    FutureWeatherView *MainWeatherView::GetFutureWeatherView(void)\r
+    {\r
+        return futureWeatherView;\r
+    }\r
+\r
+    /*\r
+     * @brief 天气页面视图初始化\r
+     */\r
+    AppGroupView *MainWeatherView::WeatherViewPageInit(void)\r
+    {\r
+        weatherView = new WeatherView();\r
+        if (weatherView == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView::new weatherView fail!");\r
+            return nullptr;\r
+        }\r
+\r
+        return weatherView;\r
+    }\r
+\r
+    /*\r
+     * @brief 气象报告视图初始化\r
+     */\r
+    AppGroupView *MainWeatherView::WeatherReportViewPageInit(void)\r
+    {\r
+        weatherReportView = new WeatherReportView();\r
+        if (weatherReportView == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView::new weatherReportView fail!");\r
+            return nullptr;\r
+        }\r
+        return weatherReportView;\r
+    }\r
+\r
+    /*\r
+     * @brief 未来天气视图初始化\r
+     */\r
+    AppGroupView *MainWeatherView::FutureWeatherViewPageInit(void)\r
+    {\r
+        futureWeatherView = new FutureWeatherView();\r
+        if (futureWeatherView == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView::new futureWeatherView fail!");\r
+            return nullptr;\r
+        }\r
+        return futureWeatherView;\r
+    }\r
+\r
+    /*\r
+     * @brief 获取天气数据失败视图初始化\r
+     */\r
+    UIScrollView *MainWeatherView::WeatherDataErrorViewPageInit(void)\r
+    {\r
+        if (getWeatherDataErrorView == nullptr)\r
+        {\r
+            getWeatherDataErrorView = new GetWeatherDataErrorView();\r
+            if (getWeatherDataErrorView == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getWeatherDataErrorView new fail!!");\r
+                return nullptr;\r
+            }\r
+        }\r
+        return getWeatherDataErrorView->GetWeatherDataErrorViewInit();\r
+    }\r
+\r
+    struct MainWeatherViewMapper\r
+    {\r
+        const int16_t viewId;\r
+        AppGroupView *(MainWeatherView::*func)(void);\r
+    };\r
+\r
+    // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与DisplayBrightnessViewMapper类中的特定成员函数指针进行了绑定。\r
+    static const MainWeatherViewMapper g_pageMapper[] = {\r
+        {MAINWEATHERVIEW, &MainWeatherView::WeatherViewPageInit},\r
+        {WEATHERREPORTVIEW, &MainWeatherView::WeatherReportViewPageInit},\r
+        {FUTUREWEATHERVIEW, &MainWeatherView::FutureWeatherViewPageInit},\r
+    };\r
+\r
+    /*\r
+     * @brief 根据提供的 WeatherPageId 查找对应的页面ID,然后根据这个页面ID来创建对应的页面视图\r
+     */\r
+    AppGroupView *MainWeatherView::CreatePage(int32_t WeatherPageId)\r
+    {\r
+        uint16_t i;\r
+        AppGroupView *view = nullptr;\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage WeatherPageId:%d", WeatherPageId);\r
+\r
+        for (i = 0; i < sizeof(g_pageMapper) / sizeof(g_pageMapper[0]); i++)\r
+        {\r
+            if (g_pageMapper[i].viewId == WeatherPageId)\r
+            {                                             // 正确使用 WeatherPageId 来匹配视图ID\r
+                view = (this->*(g_pageMapper[i].func))(); // 如果找到匹配项,则调用相应的函数创建视图\r
+                WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage view:%p", view);\r
+                return view; // 返回创建的视图\r
+            }\r
+        }\r
+        return nullptr; // 如果没有找到匹配的视图ID,返回 nullptr\r
+    }\r
+}
\ 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 (file)
index 0000000..867efa3
--- /dev/null
@@ -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<UISwipeView::OnSwipeListener *>(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 (file)
index 0000000..cd291e2
--- /dev/null
@@ -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(&timestamp, &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 (file)
index 0000000..54e0ba0
--- /dev/null
@@ -0,0 +1,461 @@
+/***\r
+ * @Date: 2024-08-19 11:01:42\r
+ * @LastEditors: Caisking 3449750381@qq.com\r
+ * @LastEditTime: 2024-08-30 19:25:11\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp\r
+ */\r
+#include "weather/include/WeatherReportView.h"\r
+#include "wearable_log.h"\r
+#include "weather/include/WeatherModel.h"\r
+#include "common/image_cache_manager.h"\r
+#include "uicomponents/UIComponents.h"\r
+namespace OHOS\r
+{\r
+    static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_X = 53;\r
+    static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_Y = 160;\r
+    static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_W = 60;\r
+    static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_H = 60;\r
+    static constexpr int16_t UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 24; // 图片帧数\r
+    static constexpr int16_t UV_IMAGE_ANIMATOR_TIME = 100;           // 图片更新间隔\r
+    static ImageAnimatorInfo UVimageAnimatorInfo[UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];\r
+\r
+    static constexpr int16_t WINDSPEED_IMAGE_ANIMATOR_VIEW_X = 203;\r
+    static constexpr int16_t WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 24; // 图片帧数\r
+    static ImageAnimatorInfo WindSpeedimageAnimatorInfo[WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];\r
+\r
+    static constexpr int16_t HUMIDITY_IMAGE_ANIMATOR_VIEW_X = 353;\r
+    static constexpr int16_t HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 20; // 图片帧数\r
+    static ImageAnimatorInfo HumidityimageAnimatorInfo[HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];\r
+\r
+    static constexpr const char *UVPaths = "/user/res/weather/weather60x60gif/UV/";\r
+    static constexpr const char *WindSpeedPaths = "/user/res/weather/weather60x60gif/WindSpeed/";\r
+    static constexpr const char *HumidityPaths = "/user/res/weather/weather60x60gif/Humidity/";\r
+\r
+    static WeatherReportView *g_pWeatherReportView{nullptr};\r
+\r
+    WeatherReportView::WeatherReportView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " WeatherReportView::WeatherReportView");\r
+        SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);\r
+        SetViewIndex(1);\r
+        WeatherModel *p_WeatherModel = &WeatherModel::GetInstance();\r
+        UVData = p_WeatherModel->GetUVIndex();          // 紫外线强度数据\r
+        WindSpeedData = p_WeatherModel->GetWindScale(); // 风速数据\r
+        HumidityData = p_WeatherModel->GetHumidity();   // 湿度数据\r
+\r
+        g_pWeatherReportView = this;\r
+    }\r
+\r
+    WeatherReportView::~WeatherReportView()\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " WeatherReportView::~WeatherReportView");\r
+        ClearAll();\r
+        g_pWeatherReportView = nullptr;\r
+    }\r
+\r
+    WeatherReportView *WeatherReportView::GetInstance()\r
+    {\r
+        return g_pWeatherReportView;\r
+    }\r
+\r
+    void WeatherReportView::ClearAll(void)\r
+    {\r
+        if (viewInitStatus == true)\r
+        {\r
+            RemoveAll();\r
+            delete title;\r
+            title = nullptr;\r
+\r
+            delete UV;\r
+            UV = nullptr;\r
+\r
+            delete UV_Number;\r
+            UV_Number = nullptr;\r
+\r
+            delete WindSpeed;\r
+            WindSpeed = nullptr;\r
+\r
+            delete WindSpeed_Number;\r
+            WindSpeed_Number = nullptr;\r
+\r
+            delete Humidity;\r
+            Humidity = nullptr;\r
+\r
+            delete Humidity_Number;\r
+            Humidity_Number = nullptr;\r
+\r
+            delete PullUpImage;\r
+            PullUpImage = nullptr;\r
+\r
+            UVImageAnimatorView->Stop();\r
+            delete UVImageAnimatorView;\r
+            UVImageAnimatorView = nullptr;\r
+\r
+            WindSpeedImageAnimatorView->Stop();\r
+            delete WindSpeedImageAnimatorView;\r
+            WindSpeedImageAnimatorView = nullptr;\r
+\r
+            HumidityImageAnimatorView->Stop();\r
+            delete HumidityImageAnimatorView;\r
+            HumidityImageAnimatorView = nullptr;\r
+\r
+            // FreeImagePathsArray(UVPathsArray, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+\r
+            // FreeImagePathsArray(WindSpeedPathsArray, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+\r
+            // FreeImagePathsArray(HumidityPathsArray, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+\r
+            FreeImageInfoArray(UVPathsArray, UVPaths, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+            FreeImageInfoArray(WindSpeedPathsArray, WindSpeedPaths, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+            FreeImageInfoArray(HumidityPathsArray, HumidityPaths, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+        }\r
+    }\r
+\r
+    // 设置标签\r
+    UILabelExt *WeatherReportView::SetUpLabel(LabelConfig &labelconfig)\r
+    {\r
+        UILabelExt *label = new UILabelExt();\r
+        if (label == nullptr)\r
+        {\r
+            return nullptr;\r
+        }\r
+        label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小\r
+        label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize);                                       // 字体大小\r
+        label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh);                                    // 字体行高\r
+        label->SetText(labelconfig.text.c_str());                                                     // 内容\r
+        label->SetLineBreakMode(labelconfig.lineBreakMode);                                           // 断行模式。\r
+        label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+        label->SetFont(GILROY_BOLD_FONT, labelconfig.fontSize);\r
+        return label;\r
+    }\r
+\r
+    UILabelExt *WeatherReportView::SetUpLabelExt(LabelConfig &labelconfig)\r
+    {\r
+        UILabelExt *label = new UILabelExt();\r
+        if (label == nullptr)\r
+        {\r
+            return nullptr;\r
+        }\r
+        label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); // 位置大小\r
+        label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize);                                       // 字体大小\r
+        label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh);                                    // 字体行高\r
+        label->SetTextId(labelconfig.textId);                                                         // 内容\r
+        label->SetLineBreakMode(labelconfig.lineBreakMode);                                           // 断行模式。\r
+        label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+        label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize);\r
+        return label;\r
+    }\r
+\r
+    bool WeatherReportView::WeatherReportViewLabelInit(void)\r
+    {\r
+        LabelConfig labelconfig = {\r
+            .left = 83,\r
+            .top = 52,\r
+            .width = 300,\r
+            .height = 35,\r
+            .fontSize = 30,\r
+            .lineHeigh = 35,\r
+            //.text = "气象报告",\r
+            .textId = STR_WEATHER_REPORT,\r
+            .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,\r
+        };\r
+        title = SetUpLabelExt(labelconfig);\r
+        if (title == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::title new fail!");\r
+            return false;\r
+        }\r
+        /* -------------------------------------------------------------------------- */\r
+        labelconfig = {\r
+            .left = 23,\r
+            .top = 240,\r
+            .width = 120,\r
+            .height = 50,\r
+            .fontSize = 40,\r
+            .lineHeigh = 50,\r
+            .text = UVData.c_str(), // 紫外线强度\r
+            .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,\r
+        };\r
+        UV_Number = SetUpLabel(labelconfig);\r
+        if (UV_Number == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::UV_Number new fail!");\r
+            return false;\r
+        }\r
+\r
+        labelconfig.left = 173;\r
+        labelconfig.text = WindSpeedData.c_str(); // 风速\r
+        WindSpeed_Number = SetUpLabel(labelconfig);\r
+        if (WindSpeed_Number == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WindSpeed_Number new fail!");\r
+            return false;\r
+        }\r
+\r
+        labelconfig.left = 323;\r
+        labelconfig.text = HumidityData.c_str(); // 湿度\r
+        Humidity_Number = SetUpLabel(labelconfig);\r
+        if (Humidity_Number == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::Humidity_Number new fail!");\r
+            return false;\r
+        }\r
+\r
+        /* -------------------------------------------------------------------------- */\r
+        labelconfig = {\r
+            .left = 23,\r
+            .top = 290,\r
+            .width = 120,\r
+            .height = 35,\r
+            .fontSize = 30,\r
+            .lineHeigh = 35,\r
+            //.text = "紫外线",\r
+            .textId = STR_ULTRAVIOLET,\r
+            .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,\r
+        };\r
+        UV = SetUpLabelExt(labelconfig);\r
+        if (UV == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::UV new fail!");\r
+            return false;\r
+        }\r
+        UV->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));\r
+\r
+        labelconfig.left = 173;\r
+        // labelconfig.text = "风速";\r
+        labelconfig.textId = STR_WIND_SPEED;\r
+        WindSpeed = SetUpLabelExt(labelconfig);\r
+        if (WindSpeed == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WindSpeed new fail!");\r
+            return false;\r
+        }\r
+        WindSpeed->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));\r
+\r
+        labelconfig.left = 323;\r
+        // labelconfig.text = "湿度";\r
+        labelconfig.textId = STR_HUMIDITY;\r
+        Humidity = SetUpLabelExt(labelconfig);\r
+        if (Humidity == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::Humidity new fail!");\r
+            return false;\r
+        }\r
+        Humidity->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));\r
+        /* ----------------------------------- Add ---------------------------------- */\r
+\r
+        Add(title);\r
+        Add(UV_Number);\r
+        Add(WindSpeed_Number);\r
+        Add(Humidity_Number);\r
+        Add(UV);\r
+        Add(WindSpeed);\r
+        Add(Humidity);\r
+\r
+        return true;\r
+    }\r
+\r
+    bool WeatherReportView::WeatherReportViewImageAnimatorViewInit(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherReportView::WeatherReportViewImageAnimatorViewInit");\r
+\r
+        /* ----------------------------- UVImageAnimatorView---------------------------- */\r
+        UVPathsArray = CreateImageInfoArray(UVPaths, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+        if (UVImageAnimatorView == nullptr)\r
+        {\r
+            UVImageAnimatorView = new UIImageAnimatorView();\r
+            if (UVImageAnimatorView == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UVImageAnimatorView new fail");\r
+                return false;\r
+            }\r
+            for (uint8_t i = 0; i < UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)\r
+            {\r
+                // UVimageAnimatorInfo[i].imagePath = UVPathsArray[i];\r
+                // UVimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;\r
+                UVimageAnimatorInfo[i].imageInfo = UVPathsArray[i];\r
+                UVimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;\r
+                UVimageAnimatorInfo[i].pos.x = UV_IMAGE_ANIMATOR_VIEW_X;\r
+                UVimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y;\r
+                UVimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W;\r
+                UVimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H;\r
+            }\r
+            UVImageAnimatorView->SetPosition(UV_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H);\r
+            UVImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
+            UVImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
+            UVImageAnimatorView->SetImageAnimatorSrc(UVimageAnimatorInfo, UV_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME);\r
+            UVImageAnimatorView->SetRepeat(true);\r
+            UVImageAnimatorView->Start();\r
+        }\r
+        /* ----------------------- WindSpeedImageAnimatorView ----------------------- */\r
+        WindSpeedPathsArray = CreateImageInfoArray(WindSpeedPaths, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+        if (WindSpeedImageAnimatorView == nullptr)\r
+        {\r
+            WindSpeedImageAnimatorView = new UIImageAnimatorView();\r
+            if (WindSpeedImageAnimatorView == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WindSpeedImageAnimatorView new fail");\r
+                return false;\r
+            }\r
+            for (uint8_t i = 0; i < WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)\r
+            {\r
+                // WindSpeedimageAnimatorInfo[i].imagePath = WindSpeedPathsArray[i];\r
+                // WindSpeedimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;\r
+                WindSpeedimageAnimatorInfo[i].imageInfo = WindSpeedPathsArray[i];\r
+                WindSpeedimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;\r
+                WindSpeedimageAnimatorInfo[i].pos.x = WINDSPEED_IMAGE_ANIMATOR_VIEW_X;\r
+                WindSpeedimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y;\r
+                WindSpeedimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W;\r
+                WindSpeedimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H;\r
+            }\r
+            WindSpeedImageAnimatorView->SetPosition(WINDSPEED_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H);\r
+            WindSpeedImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
+            WindSpeedImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
+            WindSpeedImageAnimatorView->SetImageAnimatorSrc(WindSpeedimageAnimatorInfo, WINDSPEED_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME);\r
+            WindSpeedImageAnimatorView->SetRepeat(true);\r
+            WindSpeedImageAnimatorView->Start();\r
+        }\r
+        /* ------------------------ HumidityImageAnimatorView ----------------------- */\r
+        HumidityPathsArray = CreateImageInfoArray(HumidityPaths, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);\r
+        if (HumidityImageAnimatorView == nullptr)\r
+        {\r
+            HumidityImageAnimatorView = new UIImageAnimatorView();\r
+            if (HumidityImageAnimatorView == nullptr)\r
+            {\r
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HumidityImageAnimatorView new fail");\r
+                return false;\r
+            }\r
+            for (uint8_t i = 0; i < HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++)\r
+            {\r
+                // HumidityimageAnimatorInfo[i].imagePath = HumidityPathsArray[i];\r
+                // HumidityimageAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH;\r
+                HumidityimageAnimatorInfo[i].imageInfo = HumidityPathsArray[i];\r
+                HumidityimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO;\r
+                HumidityimageAnimatorInfo[i].pos.x = HUMIDITY_IMAGE_ANIMATOR_VIEW_X;\r
+                HumidityimageAnimatorInfo[i].pos.y = UV_IMAGE_ANIMATOR_VIEW_Y;\r
+                HumidityimageAnimatorInfo[i].width = UV_IMAGE_ANIMATOR_VIEW_W;\r
+                HumidityimageAnimatorInfo[i].height = UV_IMAGE_ANIMATOR_VIEW_H;\r
+            }\r
+            HumidityImageAnimatorView->SetPosition(HUMIDITY_IMAGE_ANIMATOR_VIEW_X, UV_IMAGE_ANIMATOR_VIEW_Y, UV_IMAGE_ANIMATOR_VIEW_W, UV_IMAGE_ANIMATOR_VIEW_H);\r
+            HumidityImageAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);\r
+            HumidityImageAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
+            HumidityImageAnimatorView->SetImageAnimatorSrc(HumidityimageAnimatorInfo, HUMIDITY_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, UV_IMAGE_ANIMATOR_TIME);\r
+            HumidityImageAnimatorView->SetRepeat(true);\r
+            HumidityImageAnimatorView->Start();\r
+        }\r
+        /* -------------------------------------------------------------------------- */\r
+        PullUpImage = new UIImageView();\r
+        if (PullUpImage == nullptr)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new PullUpImage fail!");\r
+            return false;\r
+        }\r
+        PullUpImage->SetPosition(213, 400, 40, 40);\r
+        PullUpImage->SetAutoEnable(false);\r
+        PullUpImage->SetResizeMode(UIImageView::CONTAIN);\r
+        PullUpImage->SetSrc("/user/res/Sleep/up.bin");\r
+        /* ----------------------------------- Add ---------------------------------- */\r
+        Add(UVImageAnimatorView);\r
+        Add(WindSpeedImageAnimatorView);\r
+        Add(HumidityImageAnimatorView);\r
+        Add(PullUpImage);\r
+        viewInitStatus = true;\r
+\r
+        return true;\r
+    }\r
+\r
+    bool WeatherReportView::InitPage(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage");\r
+        if (!WeatherReportViewLabelInit() || !WeatherReportViewImageAnimatorViewInit())\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage fail!!");\r
+            return false;\r
+        }\r
+\r
+        return true;\r
+    }\r
+\r
+    bool WeatherReportView::InitView(void *caller)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherReportView InitView %p", caller);\r
+        if (InitPage() == false)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage fail");\r
+            return false;\r
+        }\r
+        // UpdateWeatherReportViewData();\r
+        SetDraggable(true);\r
+        SetTouchable(true);\r
+        return true;\r
+    }\r
+\r
+\r
+    // 设置文本标签的通用函数\r
+    bool WeatherReportView::SetTextLabel(UILabel *label, const std::string &text)\r
+    {\r
+        if (label)\r
+        {\r
+            label->SetText(text.c_str());\r
+            label->Invalidate();\r
+            return true;\r
+        }\r
+        return false;\r
+    }\r
+\r
+    void WeatherReportView::DumpWeatherInfo(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::DumpWeatherInfo");\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UVData:%s", UVData.c_str());\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WindSpeedData:%s", WindSpeedData.c_str());\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "HumidityData:%s", HumidityData.c_str());\r
+    }\r
+\r
+    // 更新紫外线数据\r
+    bool WeatherReportView::UpdateUVData(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateUVData");\r
+\r
+        std::string uv = WeatherModel::GetInstance().GetUVIndex();\r
+\r
+        return SetTextLabel(UV_Number, uv);\r
+    }\r
+\r
+    // 更新风速数据\r
+    bool WeatherReportView::UpdateWindSpeedData(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWindSpeedData");\r
+\r
+        std::string windscale = WeatherModel::GetInstance().GetWindScale();\r
+\r
+        return SetTextLabel(WindSpeed_Number, windscale);\r
+        return true;\r
+    }\r
+\r
+    // 更新湿度数据\r
+    bool WeatherReportView::UpdateHumidityData(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateHumidityData");\r
+\r
+        std::string humidity = WeatherModel::GetInstance().GetHumidity();\r
+\r
+        return SetTextLabel(Humidity_Number, humidity);\r
+    }\r
+\r
+    // 更新气象报告数据\r
+    bool WeatherReportView::UpdateWeatherReportViewData(void)\r
+    {\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherReportViewData");\r
+        bool success = true;\r
+        success &= UpdateUVData();\r
+        success &= UpdateWindSpeedData();\r
+        success &= UpdateHumidityData();\r
+        if (!success)\r
+        {\r
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherViewData fail!!");\r
+        }\r
+        // DumpWeatherInfo();\r
+        return true;\r
+    }\r
+\r
+}
\ 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 (file)
index 0000000..778a62f
--- /dev/null
@@ -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