From: luozheng <1732036298@qq.com> Date: Sat, 13 Apr 2024 09:31:34 +0000 (+0800) Subject: 天气视图修改,未来天气需要修改为list还需优化 X-Git-Tag: release_V1.2.70_20241020_135402~1189^2~7 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=c3262ddc524348dc1baa1aa64d94490959336066;p=mirrors%2FFD230.git 天气视图修改,未来天气需要修改为list还需优化 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index b2c504792..8ad5aaf7b 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -329,7 +329,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/MainWeatherPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/MainWeatherView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherReportView.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/FutureWeatherPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/FutureWeatherView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/GetWeatherDataErrorView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/WeatherControlView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 53d0e823f..7643650d3 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -43,7 +43,6 @@ typedef enum : uint16_t VIEW_INDOORWALK, // 室内步行 VIEW_SHUTDOWN_OR_REBOOT, // 关机或重启界面 VIEW_WEATHER, // 天气 - VIEW_FUTURE_WEATHER, // 未来天气 VIEW_SYSTEM, // 系统 VIEW_SOUND_VIBRATION, // 声音与震动 VIEW_SYSTEM_VOLUME, // 系统音量 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 80e354d6e..57e306bad 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -40,7 +40,6 @@ namespace OHOS void InitRecordingSlice(void); /* -------------------------------------------------------------------------- */ void InitWeatherSlice(void); - void InitFutureWeatherSlice(void); void InitSystemSlice(void); void InitSoundAndVibrationSlice(void); void InitSystemVolumeSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index a7852c0ff..d2fdb4305 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -68,8 +68,6 @@ #include "weather/include/MainWeatherPresenter.h" #include "weather/include/MainWeatherView.h" -#include "weather/include/FutureWeatherPresenter.h" -#include "weather/include/FutureWeatherView.h" #include "system/include/SystemPresenter.h" #include "system/include/SystemView.h" @@ -259,7 +257,6 @@ namespace OHOS {VIEW_INDOORWALK, &NativeLauncher::InitIndoorWalkSlice}, {VIEW_SHUTDOWN_OR_REBOOT, &NativeLauncher::InitRebootSlice}, {VIEW_WEATHER, &NativeLauncher::InitWeatherSlice}, // 天气 - {VIEW_FUTURE_WEATHER, &NativeLauncher::InitFutureWeatherSlice}, // 未来天气 {VIEW_SYSTEM, &NativeLauncher::InitSystemSlice}, // 系统实例化地址 {VIEW_SOUND_VIBRATION, &NativeLauncher::InitSoundAndVibrationSlice}, // 声音与震动实例化地址 {VIEW_SYSTEM_VOLUME, &NativeLauncher::InitSystemVolumeSlice}, // 系统音量 @@ -664,19 +661,6 @@ namespace OHOS NativeAbility::GetInstance().AddSliceProxy(VIEW_WEATHER, mainweather); } - void NativeLauncher::InitFutureWeatherSlice(void) // 未来天气 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitFutureWeatherSlice"); - SliceProxy *futureweather = new AbilitySliceProxy; - if (futureweather == nullptr) - { - return; - } - NativeAbility::GetInstance().AddSliceProxy(VIEW_FUTURE_WEATHER, futureweather); - } - - - void NativeLauncher::InitSystemSlice(void) // 系统 { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NativeLauncher::InitSystemSlice"); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherPresenter.h deleted file mode 100644 index 645130639..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherPresenter.h +++ /dev/null @@ -1,34 +0,0 @@ -#ifndef FUTURE_WEATHER_PRESENTER_H -#define FUTURE_WEATHER_PRESENTER_H - -#include "Presenter.h" - -#include "FutureWeatherView.h" - -namespace OHOS -{ - class FutureWeatherView; - - class FutureWeatherPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - FutureWeatherPresenter(); - virtual ~FutureWeatherPresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static FutureWeatherPresenter *GetInstance(); - - private: - // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - }; -} // namespace OHOS - -#endif // FutureWeather_PRESENTER_H \ 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 8a6aca6f0..cdc5ee1c2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-13 16:18:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h + */ #ifndef FUTURE_WEATHER_VIEW_H #define FUTURE_WEATHER_VIEW_H @@ -5,63 +12,47 @@ #include "View.h" #include "components/ui_view_group.h" #include "components/ui_scroll_view.h" -#include "components/ui_label.h" #include "components/ui_label_ext.h" #include "components/ui_list.h" #include "components/icon_adapter.h" +#include "AppGroupView.h" namespace OHOS { -#define weather_src "/user/res/weather/" -static const char *weather65x65[] = -{ -weather_src"weather_sunny.bin", //晴天 -weather_src"weather_clear-cloudy.bin", //多云 -weather_src"weather_rain.bin", //阵雨 -weather_src"weather_thundershower.bin", -weather_src"weather_foggy.bin", -weather_src"weather_unknown.bin", -weather_src"weather_overcast.bin", -weather_src"weather_clear-sunny.bin", -weather_src"weather_duststorm.bin", -weather_src"weather_haze.bin", -weather_src"weather_snow.bin", -weather_src"weather_sunny-cloudy.bin", -}; - - -} - -namespace OHOS -{ - class FutureWeatherPresenter; - class FutureWeatherView : public View +#define weather_src "/user/res/weather/weather65x65/" + static const char *weather65x65[] = + { + weather_src "weather_sunny.bin", // 晴天 + weather_src "weather_clear-cloudy.bin", // 多云 + weather_src "weather_rain.bin", // 阵雨 + weather_src "weather_thundershower.bin", + weather_src "weather_foggy.bin", + weather_src "weather_unknown.bin", + weather_src "weather_overcast.bin", + weather_src "weather_clear-sunny.bin", + weather_src "weather_duststorm.bin", + weather_src "weather_haze.bin", + weather_src "weather_snow.bin", + weather_src "weather_sunny-cloudy.bin", + }; + class FutureWeatherView : public AppGroupView { public: FutureWeatherView(); virtual ~FutureWeatherView(); static FutureWeatherView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; + bool InitPage(void); + virtual bool InitView(void *caller) override; private: - void InitView(void); - void DeInitView(void); - void PreLoad(void); - - private: - UIView::OnDragListener *draglistener{nullptr}; - UIViewGroup *container_ = nullptr; - UIScrollView *scrollView1_ = nullptr; - UILabel *label1_ = nullptr; - UIList *list = nullptr; - IconAdapter *listadapter = nullptr; - List *listdata = nullptr; - bool viewInitStatus{false}; + void ClearAll(void); + UIViewGroup *container = nullptr; + UIScrollView *scrollView{nullptr}; + UILabelExt *Title = nullptr; + UIImageView *weatherImg[7]{nullptr}; + UILabel *dateLabel[7]{nullptr}; + UILabel *maxandminTemperatureLabel[7]{nullptr}; }; -} // namespace OHOS -#endif // FutureWeather_PRESENTER_H \ No newline at end of file +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h index 09a8021ab..1950dbd2b 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-11 17:00:59 + * @LastEditTime: 2024-04-13 10:09:34 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherPresenter.h */ #ifndef MAIN_WEATHER_PRESENTER_H @@ -11,6 +11,7 @@ #include "Presenter.h" #include "View.h" #include "MainWeatherView.h" +#include "weather/include/WeatherModel.h" /*主天气视图*/ namespace OHOS { @@ -48,6 +49,8 @@ namespace OHOS bool OnDragEnd(UIView &view, const DragEvent &event) override; bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 void OnSwipe(UISwipeView &view) override; + + WeatherModel *weatherModel{nullptr}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h index ecff30147..04c1807f6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-12 19:45:12 + * @LastEditTime: 2024-04-13 10:04:53 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h */ #ifndef MAIN_WEATHER_VIEW_H @@ -15,13 +15,14 @@ #include "weather/include/WeatherView.h" #include "weather/include/WeatherReportView.h" #include "weather/include/GetWeatherDataErrorView.h" +#include "weather/include/FutureWeatherView.h" namespace OHOS { typedef enum { MAINWEATHERVIEW = 0, // 主天气视图 WEATHERREPORTVIEW, // 气象报告视图 - // FUTUREWEATHERVIEW, // 未来七天天气视图 + FUTUREWEATHERVIEW, // 未来七天天气视图 MAX_WEATHERVIEW, } WeatherPageId; class MainWeatherPresenter; @@ -36,8 +37,10 @@ namespace OHOS void ClearAll(void); AppGroupView *WeatherViewPageInit(void); AppGroupView *WeatherReportViewPageInit(void); - WeatherView * GetWeatherView(void); + AppGroupView *FutureWeatherViewPageInit(void); + WeatherView *GetWeatherView(void); WeatherReportView *GetWeatherReportView(void); + FutureWeatherView *GetFutureWeatherView(void); public: void OnStart() override; @@ -48,7 +51,8 @@ namespace OHOS private: WeatherView *weatherView{nullptr}; WeatherReportView *weatherReportView{nullptr}; - GetWeatherDataErrorView *g_GetWeatherDataErrorView{nullptr}; + FutureWeatherView *futureWeatherView{nullptr}; + GetWeatherDataErrorView *getWeatherDataErrorView{nullptr}; private: int16_t maxPage = MAX_WEATHERVIEW; UISwipeView *weatherSwipeViewList{nullptr}; // 天气滑动视图列表 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 dcecff4b9..4e1a2a16a 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-12 18:57:44 + * @LastEditTime: 2024-04-13 16:53:26 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h */ #ifndef WEATHER_MODEL_H @@ -10,6 +10,8 @@ #include "wearable_log.h" #include "iostream" +#include + namespace OHOS { #if __cplusplus @@ -81,13 +83,17 @@ namespace OHOS { public: static WeatherModel &GetInstance(void); - + void TimestampToMonthDayString(time_t timestamp, char *buffer); std::string GetWeatherImage(); std::string GetWeatherTemperature(); std::string GetWeatherDescription(); std::string GetWeatherArea(); std::string GetWeatherMaxAndMinTemperature(); - + /* -------------------------------------------------------------------------- */ + int 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); private: WeatherModel(); WeatherModel(const WeatherModel &) = delete; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherPresenter.cpp deleted file mode 100644 index cddd76bfd..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherPresenter.cpp +++ /dev/null @@ -1,74 +0,0 @@ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" -#include "NativeAbility.h" - -#include "weather/include/FutureWeatherPresenter.h" - -namespace OHOS -{ - - // 当前Presenter属性实例化的内存指针 - static FutureWeatherPresenter *g_pFutureWeatherPresenter = nullptr; - - FutureWeatherPresenter::FutureWeatherPresenter() - { - - g_pFutureWeatherPresenter = this; - } - - FutureWeatherPresenter::~FutureWeatherPresenter() - { - - g_pFutureWeatherPresenter = nullptr; - } - - FutureWeatherPresenter *FutureWeatherPresenter::GetInstance() - { - - return g_pFutureWeatherPresenter; - } - - void FutureWeatherPresenter::OnStart() - { - - Presenter::OnStart(); - } - - void FutureWeatherPresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void FutureWeatherPresenter::OnResume(void) - { - - Presenter::OnResume(); - } - - void FutureWeatherPresenter::OnStop(void) - { - - Presenter::OnStop(); - } - - bool FutureWeatherPresenter::OnDrag(UIView &view, const DragEvent &event) - { - - if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM && - (event.GetDeltaY() > 20) && (event.GetDeltaY() > (2 * MATH_ABS(event.GetDeltaX())))) - { - //NativeAbility::GetInstance().ChangeSlice(VIEW_WEATHER_REPORT); // 未来天气界面从上往下滑进入气象报告界面 - } - return true; - } - - bool FutureWeatherPresenter::OnClick(UIView &view, const ClickEvent &event) - { - - // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), 控件ID) == 0) - return true; - } -} \ 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 093399a4e..7539595a2 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp @@ -1,9 +1,6 @@ #include "weather/include/FutureWeatherView.h" -#include "weather/include/FutureWeatherPresenter.h" - -#include "common/image_cache_manager.h" -#include "UiConfig.h" -#include "ui_resource_image.h" +#include "wearable_log.h" +#include "weather/include/WeatherModel.h" namespace OHOS { @@ -12,13 +9,14 @@ namespace OHOS FutureWeatherView::FutureWeatherView() { - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::FutureWeatherView"); g_pFutureWeatherView = this; } FutureWeatherView::~FutureWeatherView() { - DeInitView(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::~FutureWeatherView"); + ClearAll(); g_pFutureWeatherView = nullptr; } @@ -28,173 +26,135 @@ namespace OHOS return g_pFutureWeatherView; } - void FutureWeatherView::InitView() - { - if (scrollView1_ == nullptr) - { - scrollView1_ = new UIScrollView(); - } - scrollView1_->SetPosition(0, 0); // widget's left position and top position - scrollView1_->Resize(466, 466); // widget's width and height - scrollView1_->SetViewId("scrollView1"); // Set style - scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - scrollView1_->SetReboundSize(50); // 设置回弹大小 - scrollView1_->SetScrollBarCenter({200, 200}); - container_->Add(scrollView1_); - scrollView1_->SetVisible(true); - - if (label1_ == nullptr) - { - label1_ = new UILabel(); - } - label1_->SetPosition(179, 52); - label1_->Resize(108, 35); - label1_->SetViewId("label1"); - label1_->SetStyle(STYLE_TEXT_FONT, 30); - label1_->SetStyle(STYLE_LINE_HEIGHT, 35); - label1_->SetText("未来7天"); - label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label1_->SetRollSpeed(0); - label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView1_->Add(label1_); - label1_->SetVisible(true); - - if (list == nullptr) - { - list = new UIList(); - } - list->SetPosition(65, 140); - list->Resize(354, 520); - list->SetViewId("list1"); - list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - list->SetReboundSize(50); // 设置回弹值 - if (listdata == nullptr) - { - listdata = new List(); - } - IconItemNode *list3data1 = new IconItemNode(); - list3data1->imagePath = "/user/res/weather/weather_sunny.bin"; - list3data1->txt = "周一 晴天 18°/24°"; - listdata->PushBack(list3data1); - - IconItemNode *list3data2 = new IconItemNode(); - list3data2->imagePath = "/user/res/weather/weather_clear-cloudy.bin"; - list3data2->txt = "周二 多云 19°/24°"; - listdata->PushBack(list3data2); - - IconItemNode *list3data3 = new IconItemNode(); - list3data3->imagePath = "/user/res/weather/weather_rain.bin"; - list3data3->txt = " 周三 阵雨 -11°/-12°"; - listdata->PushBack(list3data3); - - IconItemNode *list3data4 = new IconItemNode(); - list3data4->imagePath = "/user/res/weather/weather_sunny.bin"; - list3data4->txt = "周四 晴天 18°/22°"; - listdata->PushBack(list3data4); - - IconItemNode *list3data5 = new IconItemNode(); - list3data5->imagePath = "/user/res/weather/weather_foggy.bin"; - list3data5->txt = "周五 阴天 16°/20°"; - listdata->PushBack(list3data5); - - IconItemNode *list3data6 = new IconItemNode(); - list3data6->imagePath = "/user/res/weather/weather_thundershower.bin"; - list3data6->txt = " 周六 雷阵雨 10°/15°"; - listdata->PushBack(list3data6); - - IconItemNode *list3data7 = new IconItemNode(); - list3data7->imagePath = "/user/res/weather/weather_overcast.bin"; - list3data7->txt = "周日 阴 20°/24°"; - listdata->PushBack(list3data7); - if (listadapter == nullptr) - { - listadapter = new IconAdapter(); - } - listadapter->SetItemSize(355, 65); - listadapter->SetImageSize(65, 65); - listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); - listadapter->SetData(listdata); - list->SetAdapter(listadapter); - - // Add to scrollView1 - scrollView1_->Add(list); - list->SetVisible(true); - } - - void FutureWeatherView::DeInitView() + void FutureWeatherView::ClearAll() { - if (viewInitStatus == true) + if (container != nullptr) { - container_->RemoveAll(); - scrollView1_->RemoveAll(); - delete label1_; - label1_ = nullptr; + container->Remove(scrollView); - delete list; - list = nullptr; + scrollView->RemoveAll(); - delete listadapter; - listadapter = nullptr; + delete Title; + Title = nullptr; - delete draglistener; - draglistener = nullptr; + for (int i = 0; i < 7; i++) + { + delete weatherImg[i]; + weatherImg[i] = nullptr; - listdata->Clear(); - delete listdata; - listdata = nullptr; + delete dateLabel[i]; + dateLabel[i] = nullptr; - delete scrollView1_; - scrollView1_ = nullptr; + delete maxandminTemperatureLabel[i]; + maxandminTemperatureLabel[i] = nullptr; + } + delete scrollView; + scrollView = nullptr; - delete container_; - container_ = nullptr; + delete container; + container = nullptr; } } - void FutureWeatherView::PreLoad(void) + bool FutureWeatherView::InitPage(void) { - if (!viewInitStatus) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage"); + if (container == nullptr) { - InitView(); - viewInitStatus = true; + 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(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); } + return true; } - void FutureWeatherView::OnStart() + + bool FutureWeatherView::InitView(void *caller) { - View::OnStart(); - if (container_ == nullptr) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitView %p", caller); + if (InitPage() == false) { - container_ = new UIViewGroup(); - container_->Resize(466, 466); - container_->SetTouchable(true); - container_->SetDraggable(true); - draglistener = static_cast(FutureWeatherPresenter::GetInstance()); - container_->SetOnDragListener(draglistener); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage fail"); + return false; } - PreLoad(); - RootView::GetInstance()->Add(container_); - } - - void FutureWeatherView::OnSetUpView() - { - - View::OnSetUpView(); - Draw(); - } - - void FutureWeatherView::OnTearDownView() - { - - View::OnTearDownView(); - return; - } - - void FutureWeatherView::OnStop() - { - - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; + SetDraggable(true); + SetTouchable(true); + return true; } } \ 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 177ba4804..4b37dba20 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp @@ -1,6 +1,4 @@ #include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" #include "NativeAbility.h" #include "weather/include/MainWeatherPresenter.h" #include "common/key_code.h" @@ -15,7 +13,7 @@ namespace OHOS MainWeatherPresenter::MainWeatherPresenter() { - + weatherModel = &WeatherModel::GetInstance(); g_pMainWeatherPresenter = this; } @@ -71,7 +69,7 @@ namespace OHOS NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); return true; } - if(strcmp(view.GetViewId(),GETWEATHERDATAERRORVIEW) == 0) + if (strcmp(view.GetViewId(), GETWEATHERDATAERRORVIEW) == 0) { NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); } 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 428ec38e9..18fd11412 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.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-13 17:31:05 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp + */ #include "weather/include/MainWeatherView.h" #include "weather/include/MainWeatherPresenter.h" #include "weather/include/WeatherModel.h" @@ -38,14 +45,17 @@ namespace OHOS delete weatherReportView; weatherReportView = nullptr; + delete futureWeatherView; + futureWeatherView = nullptr; + delete weatherSwipeViewList; weatherSwipeViewList = nullptr; } - - if (g_GetWeatherDataErrorView != nullptr) + + if (getWeatherDataErrorView != nullptr) { - delete g_GetWeatherDataErrorView; - g_GetWeatherDataErrorView = nullptr; + delete getWeatherDataErrorView; + getWeatherDataErrorView = nullptr; } } @@ -122,13 +132,13 @@ namespace OHOS } else { - g_GetWeatherDataErrorView = new GetWeatherDataErrorView(); - if (g_GetWeatherDataErrorView == nullptr) + getWeatherDataErrorView = new GetWeatherDataErrorView(); + if (getWeatherDataErrorView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_GetWeatherDataErrorView new fail!!"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "getWeatherDataErrorView new fail!!"); return; } - RootView::GetInstance()->Add(g_GetWeatherDataErrorView->GetWeatherDataErrorViewInit()); + RootView::GetInstance()->Add(getWeatherDataErrorView->GetWeatherDataErrorViewInit()); } RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainWeatherPresenter::GetInstance(); RootView::GetInstance()->SetOnKeyActListener(keyactListener); @@ -166,6 +176,11 @@ namespace OHOS return weatherReportView; } + FutureWeatherView *MainWeatherView::GetFutureWeatherView(void) + { + return futureWeatherView; + } + /* * @brief 天气页面视图初始化 */ @@ -195,6 +210,20 @@ namespace OHOS return weatherReportView; } + /* + * @brief 未来天气视图初始化 + */ + AppGroupView *MainWeatherView::FutureWeatherViewPageInit(void) + { + futureWeatherView = new FutureWeatherView(); + if (futureWeatherView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherView::new futureWeatherView fail!"); + return nullptr; + } + return futureWeatherView; + } + struct MainWeatherViewMapper { const int16_t viewId; @@ -205,6 +234,7 @@ namespace OHOS static const MainWeatherViewMapper g_pageMapper[] = { {MAINWEATHERVIEW, &MainWeatherView::WeatherViewPageInit}, {WEATHERREPORTVIEW, &MainWeatherView::WeatherReportViewPageInit}, + {FUTUREWEATHERVIEW, &MainWeatherView::FutureWeatherViewPageInit}, }; /* 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 035e28e42..b5a27dd4f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp @@ -2,11 +2,10 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:09 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-12 16:34:46 + * @LastEditTime: 2024-04-13 17:07:14 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp */ #include "weather/include/WeatherModel.h" - namespace OHOS { #if __cplusplus @@ -112,6 +111,16 @@ namespace OHOS return instance; } + void WeatherModel::TimestampToMonthDayString(time_t timestamp, char *buffer) + { + // 将时间戳转换成tm结构 + struct tm *timeinfo = localtime(×tamp); + + // 格式化输出月份和日期 + // 注意: 月份tm_mon从0开始计数,所以显示时需要加1 + sprintf(buffer, "%02d.%02d", timeinfo->tm_mon + 1, timeinfo->tm_mday); + } + // 获取天气图片 std::string WeatherModel::GetWeatherImage() { @@ -150,4 +159,35 @@ namespace OHOS std::string MaxandMinTemperature = "最高" + std::to_string(maxtemperature) + "°" + " " + "最低" + std::to_string(mintemperature) + "°"; return MaxandMinTemperature; } + /* -------------------------------------------------------------------------- */ + /*获取未来七天中某一天白天天气图标*/ + int WeatherModel::GetWeather_data_seven_data_iconDay(int date) + { + return Weather_data_seven_data[date].iconDay; + } + + /*获取未来七天某一天白天天气文本*/ + std::string WeatherModel::GetWeather_data_seven_data_textDay(int date) + { + 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_LOGE(WEARABLE_LOG_MODULE_APP, "formattedDate:%s",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(maxTemp) + "°") + "/" + std::to_string(minTemp) + "°"; + return maxandminTemperature; + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp index 4bb5d2544..c1399bff9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp @@ -71,7 +71,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::WeatherView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); SetViewIndex(0); // 视图索引 - if (WEATHER_DATA_VALID) + if (1) { WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); WeatherImag = p_WeatherModel->GetWeatherImage();