天气视图优化
authorluozheng <1732036298@qq.com>
Mon, 15 Apr 2024 07:28:17 +0000 (15:28 +0800)
committerluozheng <1732036298@qq.com>
Mon, 15 Apr 2024 07:28:17 +0000 (15:28 +0800)
12 files changed:
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListAdapter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListitemView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h
code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h
code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp
code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp
code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp
code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c

index 8ad5aaf..0f0eca5 100644 (file)
@@ -334,6 +334,8 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherControlView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherView.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherModel.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/FutureWeatherListAdapter.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/FutureWeatherListitemView.cpp
 
     #系统
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemPresenter.cpp                       
diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListAdapter.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListAdapter.h
new file mode 100644 (file)
index 0000000..e003d3a
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * @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 "language/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/fd230app/nativeui/weather/include/FutureWeatherListitemView.h b/code/sdk/application/wearable/fd230app/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
index bca211e..eeeaa50 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-03-30 09:14:38\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-13 19:10:22\r
+ * @LastEditTime: 2024-04-15 14:24:52\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h\r
  */\r
 #ifndef FUTURE_WEATHER_VIEW_H\r
@@ -16,6 +16,7 @@
 #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
@@ -28,15 +29,14 @@ namespace OHOS
         static FutureWeatherView *GetInstance(void);\r
         bool InitPage(void);\r
         virtual bool InitView(void *caller) override;\r
-\r
+        void AddFutureWeatherItemToList(const FutureWeather &item);\r
+        UIList *GetFutureWeatherList();\r
     private:\r
         void ClearAll(void);\r
-        UIViewGroup *container = nullptr;\r
-        UIScrollView *scrollView{nullptr};\r
+        // UIScrollView *scrollView{nullptr};\r
         UILabelExt *Title = nullptr;\r
-        UIImageView *weatherImg[7]{nullptr};\r
-        UILabel *dateLabel[7]{nullptr};\r
-        UILabel *maxandminTemperatureLabel[7]{nullptr};\r
+        UIList *FutureWeatherList{nullptr};\r
+        FutureWeatherListAdapter *futureWeatherListAdapter{nullptr};\r
     };\r
 }\r
 #endif
\ No newline at end of file
index acaaa41..da73169 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-08 18:40:20
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-13 19:12:15
+ * @LastEditTime: 2024-04-15 14:45:55
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h
  */
 #ifndef WEATHER_MODEL_H
@@ -11,7 +11,7 @@
 #include "wearable_log.h"
 #include "iostream"
 #include <time.h>
-
+#include "weather/include/FutureWeatherListAdapter.h"
 namespace OHOS
 {
 #if __cplusplus
@@ -61,7 +61,7 @@ namespace OHOS
     }
 #endif /* __cplusplus */
 
-    #define weather_src "/user/res/weather/weather65x65/"
+#define weather_src "/user/res/weather/weather65x65/"
     static const char *weather65x65[] =
         {
             weather_src "weather_sunny.bin",        // 晴天
@@ -82,6 +82,7 @@ namespace OHOS
     {
     public:
         static WeatherModel &GetInstance(void);
+        void InitFutureWeatherItem();
         void TimestampToMonthDayString(time_t timestamp, char *buffer);
         std::string GetWeatherImage();
         std::string GetWeatherTemperature();
@@ -89,10 +90,12 @@ namespace OHOS
         std::string GetWeatherArea();
         std::string GetWeatherMaxAndMinTemperature();
         /* -------------------------------------------------------------------------- */
-        int GetWeather_data_seven_data_iconDay(int date);
+        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();
@@ -103,6 +106,7 @@ namespace OHOS
         WeatherModel(const WeatherModel &) = delete;
         WeatherModel &operator=(const WeatherModel &) = delete;
         virtual ~WeatherModel();
+        FutureWeather FutureWeatherItem[7];
     };
 
 }
diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp
new file mode 100644 (file)
index 0000000..8db0ae2
--- /dev/null
@@ -0,0 +1,91 @@
+#include "weather/include/FutureWeatherListAdapter.h"
+#include "weather/include/FutureWeatherListitemView.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+
+    FutureWeatherListAdapter::FutureWeatherListAdapter()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::FutureWeatherListAdapter");
+    }
+
+    FutureWeatherListAdapter::~FutureWeatherListAdapter()
+    {
+        WEARABLE_LOGE(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/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp
new file mode 100644 (file)
index 0000000..cb3e5d6
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-04-15 09:25:53
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-04-15 14:58: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_LOGE(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_LOGE(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());
+        // 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, 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, 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
index 191b1a0..4076d5b 100644 (file)
@@ -1,3 +1,10 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-01-29 15:37:44\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-04-15 15:01:52\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
@@ -10,6 +17,8 @@ namespace OHOS
     FutureWeatherView::FutureWeatherView()\r
     {\r
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::FutureWeatherView");\r
+        SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);\r
+        SetViewIndex(2); // 视图索引\r
         g_pFutureWeatherView = this;\r
     }\r
 \r
@@ -28,120 +37,64 @@ namespace OHOS
 \r
     void FutureWeatherView::ClearAll()\r
     {\r
-        if (container != nullptr)\r
-        {\r
-            container->Remove(scrollView);\r
-\r
-            scrollView->RemoveAll();\r
-\r
-            delete Title;\r
-            Title = nullptr;\r
+        RemoveAll();\r
+        \r
+        delete Title;\r
+        Title = nullptr;\r
 \r
-            for (int i = 0; i < 7; i++)\r
-            {\r
-                delete weatherImg[i];\r
-                weatherImg[i] = nullptr;\r
+        delete futureWeatherListAdapter;\r
+        futureWeatherListAdapter = nullptr;\r
 \r
-                delete dateLabel[i];\r
-                dateLabel[i] = nullptr;\r
-\r
-                delete maxandminTemperatureLabel[i];\r
-                maxandminTemperatureLabel[i] = nullptr;\r
-            }\r
-            delete scrollView;\r
-            scrollView = nullptr;\r
-\r
-            delete container;\r
-            container = nullptr;\r
-        }\r
+        delete FutureWeatherList;\r
+        FutureWeatherList = nullptr;\r
     }\r
 \r
     bool FutureWeatherView::InitPage(void)\r
     {\r
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage");\r
-        if (container == nullptr)\r
-        {\r
-            container = new UIViewGroup();\r
-            if (container == nullptr)\r
-            {\r
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::container is new fail!!");\r
-                return false;\r
-            }\r
-            container->SetPosition(0, 0, 466, 466);\r
-            container->SetStyle(STYLE_BACKGROUND_OPA, 0);\r
-            /* -------------------------------------------------------------------------- */\r
-            scrollView = new UIScrollView();\r
-            if (scrollView == nullptr)\r
-            {\r
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is new fail!!");\r
-                return false;\r
-            }\r
-            scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());\r
-            scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);\r
-            scrollView->SetReboundSize(50);              // 设置回弹大小\r
-            scrollView->SetHorizontalScrollState(false); // 设置横向不可以滚动\r
-            scrollView->SetScrollBlankSize(50);          // 设置高位50可滑动空白区域\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->SetText("未来7天");\r
-            Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
-            Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-            Title->SetRollSpeed(40);\r
-            Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
-            scrollView->Add(Title);\r
-            /* -------------------------------------------------------------------------- */\r
-            int yImg = 80;\r
-            int yLabel = 85;\r
-            WeatherModel *p_WeatherModel = &WeatherModel::GetInstance().GetInstance();\r
-            for (int i = 0; i < 7; ++i) // 创建7个组件组\r
-            {\r
-                // 创建天气图标\r
-                if (weatherImg[i] == nullptr)\r
-                {\r
-                    weatherImg[i] = new UIImageView();\r
-                }\r
-                weatherImg[i]->SetPosition(68, 130 + i * yImg, 65, 65);                                                                                     // SetPosition的参数分别是x, y, width, height\r
-                weatherImg[i]->SetSrc(ImageCacheManager::GetInstance().LoadSingleRes(weather65x65[p_WeatherModel->GetWeather_data_seven_data_iconDay(i)])); // 请设置实际的图片源\r
-\r
-                // 创建日期标签\r
-                if (dateLabel[i] == nullptr)\r
-                {\r
-                    dateLabel[i] = new UILabel();\r
-                }\r
-                dateLabel[i]->SetPosition(169, 148 + i * yLabel);\r
-                dateLabel[i]->SetStyle(STYLE_TEXT_FONT, 30);\r
-                dateLabel[i]->SetStyle(STYLE_LINE_HEIGHT, 35);\r
-                dateLabel[i]->SetText(p_WeatherModel->GetWeather_data_seven_data_fxDate(i).c_str()); // 设置具体日期文本\r
-                dateLabel[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-                dateLabel[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-                dateLabel[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
+        /* -------------------------------------------------------------------------- */\r
 \r
-                // 创建最高和最低气温标签\r
-                if (maxandminTemperatureLabel[i] == nullptr)\r
-                {\r
-                    maxandminTemperatureLabel[i] = new UILabel();\r
-                }\r
-                maxandminTemperatureLabel[i]->SetPosition(299, 148 + i * yLabel);\r
-                maxandminTemperatureLabel[i]->SetStyle(STYLE_TEXT_FONT, 30);\r
-                maxandminTemperatureLabel[i]->SetStyle(STYLE_LINE_HEIGHT, 35);\r
-                maxandminTemperatureLabel[i]->SetText(p_WeatherModel->GetWeather_data_seven_data_tempMinAndtempMax(i).c_str());\r
-                maxandminTemperatureLabel[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);\r
-                maxandminTemperatureLabel[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
-                maxandminTemperatureLabel[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);\r
-                scrollView->Add(weatherImg[i]);\r
-                scrollView->Add(dateLabel[i]);\r
-                scrollView->Add(maxandminTemperatureLabel[i]);\r
-            }\r
-            Add(scrollView);\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->SetText("未来7天");\r
+        Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);\r
+        Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);\r
+        Title->SetRollSpeed(40);\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, 400);\r
+        FutureWeatherList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);\r
+        FutureWeatherList->SetThrowDrag(true);\r
+        //FutureWeatherList->SetAutoSize(true);\r
+        FutureWeatherList->SetReboundSize(30);\r
+        FutureWeatherList->SetMaxScrollDistance(500);\r
+        FutureWeatherList->SetScrollBlankSize(75);\r
+        FutureWeatherList->SetAdapter(futureWeatherListAdapter);\r
+        FutureWeatherList->RefreshList();\r
+        FutureWeatherList->SetIntercept(true);\r
+        Add(FutureWeatherList);\r
         return true;\r
     }\r
 \r
@@ -157,4 +110,15 @@ namespace OHOS
         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
 }
