From: luozheng <1732036298@qq.com> Date: Mon, 15 Apr 2024 07:28:17 +0000 (+0800) Subject: 天气视图优化 X-Git-Tag: release_V1.2.70_20241020_135402~1189^2~4 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=a156b465bba8b9ea6ee7a3c434b0d287bcb39828;p=mirrors%2FFD230.git 天气视图优化 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index 8ad5aaf7b..0f0eca557 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -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 index 000000000..e003d3a40 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListAdapter.h @@ -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 + +namespace OHOS +{ + struct FutureWeather + { + std::string iconDay; // 白天天气图标 + std::string fxDate; // 日期 + std::string tempMinAndMax; + // std::string tempMin; // 最低温度 + // std::string tempMax; // 最高温度 + }; + + class FutureWeatherListAdapter : public AbstractAdapter + { + public: + explicit FutureWeatherListAdapter(); + virtual ~FutureWeatherListAdapter(); + + /* * + * @brief Sets the UIView adapter data, which is a FutureWeather linked list. + * + * @param data Indicates the FutureWeather linked list data. + * @since 1.0 + * @version 1.0 + */ + void SetData(std::list &data); + + void ClearData(void); + /* * + * @brief Obtains the data size of the UILabel adapter. + * + * @return Returns the data size of the UILabel adapter. + * @since 1.0 + * @version 1.0 + */ + virtual uint16_t GetCount(void) override; + + virtual UIView *GetView(UIView *inView, int16_t index) override; + + virtual void AddListItem(const FutureWeather &item); + + private: + std::list listData; + }; + +} + +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListitemView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListitemView.h new file mode 100644 index 000000000..c965cd71d --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListitemView.h @@ -0,0 +1,36 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-15 09:25:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-15 14:41:57 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherListitemView.h + */ +#ifndef FUTURE_WEATHER_LIST_ITEM_VIEW +#define FUTURE_WEATHER_LIST_ITEM_VIEW + +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "weather/include/FutureWeatherListAdapter.h" +namespace OHOS +{ + class FutureWeatherListitemView : public UIViewGroup + { + public: + FutureWeatherListitemView(); + virtual ~FutureWeatherListitemView(); + virtual void SetItemInfo(const FutureWeather itemInfo); + virtual void SetUpChild(); + + private: + FutureWeatherListitemView(const FutureWeatherListitemView &); + UIImageView weatherImg; // 天气图标 + UILabel dateLabel; // 日期 + UILabel minAndmaxTemperatureLabel; // 最高温度 + // UILabel minTemperatureLabel; // 最小温度 + // UILabel maxTemperatureLabel; // 最高温度 + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h index bca211e9a..eeeaa5011 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-13 19:10:22 + * @LastEditTime: 2024-04-15 14:24:52 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h */ #ifndef FUTURE_WEATHER_VIEW_H @@ -16,6 +16,7 @@ #include "components/ui_list.h" #include "components/icon_adapter.h" #include "AppGroupView.h" +#include "weather/include/FutureWeatherListAdapter.h" namespace OHOS { @@ -28,15 +29,14 @@ namespace OHOS static FutureWeatherView *GetInstance(void); bool InitPage(void); virtual bool InitView(void *caller) override; - + void AddFutureWeatherItemToList(const FutureWeather &item); + UIList *GetFutureWeatherList(); private: void ClearAll(void); - UIViewGroup *container = nullptr; - UIScrollView *scrollView{nullptr}; + // UIScrollView *scrollView{nullptr}; UILabelExt *Title = nullptr; - UIImageView *weatherImg[7]{nullptr}; - UILabel *dateLabel[7]{nullptr}; - UILabel *maxandminTemperatureLabel[7]{nullptr}; + UIList *FutureWeatherList{nullptr}; + FutureWeatherListAdapter *futureWeatherListAdapter{nullptr}; }; } #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h index acaaa415a..da731694a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:20 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-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 - +#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 index 000000000..8db0ae2a6 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp @@ -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 &data) + { + if (!listData.empty()) + { + listData.clear(); + } + std::list::iterator it; + for (it = data.begin(); it != data.end(); it++) + { + listData.push_back(*it); + } + } + + void FutureWeatherListAdapter::ClearData(void) + { + if (!listData.empty()) + { + listData.clear(); + } + } + + UIView *FutureWeatherListAdapter::GetView(UIView *inView, int16_t index) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::GetView,index %d", index); + // 1.先检查列表数据是否为空,若为空则返回空指针 + if (listData.empty()) + { + return nullptr; + } + // 2.接着检查索引是否小于0,若小于0则返回空指针 + if (index < 0) + { + return nullptr; + } + // 3.检查是否超出列表数据大小,若超出则返回空指针 + size_t uindex = index; + if (uindex >= listData.size()) + { + return nullptr; + } + // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量 + std::list::iterator it = listData.begin(); + for (int i = 0; i < index; i++) + { + it++; + } + FutureWeather itemData = *it; + FutureWeatherListitemView *item = nullptr; + // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的LanguageSwitchListItemView对象,否则将inView转换成LanguageSwitchListItemView类型的指针 + if (inView == nullptr) + { + item = new FutureWeatherListitemView(); + } + else + { + item = dynamic_cast(inView); + } + item->SetItemInfo(itemData); + return item; + } + + void FutureWeatherListAdapter::AddListItem(const FutureWeather &item) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::AddListItem"); + listData.push_back(item); + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp new file mode 100644 index 000000000..cb3e5d6f0 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp @@ -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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp index 191b1a06a..4076d5bd8 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-15 15:01:52 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp + */ #include "weather/include/FutureWeatherView.h" #include "wearable_log.h" #include "weather/include/WeatherModel.h" @@ -10,6 +17,8 @@ namespace OHOS FutureWeatherView::FutureWeatherView() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::FutureWeatherView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(2); // 视图索引 g_pFutureWeatherView = this; } @@ -28,120 +37,64 @@ namespace OHOS void FutureWeatherView::ClearAll() { - if (container != nullptr) - { - container->Remove(scrollView); - - scrollView->RemoveAll(); - - delete Title; - Title = nullptr; + RemoveAll(); + + delete Title; + Title = nullptr; - for (int i = 0; i < 7; i++) - { - delete weatherImg[i]; - weatherImg[i] = nullptr; + delete futureWeatherListAdapter; + futureWeatherListAdapter = nullptr; - delete dateLabel[i]; - dateLabel[i] = nullptr; - - delete maxandminTemperatureLabel[i]; - maxandminTemperatureLabel[i] = nullptr; - } - delete scrollView; - scrollView = nullptr; - - delete container; - container = nullptr; - } + delete FutureWeatherList; + FutureWeatherList = nullptr; } bool FutureWeatherView::InitPage(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage"); - if (container == nullptr) - { - container = new UIViewGroup(); - if (container == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::container is new fail!!"); - return false; - } - container->SetPosition(0, 0, 466, 466); - container->SetStyle(STYLE_BACKGROUND_OPA, 0); - /* -------------------------------------------------------------------------- */ - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "scrollView is new fail!!"); - return false; - } - scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); - scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - scrollView->SetReboundSize(50); // 设置回弹大小 - scrollView->SetHorizontalScrollState(false); // 设置横向不可以滚动 - scrollView->SetScrollBlankSize(50); // 设置高位50可滑动空白区域 - /* -------------------------------------------------------------------------- */ - Title = new UILabelExt(); - if (Title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::Title is new fail!!"); - return false; - } - Title->SetPosition(93, 52, 280, 47); - Title->SetStyle(STYLE_TEXT_FONT, 30); - Title->SetStyle(STYLE_LINE_HEIGHT, 35); - Title->SetText("未来7天"); - Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); - Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - Title->SetRollSpeed(40); - Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView->Add(Title); - /* -------------------------------------------------------------------------- */ - int yImg = 80; - int yLabel = 85; - WeatherModel *p_WeatherModel = &WeatherModel::GetInstance().GetInstance(); - for (int i = 0; i < 7; ++i) // 创建7个组件组 - { - // 创建天气图标 - if (weatherImg[i] == nullptr) - { - weatherImg[i] = new UIImageView(); - } - weatherImg[i]->SetPosition(68, 130 + i * yImg, 65, 65); // SetPosition的参数分别是x, y, width, height - weatherImg[i]->SetSrc(ImageCacheManager::GetInstance().LoadSingleRes(weather65x65[p_WeatherModel->GetWeather_data_seven_data_iconDay(i)])); // 请设置实际的图片源 - - // 创建日期标签 - if (dateLabel[i] == nullptr) - { - dateLabel[i] = new UILabel(); - } - dateLabel[i]->SetPosition(169, 148 + i * yLabel); - dateLabel[i]->SetStyle(STYLE_TEXT_FONT, 30); - dateLabel[i]->SetStyle(STYLE_LINE_HEIGHT, 35); - dateLabel[i]->SetText(p_WeatherModel->GetWeather_data_seven_data_fxDate(i).c_str()); // 设置具体日期文本 - dateLabel[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - dateLabel[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - dateLabel[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ - // 创建最高和最低气温标签 - if (maxandminTemperatureLabel[i] == nullptr) - { - maxandminTemperatureLabel[i] = new UILabel(); - } - maxandminTemperatureLabel[i]->SetPosition(299, 148 + i * yLabel); - maxandminTemperatureLabel[i]->SetStyle(STYLE_TEXT_FONT, 30); - maxandminTemperatureLabel[i]->SetStyle(STYLE_LINE_HEIGHT, 35); - maxandminTemperatureLabel[i]->SetText(p_WeatherModel->GetWeather_data_seven_data_tempMinAndtempMax(i).c_str()); - maxandminTemperatureLabel[i]->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - maxandminTemperatureLabel[i]->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - maxandminTemperatureLabel[i]->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView->Add(weatherImg[i]); - scrollView->Add(dateLabel[i]); - scrollView->Add(maxandminTemperatureLabel[i]); - } - Add(scrollView); + /* -------------------------------------------------------------------------- */ + Title = new UILabelExt(); + if (Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::Title is new fail!!"); + return false; + } + Title->SetPosition(93, 52, 280, 47); + Title->SetStyle(STYLE_TEXT_FONT, 30); + Title->SetStyle(STYLE_LINE_HEIGHT, 35); + Title->SetText("未来7天"); + Title->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Title->SetRollSpeed(40); + Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + Add(Title); + /* -------------------------------------------------------------------------- */ + futureWeatherListAdapter = new FutureWeatherListAdapter(); + if (futureWeatherListAdapter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FutureWeatherView::InitPage] futureWeatherListAdapter is nullptr"); + return false; + } + /* -------------------------------------------------------------------------- */ + FutureWeatherList = new UIList(UIList::VERTICAL); + if (FutureWeatherList == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::FutureWeatherList is nullptr"); + return false; } + FutureWeatherList->SetPosition(68, 130, 330, 400); + FutureWeatherList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + FutureWeatherList->SetThrowDrag(true); + //FutureWeatherList->SetAutoSize(true); + FutureWeatherList->SetReboundSize(30); + FutureWeatherList->SetMaxScrollDistance(500); + FutureWeatherList->SetScrollBlankSize(75); + FutureWeatherList->SetAdapter(futureWeatherListAdapter); + FutureWeatherList->RefreshList(); + FutureWeatherList->SetIntercept(true); + Add(FutureWeatherList); return true; } @@ -157,4 +110,15 @@ namespace OHOS SetTouchable(true); return true; } + + void FutureWeatherView::AddFutureWeatherItemToList(const FutureWeather &item) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::AddFutureWeatherItemToList"); + futureWeatherListAdapter->AddListItem(item); + } + + UIList *FutureWeatherView::GetFutureWeatherList() + { + return FutureWeatherList; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp index c8408ad08..92415d6bc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp @@ -43,7 +43,7 @@ namespace OHOS void MainWeatherPresenter::OnResume(void) { - + weatherModel->InitFutureWeatherItem(); Presenter::OnResume(); } @@ -104,6 +104,10 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherPresenter::OnSwipe,current tab index = %d", view.GetCurrentPage()); // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "the view index = %d,dragging direction = %d,current tab index = %d", view.GetViewIndex(), view.GetDirection(), view.GetCurrentPage()); + if (view.GetCurrentPage() == WEATHERREPORTVIEW) + { + MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); + } } void WeatherControlViewOnSwipeListener::OnSwipe(UISwipeView &view) @@ -113,7 +117,7 @@ namespace OHOS { view.SetIntercept(false); } - else if (view.GetCurrentPage() == WEATHERREPORTVIEW) + else { view.SetIntercept(true); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp index 734f980b3..f98918fe7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-13 19:27:19 + * @LastEditTime: 2024-04-15 15:06:51 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp */ #include "weather/include/MainWeatherView.h" @@ -89,35 +89,6 @@ namespace OHOS recordCard[i]->InitView(this); weatherSwipeViewList->Add(recordCard[i]); } - /* -------------------------------------------------------------------------- */ - if (weatherSwipeViewList != nullptr) - { - UIView::OnClickListener *weatherOnClickListener = (UIView::OnClickListener *)OHOS::MainWeatherPresenter::GetInstance(); - if (weatherOnClickListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnClickListener new fail"); - return nullptr; - } - - UIView::OnDragListener *weatherOnDragListener = (UIView::OnDragListener *)OHOS::MainWeatherPresenter::GetInstance(); - if (weatherOnDragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnDragListener new fail"); - return nullptr; - } - - UISwipeView::OnSwipeListener *weatherOnSwipeListener = (UISwipeView::OnSwipeListener *)OHOS::MainWeatherPresenter::GetInstance(); - if (weatherOnSwipeListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); - return nullptr; - } - - weatherSwipeViewList->SetOnClickListener(weatherOnClickListener); - weatherSwipeViewList->SetOnDragListener(weatherOnDragListener); - weatherSwipeViewList->SetOnSwipeListener(weatherOnSwipeListener); - } - /* -------------------------------------------------------------------------- */ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView InitPage over!!"); return weatherSwipeViewList; } @@ -128,6 +99,35 @@ namespace OHOS if (WeatherModel::WEATHER_DATA_VALID) { MainWeatherViewInit(); + /* -------------------------------------------------------------------------- */ + if (weatherSwipeViewList != nullptr) + { + UIView::OnClickListener *weatherOnClickListener = (UIView::OnClickListener *)OHOS::MainWeatherPresenter::GetInstance(); + if (weatherOnClickListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnClickListener new fail"); + return; + } + + UIView::OnDragListener *weatherOnDragListener = (UIView::OnDragListener *)OHOS::MainWeatherPresenter::GetInstance(); + if (weatherOnDragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnDragListener new fail"); + return; + } + + UISwipeView::OnSwipeListener *weatherOnSwipeListener = (UISwipeView::OnSwipeListener *)OHOS::MainWeatherPresenter::GetInstance(); + if (weatherOnSwipeListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); + return; + } + + weatherSwipeViewList->SetOnClickListener(weatherOnClickListener); + weatherSwipeViewList->SetOnDragListener(weatherOnDragListener); + weatherSwipeViewList->SetOnSwipeListener(weatherOnSwipeListener); + } + /* -------------------------------------------------------------------------- */ RootView::GetInstance()->Add(weatherSwipeViewList); } else @@ -140,6 +140,7 @@ namespace OHOS } RootView::GetInstance()->Add(getWeatherDataErrorView->GetWeatherDataErrorViewInit()); } + /* -------------------------------------------------------------------------- */ RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainWeatherPresenter::GetInstance(); RootView::GetInstance()->SetOnKeyActListener(keyactListener); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp index d40c97a40..987f0af29 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -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; + } + /* -------------------------------------------------------------------------- */ /*获取湿度*/ diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index 50a9af674..48e3bfaa3 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -1385,7 +1385,7 @@ void GetDrinkSetParamCmd(uint16_t cmd,uint8_t *crcnum,uint16_t len,uint8_t *tota } -static void jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 +void jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 { uint8_t *json; json = buf; @@ -1437,7 +1437,7 @@ static void jsonCheck_weather(uint8_t *buf)//json 格式解析 天气数据 int fxDate=cJSON_GetObjectItem(data,"fxDate")->valueint; char * textDay=cJSON_GetObjectItem(data,"textDay")->valueint; int tempMax=cJSON_GetObjectItem(data,"tempMax")->valueint; - set_weather_one_data(tempMin,iconDay,fxDate,textDay,tempMax,i); + set_weather_one_data(tempMin,iconDay,fxDate,tempMax,textDay,i); } //cJSON_GetObjectItem(daily, "daily");