From 5f84f51df043e38565d5e6300f919eb50cf13ffd Mon Sep 17 00:00:00 2001 From: =?utf8?q?=E7=BD=97=E6=AD=A3?= <1732036298@qq.com> Date: Sat, 15 Jun 2024 10:07:57 +0000 Subject: [PATCH] Merge #295 into sdk602patch0521 from refs/changes/295/head MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Code review from 罗正 * refs/changes/295/head: (2 commits squashed) - 天气界面实现app同步刷新数据 - Merge branch 'sdk602patch0521' of https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230 into sdk602patch0521 Signed-off-by: 罗正 <1732036298@qq.com> Reviewed-by: snickersun@163.com Merged-by: snickersun@163.com CR-link: https://codeup.aliyun.com/64191456b9581d62e8f81ac0/FD230/change/295 --- .../weather/include/FutureWeatherView.h | 3 +- .../weather/include/GetWeatherDataErrorView.h | 4 +- .../weather/include/MainWeatherView.h | 4 +- .../weather/include/WeatherControlView.h | 14 +++ .../nativeui/weather/include/WeatherModel.h | 7 +- .../weather/include/WeatherReportView.h | 22 +++- .../nativeui/weather/include/WeatherView.h | 3 +- .../weather/src/FutureWeatherListAdapter.cpp | 11 +- .../weather/src/FutureWeatherListitemView.cpp | 7 +- .../weather/src/FutureWeatherView.cpp | 30 +++-- .../weather/src/GetWeatherDataErrorView.cpp | 7 +- .../weather/src/MainWeatherPresenter.cpp | 8 +- .../nativeui/weather/src/MainWeatherView.cpp | 70 ++++++----- .../weather/src/WeatherControlView.cpp | 109 +++++++++++++++--- .../nativeui/weather/src/WeatherModel.cpp | 68 ++++++++--- .../weather/src/WeatherReportView.cpp | 92 +++++++++++++-- .../nativeui/weather/src/WeatherView.cpp | 24 ++-- .../service/ble_service/blemoder/bletest.cpp | 5 + .../service/ble_service/blemoder/bletest.h | 3 +- .../service/ble_service/bleservice/bleEvent.c | 1 + 20 files changed, 372 insertions(+), 120 deletions(-) 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 82c9edeeb..089b6240b 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-05-10 11:36:50 + * @LastEditTime: 2024-06-15 15:19:23 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/FutureWeatherView.h */ #ifndef FUTURE_WEATHER_VIEW_H @@ -30,6 +30,7 @@ namespace OHOS bool InitPage(void); virtual bool InitView(void *caller) override; void AddFutureWeatherItemToList(const FutureWeather &item); + bool UpdateFutureWeatherListData(void); UIList *GetFutureWeatherList(); private: void ClearAll(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h index 4f84f2d14..49ebb7f8c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-10 10:49:52 + * @LastEditTime: 2024-06-15 14:21:01 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/GetWeatherDataErrorView.h */ #ifndef Get_WEATHER_DATA_ERROR_VIEW_H @@ -31,7 +31,7 @@ namespace OHOS void ClearAll(); UIScrollView *scrollView = nullptr; - UILabel *label = nullptr; + UILabelExt *label = nullptr; UIImageView *image = nullptr; }; } 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 1e6064f9f..be02ce861 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-05-10 11:22:41 + * @LastEditTime: 2024-06-15 16:27:21 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MainWeatherView.h */ #ifndef MAIN_WEATHER_VIEW_H @@ -43,6 +43,7 @@ namespace OHOS UIView *GetWeatherPageView(void); WeatherReportView *GetWeatherReportView(void); FutureWeatherView *GetFutureWeatherView(void); + bool UpdateMainWeatherViewVisibility(void); public: void OnStart() override; @@ -61,6 +62,7 @@ namespace OHOS UISwipeView *weatherSwipeViewList{nullptr}; // 天气滑动视图列表 AppGroupView *recordCard[MAX_WEATHERVIEW]{nullptr}; AppGroupView *CreatePage(int32_t WeatherPageId); + UIScrollView *weatherScrllView{nullptr}; }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherControlView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherControlView.h index 13bc62ea7..77c4f4cd0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherControlView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherControlView.h @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-15 15:00:16 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherControlView.h + */ #ifndef WEATHER_CONTROL_VIEW_H #define WEATHER_CONTROL_VIEW_H /*该视图主要放在主视图*/ @@ -13,13 +20,20 @@ namespace OHOS public: WeatherControlView(); virtual ~WeatherControlView(); + static WeatherControlView *GetInstance(void); bool InitView(void); void PreLoad(void) override; void UnLoad(void) override; + bool UpdateWeatherControlViewVisibility(); private: void ClearAll(void); + bool InitializeWeatherScrollView(); + bool InitializeWeatherSwipeView(); + bool CreateMainWeatherView(); MainWeatherView *mainWeatherView{nullptr}; + UISwipeView *weatherSwipView{nullptr}; + UIScrollView *weatherScrllView{nullptr}; UISwipeView::OnSwipeListener *weatherOnSwipeListener{nullptr}; bool viewiInitStatus{false}; }; 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 e2f5c0fd0..8c4a5019f 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-05-09 15:46:16 + * @LastEditTime: 2024-06-15 17:33:03 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h */ #ifndef WEATHER_MODEL_H @@ -57,6 +57,9 @@ namespace OHOS void UI_set_weather_address_data(int lat, char *atm, char *city, char *subLocality, int lon); void UI_set_weather_seven_day_data(struct ONE_DAY_DATA t,int count); + + void UI_UpdateMainWeatherData(void); + #if __cplusplus } #endif /* __cplusplus */ @@ -106,6 +109,8 @@ namespace OHOS /* -------------------------------------------------------------------------- */ bool GetWeatherDataIsValid(void); void SetWeatherDataIsValid(bool value); + /* -------------------------------------------------------------------------- */ + void UpdateMainWeatherData(void); private: WeatherModel(); WeatherModel(const WeatherModel &) = delete; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h index f8b5bc505..8729039f1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-09 17:49:13 + * @LastEditTime: 2024-06-15 12:11:30 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h */ #ifndef WEATHER_REPORT_VIEW_H @@ -29,10 +29,10 @@ namespace OHOS int16_t top; int16_t width; int16_t height; - int16_t fontSize; // 字体大小 - int16_t lineHeigh; // 行高 - std::string text; // 文本 - uint16_t textId; + int16_t fontSize; // 字体大小 + int16_t lineHeigh; // 行高 + std::string text; // 文本 + uint16_t textId; uint8_t lineBreakMode; // 断行模式。 }; WeatherReportView(); @@ -45,7 +45,17 @@ namespace OHOS { return UVImageAnimatorView; } + bool UpdateWeatherReportViewData(void); + private: + bool SetTextLabel(UILabel *label, const std::string &text); + void DumpWeatherInfo(void); + bool UpdateUVData(void); + bool UpdateWindSpeedData(void); + bool UpdateHumidityData(void); + std::string UVData; // 紫外线强度数据 + std::string WindSpeedData; // 风速数据 + std::string HumidityData; // 湿度数据 private: const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages); void FreeImagePathsArray(const char **imagePaths, const int numImages); @@ -63,7 +73,7 @@ namespace OHOS UIImageAnimatorView *UVImageAnimatorView{nullptr}; // 紫外线动画 UIImageAnimatorView *WindSpeedImageAnimatorView{nullptr}; // 风速动画 UIImageAnimatorView *HumidityImageAnimatorView{nullptr}; // 湿度动画 - + const char **UVPathsArray{nullptr}; const char **WindSpeedPathsArray{nullptr}; const char **HumidityPathsArray{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h index f1189ddeb..3c93ddf58 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-30 09:14:38 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-15 11:59:38 + * @LastEditTime: 2024-06-15 16:31:50 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h */ #ifndef WEATHER_VIEW_H @@ -45,7 +45,6 @@ namespace OHOS void DumpWeatherInfo(); bool SetImageSource(UIImageView *image, const std::string &source); bool SetTextLabel(UILabel *label, const std::string &text); - bool GetInitViewState(void); bool UpdateWeatherTime(void); bool UpdateWeatherImag(void); bool UpdateWeatherTemperature(void); diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp index 8db0ae2a6..f0ad458cc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp @@ -1,3 +1,10 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-15 09:25:17 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-15 16:41:36 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListAdapter.cpp + */ #include "weather/include/FutureWeatherListAdapter.h" #include "weather/include/FutureWeatherListitemView.h" #include "wearable_log.h" @@ -7,12 +14,12 @@ namespace OHOS FutureWeatherListAdapter::FutureWeatherListAdapter() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::FutureWeatherListAdapter"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::FutureWeatherListAdapter"); } FutureWeatherListAdapter::~FutureWeatherListAdapter() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::~FutureWeatherListAdapter"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListAdapter::~FutureWeatherListAdapter"); listData.clear(); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp index cb3e5d6f0..720cb11e6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-15 09:25:53 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-04-15 14:58:08 + * @LastEditTime: 2024-06-15 17:49:39 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherListitemView.cpp */ @@ -13,7 +13,7 @@ namespace OHOS FutureWeatherListitemView::FutureWeatherListitemView() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::FutureWeatherListitemView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::FutureWeatherListitemView"); SetPosition(0, 0, 330, 85); SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); SetStyle(STYLE_BACKGROUND_OPA, 255); @@ -28,7 +28,7 @@ namespace OHOS FutureWeatherListitemView::~FutureWeatherListitemView() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::~FutureWeatherListitemView"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "FutureWeatherListitemView::~FutureWeatherListitemView"); Remove(&weatherImg); Remove(&dateLabel); Remove(&minAndmaxTemperatureLabel); @@ -42,6 +42,7 @@ namespace OHOS weatherImg.SetSrc(itemInfo.iconDay.c_str()); dateLabel.SetText(itemInfo.fxDate.c_str()); minAndmaxTemperatureLabel.SetText(itemInfo.tempMinAndMax.c_str()); + //WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "itemInfo.iconDay.c_str() = %s,itemInfo.fxDate.c_str() = %s,itemInfo.tempMinAndMax.c_str()", itemInfo.iconDay.c_str(), itemInfo.fxDate.c_str(),itemInfo.tempMinAndMax.c_str()); // minTemperatureLabel.SetText(itemInfo.tempMin.c_str()); // maxTemperatureLabel.SetText(itemInfo.tempMax.c_str()); } 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 51f24c16d..ac3989f3a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-10 11:19:59 + * @LastEditTime: 2024-06-15 17:00:27 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp */ #include "weather/include/FutureWeatherView.h" @@ -33,14 +33,13 @@ namespace OHOS FutureWeatherView *FutureWeatherView::GetInstance() { - return g_pFutureWeatherView; } void FutureWeatherView::ClearAll() { RemoveAll(); - + delete Title; Title = nullptr; @@ -86,10 +85,11 @@ namespace OHOS FutureWeatherList->SetPosition(68, 130, 330, 400); FutureWeatherList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); FutureWeatherList->SetThrowDrag(true); - //FutureWeatherList->SetAutoSize(true); + // FutureWeatherList->SetAutoSize(true); FutureWeatherList->SetReboundSize(30); FutureWeatherList->SetMaxScrollDistance(500); - FutureWeatherList->SetScrollBlankSize(75); + FutureWeatherList->SetScrollBlankSize(85); + WeatherModel::GetInstance().InitFutureWeatherItem(); FutureWeatherList->SetAdapter(futureWeatherListAdapter); FutureWeatherList->RefreshList(); FutureWeatherList->SetIntercept(true); @@ -105,11 +105,9 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::InitPage fail"); return false; } + //UpdateFutureWeatherListData(); SetDraggable(true); SetTouchable(true); - /* -------------------------------------------------------------------------- */ - WeatherModel::GetInstance().InitFutureWeatherItem(); - /* -------------------------------------------------------------------------- */ return true; } @@ -123,4 +121,20 @@ namespace OHOS { return FutureWeatherList; } + + // 更新未来七天数据 + bool FutureWeatherView::UpdateFutureWeatherListData(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FutureWeatherView::UpdateFutureWeatherListData"); + if (futureWeatherListAdapter != nullptr) + { + delete futureWeatherListAdapter; + futureWeatherListAdapter = nullptr; + } + futureWeatherListAdapter = new FutureWeatherListAdapter(); + WeatherModel::GetInstance().InitFutureWeatherItem(); + FutureWeatherList->SetAdapter(futureWeatherListAdapter); + FutureWeatherList->RefreshList(); + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp index 1e36a452d..015e59768 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp @@ -2,14 +2,13 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-05-10 10:49:39 + * @LastEditTime: 2024-06-15 14:22:18 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/GetWeatherDataErrorView.cpp */ #include "weather/include/GetWeatherDataErrorView.h" #include "wearable_log.h" #include "weather/include/MainWeatherPresenter.h" #include "language/font/ui_resource_string.h" -#include "uicomponents/UIComponents.h" /* 天气获取数据失败后会调用该视图*/ namespace OHOS @@ -62,7 +61,7 @@ namespace OHOS image->SetSrc(ImgSr); scrollView->Add(image); /* -------------------------------------------------------------------------- */ - label = new UILabel(); + label = new UILabelExt(); if (label == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label is new fail!!"); @@ -71,7 +70,7 @@ namespace OHOS label->SetPosition(33, 268, 400, 70); label->SetStyle(STYLE_TEXT_FONT, 30); label->SetStyle(STYLE_LINE_HEIGHT, 35); - SetLabelId(label,STR_GET_WEATHER_ERROR); + label->SetTextId(STR_GET_WEATHER_ERROR); label->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); 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 a882bd326..daaba8b2c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherPresenter.cpp @@ -68,7 +68,7 @@ namespace OHOS UNUSED(view); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MainWeatherPresenter::X_DRAG_FLAG) { - NativeAbility::GetInstance().Back(); + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); X_DRAG_FLAG = false; } return true; @@ -92,7 +92,7 @@ namespace OHOS // 如果是power键就返回上一级 if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().Back(); + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); } return true; } @@ -103,7 +103,7 @@ namespace OHOS // 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(); + //MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); } } @@ -113,7 +113,7 @@ namespace OHOS if (view.GetCurrentPage() == MAINWEATHERVIEW) { view.SetIntercept(false); - MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); + //MainWeatherView::GetInstance()->GetFutureWeatherView()->GetFutureWeatherList()->RefreshList(); } else { 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 002044dba..a5a0e34d8 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-05-10 11:31:08 + * @LastEditTime: 2024-06-15 16:32:55 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MainWeatherView.cpp */ #include "weather/include/MainWeatherView.h" @@ -20,7 +20,6 @@ namespace OHOS MainWeatherView::~MainWeatherView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::~MainWeatherView"); - ClearAll(); g_pMainWeatherView = nullptr; } @@ -59,6 +58,14 @@ namespace OHOS } } + // 设置按键监听 + static void SetKeyActListener() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetKeyActListener"); + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainWeatherPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); + } + /* * @brief 主天气页面视图初始化 */ @@ -78,6 +85,7 @@ namespace OHOS weatherSwipeViewList->SetViewId(MAIN_WEATHER_VIEW); weatherSwipeViewList->SetDraggable(true); weatherSwipeViewList->SetTouchable(true); + weatherSwipeViewList->SetVisible(false); for (uint16_t i = 0; i < maxPage; i++) { recordCard[i] = CreatePage(i); @@ -93,24 +101,38 @@ namespace OHOS return weatherSwipeViewList; } - // 获取天气页面视图 - UIView *MainWeatherView::GetWeatherPageView() + bool MainWeatherView::UpdateMainWeatherViewVisibility() { - if (WeatherModel::GetInstance().GetWeatherDataIsValid()) // 如果天气数据有效 + if (weatherSwipeViewList != nullptr && weatherScrllView != nullptr) { - return dynamic_cast(MainWeatherViewInit()); - } - else - { - return dynamic_cast(WeatherDataErrorViewPageInit()); + if (WeatherModel::GetInstance().GetWeatherDataIsValid()) + { + weatherSwipeViewList->SetVisible(true); + weatherScrllView->SetVisible(false); + } + else + { + weatherScrllView->SetVisible(true); + weatherSwipeViewList->SetVisible(false); + } + container_->Invalidate(); + return true; } - return nullptr; + return false; } void MainWeatherView::OnStart() { View::OnStart(); - RootView::GetInstance()->Add(GetWeatherPageView()); + SetContainerView(new UIViewGroup()); + container_->SetDraggable(true); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetOnDragListener(presenter_); + container_->SetTouchable(true); + container_->Add(MainWeatherViewInit()); + weatherScrllView = WeatherDataErrorViewPageInit(); + container_->Add(weatherScrllView); + if (weatherSwipeViewList != nullptr) { UIView::OnClickListener *weatherOnClickListener = (UIView::OnClickListener *)OHOS::MainWeatherPresenter::GetInstance(); @@ -137,20 +159,8 @@ namespace OHOS weatherSwipeViewList->SetOnDragListener(weatherOnDragListener); weatherSwipeViewList->SetOnSwipeListener(weatherOnSwipeListener); } - else - { - UIView::OnDragListener *dragListener = static_cast(MainWeatherPresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "dragListener is nullptr!!"); - return; - } - getWeatherDataErrorView->GetWeatherDataErrorViewInit()->SetOnDragListener(dragListener); - } - /* --------------------------------- 添加按键监听 --------------------------------- */ - RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MainWeatherPresenter::GetInstance(); - RootView::GetInstance()->SetOnKeyActListener(keyactListener); - /* -------------------------------------------------------------------------- */ + UpdateMainWeatherViewVisibility(); + SetKeyActListener(); } void MainWeatherView::OnSetUpView() @@ -169,7 +179,13 @@ namespace OHOS { View::OnStop(); RootView::GetInstance()->ClearOnKeyActListener(); - RootView::GetInstance()->RemoveAll(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + ClearAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherControlView.cpp index 987ba3103..66ef3d897 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherControlView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherControlView.cpp @@ -1,17 +1,33 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-06-15 15:09:37 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherControlView.cpp + */ #include "weather/include/WeatherControlView.h" #include "weather/include/MainWeatherPresenter.h" namespace OHOS { + + static WeatherControlView *g_pWeatherControlView{nullptr}; WeatherControlView::WeatherControlView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::WeatherControlView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pWeatherControlView = this; } WeatherControlView::~WeatherControlView() { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::~WeatherControlView"); ClearAll(); + g_pWeatherControlView = nullptr; + } + + WeatherControlView *WeatherControlView::GetInstance(void) + { + return g_pWeatherControlView; } void WeatherControlView::ClearAll(void) @@ -26,7 +42,7 @@ namespace OHOS delete weatherOnSwipeListener; weatherOnSwipeListener = nullptr; } - + if (mainWeatherView != nullptr) { delete mainWeatherView; @@ -36,37 +52,98 @@ namespace OHOS } } - bool WeatherControlView::InitView(void) + bool WeatherControlView::CreateMainWeatherView() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherControlView::InitView"); + mainWeatherView = new MainWeatherView(); if (mainWeatherView == nullptr) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::new mainweatherView fail!"); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::new mainWeatherView fail!"); + return false; + } + + return true; + } + + bool WeatherControlView::InitializeWeatherSwipeView() + { + weatherSwipView = mainWeatherView->MainWeatherViewInit(); + if (weatherSwipView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mainWeatherView->MainWeatherViewInit() == nullptr!!"); + return false; + } + + weatherOnSwipeListener = static_cast(new WeatherControlViewOnSwipeListener()); + if (weatherOnSwipeListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); + return false; + } + + weatherSwipView->SetOnSwipeListener(weatherOnSwipeListener); + weatherSwipView->SetVisible(false); + Add(weatherSwipView); + + return true; + } + + bool WeatherControlView::InitializeWeatherScrollView() + { + weatherScrllView = mainWeatherView->WeatherDataErrorViewPageInit(); + if (weatherScrllView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mainWeatherView->WeatherDataErrorViewPageInit() == nullptr!!"); return false; } - if (WeatherModel::GetInstance().GetWeatherDataIsValid()) + weatherScrllView->SetVisible(true); // 默认没有天气数据 + Add(weatherScrllView); + + return true; + } + + // 根据天气数据是否有效设置视图可见性: + bool WeatherControlView::UpdateWeatherControlViewVisibility() + { + if (weatherSwipView != nullptr && weatherScrllView != nullptr) { - UISwipeView *weatherSwipView = dynamic_cast(mainWeatherView->GetWeatherPageView()); - if (weatherSwipView == nullptr) + if (WeatherModel::GetInstance().GetWeatherDataIsValid()) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mainWeatherView->MainWeatherViewInit() == nullptr!!"); - return false; + weatherSwipView->SetVisible(true); + weatherScrllView->SetVisible(false); } - weatherOnSwipeListener = static_cast(new WeatherControlViewOnSwipeListener()); - if (weatherOnSwipeListener == nullptr) + else { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); - return false; + weatherScrllView->SetVisible(true); + weatherSwipView->SetVisible(false); } - weatherSwipView->SetOnSwipeListener(weatherOnSwipeListener); - Add(weatherSwipView); + Invalidate(); + return true; } - else + return false; + } + + bool WeatherControlView::InitView() + { + if (!CreateMainWeatherView()) { - Add(mainWeatherView->GetWeatherPageView()); + return false; + } + + if (!InitializeWeatherSwipeView()) + { + return false; } + + if (!InitializeWeatherScrollView()) + { + return false; + } + + UpdateWeatherControlViewVisibility(); + return true; } 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 83efef535..142dddac0 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,12 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-04-08 18:40:09 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-15 11:54:18 + * @LastEditTime: 2024-06-15 17:50:19 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherModel.cpp */ #include "weather/include/WeatherModel.h" #include "weather/include/MainWeatherView.h" +#include "weather/include/WeatherControlView.h" namespace OHOS { @@ -17,7 +18,7 @@ namespace OHOS static Weather_data Weather_data_t_now; static Weather_data_address Weather_data_t_address; static ONE_DAY_DATA Weather_data_seven_data[7]; - uint8_t Weather_data_seven_count=0; + uint8_t Weather_data_seven_count = 0; /* * @brief 设置当前天气数据 @@ -65,13 +66,14 @@ namespace OHOS /* * @brief 设置七天天气数据 */ - void UI_set_weather_seven_day_data(struct ONE_DAY_DATA t,int count) + void UI_set_weather_seven_day_data(struct ONE_DAY_DATA t, int count) { - if(count=0) + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_count = %d", count); + if (count == 0) { - Weather_data_seven_count=0; + Weather_data_seven_count = 0; } - if(count>=7) + if (count >= 7) { return; } @@ -82,9 +84,14 @@ namespace OHOS Weather_data_seven_data[count].fxDate = t.fxDate; memset((void *)Weather_data_seven_data[count].textDay, 0, 16); strcpy(Weather_data_seven_data[count].textDay, t.textDay); - + Weather_data_seven_count++; - + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_count = %d", Weather_data_seven_count); + } + + void UI_UpdateMainWeatherData(void) + { + WeatherModel::GetInstance().UpdateMainWeatherData(); } #if __cplusplus @@ -115,6 +122,7 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainWeatherView::GetInstance fail!!"); return; } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_count = %d", Weather_data_seven_count); for (uint8_t i = 0; i < Weather_data_seven_count; i++) { FutureWeatherItem[i].iconDay = GetWeather_data_seven_data_iconDay(i); @@ -139,7 +147,7 @@ namespace OHOS std::string WeatherModel::GetWeatherImage() { int index = Weather_data_t_now.iconNight; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "iconNight:%d", index); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "iconNight:%d", index); return weather65x65[index]; } @@ -178,14 +186,14 @@ namespace OHOS std::string WeatherModel::GetWeather_data_seven_data_iconDay(int date) { int index = Weather_data_seven_data[date].iconDay; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].iconDay = %d", date, index); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].iconDay = %d", date, index); return weather65x65[index]; } /*获取未来七天某一天白天天气文本*/ std::string WeatherModel::GetWeather_data_seven_data_textDay(int date) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].textDay = %s", date, Weather_data_seven_data[date].textDay); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].textDay = %s", date, Weather_data_seven_data[date].textDay); return Weather_data_seven_data[date].textDay; } @@ -194,7 +202,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); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].fxDate = %s", date, formattedDate); return formattedDate; } @@ -204,7 +212,7 @@ namespace OHOS int maxTemp = Weather_data_seven_data[date].tempMax; int minTemp = Weather_data_seven_data[date].tempMin; std::string maxandminTemperature = (std::to_string(minTemp) + "°") + "/" + std::to_string(maxTemp) + "°"; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "maxandminTemperature = %s", maxandminTemperature.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "maxandminTemperature = %s", maxandminTemperature.c_str()); return maxandminTemperature; } @@ -213,7 +221,7 @@ namespace OHOS { 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()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Weather_data_seven_data[%d].tempMin = %s", date, minTemperature.c_str()); return minTemperature; } @@ -222,7 +230,7 @@ namespace OHOS { 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()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " Weather_data_seven_data[%d].tempMax = %s", date, maxTemperature.c_str()); return maxTemperature; } @@ -232,7 +240,7 @@ namespace OHOS std::string WeatherModel::GetHumidity() { std::string humidity = std::to_string(Weather_data_t_now.humidity) + "%"; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "humidity:%s", humidity.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "humidity:%s", humidity.c_str()); return humidity; } @@ -240,7 +248,7 @@ namespace OHOS std::string WeatherModel::GetWindScale() { std::string windScale = Weather_data_t_now.windScale; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "windScale:%s", windScale.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "windScale:%s", windScale.c_str()); return windScale; } @@ -248,7 +256,7 @@ namespace OHOS std::string WeatherModel::GetUVIndex() { std::string uvIndex = std::to_string(Weather_data_t_now.uvIndex); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uvIndex:%s", uvIndex.c_str()); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uvIndex:%s", uvIndex.c_str()); return uvIndex; } @@ -263,4 +271,28 @@ namespace OHOS { return WEATHER_DATA_VALID; } + + // 更新所有天气数据 + void WeatherModel::UpdateMainWeatherData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "UpdateMainWeatherData"); + + MainWeatherView *p_MainWeatherView = MainWeatherView::GetInstance(); + if (p_MainWeatherView != nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "p_MainWeatherView"); + p_MainWeatherView->GetWeatherView()->UpdateWeatherViewData(); + p_MainWeatherView->GetWeatherReportView()->UpdateWeatherReportViewData(); + p_MainWeatherView->GetFutureWeatherView()->UpdateFutureWeatherListData(); + + p_MainWeatherView->UpdateMainWeatherViewVisibility(); + } + + WeatherControlView *p_WeatherControlView = WeatherControlView::GetInstance(); + if (p_WeatherControlView != nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "p_WeatherControlView"); + p_WeatherControlView->UpdateWeatherControlViewVisibility(); + } + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp index a69740923..14befa438 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp @@ -31,6 +31,11 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " WeatherReportView::WeatherReportView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); SetViewIndex(1); + WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); + UVData = p_WeatherModel->GetUVIndex(); // 紫外线强度数据 + WindSpeedData = p_WeatherModel->GetWindScale(); // 风速数据 + HumidityData = p_WeatherModel->GetHumidity(); // 湿度数据 + g_pWeatherReportView = this; } @@ -146,7 +151,6 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::title new fail!"); return false; } - WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); /* -------------------------------------------------------------------------- */ labelconfig = { .left = 23, @@ -155,7 +159,7 @@ namespace OHOS .height = 50, .fontSize = 40, .lineHeigh = 50, - .text = p_WeatherModel->GetUVIndex(), //紫外线强度 + .text = UVData.c_str(), // 紫外线强度 .lineBreakMode = UILabel::LINE_BREAK_ELLIPSIS, }; UV_Number = SetUpLabel(labelconfig); @@ -166,7 +170,7 @@ namespace OHOS } labelconfig.left = 173; - labelconfig.text = p_WeatherModel->GetWindScale();//风速 + labelconfig.text = WindSpeedData.c_str(); // 风速 WindSpeed_Number = SetUpLabel(labelconfig); if (WindSpeed_Number == nullptr) { @@ -175,7 +179,7 @@ namespace OHOS } labelconfig.left = 323; - labelconfig.text = p_WeatherModel->GetHumidity().c_str(); //湿度 + labelconfig.text = HumidityData.c_str(); // 湿度 Humidity_Number = SetUpLabel(labelconfig); if (Humidity_Number == nullptr) { @@ -204,7 +208,7 @@ namespace OHOS UV->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); labelconfig.left = 173; - //labelconfig.text = "风速"; + // labelconfig.text = "风速"; labelconfig.textId = STR_WIND_SPEED; WindSpeed = SetUpLabelExt(labelconfig); if (WindSpeed == nullptr) @@ -215,7 +219,7 @@ namespace OHOS WindSpeed->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); labelconfig.left = 323; - //labelconfig.text = "湿度"; + // labelconfig.text = "湿度"; labelconfig.textId = STR_HUMIDITY; Humidity = SetUpLabelExt(labelconfig); if (Humidity == nullptr) @@ -329,13 +333,9 @@ namespace OHOS bool WeatherReportView::InitPage(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage"); - if (!WeatherReportViewLabelInit()) - { - return false; - } - - if (!WeatherReportViewImageAnimatorViewInit()) + if (!WeatherReportViewLabelInit() || !WeatherReportViewImageAnimatorViewInit()) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage fail!!"); return false; } @@ -351,6 +351,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage fail"); return false; } + UpdateWeatherReportViewData(); SetDraggable(true); SetTouchable(true); return true; @@ -383,4 +384,71 @@ namespace OHOS } } + // 设置文本标签的通用函数 + bool WeatherReportView::SetTextLabel(UILabel *label, const std::string &text) + { + if (label) + { + label->SetText(text.c_str()); + label->Invalidate(); + return true; + } + return false; + } + + void WeatherReportView::DumpWeatherInfo(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::DumpWeatherInfo"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "UVData:%s", UVData.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WindSpeedData:%s", WindSpeedData.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "HumidityData:%s", HumidityData.c_str()); + } + + // 更新紫外线数据 + bool WeatherReportView::UpdateUVData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateUVData"); + + std::string uv = WeatherModel::GetInstance().GetUVIndex(); + + return SetTextLabel(UV_Number, uv); + } + + // 更新风速数据 + bool WeatherReportView::UpdateWindSpeedData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWindSpeedData"); + + std::string windscale = WeatherModel::GetInstance().GetWindScale(); + + return SetTextLabel(WindSpeed_Number, windscale); + return true; + } + + // 更新湿度数据 + bool WeatherReportView::UpdateHumidityData(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateHumidityData"); + + std::string humidity = WeatherModel::GetInstance().GetHumidity(); + + return SetTextLabel(Humidity_Number, humidity); + } + + // 更新气象报告数据 + bool WeatherReportView::UpdateWeatherReportViewData(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherReportViewData"); + bool success = true; + success &= UpdateUVData(); + success &= UpdateWindSpeedData(); + success &= UpdateHumidityData(); + if (!success) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherViewData fail!!"); + } + //DumpWeatherInfo(); + return true; + } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp index be8f5fbcd..5c0f6e14f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-06-12 11:44:04 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-06-15 11:57:39 + * @LastEditTime: 2024-06-15 16:31:45 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp */ #include "weather/include/WeatherView.h" @@ -82,9 +82,17 @@ namespace OHOS static WeatherView *g_pWeatherView{nullptr}; WeatherView::WeatherView() { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::WeatherView"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::WeatherView"); SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); SetViewIndex(0); // 视图索引 + + WeatherModel *p_WeatherModel = &WeatherModel::GetInstance(); + WeatherImag = p_WeatherModel->GetWeatherImage(); + Temperature = p_WeatherModel->GetWeatherTemperature(); + WeatherDescription = p_WeatherModel->GetWeatherDescription(); + WeatherArea = p_WeatherModel->GetWeatherArea(); + MaxandMinTemperature = p_WeatherModel->GetWeatherMaxAndMinTemperature(); + g_pWeatherView = this; } @@ -151,7 +159,6 @@ namespace OHOS return g_pWeatherView; } - // 初始化标签 UILabelExt *WeatherView::InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight) { UILabelExt *label = new UILabelExt(); @@ -169,7 +176,6 @@ namespace OHOS return label; } - // 初始化天气页面 bool WeatherView::InitPage(void) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " WeatherView::InitPage"); @@ -288,12 +294,6 @@ namespace OHOS return true; } - // 获取视图初始化状态 - bool WeatherView::GetInitViewState(void) - { - return viewInitStatus; - } - const char **WeatherView::CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages) { const char **imagePaths = new const char *[numImages]; @@ -348,7 +348,7 @@ namespace OHOS void WeatherView::DumpWeatherInfo() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::DumpWeatherInfo"); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherTime:", WeatherTime.c_str()); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherTime:%s", WeatherTime.c_str()); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherImag:%s", WeatherImag.c_str()); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Temperature:%s", Temperature.c_str()); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherDescription:%s", WeatherDescription.c_str()); @@ -441,7 +441,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::UpdateWeatherViewData fail!!"); } - DumpWeatherInfo(); // 输出天气信息到日志 + //DumpWeatherInfo(); // 输出天气信息到日志 return success; } diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp index 681e6f26a..3c6fd9ee8 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.cpp @@ -880,6 +880,11 @@ void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char } #endif + +void ble_UpdateMainWeatherData(void) +{ + return OHOS::UI_UpdateMainWeatherData(); +} message_infor_t message_infor_s; void read_message_data(void) { diff --git a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h index a3c54dd9b..af1fe85c3 100644 --- a/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h +++ b/code/sdk/application/wearable/service/ble_service/blemoder/bletest.h @@ -108,7 +108,8 @@ struct message_infor_t *get_message_info(void); void set_weather_now_data(int humidity, char* windScale, char* textNight,int uvIndex,int temp,int iconNight); void set_weather_address_data(int lat, char* atm, char* city,char* subLocality,int lon); -void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char *textDay,int count); +void set_weather_one_data(int tempMin, int iconDay,int fxDate, int tempMax, char *textDay,int count) ; +void ble_UpdateMainWeatherData(void); uint8_t ble_is_ready(void); void set_ble_falg(bool falg); 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 b060ea29e..bc9e427f2 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -1945,6 +1945,7 @@ uint8_t jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 天气 set_weather_one_data(tempMin,iconDay,fxDate,tempMax,textDay,i); } + ble_UpdateMainWeatherData(); cJSON_Delete(root); *check = 1; return 1; -- 2.17.1