\ No newline at end of file
index c8408ad..92415d6 100644 (file)
@@ -43,7 +43,7 @@ namespace OHOS
 \r
     void MainWeatherPresenter::OnResume(void)\r
     {\r
-\r
+        weatherModel->InitFutureWeatherItem();\r
         Presenter<MainWeatherView>::OnResume();\r
     }\r
 \r
@@ -104,6 +104,10 @@ namespace OHOS
     {\r
         WEARABLE_LOGE(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() == WEATHERREPORTVIEW)\r
+        {\r
+            MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList();\r
+        }\r
     }\r
 \r
     void WeatherControlViewOnSwipeListener::OnSwipe(UISwipeView &view)\r
@@ -113,7 +117,7 @@ namespace OHOS
         {\r
             view.SetIntercept(false);\r
         }\r
-        else if (view.GetCurrentPage() == WEATHERREPORTVIEW)\r
+        else\r
         {\r
             view.SetIntercept(true);\r
         }\r
index 734f980..f98918f 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com\r
  * @Date: 2024-01-29 15:37:44\r
  * @LastEditors: luozheng 1732036298@qq.com\r
- * @LastEditTime: 2024-04-13 19:27:19\r
+ * @LastEditTime: 2024-04-15 15:06:51\r
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp\r
  */\r
 #include "weather/include/MainWeatherView.h"\r
@@ -89,35 +89,6 @@ namespace OHOS
             recordCard[i]->InitView(this);\r
             weatherSwipeViewList->Add(recordCard[i]);\r
         }\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 nullptr;\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 nullptr;\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 nullptr;\r
-            }\r
-\r
-            weatherSwipeViewList->SetOnClickListener(weatherOnClickListener);\r
-            weatherSwipeViewList->SetOnDragListener(weatherOnDragListener);\r
-            weatherSwipeViewList->SetOnSwipeListener(weatherOnSwipeListener);\r
-        }\r
-        /* -------------------------------------------------------------------------- */\r
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView InitPage over!!");\r
         return weatherSwipeViewList;\r
     }\r
@@ -128,6 +99,35 @@ namespace OHOS
         if (WeatherModel::WEATHER_DATA_VALID)\r
         {\r
             MainWeatherViewInit();\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
+\r
+                weatherSwipeViewList->SetOnClickListener(weatherOnClickListener);\r
+                weatherSwipeViewList->SetOnDragListener(weatherOnDragListener);\r
+                weatherSwipeViewList->SetOnSwipeListener(weatherOnSwipeListener);\r
+            }\r
+            /* -------------------------------------------------------------------------- */\r
             RootView::GetInstance()->Add(weatherSwipeViewList);\r
         }\r
         else\r
