From: Caisking Date: Tue, 15 Apr 2025 07:01:03 +0000 (+0800) Subject: 【每日目标】UI X-Git-Tag: leiniao_debug_1.0.0_20250922_020716~380 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=a17307fe1c59ec85a24bb6a7b7dc422d8aa639fb;p=mirrors%2FFD230.git 【每日目标】UI --- diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/Maingoalpresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/Maingoalpresenter.h new file mode 100644 index 000000000..1a4c3a806 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/Maingoalpresenter.h @@ -0,0 +1,58 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-05-10 10:58:31 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MaingoalPresenter.h + */ +#ifndef MAIN_GOAL_PRESENTER_H +#define MAIN_GOAL_PRESENTER_H + +#include "Presenter.h" +#include "View.h" +#include "Maingoalview.h" +#include "goal/include/goalmodel.h" +/*主天气视图*/ +namespace OHOS +{ + static constexpr const char *MAIN_GOAL_VIEW = "MainWeatherview"; + class GoalControlViewOnSwipeListener : public UISwipeView::OnSwipeListener + { + public: + GoalControlViewOnSwipeListener() {} + ~GoalControlViewOnSwipeListener() {} + void OnSwipe(UISwipeView &view) override; + }; + + class MaingoalrView; + class MaingoalPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener, + public UISwipeView::OnSwipeListener + { + public: + MaingoalPresenter(); + virtual ~MaingoalPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static MaingoalPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnDragEnd(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + void OnSwipe(UISwipeView &view) override; + + GoalModel *GoalModelModel{nullptr}; + bool X_DRAG_FLAG{false}; + }; +} // namespace OHOS + +#endif // MainWeather_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/Maingoalview.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/Maingoalview.h new file mode 100644 index 000000000..781a39e87 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/Maingoalview.h @@ -0,0 +1,69 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-05-10 11:22:41 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/MaingoalrView.h + */ +#ifndef MAIN_GOAL_VIEW_H +#define MAIN_GOAL_VIEW_H + + +#include "View.h" +#include "components/ui_swipe_view.h" +#include "goal/include/goalview.h" +#include "goal/include/goalother.h" +#include "goal/include/goalhint.h" + +namespace OHOS +{ + typedef enum + { + MAINGOALVIEW = 0, // 主目标视图 + GOALOTHERVIEW, // 其他目标 + GOALHINTVIEW, // 提示 + MAX_GOALVIEW, + } goalPageId; + class MaingoalPresenter; + class MaingoalrView : public View + { + + public: + MaingoalrView(); + virtual ~MaingoalrView(); + static MaingoalrView *GetInstance(void); + UISwipeView *MaingoalViewInit(void); + void ClearAll(void); + AppGroupView *GoalViewPageInit(void); + AppGroupView *OtherGoalPageInit(void); + AppGroupView *HintGoalPageInit(void); + + AppGroupView *FutureWeatherViewPageInit(void); + UIScrollView *WeatherDataErrorViewPageInit(void); + + GoalView *GetgoalView(void); + GoalotherView *GetohergoalView(void); + + UIView *GetGoalPageView(void); + UISwipeView *getSwipeView(void) + { + return goalSwipeViewList; + } + + public: + void OnStart() override; + + + private: + GoalView *goalView{nullptr}; + GoalotherView *goalotherView{nullptr}; + GoalhintView *goalhintView{nullptr}; + + private: + int16_t maxPage = MAX_GOALVIEW; + UISwipeView *goalSwipeViewList{nullptr}; // 天气滑动视图列表 + AppGroupView *recordCard[MAX_GOALVIEW]{nullptr}; + AppGroupView *CreatePage(int32_t WeatherPageId); + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalControlView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalControlView.h new file mode 100644 index 000000000..d3d34805d --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalControlView.h @@ -0,0 +1,29 @@ +#ifndef GOAL_CONTROL_VIEW_H +#define GOAL_CONTROL_VIEW_H +/*该视图主要放在主视图*/ + +#include "components/root_view.h" +#include "components/ui_card_page.h" +#include "wearable_log.h" +#include "goal/include/Maingoalview.h" +namespace OHOS +{ + class goalControlView : public UICardPage + { + public: + goalControlView(); + virtual ~goalControlView(); + bool InitView(void); + void PreLoad(void) override; + void UnLoad(void) override; + UISwipeView *GetGoalControlSwipView(void); + static goalControlView *GetInstance(void); + + private: + void ClearAll(void); + MaingoalrView *maingoalView{nullptr}; + UISwipeView::OnSwipeListener *goalOnSwipeListener{nullptr}; + bool viewiInitStatus{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalhint.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalhint.h new file mode 100644 index 000000000..47e4558bd --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalhint.h @@ -0,0 +1,49 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-13 18:34:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/GoalhintView.h + */ +#ifndef GOAL_HINT_VIEW_H +#define GOAL_HINT_VIEW_H + + +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" + +#include "wearable_log.h" +#include "AppGroupView.h" +#include + +namespace OHOS +{ + //static constexpr const char *WeatherBackground = "/user/res/weather/WEATHER_BACKGROUND.bin"; // 天气背景 + class GoalhintView : public AppGroupView + { + + public: + GoalhintView(); + virtual ~GoalhintView(); + static GoalhintView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + + private: + UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); + private: + UILabelExt *goalhintlabel{nullptr}; + bool viewInitStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalmodel.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalmodel.h new file mode 100644 index 000000000..bbe14dfa7 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalmodel.h @@ -0,0 +1,100 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-08 18:40:20 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-05-09 15:46:16 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/WeatherModel.h + */ +#ifndef GOAL_MODEL_H +#define GOAL_MODEL_H + +#include "wearable_log.h" +#include "iostream" +#include + +namespace OHOS +{ + + class GoalModel + { + public: + static GoalModel &GetInstance(void); + + bool is_goal_DISTANCE_done(); + + bool is_goal_fatburning_done(); + + bool is_goal_stand_done(); + + bool is_goal_calories_done(); + + uint8_t getstepvalue(); + + std::string getstepGoal(); + std::string getstepnew(); + + std::string getcaloriesGoal(); + std::string getcaloriespnew(); + + std::string getdistanceGoal(); + std::string getdistancenew(); + + std::string getfatburninggoal(); + std::string getfatburningnew(); + + std::string getstandgoal(); + std::string getstandnew(); + void updata(); + void GoalModelInitdata(); + uint32_t getstepgoaldata(); + uint32_t getKcalgoaldata(); + + uint8_t get_step_goal_show() + { + return step_goal_show; + } + + uint8_t get_other_goal_show() + { + return other_goal_show; + } + + uint32_t goal_parse_step_data(void); + float goal_parse_calories_data(void); + float goal_parse_distance_data(void); + uint32_t goal_parse_fat_data(void); + + uint32_t show_data_step_refresh(void); + float show_data_calories_refresh(void); + float show_data_distance_refresh(void); + uint32_t show_data_fat_refresh(void); + private: + //目标数据 + uint32_t step_goal=0; + uint32_t distanc_goal=0; + uint32_t fat_goal=0; + uint32_t calories_goal=0; + uint32_t stand_goal=0; + + //展示数据 + uint32_t show_step=0; + float show_distance=0; + uint32_t show_fat=0; + float show_calories=0; + uint32_t show_stand=0; + + uint32_t standdata_now=0; + + uint8_t step_goal_show=0; + uint8_t other_goal_show=0; + + GoalModel(); + GoalModel(const GoalModel &) = delete; + GoalModel &operator=(const GoalModel &) = delete; + virtual ~GoalModel(); + bool WEATHER_DATA_VALID{false}; // 天气数据是否有效 + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalother.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalother.h new file mode 100644 index 000000000..58f882270 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalother.h @@ -0,0 +1,87 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-13 18:34:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/GoalView.h + */ +#ifndef GOAL_OTHER_VIEW_H +#define GOAL_OTHER_VIEW_H + + +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" + +#include "wearable_log.h" +#include "AppGroupView.h" +#include + +namespace OHOS +{ + //static constexpr const char *WeatherBackground = "/user/res/weather/WEATHER_BACKGROUND.bin"; // 天气背景 + class GoalotherView : public AppGroupView + { + + public: + GoalotherView(); + virtual ~GoalotherView(); + static GoalotherView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + + void GoalViewrefresh(); + + private: + UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); + + private: + void DumpWeatherInfo(); + std::string WeatherImag; // 天气图片 + std::string Temperature; // 温度 + std::string WeatherDescription; // 天气描述 + std::string WeatherArea; // 天气地区 + std::string MaxandMinTemperature; // 最高与最低气温 + private: + + + UILabelExt *caloriegoalTitle{nullptr}; // 卡路里标题 + UILabelExt *mileagegoalTitle{nullptr}; // 里程标题 + UILabelExt *fatburninggoalTitle{nullptr}; // 燃脂标题 + UILabelExt *standgoalTitle{nullptr}; // 站立标题 + + UILabel *caloriegoaldataLabel{nullptr}; // 目标 + UILabel *calorienowdataLabel{nullptr}; // 完成 + + + UILabel *mileagegoaldataLabel{nullptr}; // 目标 + UILabel *mileagenowdataLabel{nullptr}; // 完成 + + + UILabel *fatburninggoaldataLabel{nullptr}; // 目标 + UILabel *fatburningnowdataLabel{nullptr}; // 完成 + + + UILabel *standgoaldataLabel{nullptr}; // 目标 + UILabel *standnowdataLabel{nullptr}; // 完成 + + UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 + + UIImageView *transverseline_1{nullptr}; + UIImageView *transverseline_2{nullptr}; + UIImageView *verticalline{nullptr}; + + const char **PullUpPathsArray{nullptr}; + bool viewInitStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalview.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalview.h new file mode 100644 index 000000000..adb4350b4 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/include/goalview.h @@ -0,0 +1,67 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-03-30 09:14:38 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-04-13 18:34:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/include/GoalView.h + */ +#ifndef GOAL_VIEW_H +#define GOAL_VIEW_H + + +#include "View.h" + +#include "components/root_view.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include "components/ui_circle_progress.h" +#include "common/image_cache_manager.h" + +#include "wearable_log.h" +#include "AppGroupView.h" +#include + +namespace OHOS +{ + //static constexpr const char *WeatherBackground = "/user/res/weather/WEATHER_BACKGROUND.bin"; // 天气背景 + class GoalView : public AppGroupView + { + + public: + + GoalView(); + virtual ~GoalView(); + static GoalView *GetInstance(void); + bool InitPage(void); + virtual bool InitView(void *caller) override; + void ClearAll(); + bool GetInitViewState(void); + void GoalViewrefresh(); + ImageAnimatorInfo PullUpimageAnimatorInfo[70]{0}; + + private: + UILabelExt *InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight); + + + private: + UICircleProgress * circleProgress1_{nullptr}; //步数进度条 + + UILabelExt *goalTitle{nullptr}; // 目标 + UILabelExt *goalstepLabel{nullptr}; // 目标 + UILabelExt *nowstepLabel{nullptr}; // 完成 + UIImageView* circleProgressimage{nullptr}; + UIImageAnimatorView *PullUpAnimatorView{nullptr}; // 上拉动画 + UIImageAnimatorView *stepAnimatorView{nullptr}; // 走路动画 + ImageAnimatorInfo goalAnimatorInfo[20]{0}; + const ImageInfo** goalAnimator_imageInfo{nullptr}; + const ImageInfo** PullUpimageAnimator_imageInfo{nullptr}; + // const char **PullUpPathsArray{nullptr}; + // const char **goalPathsArray{nullptr}; + bool viewInitStatus{false}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalpresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalpresenter.cpp new file mode 100644 index 000000000..67a22a8ae --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalpresenter.cpp @@ -0,0 +1,124 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "goal/include/Maingoalpresenter.h" +#include "common/key_code.h" +#include "common/key_code.h" +#include +#include +#include "UiConfig.h" +#include "gfx_utils/mem_check.h" + +#include "NativeRegisterManager.h" + +#include "ui_resource_string.h" +namespace OHOS +{ + + REGIST_MENU_PRO(VIEW_GOAL, MaingoalrView, MaingoalPresenter, + PNG_APPLIST_GOAL_IMAGE_BIG, PNG_APPLIST_GOAL_IMAGE,PNG_APPLIST_GOAL_IMAGE, "每日目标", STR_ACTIVITY); + + // 当前Presenter属性实例化的内存指针 + static MaingoalPresenter *g_pMainWeatherPresenter = nullptr; + + MaingoalPresenter::MaingoalPresenter() + { + GoalModelModel = &GoalModel::GetInstance(); + g_pMainWeatherPresenter = this; +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(true); +#endif + } + + MaingoalPresenter::~MaingoalPresenter() + { + g_pMainWeatherPresenter = nullptr; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaingoalPresenter::~MaingoalPresenter"); +#ifdef MEM_CHECK + MemCheck::GetInstance()->EnableLeakCheck(false); +#endif + } + + MaingoalPresenter *MaingoalPresenter::GetInstance() + { + + return g_pMainWeatherPresenter; + } + + void MaingoalPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void MaingoalPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MaingoalPresenter::OnResume(void) + { + Presenter::OnResume(); + } + + void MaingoalPresenter::OnStop(void) + { + Presenter::OnStop(); + } + + bool MaingoalPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + MaingoalPresenter::X_DRAG_FLAG = true; + } + return true; + } + + bool MaingoalPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MaingoalPresenter::OnDragEnd"); + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && MaingoalPresenter::X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + X_DRAG_FLAG = false; + } + return true; + } + + bool MaingoalPresenter::OnClick(UIView &view, const ClickEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " MaingoalPresenter::OnClick"); + + UNUSED(view); + UNUSED(event); + return true; + } + + // 增加按键事件 + bool MaingoalPresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16_t keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS); + } + return true; + } + + void MaingoalPresenter::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainWeatherPresenter::OnSwipe,current tab index = %d", view.GetCurrentPage()); + } + + void GoalControlViewOnSwipeListener::OnSwipe(UISwipeView &view) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalControlViewOnSwipeListener::OnSwipe,current tab index = %d", view.GetCurrentPage()); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalview.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalview.cpp new file mode 100644 index 000000000..34c34de05 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/Maingoalview.cpp @@ -0,0 +1,230 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-01-29 15:37:44 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-10-23 18:23:40 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/MaingoalrView.cpp + */ +#include "goal/include/Maingoalview.h" +#include "goal/include/Maingoalpresenter.h" +#include "goal/include/goalmodel.h" +namespace OHOS +{ + static MaingoalrView *g_pgoalView{nullptr}; + MaingoalrView::MaingoalrView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MaingoalrView::MaingoalrView"); + g_pgoalView = this; + } + + MaingoalrView::~MaingoalrView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaingoalrView::~MaingoalrView"); + ClearAll(); + g_pgoalView = nullptr; + } + + MaingoalrView *MaingoalrView::GetInstance(void) + { + return g_pgoalView; + } + + void MaingoalrView::ClearAll(void) + { + + if(goalSwipeViewList) + { + goalSwipeViewList->RemoveAll(); + + delete goalView; + goalView = nullptr; + + delete goalotherView; + goalotherView = nullptr; + + delete goalhintView; + goalhintView = nullptr; + + + delete goalSwipeViewList; + goalSwipeViewList = nullptr; + + for (int32_t i = 0; i < 3; i++) + { + recordCard[i] = nullptr; + } + } + + + } + + /* + * @brief 主天气页面视图初始化 + */ + UISwipeView *MaingoalrView::MaingoalViewInit(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaingoalrView::MaingoalViewInit"); + goalSwipeViewList = new UISwipeView(UISwipeView::VERTICAL); + if (nullptr == goalSwipeViewList) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goalSwipeViewList new fail!!"); + return nullptr; + } + + goalSwipeViewList->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); + goalSwipeViewList->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); // 0 : X; 0 : Y + goalSwipeViewList->SetAnimatorTime(50); // 50:animator drag time(ms) + goalSwipeViewList->SetViewId(MAIN_GOAL_VIEW); + goalSwipeViewList->SetDraggable(true); + goalSwipeViewList->SetTouchable(true); + for (uint16_t i = 0; i < 3; i++) + { + recordCard[i] = CreatePage(i); + if (nullptr == recordCard[i]) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "recordCard[%d] is nullptr!!", i); + return nullptr; + } + recordCard[i]->InitView(this); + goalSwipeViewList->Add(recordCard[i]); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaingoalrView InitPage over!!"); + return goalSwipeViewList; + } + + UIView *MaingoalrView::GetGoalPageView() + { + + return dynamic_cast(MaingoalViewInit()); + + } + + void MaingoalrView::OnStart() + { + + AddViewToRootContainer(GetGoalPageView()); + // RootView::GetInstance()->Add(GetGoalPageView()); + + if (goalSwipeViewList != nullptr) + { + UIView::OnClickListener *goalOnClickListener = (UIView::OnClickListener *)OHOS::MaingoalPresenter::GetInstance(); + if (goalOnClickListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goalOnClickListener new fail"); + return; + } + + UIView::OnDragListener *goalOnDragListener = (UIView::OnDragListener *)OHOS::MaingoalPresenter::GetInstance(); + if (goalOnDragListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnDragListener new fail"); + return; + } + + UISwipeView::OnSwipeListener *goalOnSwipeListener = (UISwipeView::OnSwipeListener *)OHOS::MaingoalPresenter::GetInstance(); + if (goalOnSwipeListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); + return; + } + goalSwipeViewList->SetOnClickListener(goalOnClickListener); + goalSwipeViewList->SetOnDragListener(goalOnDragListener); + goalSwipeViewList->SetOnSwipeListener(goalOnSwipeListener); + } + + /* --------------------------------- 添加按键监听 --------------------------------- */ + // RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::MaingoalPresenter::GetInstance(); + // RootView::GetInstance()->SetOnKeyActListener(keyactListener); + /* -------------------------------------------------------------------------- */ + } + + + + + GoalView *MaingoalrView::GetgoalView(void) + { + return goalView; + } + + GoalotherView *MaingoalrView::GetohergoalView(void) + { + return goalotherView; + } + + /* + * @brief 天气页面视图初始化 + */ + AppGroupView *MaingoalrView::GoalViewPageInit(void) + { + goalView = new GoalView(); + if (goalView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaingoalrView::new goalView fail!"); + return nullptr; + } + return goalView; + } + + AppGroupView *MaingoalrView::OtherGoalPageInit(void) + { + goalotherView = new GoalotherView(); + if (goalotherView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaingoalrView::new goalView fail!"); + return nullptr; + } + + return goalotherView; + } + + AppGroupView *MaingoalrView::HintGoalPageInit(void) + { + goalhintView = new GoalhintView(); + if (goalhintView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MaingoalrView::new goalView fail!"); + return nullptr; + } + return goalhintView; + } + + + /* + * @brief 气象报告视图初始化 + */ + + struct MainWeatherViewMapper + { + const int16_t viewId; + AppGroupView *(MaingoalrView::*func)(void); + }; + + // 2.ViewMapper[] 是一个静态的视图映射数组,将视图ID与DisplayBrightnessViewMapper类中的特定成员函数指针进行了绑定。 + static const MainWeatherViewMapper g_pageMapper[] = { + {MAINGOALVIEW, &MaingoalrView::GoalViewPageInit}, + {GOALOTHERVIEW, &MaingoalrView::OtherGoalPageInit}, + {GOALHINTVIEW, &MaingoalrView::HintGoalPageInit}, + }; + + /* + * @brief 根据提供的 WeatherPageId 查找对应的页面ID,然后根据这个页面ID来创建对应的页面视图 + */ + AppGroupView *MaingoalrView::CreatePage(int32_t WeatherPageId) + { + uint16_t i; + AppGroupView *view = nullptr; + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CreatePage WeatherPageId:%d", WeatherPageId); + + for (i = 0; i < 3;i++) + //sizeof(g_pageMapper) / sizeof(g_pageMapper[0]); i++) + { + if (g_pageMapper[i].viewId == WeatherPageId) + { // 正确使用 WeatherPageId 来匹配视图ID + view = (this->*(g_pageMapper[i].func))(); // 如果找到匹配项,则调用相应的函数创建视图 + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CreatePage view:%p", view); + return view; // 返回创建的视图 + } + } + return nullptr; // 如果没有找到匹配的视图ID,返回 nullptr + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalControlView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalControlView.cpp new file mode 100644 index 000000000..561250473 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalControlView.cpp @@ -0,0 +1,100 @@ +#include "goal/include/goalControlView.h" +#include "goal/include/Maingoalpresenter.h" +namespace OHOS +{ + static goalControlView *g_pgoalControlView{nullptr}; + + goalControlView::goalControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::WeatherControlView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pgoalControlView = this; + } + + goalControlView::~goalControlView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherControlView::~WeatherControlView"); + ClearAll(); + g_pgoalControlView = nullptr; + } + + goalControlView *goalControlView::GetInstance(void) + { + return g_pgoalControlView; + } + + + void goalControlView::ClearAll(void) + { + if (viewiInitStatus == true) + { + RemoveAll(); + if (maingoalView != nullptr) + { + if (goalOnSwipeListener != nullptr) + { + delete goalOnSwipeListener; + goalOnSwipeListener = nullptr; + } + + if (maingoalView != nullptr) + { + delete maingoalView; + maingoalView = nullptr; + } + } + } + } + + bool goalControlView::InitView(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goalControlView::InitView"); + maingoalView = new MaingoalrView(); + if (maingoalView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WeatherView::new mainweatherView fail!"); + return false; + } + + + UISwipeView *goalSwipView = dynamic_cast(maingoalView->GetGoalPageView()); + if (goalSwipView == nullptr) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "mainWeatherView->MainWeatherViewInit() == nullptr!!"); + return false; + } + + goalOnSwipeListener = static_cast(new GoalControlViewOnSwipeListener()); + if (goalOnSwipeListener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "weatherOnSwipeListener new fail"); + return false; + } + goalSwipView->SetOnSwipeListener(goalOnSwipeListener); + Add(goalSwipView); + + return true; + } + + void goalControlView::PreLoad(void) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goalControlView::PreLoad"); + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + + void goalControlView::UnLoad(void) + { + // Weather's usage scenes is complicated, so we do not release it's resources inner slice. + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "goalControlView::UnLoad"); + } + + UISwipeView *goalControlView::GetGoalControlSwipView(void) + { + return maingoalView->getSwipeView(); + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalhint.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalhint.cpp new file mode 100644 index 000000000..90be1d960 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalhint.cpp @@ -0,0 +1,108 @@ +#include "goal/include/goalhint.h" +#include "ConfigModel.h" +#include "goal/include/goalmodel.h" +#include "common/image_cache_manager.h" +#include "ui_resource_string.h" +/* +当至天气界面时,主动获取最新天气数据。 +(此操作静默将进行,获取到则立刻更新显示,获取不到则重试 +重试3次无果结束更新) +在加载该视图时,需要加载:1时间,2天气图片,3温度,4天气描述,5,地点,6,温度范围 +*/ + +namespace OHOS +{ + + static GoalhintView *g_pgoalView{nullptr}; + GoalhintView::GoalhintView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalhintView::GoalhintView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pgoalView = this; + } + + GoalhintView::~GoalhintView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " GoalhintView::~GoalhintView"); + ClearAll(); + g_pgoalView = nullptr; + } + + + void GoalhintView::ClearAll() + { + RemoveAll(); + if (goalhintlabel != nullptr) + { + delete goalhintlabel; + goalhintlabel = nullptr; + } + + } + + GoalhintView *GoalhintView::GetInstance() + { + return g_pgoalView; + } + + // 初始化标签 + UILabelExt *GoalhintView::InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(x, y, w, h); + label->SetStyle(STYLE_TEXT_FONT, textfont); + label->SetStyle(STYLE_LINE_HEIGHT, lineheight); + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, textfont); + return label; + } + + // 初始化天气页面 + bool GoalhintView::InitPage(void) + { + if (goalhintlabel == nullptr) { + goalhintlabel = new UILabelExt(); + } + goalhintlabel->SetPosition(98, 198); // widget's left position and top position + goalhintlabel->Resize(270, 70); // widget's width and height + goalhintlabel->SetViewId("label13");// Set style + goalhintlabel->SetStyle(STYLE_TEXT_FONT, 30); + + // Set additional property + // goalhintlabel->SetText("目标设置及更多数据请前往手机APP查看"); + goalhintlabel->SetTextId(STR_GOAL_HINT); + goalhintlabel->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + goalhintlabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + goalhintlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + goalhintlabel->SetRollSpeed(0); + goalhintlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + // Add to rootView + Add(goalhintlabel); + goalhintlabel->SetVisible(true); + + return true; + } + + bool GoalhintView::InitView(void *caller) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalhintView InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalhintView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + return true; + } + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalmodel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalmodel.cpp new file mode 100644 index 000000000..da1e857ae --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalmodel.cpp @@ -0,0 +1,579 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-04-08 18:40:09 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-12-04 16:28:23 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/weather/src/GoalModel.cpp + */ +#include "goal/include/goalmodel.h" +#include "goal/include/Maingoalview.h" + +#include "ActivityModel.h" +#include "ConfigModel.h" +// #include "cywee_hal.h" +// #include "goal_notification.h" +#include "custom_utils.h" +// #include "cywee_ble_Service.h" +// #include "goalmodel.h" +namespace OHOS +{ + + GoalModel::GoalModel() + { + // GoalModelInitdata(); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GoalModel::GoalModel"); + } + + + + void GoalModel::GoalModelInitdata() + { + // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES_TIME),OHOS::GOAL_CALOREIE); + // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES_TIME),OHOS::GOAL_STAND); + // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION_TIME),OHOS::GOAL_FAT); + // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE_TIME),OHOS::GOAL_DISTANCE); + // OHOS::set_Is_show_flag(ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT_TIME),OHOS::GOAL_STEP); + + // step_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEP); + // other_goal_show=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_OTHER); + + // step_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STEPCOUNT); + // distanc_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DISTANCE); + // fat_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_DURATION); + // calories_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_CALORIES); + // stand_goal=ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_SPORTS_GOAL_STANDUP_TIMES); + + // standdata_now=get_now_stand_count(); + + // show_step=goal_parse_step_data(); + // show_calories=goal_parse_calories_data(); + // show_distance=goal_parse_distance_data(); + // show_fat=goal_parse_fat_data(); + + } + + + GoalModel::~GoalModel() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GoalModel::~GoalModel"); + } + uint8_t GoalModel::getstepvalue() + { + int stepgoal = step_goal; + int stepdata = show_data_step_refresh();//get_step_data();//OHOS::ActivityModel::GetInstance()->GetStepCounter(); + // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d %d %f ",stepdata,stepgoal,((float)stepdata/(float)stepgoal) * 100); + uint8_t value = ((float)stepdata / (float)stepgoal) * 100; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d", value); + if (value > 100) + { + value = 100; + } + return value; + } + uint32_t GoalModel::getstepgoaldata() + { + return step_goal; + } + + uint32_t GoalModel::getKcalgoaldata() + { + return calories_goal; + } + + std::string GoalModel::getstepGoal() + { + // int stepgoal = step; + // memset((void *)stepgoalstr, 0, 20); + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "/%d", step_goal); + std::string stepgoalstr; + stepgoalstr= temp_str; + return stepgoalstr; + } + + + std::string GoalModel::getstepnew() + { + + int stepdata = show_data_step_refresh(); + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "%d", stepdata); + + std::string stepnewstr=temp_str; + + return stepnewstr; + } + + + std::string GoalModel::getcaloriesGoal() + { + std::string caloriesgoalstr; + + int caloriesdata =calories_goal; + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "/%d", caloriesdata); + caloriesgoalstr=temp_str; + + return caloriesgoalstr; + } + + + std::string GoalModel::getcaloriespnew() + { + std::string caloriesnewstr; + + int caloriesdata = show_data_calories_refresh(); + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "%d", caloriesdata); + + caloriesnewstr=temp_str; + + return caloriesnewstr; + } + + std::string GoalModel::getdistanceGoal() + { + std::string distancegoalstr; + + int distancedata = distanc_goal; + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "/%d", distancedata); + + distancegoalstr=temp_str; + + return distancegoalstr; + } + + + std::string GoalModel::getdistancenew() + { + std::string distancenewstr; + + float distancedata = show_data_distance_refresh(); + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "%0.1f", distancedata); + + distancenewstr=temp_str; + + return distancenewstr; + } + + + std::string GoalModel::getfatburninggoal() + { + std::string fatburninggoalstr; + + int fatburningdata = fat_goal; + + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "/%d", fatburningdata); + fatburninggoalstr=temp_str; + + return fatburninggoalstr; + } + + std::string GoalModel::getfatburningnew() + { + + std::string fatburningnewstr; + + int fatburningdata = show_data_fat_refresh();; + + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "%d", fatburningdata); + fatburningnewstr=temp_str; + + return fatburningnewstr; + } + + + std::string GoalModel::getstandgoal() + { + std::string standstr; + + int standdata =stand_goal; + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "/%d", standdata); + standstr=temp_str; + + return standstr; + } + + + std::string GoalModel::getstandnew() + { + std::string standnewstr; + + int standdata = standdata_now; + char temp_str[20]={0}; + sprintf_s(temp_str, 20, "%d", standdata); + standnewstr=temp_str; + + return standnewstr; + } + + + + bool GoalModel::is_goal_DISTANCE_done() + { + float distancedata_now = show_data_distance_refresh(); + int distancedata_goal = distanc_goal; + + if(distancedata_now>=distancedata_goal) + return true; + else + return false; + + } + + bool GoalModel::is_goal_fatburning_done() + { + int fatburningdata_now =show_data_fat_refresh(); + + int fatburningdata_goal = fat_goal; + + if(fatburningdata_now>=fatburningdata_goal) + return true; + else + return false; + + } + + bool GoalModel::is_goal_stand_done() + { + int standdata_now_ = standdata_now; + + int standdata_goal = stand_goal; + + if(standdata_now_>=standdata_goal) + return true; + else + return false; + + } + + bool GoalModel::is_goal_calories_done() + { + int calories_now = show_data_calories_refresh(); + + int caloriesdata_goal = calories_goal; + + if(calories_now>=caloriesdata_goal) + return true; + else + return false; + + } + + + + GoalModel &GoalModel::GetInstance() + { + static GoalModel instance; + return instance; + } + + void GoalModel::updata(void) + { + GoalModel::GetInstance().GoalModelInitdata(); + + if(OHOS::GoalView::GetInstance()) + { + OHOS::GoalView::GetInstance()->GoalViewrefresh(); + } + if(OHOS::GoalotherView::GetInstance()) + { + OHOS::GoalotherView::GetInstance()->GoalViewrefresh(); + } + } + + uint32_t GoalModel::goal_parse_step_data(void) + { + // char path_[64]={0}; + // char timeday[12] = {0}; + // uapi_get_YYMMDD_Time_extend(timeday, '_',0); + // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_PATH,timeday); + // FILE * fp = fopen(path_,"rb+"); + // uint32_t size=0; + // uint32_t toal_data=0; + + // time_t currtime; + // struct tm *timeinfo_now; + // time(&currtime); + // timeinfo_now = localtime(&currtime); + + // uint8_t mon_now=timeinfo_now->tm_mon; + // uint8_t day_now=timeinfo_now->tm_mday; + + // if (fp != NULL) + // { + // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + // size = ftell(fp); // 获取当前文件指针位置,即文件大小 + // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + // } + // else + // { + // return 0; + // } + // uint8_t *date=(uint8_t *)malloc(size); + // if(date==NULL) return 0; + + // fread(date,sizeof(uint8_t),size,fp); + // fclose(fp); + // int32_t sing_date=0; + // int32_t timetemp=0; + + // for(int i=0;i0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) + // toal_data+=sing_date; + // } + // free(date); + // return toal_data; + return 0; + } + + float GoalModel::goal_parse_calories_data(void) + { + // char path_[64]={0}; + // char timeday[12] = {0}; + // uapi_get_YYMMDD_Time_extend(timeday, '_',0); + // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_CALORIES_PATH,timeday); + // FILE * fp = fopen(path_,"rb+"); + // uint32_t size=0; + // float toal_data=0; + + // time_t currtime; + // struct tm *timeinfo_now; + // time(&currtime); + // timeinfo_now = localtime(&currtime); + + // uint8_t mon_now=timeinfo_now->tm_mon; + // uint8_t day_now=timeinfo_now->tm_mday; + + // if (fp != NULL) + // { + // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + // size = ftell(fp); // 获取当前文件指针位置,即文件大小 + // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + // } + // else + // { + // return 0; + // } + // uint8_t *date=(uint8_t *)malloc(size); + // if(date==NULL) return 0; + + // fread(date,sizeof(uint8_t),size,fp); + // fclose(fp); + // float sing_date=0; + // int32_t timetemp=0; + + // for(int i=0;i0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) + // toal_data+=sing_date; + // } + // free(date); + // return toal_data; + return 0; + } + + float GoalModel::goal_parse_distance_data(void) + { + // char path_[64]={0}; + // char timeday[12] = {0}; + // uapi_get_YYMMDD_Time_extend(timeday, '_',0); + // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_DISTANCE_PATH,timeday); + // FILE * fp = fopen(path_,"rb+"); + // uint32_t size=0; + // float toal_data=0; + + // time_t currtime; + // struct tm *timeinfo_now; + // time(&currtime); + // timeinfo_now = localtime(&currtime); + + // uint8_t mon_now=timeinfo_now->tm_mon; + // uint8_t day_now=timeinfo_now->tm_mday; + + // if (fp != NULL) + // { + // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + // size = ftell(fp); // 获取当前文件指针位置,即文件大小 + // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + // } + // else + // { + // return 0; + // } + // uint8_t *date=(uint8_t *)malloc(size); + // if(date==NULL) return 0; + + // fread(date,sizeof(uint8_t),size,fp); + // fclose(fp); + // float sing_date=0; + // int32_t timetemp=0; + + // for(int i=0;i0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) + // toal_data+=sing_date; + // } + // free(date); + // return toal_data; + return 0; + } + + + uint32_t GoalModel::goal_parse_fat_data(void) + { + // char path_[64]={0}; + // char timeday[12] = {0}; + // uapi_get_YYMMDD_Time_extend(timeday, '_',0); + // sprintf_s(path_,64,"%s%s.bin",CWM_HISTORY_DATA_FAT_PATH,timeday); + // FILE * fp = fopen(path_,"rb+"); + // uint32_t size=0; + // float toal_data=0; + + // time_t currtime; + // struct tm *timeinfo_now; + // time(&currtime); + // timeinfo_now = localtime(&currtime); + + // uint8_t mon_now=timeinfo_now->tm_mon; + // uint8_t day_now=timeinfo_now->tm_mday; + + + // if (fp != NULL) + // { + // fseek(fp, 0, SEEK_END); // 将文件指针移动到文件末尾 + // size = ftell(fp); // 获取当前文件指针位置,即文件大小 + // fseek(fp, 0, SEEK_SET); // 将文件指针移回文件开头 + // } + // else + // { + // return 0; + // } + // uint8_t *date=(uint8_t *)malloc(size); + // if(date==NULL) return 0; + + // fread(date,sizeof(uint8_t),size,fp); + // fclose(fp); + // uint16 sing_date=0; + // int32_t timetemp=0; + + // for(int i=0;i0 && timeinfo->tm_mday==day_now && timeinfo->tm_mon==mon_now) + // toal_data+=sing_date; + // } + // free(date); + // return toal_data; + return 0; + } + + + + + uint32_t GoalModel::show_data_step_refresh(void) + { + // int32_t value=0; + // uint32_t toal_date; + + // toal_date=show_step; + // get_now_hour_data(&value,CYWEE_SAVE_DATA_STEP); + // if(value>0) + // toal_date+=value; + // return toal_date; + return 0; + } + + float GoalModel::show_data_calories_refresh(void) + { + + // float _f_value=0; + // float toal_date; + // toal_date=show_calories; + // get_now_hour_data(&_f_value,CYWEE_SAVE_DATA_CALORIES); + // if(_f_value>0) + // toal_date+=_f_value; + + // return toal_date; + return 0; + } + + float GoalModel::show_data_distance_refresh(void) + { + + // float _f_value=0; + // float toal_date; + // toal_date=show_distance; + // get_now_hour_data(&_f_value,CYWEE_SAVE_DATA_DISTANCE); + // if(_f_value>0) + // toal_date+=_f_value; + + // return toal_date; + + return 0; + } + + uint32_t GoalModel::show_data_fat_refresh(void) + { + + // uint16_t _16_value=0; + // uint32_t toal_date; + // toal_date=show_fat; + // get_now_hour_data(&_16_value,CYWEE_SAVE_DATA_FAT); + // if(_16_value>0) + // toal_date+=_16_value; + + // return toal_date; + + return 0; + } + + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalother.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalother.cpp new file mode 100644 index 000000000..51cae63b6 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalother.cpp @@ -0,0 +1,509 @@ +#include "goal/include/goalother.h" +#include "ConfigModel.h" +#include "goal/include/goalmodel.h" +#include "common/image_cache_manager.h" +#include "goal/include/goalview.h" +#include "uicomponents/UIComponents.h" +/* +当至天气界面时,主动获取最新天气数据。 +(此操作静默将进行,获取到则立刻更新显示,获取不到则重试 +重试3次无果结束更新) +在加载该视图时,需要加载:1时间,2天气图片,3温度,4天气描述,5,地点,6,温度范围 +*/ + +namespace OHOS +{ + + + static constexpr int16_t PULLUP_ANIMATOR_VIEW_X = 213; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_Y = 430; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_W = 40; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_H = 40; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_NUM_FRAMES = 70; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_TIME = 100; + //static ImageAnimatorInfo PullUpimageAnimatorInfo[PULLUP_ANIMATOR_VIEW_NUM_FRAMES]; + + static ImageAnimatorInfo goalAnimatorInfo[20]; + static constexpr const char *PullUpPaths = "/user/res/weather/PullUp/PullUp_"; + + + static GoalotherView *g_pgoalView{nullptr}; + GoalotherView::GoalotherView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalotherView::GoalotherView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pgoalView = this; + } + + GoalotherView::~GoalotherView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " GoalotherView::~GoalotherView"); + ClearAll(); + g_pgoalView = nullptr; + } + + void GoalotherView::GoalViewrefresh() + { + if(mileagenowdataLabel) + mileagenowdataLabel->SetText(GoalModel::GetInstance().getdistancenew().c_str()); + if(mileagegoaldataLabel) + mileagegoaldataLabel->SetText(GoalModel::GetInstance().getdistanceGoal().c_str()); + if(fatburningnowdataLabel) + fatburningnowdataLabel->SetText(GoalModel::GetInstance().getfatburningnew().c_str()); + if(fatburninggoaldataLabel) + fatburninggoaldataLabel->SetText(GoalModel::GetInstance().getfatburninggoal().c_str()); + if(standnowdataLabel) + standnowdataLabel->SetText(GoalModel::GetInstance().getstandnew().c_str()); + if(standgoaldataLabel) + standgoaldataLabel->SetText(GoalModel::GetInstance().getstandgoal().c_str()); + if(calorienowdataLabel) + calorienowdataLabel->SetText(GoalModel::GetInstance().getcaloriespnew().c_str()); + if(caloriegoaldataLabel) + caloriegoaldataLabel->SetText(GoalModel::GetInstance().getcaloriesGoal().c_str()); + + Invalidate(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalViewrefresh Invalidat "); + // RootView::GetInstance()->Invalidate(); + + + } + + void GoalotherView::ClearAll() + { + RemoveAll(); + if (caloriegoalTitle != nullptr) + { + delete caloriegoalTitle; + caloriegoalTitle = nullptr; + } + if (mileagegoalTitle != nullptr) + { + delete mileagegoalTitle; + mileagegoalTitle = nullptr; + } + if (fatburninggoalTitle != nullptr) + { + delete fatburninggoalTitle; + fatburninggoalTitle = nullptr; + } + if (standgoalTitle != nullptr) + { + delete standgoalTitle; + standgoalTitle = nullptr; + } + + if (caloriegoaldataLabel != nullptr) + { + delete caloriegoaldataLabel; + caloriegoaldataLabel = nullptr; + } + if (calorienowdataLabel != nullptr) + { + delete calorienowdataLabel; + calorienowdataLabel = nullptr; + } + + if (mileagegoaldataLabel != nullptr) + { + delete mileagegoaldataLabel; + mileagegoaldataLabel = nullptr; + } + if (mileagenowdataLabel != nullptr) + { + delete mileagenowdataLabel; + mileagenowdataLabel = nullptr; + } + + if (fatburninggoaldataLabel != nullptr) + { + delete fatburninggoaldataLabel; + fatburninggoaldataLabel = nullptr; + } + if (fatburningnowdataLabel != nullptr) + { + delete fatburningnowdataLabel; + fatburningnowdataLabel = nullptr; + } + + if (standgoaldataLabel != nullptr) + { + delete standgoaldataLabel; + standgoaldataLabel = nullptr; + } + if (standnowdataLabel != nullptr) + { + delete standnowdataLabel; + standnowdataLabel = nullptr; + } + + if (transverseline_1 != nullptr) + { + delete transverseline_1; + transverseline_1 = nullptr; + } + if (transverseline_2 != nullptr) + { + delete transverseline_2; + transverseline_2 = nullptr; + } + if (verticalline != nullptr) + { + delete verticalline; + verticalline = nullptr; + } + + if (PullUpAnimatorView != nullptr) + { + PullUpAnimatorView->Stop(); + delete PullUpAnimatorView; + PullUpAnimatorView = nullptr; + } + //FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + + } + + GoalotherView *GoalotherView::GetInstance() + { + return g_pgoalView; + } + + // 初始化标签 + UILabelExt *GoalotherView::InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(x, y, w, h); + label->SetStyle(STYLE_TEXT_FONT, textfont); + label->SetStyle(STYLE_LINE_HEIGHT, lineheight); + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, textfont); + return label; + } + + // 初始化天气页面 + bool GoalotherView::InitPage(void) + { + /////////////////////////////////线//////////////////////////////////////////////// + if (transverseline_1 == nullptr) { + transverseline_1 = new UIImageView(); + } + transverseline_1->SetPosition(0, 169); // widget's left position and top position + transverseline_1->Resize(466, 2); // widget's width and height + transverseline_1->SetViewId("image1");// Set style + transverseline_1->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + transverseline_1->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + transverseline_1->SetVisible(true); + + // Add ImageView to App + if (transverseline_2 == nullptr) { + transverseline_2 = new UIImageView(); + } + transverseline_2->SetPosition(232, 191); // widget's left position and top position + transverseline_2->Resize(2, 82); // widget's width and height + transverseline_2->SetViewId("image2");// Set style + transverseline_2->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + transverseline_2->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + transverseline_2->SetVisible(true); + + // Add ImageView to App + if (verticalline == nullptr) { + verticalline = new UIImageView(); + } + verticalline->SetPosition(0, 296); // widget's left position and top position + verticalline->Resize(466, 2); // widget's width and height + verticalline->SetViewId("image1");// Set style + verticalline->SetStyle(STYLE_BACKGROUND_COLOR, 0xff333333); + verticalline->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + verticalline->SetVisible(true); + + + /////////////////////////////////标题///////////////////////////////////////// + if (mileagegoalTitle == nullptr) { + mileagegoalTitle = new UILabelExt(); + } + mileagegoalTitle->SetPosition(113, 61); // widget's left position and top position + mileagegoalTitle->Resize(240, 35); // widget's width and height + mileagegoalTitle->SetViewId("label1");// Set style + mileagegoalTitle->SetStyle(STYLE_TEXT_FONT, 30); + + // Set additional property + // mileagegoalTitle->SetText("里程(KM)"); + mileagegoalTitle->SetTextId(STR_MILEAGE); + mileagegoalTitle->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + mileagegoalTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + mileagegoalTitle->SetRollSpeed(0); + mileagegoalTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + mileagegoalTitle->SetVisible(true); + + if (fatburninggoalTitle == nullptr) { + fatburninggoalTitle = new UILabelExt(); + } + fatburninggoalTitle->SetPosition(8, 188); // widget's left position and top position + fatburninggoalTitle->Resize(200, 35); // widget's width and height + fatburninggoalTitle->SetViewId("label1");// Set style + fatburninggoalTitle->SetStyle(STYLE_TEXT_FONT, 30); + + // Set additional property + // fatburninggoalTitle->SetText("燃脂时间"); + fatburninggoalTitle->SetTextId(STR_FAT_BURNING_TIME); + fatburninggoalTitle->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + fatburninggoalTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + fatburninggoalTitle->SetRollSpeed(0); + fatburninggoalTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + fatburninggoalTitle->SetVisible(true); + + if (standgoalTitle == nullptr) { + standgoalTitle = new UILabelExt(); + } + standgoalTitle->SetPosition(257, 188); // widget's left position and top position + standgoalTitle->Resize(200, 35); // widget's width and height + standgoalTitle->SetViewId("label1");// Set style + standgoalTitle->SetStyle(STYLE_TEXT_FONT, 30); + // Set additional property + // standgoalTitle->SetText("站立次数"); + standgoalTitle->SetTextId(STR_NUMBER_OF_STANDS); + standgoalTitle->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + standgoalTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + standgoalTitle->SetRollSpeed(0); + standgoalTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + standgoalTitle->SetVisible(true); + + if (caloriegoalTitle == nullptr) { + caloriegoalTitle = new UILabelExt(); + } + caloriegoalTitle->SetPosition(53, 317); // widget's left position and top position + caloriegoalTitle->Resize(360, 35); // widget's width and height + caloriegoalTitle->SetViewId("label1");// Set style + caloriegoalTitle->SetStyle(STYLE_TEXT_FONT, 30); + // Set additional property + // caloriegoalTitle->SetText("消耗卡路里"); + caloriegoalTitle->SetTextId(STR_CONSUME_CALORIES); + caloriegoalTitle->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + caloriegoalTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + caloriegoalTitle->SetRollSpeed(0); + caloriegoalTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + caloriegoalTitle->SetVisible(true); + + ////////////////////////里程/////////////////////////// + if (mileagenowdataLabel == nullptr) { + mileagenowdataLabel = new UILabel(); + } + mileagenowdataLabel->SetPosition(163-20+10, 87); // widget's left position and top position + mileagenowdataLabel->Resize(75, 60); // widget's width and height + mileagenowdataLabel->SetViewId("label2");// Set style + mileagenowdataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + mileagenowdataLabel->SetText(GoalModel::GetInstance().getdistancenew().c_str()); + mileagenowdataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + mileagenowdataLabel->SetTextColor(Color::GetColorFromRGBA(0x4F, 0xC3, 0x4C, 0xff)); + mileagenowdataLabel->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + mileagenowdataLabel->SetRollSpeed(0); + mileagenowdataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + mileagenowdataLabel->SetVisible(true); + + // Add Label to App + if (mileagegoaldataLabel == nullptr) { + mileagegoaldataLabel = new UILabel(); + } + mileagegoaldataLabel->SetPosition(243-20+10, 86); // widget's left position and top position + mileagegoaldataLabel->Resize(82, 60); // widget's width and height + mileagegoaldataLabel->SetViewId("label2");// Set style + mileagegoaldataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + mileagegoaldataLabel->SetText(GoalModel::GetInstance().getdistanceGoal().c_str()); + mileagegoaldataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + mileagegoaldataLabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + mileagegoaldataLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + mileagegoaldataLabel->SetRollSpeed(0); + mileagegoaldataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + mileagegoaldataLabel->SetVisible(true); + + ///////////////////////燃脂/////////////////////////// + if (fatburningnowdataLabel == nullptr) { + fatburningnowdataLabel = new UILabel(); + } + fatburningnowdataLabel->SetPosition(47-20-10, 223); // widget's left position and top position + fatburningnowdataLabel->Resize(75, 60); // widget's width and height + fatburningnowdataLabel->SetViewId("label2");// Set style + fatburningnowdataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + fatburningnowdataLabel->SetText(GoalModel::GetInstance().getfatburningnew().c_str()); + fatburningnowdataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + fatburningnowdataLabel->SetTextColor(Color::GetColorFromRGBA(0x4F, 0xC3, 0x4C, 0xff)); + fatburningnowdataLabel->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + fatburningnowdataLabel->SetRollSpeed(0); + fatburningnowdataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + fatburningnowdataLabel->SetVisible(true); + // Add Label to App + if (fatburninggoaldataLabel == nullptr) { + fatburninggoaldataLabel = new UILabel(); + } + fatburninggoaldataLabel->SetPosition(128-20-10, 223); // widget's left position and top position + fatburninggoaldataLabel->Resize(82, 60); // widget's width and height + fatburninggoaldataLabel->SetViewId("label2");// Set style + fatburninggoaldataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + fatburninggoaldataLabel->SetText(GoalModel::GetInstance().getfatburninggoal().c_str()); + fatburninggoaldataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + fatburninggoaldataLabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + fatburninggoaldataLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + fatburninggoaldataLabel->SetRollSpeed(0); + fatburninggoaldataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + fatburninggoaldataLabel->SetVisible(true); + ///////////////////////站立/////////////////////////// + if (standnowdataLabel == nullptr) { + standnowdataLabel = new UILabel(); + } + standnowdataLabel->SetPosition(47+200+10, 223); // widget's left position and top position + standnowdataLabel->Resize(75, 60); // widget's width and height + standnowdataLabel->SetViewId("label2");// Set style + standnowdataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + + standnowdataLabel->SetText(GoalModel::GetInstance().getstandnew().c_str()); + standnowdataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + standnowdataLabel->SetTextColor(Color::GetColorFromRGBA(0x4F, 0xC3, 0x4C, 0xff)); + standnowdataLabel->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + standnowdataLabel->SetRollSpeed(0); + standnowdataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + standnowdataLabel->SetVisible(true); + + if (standgoaldataLabel == nullptr) { + standgoaldataLabel = new UILabel(); + } + standgoaldataLabel->SetPosition(128+200+10, 223); // widget's left position and top position + standgoaldataLabel->Resize(82, 60); // widget's width and height + standgoaldataLabel->SetViewId("label2");// Set style + standgoaldataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + standgoaldataLabel->SetText(GoalModel::GetInstance().getstandgoal().c_str()); + standgoaldataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + standgoaldataLabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + standgoaldataLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + standgoaldataLabel->SetRollSpeed(0); + standgoaldataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + + ///////////////////////卡路里/////////////////////////// + if (calorienowdataLabel == nullptr) { + calorienowdataLabel = new UILabel(); + } + calorienowdataLabel->SetPosition(163-20-10, 353); // widget's left position and top position + calorienowdataLabel->Resize(75, 60); // widget's width and height + calorienowdataLabel->SetViewId("label2");// Set style + calorienowdataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + calorienowdataLabel->SetText(GoalModel::GetInstance().getcaloriespnew().c_str()); + calorienowdataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + calorienowdataLabel->SetTextColor(Color::GetColorFromRGBA(0x4F, 0xC3, 0x4C, 0xff)); + calorienowdataLabel->SetAlign(TEXT_ALIGNMENT_RIGHT, TEXT_ALIGNMENT_CENTER); + calorienowdataLabel->SetRollSpeed(0); + calorienowdataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + calorienowdataLabel->SetVisible(true); + + if (caloriegoaldataLabel == nullptr) { + caloriegoaldataLabel = new UILabel(); + } + caloriegoaldataLabel->SetPosition(243-20-10, 353); // widget's left position and top position + caloriegoaldataLabel->Resize(82+40, 60); // widget's width and height + caloriegoaldataLabel->SetViewId("label2");// Set style + caloriegoaldataLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + caloriegoaldataLabel->SetText(GoalModel::GetInstance().getcaloriesGoal().c_str()); + + caloriegoaldataLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + caloriegoaldataLabel->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + caloriegoaldataLabel->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); + caloriegoaldataLabel->SetRollSpeed(0); + caloriegoaldataLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + caloriegoaldataLabel->SetVisible(true); + + if (PullUpAnimatorView == nullptr) + { + PullUpAnimatorView = new UIImageAnimatorView(); + if (PullUpAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpAnimatorView new fail"); + return false; + } + if(GoalView::GetInstance()) + { + // PullUpPathsArray = CreateImagePathsArray(PullUpPaths, "bin", PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + for (uint8_t i = 0; i < PULLUP_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + GoalView::GetInstance()->PullUpimageAnimatorInfo[i].pos.y = PULLUP_ANIMATOR_VIEW_Y; + } + // PullUpAnimatorView->SetPosition(PULLUP_ANIMATOR_VIEW_X, PULLUP_ANIMATOR_VIEW_Y, PULLUP_ANIMATOR_VIEW_W, PULLUP_ANIMATOR_VIEW_H); + // PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + // PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + PullUpAnimatorView->SetImageAnimatorSrc(GoalView::GetInstance()->PullUpimageAnimatorInfo, PULLUP_ANIMATOR_VIEW_NUM_FRAMES, PULLUP_ANIMATOR_VIEW_TIME); + PullUpAnimatorView->SetRepeat(true); + PullUpAnimatorView->Start(); + Add(PullUpAnimatorView); + } + } + + + + + /* -------------------------------- 将组件添加到根视图 ------------------------------- */ + Add(caloriegoalTitle); + Add(mileagegoalTitle); + Add(fatburninggoalTitle); + Add(standgoalTitle); + + Add(caloriegoaldataLabel); + Add(calorienowdataLabel); + + Add(mileagegoaldataLabel); + Add(mileagenowdataLabel); + + Add(fatburninggoaldataLabel); + Add(fatburningnowdataLabel); + + Add(standgoaldataLabel); + Add(standnowdataLabel); + + + + Add(transverseline_1); + Add(transverseline_2); + Add(verticalline); + return true; + } + + bool GoalotherView::InitView(void *caller) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalotherView InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalotherView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + return true; + } + + // 获取视图初始化状态 + bool GoalotherView::GetInitViewState(void) + { + return viewInitStatus; + } + + +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalview.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalview.cpp new file mode 100644 index 000000000..2b5d66409 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/goal/src/goalview.cpp @@ -0,0 +1,368 @@ +#include "goal/include/goalview.h" +#include "ConfigModel.h" +#include "goal/include/goalmodel.h" +#include "common/image_cache_manager.h" +#include "gfx_utils/mem_api.h" +#include "uicomponents/UIComponents.h" + + +// #include "goal_notification.h" + +namespace OHOS +{ + + + static constexpr int16_t PULLUP_ANIMATOR_VIEW_X = 213; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_Y = 380; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_W = 40; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_H = 40; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_NUM_FRAMES = 70; + static constexpr int16_t PULLUP_ANIMATOR_VIEW_TIME = 100; + + + static constexpr const char *PullUpPaths = "/user/res/weather/PullUp/PullUp_"; + + static constexpr const char *stepPaths = "/user/res/step/"; + + static GoalView *g_pgoalView{nullptr}; + GoalView::GoalView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalView::GoalView"); + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + SetViewIndex(0); // 视图索引 + + g_pgoalView = this; + } + + GoalView::~GoalView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " GoalView::~GoalView"); + ClearAll(); + g_pgoalView = nullptr; + } + + + void GoalView::GoalViewrefresh() + { + if(nowstepLabel) + nowstepLabel->SetText(GoalModel::GetInstance().getstepnew().c_str()); + if(goalstepLabel) + goalstepLabel->SetText(GoalModel::GetInstance().getstepGoal().c_str()); + if(circleProgress1_) + circleProgress1_->SetValue(GoalModel::GetInstance().getstepvalue()); + + + + Invalidate(); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalViewrefresh Invalidat "); + // RootView::GetInstance()->Invalidate(); + + } + + void GoalView::ClearAll() + { + RemoveAll(); + if (circleProgress1_ != nullptr) + { + delete circleProgress1_; + circleProgress1_ = nullptr; + } + if (goalstepLabel != nullptr) + { + delete goalstepLabel; + goalstepLabel = nullptr; + } + if (nowstepLabel != nullptr) + { + delete nowstepLabel; + nowstepLabel = nullptr; + } + if (goalTitle != nullptr) + { + delete goalTitle; + goalTitle = nullptr; + } + if (stepAnimatorView != nullptr) + { + stepAnimatorView->Stop(); + //stepAnimatorView->ClearImagesCache(); + delete stepAnimatorView; + stepAnimatorView = nullptr; + } + if (PullUpAnimatorView != nullptr) + { + PullUpAnimatorView->Stop(); + delete PullUpAnimatorView; + PullUpAnimatorView = nullptr; + } + if (circleProgressimage != nullptr) + { + delete circleProgressimage; + circleProgressimage = nullptr; + } + // for(int i=0;i<20;i++) + // { + + // } + ImageCacheManager::GetInstance().UnloadSingleRes("/user/res/step/step_b.bin"); + FreeImageInfoArray(goalAnimator_imageInfo,stepPaths, 20); + FreeImageInfoArray(PullUpimageAnimator_imageInfo,PullUpPaths, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + // FreeImagePathsArray(PullUpPathsArray, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + // FreeImagePathsArray(goalPathsArray, 20); + + // if(goalAnimatorInfo) + // { + + // delete goalAnimatorInfo; + // goalAnimatorInfo= nullptr; + // } + + } + + GoalView *GoalView::GetInstance() + { + return g_pgoalView; + } + + // 初始化标签 + UILabelExt *GoalView::InitLabelExt(int x, int y, int w, int h, const char *text, int textfont, int lineheight) + { + UILabelExt *label = new UILabelExt(); + if (label == nullptr) + { + return nullptr; + } + label->SetPosition(x, y, w, h); + label->SetStyle(STYLE_TEXT_FONT, textfont); + label->SetStyle(STYLE_LINE_HEIGHT, lineheight); + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, textfont); + return label; + } + + // 初始化天气页面 + bool GoalView::InitPage(void) + { + + /* --------------------------------goalTitle--------------------------------- */ + if (goalTitle == nullptr) { + goalTitle = new UILabelExt(); + } + goalTitle->SetPosition(83, 50); // widget's left position and top position + goalTitle->Resize(300, 35); // widget's width and height + goalTitle->SetViewId("label1");// Set style + goalTitle->SetStyle(STYLE_TEXT_FONT, 30); + + // Set additional property + // goalTitle->SetText("今日步数"); + goalTitle->SetTextId(STR_STEPS_OF_THE_DAY); + goalTitle->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + goalTitle->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + goalTitle->SetRollSpeed(0); + goalTitle->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /*----------------------------------------------------------------------------- */ + + + // Add Label to App + if (nowstepLabel == nullptr) { + nowstepLabel = new UILabelExt(); + } + nowstepLabel->SetPosition(121-40, 201); // widget's left position and top position + nowstepLabel->Resize(223+80, 94); // widget's width and height + nowstepLabel->SetViewId("nowstepLabel");// Set style + nowstepLabel->SetStyle(STYLE_TEXT_FONT, 80); + + // Set additional property + + nowstepLabel->SetText(GoalModel::GetInstance().getstepnew().c_str());//); + nowstepLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + //nowstepLabel->SetTextColor(0x4FC34C); + nowstepLabel->SetTextColor(Color::GetColorFromRGBA(0x4F, 0xC3, 0x4C, 0xff)); + nowstepLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + nowstepLabel->SetRollSpeed(0); + nowstepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 80); + + + // Add Label to App + if (goalstepLabel == nullptr) { + goalstepLabel = new UILabelExt(); + } + goalstepLabel->SetPosition(157, 297); // widget's left position and top position + goalstepLabel->Resize(152, 47); // widget's width and height + goalstepLabel->SetViewId("goalstepLabel");// Set style + goalstepLabel->SetStyle(STYLE_TEXT_FONT, 40); + + // Set additional property + goalstepLabel->SetText(GoalModel::GetInstance().getstepGoal().c_str()); + goalstepLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + goalstepLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + goalstepLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + goalstepLabel->SetRollSpeed(0); + goalstepLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 40); + + + /*----------------------------------------------------------------------------- */ + + // Add ImageView to App + if (circleProgressimage == nullptr) { + circleProgressimage = new UIImageView(); + } + circleProgressimage->SetPosition(28, 80-5); // widget's left position and top position + circleProgressimage->Resize(100, 100); // widget's width and height + circleProgressimage->SetViewId("image5");// Set style + + + char* image5imagesPath = "/user/res/step/step_b.bin"; + ImageInfo *info= ImageCacheManager::GetInstance().LoadSingleRes(image5imagesPath); + circleProgressimage->SetSrc(info); + + // Add to rootView + + circleProgressimage->SetVisible(true); + if(circleProgressimage!=NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "circleProgressimage"); + } + + + if (circleProgress1_ == nullptr) { + circleProgress1_ = new UICircleProgress(); + } + circleProgress1_->SetPosition(0, -5); // widget's left position and top position + circleProgress1_->Resize(466, 466); // widget's width and height + circleProgress1_->SetViewId("circleProgress1");// Set style + circleProgress1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + // Set additional property + // Set BackgroundStyle + circleProgress1_->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + circleProgress1_->SetBackgroundStyle(STYLE_BACKGROUND_OPA, 0x00); + circleProgress1_->SetBackgroundStyle(STYLE_LINE_HEIGHT, 200); + circleProgress1_->SetBackgroundStyle(STYLE_LINE_WIDTH, 21); + circleProgress1_->SetBackgroundStyle(STYLE_LINE_OPA, 0x00); + + + // Set ForegroundStyle + circleProgress1_->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6); + circleProgress1_->SetForegroundStyle(STYLE_BORDER_WIDTH, 200); + circleProgress1_->SetForegroundStyle(STYLE_BORDER_RADIUS, 200); + circleProgress1_->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000); + circleProgress1_->SetForegroundStyle(STYLE_LINE_HEIGHT, 35); + circleProgress1_->SetForegroundStyle(STYLE_LINE_COLOR, 0xff45ff5d); + circleProgress1_->SetForegroundStyle(STYLE_LINE_WIDTH, 20); + circleProgress1_->SetCenterPosition(233, 229); + circleProgress1_->SetRadius(205); + circleProgress1_->SetStartAngle(320); + circleProgress1_->SetEndAngle(40); + circleProgress1_->SetValue(GoalModel::GetInstance().getstepvalue()); + circleProgress1_->SetBackgroundImagePosition(36, 26); + circleProgress1_->SetCapType(CAP_ROUND); + + /*----------------------------------------------------------------------------- */ + goalAnimator_imageInfo=CreateImageInfoArray(stepPaths, 20); + if (stepAnimatorView == nullptr) + { + stepAnimatorView = new UIImageAnimatorView(); + if (stepAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpAnimatorView new fail"); + return false; + } + for (uint8_t i = 0; i < 20; i++) + { + //goalAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(goalPathsArray[i]); + //goalAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; + //goalAnimatorInfo=new ImageAnimatorInfo [20]; + //goalAnimatorInfo[i].imageInfo=nullptr; + goalAnimatorInfo[i].imageInfo = goalAnimator_imageInfo[i]; + goalAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; + + //goalAnimatorInfo[i].imagePath = goalPathsArray[i]; + //goalAnimatorInfo[i].imageInfo=nullptr; + //goalAnimatorInfo[i].imageType = IMG_SRC_FILE_PATH; + goalAnimatorInfo[i].pos.x = 193; + goalAnimatorInfo[i].pos.y = 90; + goalAnimatorInfo[i].width = 100; + goalAnimatorInfo[i].height = 100; + + } + stepAnimatorView->SetPosition(183, 90, 100, 100); + stepAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + stepAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + //这里出现内存泄露 + stepAnimatorView->SetImageAnimatorSrc(goalAnimatorInfo, 20, 50); + + stepAnimatorView->SetRepeat(true); + stepAnimatorView->Start(); + } + + + + PullUpimageAnimator_imageInfo =CreateImageInfoArray(PullUpPaths, PULLUP_ANIMATOR_VIEW_NUM_FRAMES); + if (PullUpAnimatorView == nullptr) + { + PullUpAnimatorView = new UIImageAnimatorView(); + if (PullUpAnimatorView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PullUpAnimatorView new fail"); + return false; + } + for (uint8_t i = 0; i < PULLUP_ANIMATOR_VIEW_NUM_FRAMES; i++) + { + //PullUpimageAnimatorInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(PullUpPathsArray[i]); + //PullUpimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; + PullUpimageAnimatorInfo[i].imageInfo = PullUpimageAnimator_imageInfo[i]; + //PullUpPathsArray[i]; + PullUpimageAnimatorInfo[i].imageType = IMG_SRC_IMAGE_INFO; + PullUpimageAnimatorInfo[i].pos.x = PULLUP_ANIMATOR_VIEW_X; + PullUpimageAnimatorInfo[i].pos.y = PULLUP_ANIMATOR_VIEW_Y; + PullUpimageAnimatorInfo[i].width = PULLUP_ANIMATOR_VIEW_W; + PullUpimageAnimatorInfo[i].height = PULLUP_ANIMATOR_VIEW_H; + } + PullUpAnimatorView->SetPosition(PULLUP_ANIMATOR_VIEW_X, PULLUP_ANIMATOR_VIEW_Y, PULLUP_ANIMATOR_VIEW_W, PULLUP_ANIMATOR_VIEW_H); + PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + PullUpAnimatorView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + PullUpAnimatorView->SetImageAnimatorSrc(PullUpimageAnimatorInfo, PULLUP_ANIMATOR_VIEW_NUM_FRAMES, PULLUP_ANIMATOR_VIEW_TIME); + PullUpAnimatorView->SetRepeat(true); + PullUpAnimatorView->Start(); + } + /* -------------------------------- 将组件添加到根视图 ------------------------------- */ + Add(circleProgressimage); + + Add(circleProgress1_); + + Add(goalstepLabel); + Add(nowstepLabel); + Add(PullUpAnimatorView); + Add(goalTitle); + Add(stepAnimatorView); + + + viewInitStatus = true; + return true; + } + + bool GoalView::InitView(void *caller) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalView InitView %p", caller); + if (InitPage() == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GoalView::InitPage fail"); + return false; + } + SetDraggable(true); + SetTouchable(true); + return true; + } + + // 获取视图初始化状态 + bool GoalView::GetInitViewState(void) + { + return viewInitStatus; + } + + + +} \ No newline at end of file