From: Caisking <3449750381@qq.com> Date: Wed, 13 Dec 2023 11:04:28 +0000 (+0800) Subject: 增加GPS训练目标选择;增加距离目标滚动条;步数目标滚动条 X-Git-Url: http://git.snicker.com.cn/css/static/script.js?a=commitdiff_plain;h=8beadd5e42f8ff0e98e39b6c6da758682e520337;p=mirrors%2FFD230.git 增加GPS训练目标选择;增加距离目标滚动条;步数目标滚动条 --- diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index cf7b6947c..5e088c4d3 100755 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -252,6 +252,12 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingNomalPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSsetView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSsetPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetDistView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetDistPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetSeptView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetSeptPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetTimeView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetTimePresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetCaluliView.cpp @@ -274,6 +280,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSlackPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSnoteView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingGPSnotePresenter.cpp + #ָ���� ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassControlView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassCalibrationView.cpp diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h index c1b85fd6e..dffae12d8 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -81,8 +81,11 @@ typedef enum : uint16_t VIEW_TRAININGLIMIT, // 极限运动子列表 VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外) VIEW_TRAININGSET, // 训练目标(时长,卡路里) + VIEW_TRAININGGPSSET, // GPS训练目标(时长,距离,卡路里,步数) VIEW_TRAININGSETTIME, // 设置训练时长 VIEW_TRAININGSETCALULI, // 设置训练卡路里 + VIEW_TRAININGSETDIST, // 设置训练路程 + VIEW_TRAININGSETSTEP, // 设置训练步数 VIEW_TRAININGCRAD, // 训练卡片 VIEW_TRAININGCONTROL, // 训练控制(包括结束,暂停,继续训练) VIEW_TRAININGDATA, // 训练数据 diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index 3684c83d9..a256f1e74 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -67,8 +67,11 @@ public: void InitTraingLimitSlice(void); void InitTraingNomalSlice(void); void InitTraingSetSlice(void); + void InitTraingGPSSetSlice(void); void InitTraingSetTimeSlice(void); void InitTraingSetCaluliSlice(void); + void InitTraingSetDistSlice(void); + void InitTraingSetStepSlice(void); void InitTraingControlSlice(void); void InitTraingCardSlice(void); void InitTraingDataSlice(void); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index d211d9967..5423a84ad 100755 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -111,10 +111,16 @@ #include "traing/include/TraingNomalView.h" #include "traing/include/TraingSetPresenter.h" #include "traing/include/TraingSetView.h" +#include "traing/include/TraingGPSsetPresenter.h" +#include "traing/include/TraingGPSsetView.h" #include "traing/include/TraingSetTimePresenter.h" #include "traing/include/TraingSetTimeView.h" #include "traing/include/TraingSetCaluliPresenter.h" #include "traing/include/TraingSetCaluliView.h" +#include "traing/include/TraingSetDistPresenter.h" +#include "traing/include/TraingSetDistView.h" +#include "traing/include/TraingSetSeptPresenter.h" +#include "traing/include/TraingSetSeptView.h" #include "traing/include/TraingControlPresenter.h" #include "traing/include/TraingControlView.h" #include "traing/include/TraingCardPresenter.h" @@ -281,8 +287,11 @@ static const AppViewMapper SLICE_MAPPER[] = { {VIEW_TRAININGLIMIT, &NativeLauncher::InitTraingLimitSlice}, //极限训练 {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice}, //正常训练初始界面 {VIEW_TRAININGSET, &NativeLauncher::InitTraingSetSlice}, //训练目标设置界面 + {VIEW_TRAININGGPSSET, &NativeLauncher::InitTraingGPSSetSlice}, //训练GPS目标设置界面 {VIEW_TRAININGSETTIME, &NativeLauncher::InitTraingSetTimeSlice}, //设置目标时长 {VIEW_TRAININGSETCALULI, &NativeLauncher::InitTraingSetCaluliSlice}, //设置目标卡路里 + {VIEW_TRAININGSETDIST, &NativeLauncher::InitTraingSetDistSlice}, //设置目标距离 + {VIEW_TRAININGSETSTEP, &NativeLauncher::InitTraingSetStepSlice}, //设置目标步数 {VIEW_TRAININGCONTROL, &NativeLauncher::InitTraingControlSlice}, //训练控制 {VIEW_TRAININGCRAD, &NativeLauncher::InitTraingCardSlice}, //训练卡片 {VIEW_TRAININGDATA, &NativeLauncher::InitTraingDataSlice}, //训练数据 @@ -290,8 +299,9 @@ static const AppViewMapper SLICE_MAPPER[] = { {VIEW_TRAININGENDNOTE, &NativeLauncher::InitTraingEndnoteSlice}, //训练结束提醒 {VIEW_TRAININGENDDATA, &NativeLauncher::InitTraingEnddataSlice}, //训练结束详细数据 {VIEW_TRAININGGPS, &NativeLauncher::InitTraingGPSSlice}, //GPS训练 - {VIEW_TRAININGGPSLACK, &NativeLauncher::InitTraingGPSlackSlice}, //GPS训练 - {VIEW_TRAININGGPSNOTE, &NativeLauncher::InitTraingGPSnoteSlice}, //GPS训练 + {VIEW_TRAININGGPSLACK, &NativeLauncher::InitTraingGPSlackSlice}, //GPS缺少 + {VIEW_TRAININGGPSNOTE, &NativeLauncher::InitTraingGPSnoteSlice}, //提醒连接GPS + {VIEW_DISPLAY_BRIGHTNESS,&NativeLauncher::InitUIDisplayBrightnessSlice}, //显示与亮度的实例化地址 {VIEW_CONNECT_BLUETOOTH,&NativeLauncher::InitBlueToothSettingSlice}, //蓝牙设置的实例化地址 @@ -898,6 +908,11 @@ void NativeLauncher::InitTraingSetSlice(void) SliceProxy *traingsetview = new AbilitySliceProxy; NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSET, traingsetview); } +void NativeLauncher::InitTraingGPSSetSlice(void) +{ + SliceProxy *traingGPSsetview = new AbilitySliceProxy; + NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGGPSSET, traingGPSsetview); +} void NativeLauncher::InitTraingSetTimeSlice(void) { SliceProxy *traingsettimeview = new AbilitySliceProxy; @@ -908,6 +923,16 @@ void NativeLauncher::InitTraingSetCaluliSlice(void) SliceProxy *traingsetcaluliview = new AbilitySliceProxy; NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSETCALULI, traingsetcaluliview); } +void NativeLauncher::InitTraingSetDistSlice(void) +{ + SliceProxy *traingsetdistview = new AbilitySliceProxy; + NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSETDIST, traingsetdistview); +} +void NativeLauncher::InitTraingSetStepSlice(void) +{ + SliceProxy *traingsetstepview = new AbilitySliceProxy; + NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSETSTEP, traingsetstepview); +} void NativeLauncher::InitTraingControlSlice(void) { SliceProxy *traingcontrolview = new AbilitySliceProxy; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSsetPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSsetPresenter.h new file mode 100644 index 000000000..99e9c48e1 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSsetPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingGPSset_PRESENTER_H +#define _TraingGPSset_PRESENTER_H + +#include "Presenter.h" +#include "TraingGPSsetView.h" + +namespace OHOS +{ + class TraingGPSsetView; + + class TraingGPSsetPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingGPSsetPresenter(); + virtual ~TraingGPSsetPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingGPSsetPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSsetView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSsetView.h new file mode 100644 index 000000000..550339843 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSsetView.h @@ -0,0 +1,79 @@ +#ifndef _TraingGPSset_VIEW_H +#define _TraingGPSset_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_chart.h" +#include "components/ui_list.h" +#include "components/icon_adapter.h" +#include "wearable_log.h" +#include "ohos_types.h" +#include "components/ui_card_page.h" + +#include "TraingGPSsetPresenter.h" +namespace OHOS +{ +#define BUTTONTIME "button1" +#define BUTTONMIL "button2" +#define BUTTONCALULI "button3" +#define BUTTONWALK "button4" + + class TraingGPSsetPresenter; + class TraingGPSsetView : public View + { + + public: + TraingGPSsetView(); + virtual ~TraingGPSsetView(); + static TraingGPSsetView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + void InitView(); + void DeInit(); + void InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); + void InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId); + void InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); + void InitList(); + void PreLoad(void); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingGPSsetView(TraingGPSsetView &&) = delete; + TraingGPSsetView &operator=(TraingGPSsetView &&) = delete; + + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UILabel *label5_ = nullptr; + + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + UIButton *button3_ = nullptr; + UIButton *button4_ = nullptr; + + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + UIImageView *image3_ = nullptr; + UIImageView *image4_ = nullptr; + + UIList *list1_ = nullptr; + IconAdapter *list1adapter_ = nullptr; + List *list1data_ = nullptr; + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingGPSset_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetDistPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetDistPresenter.h new file mode 100644 index 000000000..23af5de59 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetDistPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingSetDist_PRESENTER_H +#define _TraingSetDist_PRESENTER_H + +#include "Presenter.h" +#include "TraingSetDistView.h" + +namespace OHOS +{ + class TraingSetDistView; + + class TraingSetDistPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingSetDistPresenter(); + virtual ~TraingSetDistPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingSetDistPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetDistView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetDistView.h new file mode 100644 index 000000000..93807d2b9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetDistView.h @@ -0,0 +1,63 @@ + +#ifndef _TraingSetDist_VIEW_H +#define _TraingSetDist_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_chart.h" +#include "components/ui_list.h" +#include "components/icon_adapter.h" +#include "wearable_log.h" +#include "ohos_types.h" +#include "components/ui_card_page.h" +#include "components/ui_picker.h" + +#include "TraingSetDistPresenter.h" +namespace OHOS +{ +#define BUTTONOK "button1" + + + class TraingSetDistPresenter; + class TraingSetDistView : public View + { + + public: + TraingSetDistView(); + virtual ~TraingSetDistView(); + static TraingSetDistView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + void InitView(); + void DeInit(); + void InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); + void InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId); + void InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); + void InitUIPicker(UIPicker *&picker, int x, int y, int width, int height, const char *viewId); + void InitList(); + void PreLoad(void); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingSetDistView(TraingSetDistView &&) = delete; + TraingSetDistView &operator=(TraingSetDistView &&) = delete; + + UIViewGroup *container_ = nullptr; + UILabel *label1_ = nullptr; + UIButton *button1_ = nullptr; + UIPicker *uiPicker1_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingSetDist_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetSeptPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetSeptPresenter.h new file mode 100644 index 000000000..74034c068 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetSeptPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingSetSept_PRESENTER_H +#define _TraingSetSept_PRESENTER_H + +#include "Presenter.h" +#include "TraingSetSeptView.h" + +namespace OHOS +{ + class TraingSetSeptView; + + class TraingSetSeptPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingSetSeptPresenter(); + virtual ~TraingSetSeptPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingSetSeptPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetSeptView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetSeptView.h new file mode 100644 index 000000000..a57c92d66 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetSeptView.h @@ -0,0 +1,63 @@ + +#ifndef _TraingSetSept_VIEW_H +#define _TraingSetSept_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_chart.h" +#include "components/ui_list.h" +#include "components/icon_adapter.h" +#include "wearable_log.h" +#include "ohos_types.h" +#include "components/ui_card_page.h" +#include "components/ui_picker.h" + +#include "TraingSetSeptPresenter.h" +namespace OHOS +{ +#define BUTTONOK "button1" + + + class TraingSetSeptPresenter; + class TraingSetSeptView : public View + { + + public: + TraingSetSeptView(); + virtual ~TraingSetSeptView(); + static TraingSetSeptView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + void InitView(); + void DeInit(); + void InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); + void InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId); + void InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); + void InitUIPicker(UIPicker *&picker, int x, int y, int width, int height, const char *viewId); + void InitList(); + void PreLoad(void); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingSetSeptView(TraingSetSeptView &&) = delete; + TraingSetSeptView &operator=(TraingSetSeptView &&) = delete; + + UIViewGroup *container_ = nullptr; + UILabel *label1_ = nullptr; + UIButton *button1_ = nullptr; + UIPicker *uiPicker1_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingSetSept_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSPresenter.cpp index 589c89252..c436678eb 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSPresenter.cpp @@ -62,7 +62,7 @@ namespace OHOS (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING); } UNUSED(view); return true; @@ -73,7 +73,7 @@ namespace OHOS // 根据控件id查找是哪个控件触发了点击回调 if (strcmp(view.GetViewId(), BUTTONSET) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGGPSSET); } if (strcmp(view.GetViewId(), BUTTONGO) == 0) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackPresenter.cpp index 8cf922caa..64f862514 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackPresenter.cpp @@ -62,7 +62,7 @@ namespace OHOS (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSlice(preSlice); } UNUSED(view); return true; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnotePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnotePresenter.cpp index 3c125e321..26d705b6f 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnotePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnotePresenter.cpp @@ -62,7 +62,7 @@ namespace OHOS (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSlice(preSlice); } UNUSED(view); return true; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSsetPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSsetPresenter.cpp new file mode 100644 index 000000000..706a1243b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSsetPresenter.cpp @@ -0,0 +1,92 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingGPSsetPresenter.h" +// #include "TraingGPSsetView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingGPSsetPresenter *g_pTraingGPSsetPresenter = nullptr; + + TraingGPSsetPresenter::TraingGPSsetPresenter() + { + + g_pTraingGPSsetPresenter = this; + } + + TraingGPSsetPresenter::~TraingGPSsetPresenter() + { + + g_pTraingGPSsetPresenter = nullptr; + } + + TraingGPSsetPresenter *TraingGPSsetPresenter::GetInstance() + { + + return g_pTraingGPSsetPresenter; + } + + void TraingGPSsetPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingGPSsetPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingGPSsetPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingGPSsetPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingGPSsetPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGGPS); + } + UNUSED(view); + return true; + } + + bool TraingGPSsetPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONTIME) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSETTIME); + } + if (strcmp(view.GetViewId(), BUTTONMIL) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSETDIST); + } + if (strcmp(view.GetViewId(), BUTTONCALULI) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSETCALULI); + } + if (strcmp(view.GetViewId(), BUTTONWALK) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSETSTEP); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSsetView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSsetView.cpp new file mode 100644 index 000000000..bd19af445 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSsetView.cpp @@ -0,0 +1,301 @@ + +#include "traing/include/TraingGPSsetView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +namespace OHOS +{ + // 定义全局变量 + static char *imagePaths[] = {"/user/res/Training/time.bin", + "/user/res/Training/mileage.bin", + "/user/res/Training/calories.bin", + "/user/res/Training/walking.bin"}; + + static char *text[] = {"时长", "距离", "卡路里", "步数"}; + static const char *imagePath_iocn = "/user/res/Training/icon.bin"; + static TraingGPSsetView *g_pTraingGPSsetView{nullptr}; + + TraingGPSsetView::TraingGPSsetView() + { + g_pTraingGPSsetView = this; + } + + TraingGPSsetView::~TraingGPSsetView() + { + DeInit(); + g_pTraingGPSsetView = nullptr; + } + + TraingGPSsetView *TraingGPSsetView::GetInstance() + { + + return g_pTraingGPSsetView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingGPSsetView::InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize) + { + // 检查标签指针是否为空 + if (label == nullptr) + { + label = new UILabel(); + } + // 设置标签的位置和大小 + label->SetPosition(left, top); + label->Resize(width, height); + // 设置标签的视图 ID + label->SetViewId(viewId); + // 设置标签的样式 + label->SetStyle(STYLE_TEXT_FONT, fontSize); + label->SetFont(fontName, fontSize); + // 设置标签的文本和其他属性 + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(0); + // 设置标签可见 + label->SetVisible(true); + } + /* + InitButton:初始化按钮 + @param button 按钮指针 + @param left 按钮左边位置 + @param top 按钮顶部位置 + @param width 按钮宽度 + @param height 按钮高度 + @param viewId 按钮的视图 ID + */ + void TraingGPSsetView::InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId) + { + // 设置按钮的背景颜色 + uint32_t backgroundColor = 0xff191919; // 默认背景颜色 + uint32_t pressedBackgroundColor = 0xff249115; // 按下时的背景颜色 + uint32_t pressedBorderColor = 0xff0b1928; // 按下时的边框颜色 + // 创建新按钮(如果当前按钮为空) + if (button == nullptr) + { + button = new UIButton(); + } + button->SetPosition(left, top); + button->Resize(width, height); + button->SetViewId(viewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, pressedBackgroundColor, UIButton::PRESSED); + button->SetStyleForState(STYLE_BORDER_COLOR, pressedBorderColor, UIButton::PRESSED); + // 设置按钮的点击事件监听器为 TraingGPSsetPresenter 的实例 + button->SetOnClickListener(static_cast(TraingGPSsetPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingGPSsetView::InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath) + { + if (imageView == nullptr) + { + imageView = new UIImageView(); + } + imageView->SetPosition(left, top); + imageView->Resize(width, height); + imageView->SetViewId(viewId); + imageView->SetSrc(imagePath); + imageView->SetVisible(true); + } + /* Traing:初始化list */ + void TraingGPSsetView::InitList() + { + // Add List to App + if (list1_ == nullptr) + { + list1_ = new UIList(); + } + list1_->SetPosition(60, 110); // widget's left position and top position + list1_->Resize(300, 530); // widget's width and height + list1_->SetViewId("list1"); // Set style + list1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + list1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + + // Set additional property + if (list1data_ == nullptr) + { + list1data_ = new List(); + } + + // 使用全局变量来初始化列表项 + for (int i = 0; i < 4; ++i) + { + IconItemNode *listData = new IconItemNode(); + listData->imagePath = imagePaths[i]; + listData->txt = text[i]; + list1data_->PushBack(listData); + } + + if (list1adapter_ == nullptr) + { + list1adapter_ = new IconAdapter(); + } + list1adapter_->SetItemSize(190, 120); + list1adapter_->SetImageSize(70, 120); + list1adapter_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + list1adapter_->SetData(list1data_); + list1_->SetAdapter(list1adapter_); + + // Add to scrollView1 + // scrollView1_->Add(list1_); + list1_->SetVisible(true); + } + /* InitView:初始化界面*/ + void TraingGPSsetView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); // widget's left position and top position + scrollView1_->Resize(466, 466); // widget's width and height + scrollView1_->SetViewId("scrollView1"); // Set style + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView1_->SetReboundSize(100); + scrollView1_->SetScrollBlankSize(52); + scrollView1_->SetHorizontalScrollState(false); + // Add to rootView + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + + // 初始化Button + InitButton(button1_, 43, 120, 380, 100, BUTTONTIME); + InitButton(button2_, 43, 240, 380, 100, BUTTONMIL); + InitButton(button3_, 43, 360, 380, 100, BUTTONCALULI); + InitButton(button4_, 43, 480, 380, 100, BUTTONWALK); + scrollView1_->Add(button1_); + scrollView1_->Add(button2_); + scrollView1_->Add(button3_); + scrollView1_->Add(button4_); + + // 初始化Image + InitImageView(image1_, 380, 160, 100, 100, "image1", imagePath_iocn); + InitImageView(image2_, 380, 280, 100, 100, "image2", imagePath_iocn); + InitImageView(image3_, 380, 400, 100, 100, "image3", imagePath_iocn); + InitImageView(image4_, 380, 520, 100, 100, "image4", imagePath_iocn); + scrollView1_->Add(image1_); + scrollView1_->Add(image2_); + scrollView1_->Add(image3_); + scrollView1_->Add(image4_); + + // 初始化Lable + InitLabel(label1_, 203, 52, 120, 35, "label1", "骑行", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label2_, 300, 160, 60, 35, "label2", "30 分钟", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label3_, 300, 280, 69, 23, "label3", "5 公里", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label4_, 300, 400, 60, 35, "label4", "500 千卡", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label5_, 300, 520, 60, 35, "label5", "2000 æ­¥", DEFAULT_VECTOR_FONT_FILENAME, 20); + scrollView1_->Add(label1_); + scrollView1_->Add(label2_); + scrollView1_->Add(label3_); + scrollView1_->Add(label4_); + scrollView1_->Add(label5_); + + // 初始化list + InitList(); + scrollView1_->Add(list1_); + } + /* DeInit:删除组件 */ + void TraingGPSsetView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingGPSsetView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingGPSsetView::OnStart() + { + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight()); + + // 创建 draglistener 实例并设置为拖动监听器 + UIView::OnDragListener *draglistener = static_cast(TraingGPSsetPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingGPSsetView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingGPSsetView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingGPSsetView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliPresenter.cpp index 089837178..1d41ef508 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliPresenter.cpp @@ -72,7 +72,8 @@ namespace OHOS // 根据控件id查找是哪个控件触发了点击回调 if (strcmp(view.GetViewId(), BUTTONOK) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); } return true; } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetDistPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetDistPresenter.cpp new file mode 100644 index 000000000..0fb5cf850 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetDistPresenter.cpp @@ -0,0 +1,80 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingSetDistPresenter.h" +// #include "TraingSetDistView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingSetDistPresenter *g_pTraingSetDistPresenter = nullptr; + + TraingSetDistPresenter::TraingSetDistPresenter() + { + + g_pTraingSetDistPresenter = this; + } + + TraingSetDistPresenter::~TraingSetDistPresenter() + { + + g_pTraingSetDistPresenter = nullptr; + } + + TraingSetDistPresenter *TraingSetDistPresenter::GetInstance() + { + + return g_pTraingSetDistPresenter; + } + + void TraingSetDistPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingSetDistPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingSetDistPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingSetDistPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingSetDistPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + // if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + // (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + // } + UNUSED(view); + return true; + } + + bool TraingSetDistPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONOK) == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGGPSSET); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetDistView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetDistView.cpp new file mode 100644 index 000000000..634ea19e9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetDistView.cpp @@ -0,0 +1,280 @@ + +#include "traing/include/TraingSetDistView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +#include "common/screen.h" +#include +#include +#include + +namespace OHOS +{ + + /***************************************************************************************/ + // 动态生成包含指定公里区间内所有公里的字符串数组 + std::vector GenerateDistValues(int minDist, int maxDist, int interval) + { + std::vector values; + for (int i = minDist; i <= maxDist; i += interval) + { + values.push_back(std::to_string(i) + " 公里"); + } + return values; + } + /***************************************************************************************/ + static TraingSetDistView *g_pTraingSetDistView{nullptr}; + + TraingSetDistView::TraingSetDistView() + { + g_pTraingSetDistView = this; + } + + TraingSetDistView::~TraingSetDistView() + { + DeInit(); + g_pTraingSetDistView = nullptr; + } + + TraingSetDistView *TraingSetDistView::GetInstance() + { + + return g_pTraingSetDistView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingSetDistView::InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize) + { + // 检查标签指针是否为空 + if (label == nullptr) + { + label = new UILabel(); + } + // 设置标签的位置和大小 + label->SetPosition(left, top); + label->Resize(width, height); + // 设置标签的视图 ID + label->SetViewId(viewId); + // 设置标签的样式 + label->SetStyle(STYLE_TEXT_FONT, fontSize); + label->SetFont(fontName, fontSize); + // 设置标签的文本和其他属性 + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(0); + // 设置标签可见 + label->SetVisible(true); + } + /* + InitButton:初始化按钮 + @param button 按钮指针 + @param left 按钮左边位置 + @param top 按钮顶部位置 + @param width 按钮宽度 + @param height 按钮高度 + @param viewId 按钮的视图 ID + */ + void TraingSetDistView::InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId) + { + // 设置按钮的背景颜色 + uint32_t backgroundColor = 0xff191919; // 默认背景颜色 + uint32_t pressedBackgroundColor = 0xff249115; // 按下时的背景颜色 + uint32_t pressedBorderColor = 0xff0b1928; // 按下时的边框颜色 + // 创建新按钮(如果当前按钮为空) + if (button == nullptr) + { + button = new UIButton(); + } + button->SetPosition(left, top); + button->Resize(width, height); + button->SetViewId(viewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, pressedBackgroundColor, UIButton::PRESSED); + button->SetStyleForState(STYLE_BORDER_COLOR, pressedBorderColor, UIButton::PRESSED); + // 设置按钮的点击事件监听器为 TraingSetDistPresenter 的实例 + button->SetOnClickListener(static_cast(TraingSetDistPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitUIPicker: 初始化UIPicker组件 + @param picker: 指向UIPicker的指针 + @param x: UIPicker的左边位置 + @param y: UIPicker的顶部位置 + @param width: UIPicker的宽度 + @param height: UIPicker的高度 + @param viewId: UIPicker的视图 ID + @param values: 选项数组 + @param count: 选项数量 + @param backgroundFontSize: 普通文本大小 + @highlightFontSize: 高光文本大小 + */ + void TraingSetDistView::InitUIPicker(UIPicker *&picker, int x, int y, int width, int height, const char *viewId) + { + // 文本大小 + constexpr uint8_t BACKGROUND_FONT = 40; + constexpr uint8_t HIGHTLIGHT_FONT = 60; + // 获取value数组 + int minDist = 1; + int maxDist = 20; + int interval = 1; + std::vector DistValues = GenerateDistValues(minDist, maxDist, interval); + + const char **values = new const char *[DistValues.size()]; + for (size_t i = 0; i < DistValues.size(); i++) + { + values[i] = DistValues[i].c_str(); + } + // 创建 UIPicker + if (picker == nullptr) + { + picker = new UIPicker(); + } + + // 设置 UIPicker 的位置和大小 + picker->SetPosition(x, y); + picker->Resize(width, height); + // 设置 UIPicker 的 ViewId + picker->SetViewId(viewId); + // 设置 UIPicker 的属性 + picker->SetItemHeight(70); + picker->SetLoopState(true); + picker->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff), Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + picker->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); // 设置普通文本大小 + picker->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); // 设置高光文本大小 + picker->SetValues(values, DistValues.size()); + // 将 UIPicker 设置为显示 + picker->SetVisible(true); + } + + /* InitView:初始化界面*/ + void TraingSetDistView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + // 初始化Lable + InitLabel(label1_, 173, 52, 120, 35, "label1", "步数设定", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label1_); + + // 初始化UIPicker + InitUIPicker(uiPicker1_, 43, 106, 380, 240, "uiPicker1"); + container_->Add(uiPicker1_); + // 初始化Button + InitButton(button1_, 0, 366, 466, 100, BUTTONOK); + // Set additional property + char *button1defaultImgSrc = "/user/res/Training/buttonok.bin"; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + container_->Add(button1_); + } + /* DeInit:删除组件 */ + void TraingSetDistView::DeInit() + { + // 删除Label + if (label1_ != nullptr) + { + container_->Remove(label1_); + delete label1_; + label1_ = nullptr; + } + // 删除Button + if (button1_ != nullptr) + { + container_->Remove(button1_); + delete button1_; + button1_ = nullptr; + } + + // 删除Image + + // 删除滚动选择器 + if (uiPicker1_ != nullptr) + { + container_->Remove(uiPicker1_); + delete uiPicker1_; + uiPicker1_ = nullptr; + } + + // 删除容器 + if (container_ != nullptr) + { + container_->RemoveAll(); // 移除容器中的所有组件 + delete container_; + container_ = nullptr; + } + } + + void TraingSetDistView::PreLoad(void) + { + if (!viewiInitStatus) + { + //printf("init TraingSetDistview\n"); + InitView(); + viewiInitStatus = true; + } + } + void TraingSetDistView::OnStart() + { + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight()); + + // 创建 draglistener 实例并设置为拖动监听器 + UIView::OnDragListener *draglistener = static_cast(TraingSetDistPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingSetDistView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingSetDistView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingSetDistView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp index fcb3da54d..11be7f9ff 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp @@ -62,7 +62,7 @@ namespace OHOS (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSlice(preSlice); } UNUSED(view); return true; diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetSeptPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetSeptPresenter.cpp new file mode 100644 index 000000000..5841d3d58 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetSeptPresenter.cpp @@ -0,0 +1,80 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingSetSeptPresenter.h" +// #include "TraingSetSeptView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingSetSeptPresenter *g_pTraingSetSeptPresenter = nullptr; + + TraingSetSeptPresenter::TraingSetSeptPresenter() + { + + g_pTraingSetSeptPresenter = this; + } + + TraingSetSeptPresenter::~TraingSetSeptPresenter() + { + + g_pTraingSetSeptPresenter = nullptr; + } + + TraingSetSeptPresenter *TraingSetSeptPresenter::GetInstance() + { + + return g_pTraingSetSeptPresenter; + } + + void TraingSetSeptPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingSetSeptPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingSetSeptPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingSetSeptPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingSetSeptPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + // if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + // (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + // } + UNUSED(view); + return true; + } + + bool TraingSetSeptPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONOK) == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGGPSSET); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetSeptView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetSeptView.cpp new file mode 100644 index 000000000..8bd73c1e0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetSeptView.cpp @@ -0,0 +1,280 @@ + +#include "traing/include/TraingSetSeptView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +#include "common/screen.h" +#include +#include +#include + +namespace OHOS +{ + + /***************************************************************************************/ + // 动态生成包含指定步数区间内所有步数的字符串数组 + std::vector GenerateSeptValues(int minSept, int maxSept, int interval) + { + std::vector values; + for (int i = minSept; i <= maxSept; i += interval) + { + values.push_back(std::to_string(i) + " æ­¥"); + } + return values; + } + /***************************************************************************************/ + static TraingSetSeptView *g_pTraingSetSeptView{nullptr}; + + TraingSetSeptView::TraingSetSeptView() + { + g_pTraingSetSeptView = this; + } + + TraingSetSeptView::~TraingSetSeptView() + { + DeInit(); + g_pTraingSetSeptView = nullptr; + } + + TraingSetSeptView *TraingSetSeptView::GetInstance() + { + + return g_pTraingSetSeptView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingSetSeptView::InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize) + { + // 检查标签指针是否为空 + if (label == nullptr) + { + label = new UILabel(); + } + // 设置标签的位置和大小 + label->SetPosition(left, top); + label->Resize(width, height); + // 设置标签的视图 ID + label->SetViewId(viewId); + // 设置标签的样式 + label->SetStyle(STYLE_TEXT_FONT, fontSize); + label->SetFont(fontName, fontSize); + // 设置标签的文本和其他属性 + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(0); + // 设置标签可见 + label->SetVisible(true); + } + /* + InitButton:初始化按钮 + @param button 按钮指针 + @param left 按钮左边位置 + @param top 按钮顶部位置 + @param width 按钮宽度 + @param height 按钮高度 + @param viewId 按钮的视图 ID + */ + void TraingSetSeptView::InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId) + { + // 设置按钮的背景颜色 + uint32_t backgroundColor = 0xff191919; // 默认背景颜色 + uint32_t pressedBackgroundColor = 0xff249115; // 按下时的背景颜色 + uint32_t pressedBorderColor = 0xff0b1928; // 按下时的边框颜色 + // 创建新按钮(如果当前按钮为空) + if (button == nullptr) + { + button = new UIButton(); + } + button->SetPosition(left, top); + button->Resize(width, height); + button->SetViewId(viewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, pressedBackgroundColor, UIButton::PRESSED); + button->SetStyleForState(STYLE_BORDER_COLOR, pressedBorderColor, UIButton::PRESSED); + // 设置按钮的点击事件监听器为 TraingSetSeptPresenter 的实例 + button->SetOnClickListener(static_cast(TraingSetSeptPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitUIPicker: 初始化UIPicker组件 + @param picker: 指向UIPicker的指针 + @param x: UIPicker的左边位置 + @param y: UIPicker的顶部位置 + @param width: UIPicker的宽度 + @param height: UIPicker的高度 + @param viewId: UIPicker的视图 ID + @param values: 选项数组 + @param count: 选项数量 + @param backgroundFontSize: 普通文本大小 + @highlightFontSize: 高光文本大小 + */ + void TraingSetSeptView::InitUIPicker(UIPicker *&picker, int x, int y, int width, int height, const char *viewId) + { + // 文本大小 + constexpr uint8_t BACKGROUND_FONT = 40; + constexpr uint8_t HIGHTLIGHT_FONT = 60; + // 获取value数组 + int minSept = 500; + int maxSept = 50000; + int interval = 500; + std::vector SeptValues = GenerateSeptValues(minSept, maxSept, interval); + + const char **values = new const char *[SeptValues.size()]; + for (size_t i = 0; i < SeptValues.size(); i++) + { + values[i] = SeptValues[i].c_str(); + } + // 创建 UIPicker + if (picker == nullptr) + { + picker = new UIPicker(); + } + + // 设置 UIPicker 的位置和大小 + picker->SetPosition(x, y); + picker->Resize(width, height); + // 设置 UIPicker 的 ViewId + picker->SetViewId(viewId); + // 设置 UIPicker 的属性 + picker->SetItemHeight(70); + picker->SetLoopState(true); + picker->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff), Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + picker->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); // 设置普通文本大小 + picker->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); // 设置高光文本大小 + picker->SetValues(values, SeptValues.size()); + // 将 UIPicker 设置为显示 + picker->SetVisible(true); + } + + /* InitView:初始化界面*/ + void TraingSetSeptView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + // 初始化Lable + InitLabel(label1_, 173, 52, 120, 35, "label1", "步数设定", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label1_); + + // 初始化UIPicker + InitUIPicker(uiPicker1_, 43, 106, 380, 240, "uiPicker1"); + container_->Add(uiPicker1_); + // 初始化Button + InitButton(button1_, 0, 366, 466, 100, BUTTONOK); + // Set additional property + char *button1defaultImgSrc = "/user/res/Training/buttonok.bin"; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + container_->Add(button1_); + } + /* DeInit:删除组件 */ + void TraingSetSeptView::DeInit() + { + // 删除Label + if (label1_ != nullptr) + { + container_->Remove(label1_); + delete label1_; + label1_ = nullptr; + } + // 删除Button + if (button1_ != nullptr) + { + container_->Remove(button1_); + delete button1_; + button1_ = nullptr; + } + + // 删除Image + + // 删除滚动选择器 + if (uiPicker1_ != nullptr) + { + container_->Remove(uiPicker1_); + delete uiPicker1_; + uiPicker1_ = nullptr; + } + + // 删除容器 + if (container_ != nullptr) + { + container_->RemoveAll(); // 移除容器中的所有组件 + delete container_; + container_ = nullptr; + } + } + + void TraingSetSeptView::PreLoad(void) + { + if (!viewiInitStatus) + { + //printf("init TraingSetSeptview\n"); + InitView(); + viewiInitStatus = true; + } + } + void TraingSetSeptView::OnStart() + { + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight()); + + // 创建 draglistener 实例并设置为拖动监听器 + UIView::OnDragListener *draglistener = static_cast(TraingSetSeptPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingSetSeptView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingSetSeptView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingSetSeptView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetTimePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetTimePresenter.cpp index f28506d5d..124473c74 100755 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetTimePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetTimePresenter.cpp @@ -72,7 +72,8 @@ namespace OHOS // 根据控件id查找是哪个控件触发了点击回调 if (strcmp(view.GetViewId(), BUTTONOK) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); } if (strcmp(view.GetViewId(), "Remind") == 0) {