@@ -140,6 +140,7 @@ namespace OHOS
             }\r
             RootView::GetInstance()->Add(getWeatherDataErrorView->GetWeatherDataErrorViewInit());\r
         }\r
+        /* -------------------------------------------------------------------------- */\r
         RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainWeatherPresenter::GetInstance();\r
         RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
     }\r
index d40c97a..987f0af 100644 (file)
@@ -2,10 +2,12 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-04-08 18:40:09
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-04-13 19:07:14
+ * @LastEditTime: 2024-04-15 15:16:06
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp
  */
 #include "weather/include/WeatherModel.h"
+#include "weather/include/MainWeatherView.h"
+
 namespace OHOS
 {
 #if __cplusplus
@@ -81,18 +83,18 @@ namespace OHOS
     }
 #endif /* __cplusplus */
 
-    static constexpr const char json_data[] =
-        "{\"now\": {\"humidity\":89,\"windScale\":\"2\",\"textNight\":\"多云\",\"uvIndex\":3,\"temp\":24,\"iconNight\":4},"
-        "\"address\": {\"lat\":225737664,\"atm\":\"1010\",\"city\":\"深圳\",\"subLocality\":\"宝安\",\"lon\":1138535138},"
-        "\"daily\": [{\"tempMin\":22,\"iconDay\":6,\"fxDate\":1712505600,\"textDay\":\"阵雨\",\"tempMax\":29},"
-        "{\"tempMax\":27,\"textDay\":\"多云\",\"iconDay\":3,\"fxDate\":1712592000,\"tempMin\":22},"
-        "{\"tempMax\":29,\"fxDate\":1712678400,\"textDay\":\"多云\",\"iconDay\":3,\"tempMin\":22},"
-        "{\"tempMin\":23,\"textDay\":\"多云\",\"fxDate\":1712764800,\"tempMax\":30,\"iconDay\":3},"
-        "{\"fxDate\":1712851200,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":31,\"tempMin\":24},"
-        "{\"fxDate\":1712937600,\"iconDay\":3,\"tempMax\":31,\"tempMin\":24,\"textDay\":\"多云\"},"
-        "{\"fxDate\":1713024000,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":29,\"tempMin\":25}],"
-        "\"code\":1}";
-
+    // static constexpr const char json_data[] =
+    //     "{\"now\": {\"humidity\":89,\"windScale\":\"2\",\"textNight\":\"多云\",\"uvIndex\":3,\"temp\":24,\"iconNight\":4},"
+    //     "\"address\": {\"lat\":225737664,\"atm\":\"1010\",\"city\":\"深圳\",\"subLocality\":\"宝安\",\"lon\":1138535138},"
+    //     "\"daily\": [{\"tempMin\":22,\"iconDay\":6,\"fxDate\":1712505600,\"textDay\":\"阵雨\",\"tempMax\":29},"
+    //     "{\"tempMax\":27,\"textDay\":\"多云\",\"iconDay\":3,\"fxDate\":1712592000,\"tempMin\":22},"
+    //     "{\"tempMax\":29,\"fxDate\":1712678400,\"textDay\":\"多云\",\"iconDay\":3,\"tempMin\":22},"
+    //     "{\"tempMin\":23,\"textDay\":\"多云\",\"fxDate\":1712764800,\"tempMax\":30,\"iconDay\":3},"
+    //     "{\"fxDate\":1712851200,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":31,\"tempMin\":24},"
+    //     "{\"fxDate\":1712937600,\"iconDay\":3,\"tempMax\":31,\"tempMin\":24,\"textDay\":\"多云\"},"
+    //     "{\"fxDate\":1713024000,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":29,\"tempMin\":25}],"
+    //     "\"code\":1}";
+    static constexpr const char json_data[2048] = "{\"now\":{\"humidity\":89,\"windScale\":\"2\",\"textNight\":\"多云\",\"uvIndex\":3,\"temp\":24,\"iconNight\":4},\"address\":{\"lat\":225737664,\"atm\":\"1010\",\"city\":\"深圳\",\"subLocality\":\"宝安\",\"lon\":1138535138},\"daily\":[{\"tempMin\":22,\"iconDay\":6,\"fxDate\":1712505600,\"textDay\":\"阵雨\",\"tempMax\":29},{\"tempMax\":27,\"textDay\":\"多云\",\"iconDay\":3,\"fxDate\":1712592000,\"tempMin\":22},{\"tempMax\":29,\"fxDate\":1712678400,\"textDay\":\"多云\",\"iconDay\":3,\"tempMin\":22},{\"tempMin\":23,\"textDay\":\"多云\",\"fxDate\":1712764800,\"tempMax\":30,\"iconDay\":3},{\"fxDate\":1712851200,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":31,\"tempMin\":24},{\"fxDate\":1712937600,\"iconDay\":3,\"tempMax\":31,\"tempMin\":24,\"textDay\":\"多云\"},{\"fxDate\":1713024000,\"textDay\":\"多云\",\"iconDay\":3,\"tempMax\":29,\"tempMin\":25}],\"code\":1}";
     /* -------------------------------------------------------------------------- */
     uint8_t WeatherModel::WEATHER_DATA_VALID = 0;
     WeatherModel::WeatherModel()
