From f72687951fdc1a8834f7557d1fec3f27246a3f14 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Sat, 17 Aug 2024 16:38:31 +0800 Subject: [PATCH] =?utf8?q?=E5=A4=A9=E6=B0=94=E7=95=8C=E9=9D=A2=E6=B7=BB?= =?utf8?q?=E5=8A=A0=E5=8E=86=E5=8F=B2=E6=95=B0=E6=8D=AE=E4=BF=9D=E5=AD=98?= =?utf8?q?=EF=BC=8C=E5=A4=A9=E6=B0=94=E7=95=8C=E9=9D=A2ui=E4=BC=98?= =?utf8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativelauncher/src/NativeLauncher.cpp | 3 + .../weather/include/WeatherReportView.h | 5 +- .../nativeui/weather/include/WeatherView.h | 10 ++- .../weather/src/FutureWeatherView.cpp | 12 ++-- .../weather/src/WeatherReportView.cpp | 17 ++++- .../nativeui/weather/src/WeatherView.cpp | 42 +++++++++++-- .../service/ble_service/bleservice/bleEvent.c | 62 ++++++++++++++++--- .../service/ble_service/bleservice/bleEvent.h | 2 + 8 files changed, 131 insertions(+), 22 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 82b09f2db..cd93d058c 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -278,6 +278,7 @@ #ifdef JS_ENABLE #include "product_adapter.h" #endif +#include "bleEvent.h" namespace OHOS { @@ -492,6 +493,8 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Power is Charging!"); DialModelCharge::GetInstance()->UpdateChargeStuaut(1); } + /*开机读取天气历史数据*/ + read_jsonHistory_weather(); } void NativeLauncher::InitAllNativeSlices(void) 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 35058b851..b4c928555 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-06-15 12:11:30 + * @LastEditTime: 2024-08-17 16:20:42 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherReportView.h */ #ifndef WEATHER_REPORT_VIEW_H @@ -70,6 +70,9 @@ namespace OHOS UILabelExt *WindSpeed_Number{nullptr}; // UILabelExt *Humidity{nullptr}; // 湿度 UILabelExt *Humidity_Number{nullptr}; // + + UIImageView *PullUpImage{nullptr}; // 上拉图片 + UIImageAnimatorView *UVImageAnimatorView{nullptr}; // 紫外线动画 UIImageAnimatorView *WindSpeedImageAnimatorView{nullptr}; // 风速动画 UIImageAnimatorView *HumidityImageAnimatorView{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 618c91589..56bc2ff70 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-07-23 14:51:03 + * @LastEditTime: 2024-08-17 16:03:36 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherView.h */ #ifndef WEATHER_VIEW_H @@ -23,6 +23,7 @@ namespace OHOS { +#define IS_USE_IMAGEANIMATOR 0 static constexpr const char *WeatherBackground = "/user/res/weather/WEATHER_BACKGROUND.bin"; // 天气背景 class WeatherView : public AppGroupView { @@ -66,8 +67,13 @@ namespace OHOS UILabelExt *showWeatherDescriptionLabel{nullptr}; // 显示天气描述 UILabelExt *showWeatherAreaLabel{nullptr}; // 显示天气地区 UILabelExt *showMaxandMinTemperatureLabel{nullptr}; // 显示最高与最低气温 - UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 +#if IS_USE_IMAGEANIMATOR + UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 const char **PullUpPathsArray{nullptr}; +#else + + UIImageView *PullUpImage{nullptr}; // 上拉图片 +#endif bool viewInitStatus{false}; }; } // namespace OHOS 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 39107a321..7a9183566 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-06-19 10:46:16 + * @LastEditTime: 2024-08-17 16:27:56 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/FutureWeatherView.cpp */ #include "weather/include/FutureWeatherView.h" @@ -84,16 +84,16 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::FutureWeatherList is nullptr"); return false; } - FutureWeatherList->SetPosition(68, 130, 330, 400); + FutureWeatherList->SetPosition(68, 130, 330, 300); FutureWeatherList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); FutureWeatherList->SetThrowDrag(true); - // FutureWeatherList->SetAutoSize(true); FutureWeatherList->SetReboundSize(30); - FutureWeatherList->SetMaxScrollDistance(500); - FutureWeatherList->SetScrollBlankSize(85); + FutureWeatherList->SetMaxScrollDistance(1000); + FutureWeatherList->SetScrollBlankSize(30); + FutureWeatherList->SetDragACCLevel(5); + FutureWeatherList->SetSwipeACCLevel(800); WeatherModel::GetInstance().InitFutureWeatherItem(); FutureWeatherList->SetAdapter(futureWeatherListAdapter); - FutureWeatherList->RefreshList(); FutureWeatherList->SetIntercept(true); Add(FutureWeatherList); viewInitStatus = true; 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 a5f86d720..641e0dbe7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherReportView.cpp @@ -77,6 +77,9 @@ namespace OHOS delete Humidity_Number; Humidity_Number = nullptr; + delete PullUpImage; + PullUpImage = nullptr; + UVImageAnimatorView->Stop(); delete UVImageAnimatorView; UVImageAnimatorView = nullptr; @@ -323,10 +326,22 @@ namespace OHOS HumidityImageAnimatorView->SetRepeat(true); HumidityImageAnimatorView->Start(); } + /* -------------------------------------------------------------------------- */ + PullUpImage = new UIImageView(); + if (PullUpImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new PullUpImage fail!"); + return false; + } + PullUpImage->SetPosition(213, 400, 40, 40); + PullUpImage->SetAutoEnable(false); + PullUpImage->SetResizeMode(UIImageView::CONTAIN); + PullUpImage->SetSrc("/user/res/Sleep/up.bin"); /* ----------------------------------- Add ---------------------------------- */ Add(UVImageAnimatorView); Add(WindSpeedImageAnimatorView); Add(HumidityImageAnimatorView); + Add(PullUpImage); viewInitStatus = true; return true; @@ -352,7 +367,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherReportView::InitPage fail"); return false; } - //UpdateWeatherReportViewData(); + // UpdateWeatherReportViewData(); SetDraggable(true); SetTouchable(true); return true; 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 d4c105770..e23379c84 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-07-23 14:44:07 + * @LastEditTime: 2024-08-17 16:08:22 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/WeatherView.cpp */ #include "weather/include/WeatherView.h" @@ -70,6 +70,7 @@ namespace OHOS static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_TEXT_FONT = 20; static constexpr int16_t MAXANDMIN_TEMPERATURE_LABEL_LINE_HEIGHT = 23; +#if IS_USE_IMAGEANIMATOR static constexpr int16_t PULLUP_ANIMATOR_VIEW_X = 213; static constexpr int16_t PULLUP_ANIMATOR_VIEW_Y = 400; static constexpr int16_t PULLUP_ANIMATOR_VIEW_W = 40; @@ -78,6 +79,13 @@ namespace OHOS static constexpr int16_t PULLUP_ANIMATOR_VIEW_TIME = 100; ImageAnimatorInfo PullUpimageAnimatorInfo[PULLUP_ANIMATOR_VIEW_NUM_FRAMES]; static constexpr const char *PullUpPaths = "/user/res/weather/PullUp/PullUp_"; +#else + /*上拉图片*/ + static constexpr int16_t PULLUP_IMAGE_X = 213; + static constexpr int16_t PULLUP_IMAGE_Y = 400; + static constexpr int16_t PULLUP_IMAGE_W = 40; + static constexpr int16_t PULLUP_IMAGE_H = 40; +#endif static WeatherView *g_pWeatherView{nullptr}; WeatherView::WeatherView() @@ -144,14 +152,21 @@ namespace OHOS delete showMaxandMinTemperatureLabel; showMaxandMinTemperatureLabel = nullptr; } +#if IS_USE_IMAGEANIMATOR if (PullUpAnimatorView != nullptr) { PullUpAnimatorView->Stop(); delete PullUpAnimatorView; PullUpAnimatorView = nullptr; } - FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); +#else + if (PullUpImage != nullptr) + { + delete PullUpImage; + PullUpImage = nullptr; + } +#endif } } @@ -242,7 +257,8 @@ namespace OHOS return false; } showMaxandMinTemperatureLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); - /* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ +#if IS_USE_IMAGEANIMATOR PullUpPathsArray = CreateImagePathsArray(PullUpPaths, "bin", PULLUP_ANIMATOR_VIEW_NUM_FRAMES); if (PullUpAnimatorView == nullptr) { @@ -268,6 +284,18 @@ namespace OHOS PullUpAnimatorView->SetRepeat(true); PullUpAnimatorView->Start(); } +#else + PullUpImage = new UIImageView(); + if (PullUpImage == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::new PullUpImage fail!"); + return false; + } + PullUpImage->SetPosition(PULLUP_IMAGE_X, PULLUP_IMAGE_Y, PULLUP_IMAGE_W, PULLUP_IMAGE_H); + PullUpImage->SetAutoEnable(false); + PullUpImage->SetResizeMode(UIImageView::CONTAIN); + PullUpImage->SetSrc("/user/res/Sleep/up.bin"); +#endif /* -------------------------------- 将组件添加到根视图 ------------------------------- */ Add(WeatherBackGroundImg); Add(showWeatherImage); @@ -276,7 +304,11 @@ namespace OHOS Add(showWeatherDescriptionLabel); Add(showWeatherAreaLabel); Add(showMaxandMinTemperatureLabel); +#if IS_USE_IMAGEANIMATOR Add(PullUpAnimatorView); +#else + Add(PullUpImage); +#endif viewInitStatus = true; return true; @@ -290,7 +322,7 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WeatherView::InitPage fail"); return false; } - //UpdateWeatherViewData(); + // UpdateWeatherViewData(); SetDraggable(true); SetTouchable(true); return true; @@ -435,7 +467,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/bleservice/bleEvent.c b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c index f84f65b74..58cd7ff04 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.c @@ -2069,20 +2069,29 @@ void SetsteptargetParamCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *tota uint8_t jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 天气数据 { - uint8_t flag = 0; - // flag = 2; - // memcpy(check,&flag,1); - // return 0; uint8_t *json; json = buf; // printf("jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json)); - #if 0 - FILE *fp=fopen("user/weather.json","wb+"); + FILE *fp=fopen("/user/userdata/weather.json","wb+"); + if(fp != NULL) + { printf("jsonCheck_weather len %d",strlen((char *)buf)+1); //fwrite((void*)buf,1,strlen((char *)buf)+1,fp); fputs((char *)buf,fp); fclose(fp); - #endif + } + return parse_jsonCheck_weather(buf,check); +} + +uint8_t parse_jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 天气数据 +{ + uint8_t flag = 0; + // flag = 2; + // memcpy(check,&flag,1); + // return 0; + uint8_t *json; + json = buf; + // printf("jsonCheck_weather:len: json:%f jsonlen:%d\r\n",0.011,strlen((char *)json)); cJSON* root = cJSON_Parse((const char *)json); if (root == NULL) { printf("天气 JSON解析错误\n"); @@ -2137,6 +2146,45 @@ uint8_t jsonCheck_weather(uint8_t *buf,uint8_t *check)//json 格式解析 天气 *check = 1; return 1; } +/*读取天气历史数据*/ +uint8_t read_jsonHistory_weather(void) +{ + uint8_t *buf = NULL; + FILE *fp=fopen("/user/userdata/weather.json","rb"); + if(fp == NULL) + { + printf("read_jsonHistory_weather:fopen error\r\n"); + return 0; + } + fseek(fp, 0, SEEK_END); + long size = ftell(fp); + fseek(fp, 0, SEEK_SET); + if (size == 0) + { + fclose(fp); + return 0; + } + // printf("file size = %d\r\n",size); + buf = (uint8_t*)malloc(size + 1); + if(buf == NULL) + { + fclose(fp); + return 0; + } + char *str = fgets((char *)buf,size + 1,fp); + if(str!=NULL) + { + // printf("file str = %s\r\n",str); + } + + fclose(fp); + + uint8_t check = 0; + parse_jsonCheck_weather(buf,&check); + free(buf); + + return 1; +} uint8_t binCheck_AI(uint8_t *buf,uint8_t *check,uint16_t len)//json 格式解析 天气数据 { diff --git a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h index 08d05466d..d229fd919 100644 --- a/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h +++ b/code/sdk/application/wearable/service/ble_service/bleservice/bleEvent.h @@ -799,6 +799,8 @@ void GetCurDataCmd(uint16_t cmd,uint8_t *data,uint16_t len,uint8_t *totaldata,ui bool get_ctkd_flag(void); +uint8_t parse_jsonCheck_weather(uint8_t *buf,uint8_t *check);//json 格式解析 天气数据 +uint8_t read_jsonHistory_weather(void); ///////////////////////////自定义文件传输协议///////////////////////////// #define OTA_FILE_MSG_CMD 0x0601 #define OTA_FILE_DATA_CMD 0x0602 -- 2.17.1