@@ -112,6 +114,20 @@ namespace OHOS
         return instance;
     }
 
+    void WeatherModel::InitFutureWeatherItem()
+    {
+        MainWeatherView *p_MainWeatherView = MainWeatherView::GetInstance();
+        for (uint8_t i = 0; i < 7; 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);
+            // FutureWeatherItem[i].tempMin = GetWeather_data_seven_data_tempMin(i);
+            // FutureWeatherItem[i].tempMax = GetWeather_data_seven_data_tempMax(i);
+            p_MainWeatherView->GetFutureWeatherView()->AddFutureWeatherItemToList(FutureWeatherItem[i]);
+        }
+    }
+
     void WeatherModel::TimestampToMonthDayString(time_t timestamp, char *buffer)
     {
         // 将时间戳转换成tm结构
@@ -125,9 +141,9 @@ namespace OHOS
     // 获取天气图片
     std::string WeatherModel::GetWeatherImage()
     {
-        int size = Weather_data_t_now.iconNight;
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "iconNight:%d", size);
-        return weather65x65[size];
+        int index = Weather_data_t_now.iconNight;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "iconNight:%d", index);
+        return weather65x65[index];
     }
 
     // 获取温度
@@ -162,14 +178,17 @@ namespace OHOS
     }
     /* -------------------------------------------------------------------------- */
     /*获取未来七天中某一天白天天气图标*/
-    int WeatherModel::GetWeather_data_seven_data_iconDay(int date)
+    std::string WeatherModel::GetWeather_data_seven_data_iconDay(int date)
     {
-        return Weather_data_seven_data[date].iconDay;
+        int index = Weather_data_seven_data[date].iconDay;
+        WEARABLE_LOGE(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_LOGE(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;
     }
 
@@ -178,6 +197,7 @@ namespace OHOS
     {
         static char formattedDate[6]; // 5字符加上终结符'\0'
         TimestampToMonthDayString(Weather_data_seven_data[date].fxDate, formattedDate);
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].fxDate = %s", date, formattedDate);
         return formattedDate;
     }
 
@@ -186,10 +206,29 @@ namespace OHOS
     {
         int maxTemp = Weather_data_seven_data[date].tempMax;
         int minTemp = Weather_data_seven_data[date].tempMin;
-        std::string maxandminTemperature = (std::to_string(maxTemp) + "°") + "/" + std::to_string(minTemp) + "°";
+        std::string maxandminTemperature = (std::to_string(minTemp) + "°") + "/" + std::to_string(maxTemp) + "°";
+        WEARABLE_LOGE(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_LOGE(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_LOGE(WEARABLE_LOG_MODULE_APP, " Weather_data_seven_data[%d].tempMax = %s", date, maxTemperature.c_str());
+        return maxTemperature;
+    }
+
     /* -------------------------------------------------------------------------- */
 
     /*获取湿度*/
index 50a9af6..48e3bfa 100644 (file)
@@ -1385,7 +1385,7 @@ void GetDrinkSetParamCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tota
     \r
 }\r
 \r
-static void jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据\r
+void jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据\r
 {\r
     uint8_t *json;\r
     json = buf;\r
@@ -1437,7 +1437,7 @@ static void jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据
         int  fxDate=cJSON_GetObjectItem(data,"fxDate")->valueint;\r
         char *  textDay=cJSON_GetObjectItem(data,"textDay")->valueint;\r
         int  tempMax=cJSON_GetObjectItem(data,"tempMax")->valueint;\r
-        set_weather_one_data(tempMin,iconDay,fxDate,textDay,tempMax,i);\r
+        set_weather_one_data(tempMin,iconDay,fxDate,tempMax,textDay,i);\r
     }\r
    \r
     //cJSON_GetObjectItem(daily, "daily");\r