From: Caisking <3449750381@qq.com> Date: Thu, 18 Apr 2024 06:41:01 +0000 (+0800) Subject: 增加设置时长SubView,删除原Slice X-Git-Tag: release_V1.2.70_20241020_135402~1171^2~12 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=56b6e1a685f888cfa6f809c72dddf42672f6d9d1;p=mirrors%2FFD230.git 增加设置时长SubView,删除原Slice --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index d6e97ae2a..05d926fac 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -478,13 +478,12 @@ set(SOURCES ${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/TraingEnddataView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingEnddataPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingWinView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingWinPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TrainingSetCaluliView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TrainingSetTimeView.cpp #主界面训练卡片 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/Training_CardView.cpp @@ -499,7 +498,6 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordPresenter.cpp - #训练列表 #极限训练 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_list_limit/src/TraingLimitView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h index 3bfbd5b8e..3fd8dccbe 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h @@ -74,7 +74,6 @@ typedef enum : uint16_t VIEW_TRAINING, // 训练 VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外) VIEW_TRAININGSET, // 训练目标(时长,卡路里) - VIEW_TRAININGSETTIME, // 设置训练时长 VIEW_TRAININGSETDIST, // 设置训练路程 VIEW_TRAININGSETSTEP, // 设置训练步数 VIEW_TRAININGCRAD, // 训练控制卡片 diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h index 8af8f43cf..348dc09d2 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h @@ -67,7 +67,6 @@ namespace OHOS void InitTraingSlice(void); void InitTraingNomalSlice(void); void InitTraingSetSlice(void); - void InitTraingSetTimeSlice(void); void InitTraingSetDistSlice(void); void InitTraingSetStepSlice(void); void InitTraingCardSlice(void); diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index 9684c2fb7..6850a891c 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -163,8 +163,6 @@ #include "traing/include/TraingNomalView.h" #include "traing/include/TraingSetPresenter.h" #include "traing/include/TraingSetView.h" -#include "traing/include/TraingSetTimePresenter.h" -#include "traing/include/TraingSetTimeView.h" #include "traing/include/TraingSetDistPresenter.h" #include "traing/include/TraingSetDistView.h" #include "traing/include/TraingSetSeptPresenter.h" @@ -284,7 +282,6 @@ namespace OHOS {VIEW_TRAINING, &NativeLauncher::InitTraingSlice}, // 训练 {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice}, // 正常训练初始界面 {VIEW_TRAININGSET, &NativeLauncher::InitTraingSetSlice}, // 训练目标设置界面 - {VIEW_TRAININGSETTIME, &NativeLauncher::InitTraingSetTimeSlice}, // 设置目标时长 {VIEW_TRAININGSETDIST, &NativeLauncher::InitTraingSetDistSlice}, // 设置目标距离 {VIEW_TRAININGSETSTEP, &NativeLauncher::InitTraingSetStepSlice}, // 设置目标步数 {VIEW_TRAININGCRAD, &NativeLauncher::InitTraingCardSlice}, // 训练卡片 @@ -866,11 +863,6 @@ namespace OHOS SliceProxy *traingsetview = new AbilitySliceProxy; NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSET, traingsetview); } - void NativeLauncher::InitTraingSetTimeSlice(void) - { - SliceProxy *traingsettimeview = new AbilitySliceProxy; - NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSETTIME, traingsettimeview); - } void NativeLauncher::InitTraingSetDistSlice(void) { SliceProxy *traingsetdistview = new AbilitySliceProxy; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetTimePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetTimePresenter.h deleted file mode 100644 index 625733028..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetTimePresenter.h +++ /dev/null @@ -1,35 +0,0 @@ - -#ifndef _TraingSetTime_PRESENTER_H -#define _TraingSetTime_PRESENTER_H - -#include "Presenter.h" -#include "TraingSetTimeView.h" - -namespace OHOS -{ - class TraingSetTimeView; - - class TraingSetTimePresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - TraingSetTimePresenter(); - virtual ~TraingSetTimePresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static TraingSetTimePresenter *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; - }; -} // namespace OHOS - -#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetTimeView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetTimeView.h deleted file mode 100644 index 81699a143..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetTimeView.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef _TraingSetTime_VIEW_H -#define _TraingSetTime_VIEW_H - -#include "BaseView.h" -#include "View.h" -#include -#include "components/ui_view_group.h" -#include "components/ui_label.h" -#include "components/ui_label_ext.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 "traing/include/TraingModel.h" -#include "traing/Training_UiConfig.h" -#include "components/ui_picker.h" - -#include "TraingSetTimePresenter.h" -namespace OHOS -{ -#define BUTTONOK "button1" - - - class TraingSetTimePresenter; - class TraingSetTimeView : public View - { - - public: - TraingSetTimeView(); - virtual ~TraingSetTimeView(); - static TraingSetTimeView *GetInstance(void); - - void OnStart() override; - void OnSetUpView() override; - void OnTearDownView() override; - void OnStop() override; - void InitView(); - void DeInit(); - - 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}; - TraingSetTimeView(TraingSetTimeView &&) = delete; - TraingSetTimeView &operator=(TraingSetTimeView &&) = delete; - - UIViewGroup *container_ = nullptr; - UILabelExt *label1_ = nullptr; - UIButton *button1_ = nullptr; - UIPicker *uiPicker1_ = nullptr; - - bool viewiInitStatus{false}; - }; -} // namespace OHOS -#endif // TraingSetTime_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h index 4129f46a3..012ea3982 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h @@ -23,6 +23,7 @@ #include "traing/Training_UiConfig.h" #include "traing/include/TrainingSetCaluliView.h" +#include "traing/include/TrainingSetTimeView.h" #include "TraingSetPresenter.h" namespace OHOS { @@ -31,6 +32,7 @@ namespace OHOS class TraingSetPresenter; class TrainingSetCaluliView; + class TrainingSetTimeView; class TraingSetView : public View { @@ -63,6 +65,7 @@ namespace OHOS UIViewGroup *container_ = nullptr; UIScrollView *SetTagScrollView[4]{nullptr}; TrainingSetCaluliView *setcalories{nullptr}; + TrainingSetTimeView *settime{nullptr}; UILabelExt *labeltitle = nullptr; UILabelExt *labeltime = nullptr; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetCaluliView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetCaluliView.h index 7aeab78dd..75f69af99 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetCaluliView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetCaluliView.h @@ -23,7 +23,7 @@ namespace OHOS { -#define BUTTONOK "button1" +#define BUTTONCALULIOK "buttoncaluli" class TraingSetPresenter; class TrainingSetCaluliView : public View @@ -33,7 +33,7 @@ namespace OHOS TrainingSetCaluliView(); virtual ~TrainingSetCaluliView(); static TrainingSetCaluliView *GetInstance(void); - UIScrollView *SetCaloriesViewInit(); + UIScrollView *SetCaluliViewInit(); void InitUIPicker(UIPicker *&picker, int x, int y, int width, int height, const char *viewId); @@ -44,7 +44,7 @@ namespace OHOS UILabelButtonExt*buttonok_ = nullptr; UIPicker *calPicker_ = nullptr; - UIScrollView *SetCaloriesScrollView; + UIScrollView *SetCaluliScrollView; }; } // namespace OHOS #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetTimeView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetTimeView.h index e69de29bb..aa31a7e98 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetTimeView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetTimeView.h @@ -0,0 +1,50 @@ +/*** + * @Date: 2024-04-18 10:57:45 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-04-18 11:00:03 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/include/TrainingSetTimeView.h + */ +#ifndef _Training_SetTime_VIEW_H +#define _Training_SetTime_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_label_ext.h" +#include "components/ui_button.h" +#include "components/ui_label_button_ext.h" +#include "wearable_log.h" +#include "traing/include/TraingModel.h" +#include "traing/Training_UiConfig.h" +#include "components/ui_picker.h" +#include "components/ui_scroll_view.h" + +#include "traing/include/TraingSetPresenter.h" +#include "traing/include/TrainingSetTimeView.h" + +namespace OHOS +{ +#define BUTTONTIMEOK "buttontime" + + class TraingSetPresenter; + class TrainingSetTimeView : public View + { + + public: + TrainingSetTimeView(); + virtual ~TrainingSetTimeView(); + static TrainingSetTimeView *GetInstance(void); + UIScrollView *SetTimeViewInit(); + + void InitUIPicker(UIPicker *&picker, int x, int y, int width, int height, const char *viewId); + + private: + UIView::OnDragListener *draglistener{nullptr}; + + UILabelExt *labeltitle_ = nullptr; + UILabelButtonExt*buttonok_ = nullptr; + UIPicker *calPicker_ = nullptr; + + UIScrollView *SetTimeScrollView; + }; +} // namespace OHOS +#endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp index 90e2639ea..f6628cc24 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp @@ -84,11 +84,10 @@ namespace OHOS // 根据控件id查找是哪个控件触发了点击回调 if (strcmp(view.GetViewId(), BUTTONTIME) == 0) { - NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGSETTIME); + TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_DURATION); } if (strcmp(view.GetViewId(), BUTTONCALULI) == 0) { - // NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGSETCALULI); TraingSetView::GetInstance()->ChangeView(SET_VIEW, SET_CALORIES); } return true; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetTimePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetTimePresenter.cpp deleted file mode 100644 index 73c2261b6..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetTimePresenter.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/*** - * @Date: 2024-04-15 10:55:58 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-04-17 11:58:48 - * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetTimePresenter.cpp - */ -#include "AppViewIDs.h" -#include "components/ui_label_ext.h" -#include"language/font/ui_resource_string.h" -#include "NativeAbility.h" - -#include -#include -#include -#include "traing/include/TraingSetTimePresenter.h" -// #include "TraingSetTimeView.h" - -namespace OHOS -{ - - // 当前Presenter属性实例化的内存指针 - static TraingSetTimePresenter *g_pTraingSetTimePresenter = nullptr; - - TraingSetTimePresenter::TraingSetTimePresenter() - { - - g_pTraingSetTimePresenter = this; - } - - TraingSetTimePresenter::~TraingSetTimePresenter() - { - - g_pTraingSetTimePresenter = nullptr; - } - - TraingSetTimePresenter *TraingSetTimePresenter::GetInstance() - { - - return g_pTraingSetTimePresenter; - } - - void TraingSetTimePresenter::OnStart() - { - - Presenter::OnStart(); - } - - void TraingSetTimePresenter::OnPause(void) - { - - Presenter::OnPause(); - } - - void TraingSetTimePresenter::OnResume(void) - { - - Presenter::OnResume(); - } - - void TraingSetTimePresenter::OnStop(void) - { - - Presenter::OnStop(); - } - - bool TraingSetTimePresenter::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 TraingSetTimePresenter::OnClick(UIView &view, const ClickEvent &event) - { - // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), BUTTONOK) == 0) - { - NativeAbility::GetInstance().Back(); - } - if (strcmp(view.GetViewId(), "Remind") == 0) - { - // 模拟心率监测,等待20秒 - // std::this_thread::sleep_for(std::chrono::seconds(20)); - // NativeAbility::GetInstance().ChangeSlice(VIEW_TraingSetTimeREMIND); - } - return true; - } -} diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetTimeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetTimeView.cpp deleted file mode 100644 index 712e07c91..000000000 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetTimeView.cpp +++ /dev/null @@ -1,217 +0,0 @@ - -#include "traing/include/TraingSetTimeView.h" - -#include "common/image_cache_manager.h" -#include "components/ui_label_ext.h" -#include "language/font/ui_resource_string.h" -#include "UiConfig.h" -#include "ui_resource_image.h" -#include -#include "components/ui_button.h" -#include "common/screen.h" -#include -#include -#include -#include "traing/include/TraingModel.h" -#include "traing/Training_UiConfig.h" -namespace OHOS -{ - - /***************************************************************************************/ - // 动态生成包含指定时间区间内所有分钟数的字符串数组 - std::vector GenerateTimeValues(int minTime, int maxTime, int interval) - { - std::vector values; - for (int i = minTime; i <= maxTime; i += interval) - { - values.push_back(std::to_string(i) + " 分钟"); - } - return values; - } - /***************************************************************************************/ - static TraingSetTimeView *g_pTraingSetTimeView{nullptr}; - - TraingSetTimeView::TraingSetTimeView() - { - g_pTraingSetTimeView = this; - } - - TraingSetTimeView::~TraingSetTimeView() - { - DeInit(); - g_pTraingSetTimeView = nullptr; - } - - TraingSetTimeView *TraingSetTimeView::GetInstance() - { - - return g_pTraingSetTimeView; - } - - /* - 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 TraingSetTimeView::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 minTime = 10; - int maxTime = 600; - int interval = 10; - std::vector timeValues = GenerateTimeValues(minTime, maxTime, interval); - - const char **values = new const char *[timeValues.size()]; - for (size_t i = 0; i < timeValues.size(); i++) - { - values[i] = timeValues[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, timeValues.size()); - // 将 UIPicker 设置为显示 - picker->SetVisible(true); - } - - /* InitView:初始化界面*/ - void TraingSetTimeView ::InitView() - { - if (container_ == nullptr) - { - container_ = new UIViewGroup(); - container_->SetPosition(0, 0, 466, 466); - container_->SetStyle(STYLE_BACKGROUND_OPA, 0); - } - // 初始化Lable - TraingModel::GetInstance()->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 - TraingModel::GetInstance()->InitButton(button1_, 0, 366, 466, 100, BUTTONOK); - button1_->SetOnClickListener(static_cast(TraingSetTimePresenter::GetInstance())); - // Set additional property - button1_->SetImageSrc(BUTTONOK_IMAGE, BUTTONOK_IMAGE); - container_->Add(button1_); - } - /* DeInit:删除组件 */ - void TraingSetTimeView::DeInit() - { - container_->RemoveAll(); - // 删除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 TraingSetTimeView::PreLoad(void) - { - if (!viewiInitStatus) - { - InitView(); - viewiInitStatus = true; - } - } - void TraingSetTimeView::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(TraingSetTimePresenter::GetInstance()); - if (draglistener == nullptr) - { - return; - } - container_->SetOnDragListener(draglistener); - - container_->SetTouchable(true); - container_->SetDraggable(true); - - PreLoad(); - RootView::GetInstance()->Add(container_); - } - - void TraingSetTimeView::OnSetUpView() - { - - View::OnSetUpView(); - Draw(); - } - - void TraingSetTimeView::OnTearDownView() - { - - View::OnTearDownView(); - return; - } - - void TraingSetTimeView::OnStop() - { - View::OnStop(); - RootView::GetInstance()->RemoveAll(); - return; - } -} diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp index bcbf341ae..772d94a56 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp @@ -164,12 +164,27 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView:: new scrollView[%d] fail", thisview); return false; } - SetTagScrollView[thisview] = setcalories->SetCaloriesViewInit(); + SetTagScrollView[thisview] = setcalories->SetCaluliViewInit(); + RootView::GetInstance()->Add(SetTagScrollView[thisview]); + } + return true; + } + bool TraingSetView::ChangeSetDurationView(int16_t thisview) + { + if (SetTagScrollView[thisview] == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView::ChangeBandoffView"); + settime = new TrainingSetTimeView(); + if (settime == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodOxygenView:: new scrollView[%d] fail", thisview); + return false; + } + SetTagScrollView[thisview] = settime->SetTimeViewInit(); RootView::GetInstance()->Add(SetTagScrollView[thisview]); } return true; } - bool TraingSetView::ChangeSetDurationView(int16_t thisview) {} bool TraingSetView::ChangeSetStepsView(int16_t thisview) {} bool TraingSetView::ChangeSetDistanceView(int16_t thisview) {} /* -------------------------------------------------------------------------- */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetCaluliView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetCaluliView.cpp index f4e32983c..b46382956 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetCaluliView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetCaluliView.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-18 10:57:22 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-04-18 14:28:29 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetCaluliView.cpp + */ #include "traing/include/TrainingSetCaluliView.h" @@ -36,25 +42,25 @@ namespace OHOS labeltitle_ = nullptr; buttonok_ = nullptr; calPicker_ = nullptr; - SetCaloriesScrollView = nullptr; + SetCaluliScrollView = nullptr; g_pTraingSetCaluliView = this; } TrainingSetCaluliView::~TrainingSetCaluliView() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingSetCaluliView::~TrainingSetCaluliView"); - SetCaloriesScrollView->RemoveAll(); + SetCaluliScrollView->RemoveAll(); // 删除Label if (labeltitle_ != nullptr) { - SetCaloriesScrollView->Remove(labeltitle_); + SetCaluliScrollView->Remove(labeltitle_); delete labeltitle_; labeltitle_ = nullptr; } // 删除Button if (buttonok_ != nullptr) { - SetCaloriesScrollView->Remove(buttonok_); + SetCaluliScrollView->Remove(buttonok_); delete buttonok_; buttonok_ = nullptr; } @@ -62,17 +68,17 @@ namespace OHOS // 删除滚动选择器 if (calPicker_ != nullptr) { - SetCaloriesScrollView->Remove(calPicker_); + SetCaluliScrollView->Remove(calPicker_); delete calPicker_; calPicker_ = nullptr; } // 删除容器 - if (SetCaloriesScrollView != nullptr) + if (SetCaluliScrollView != nullptr) { - SetCaloriesScrollView->RemoveAll(); // 移除容器中的所有组件 - delete SetCaloriesScrollView; - SetCaloriesScrollView = nullptr; + SetCaluliScrollView->RemoveAll(); // 移除容器中的所有组件 + delete SetCaluliScrollView; + SetCaluliScrollView = nullptr; } g_pTraingSetCaluliView = nullptr; } @@ -135,20 +141,20 @@ namespace OHOS } /* InitView:初始化界面*/ - UIScrollView *TrainingSetCaluliView ::SetCaloriesViewInit() + UIScrollView *TrainingSetCaluliView ::SetCaluliViewInit() { /* -------------------------------------------------------------------------- */ - SetCaloriesScrollView = new UIScrollView(); - if (SetCaloriesScrollView == nullptr) + SetCaluliScrollView = new UIScrollView(); + if (SetCaluliScrollView == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingSetCaluliView::new SetCaloriesScrollView fail"); + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingSetCaluliView::new SetCaluliScrollView fail"); return nullptr; } - SetCaloriesScrollView->SetPosition(0, 0); - SetCaloriesScrollView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); - SetCaloriesScrollView->SetScrollBlankSize(35); - SetCaloriesScrollView->SetReboundSize(50); - SetCaloriesScrollView->SetDirection(1); + SetCaluliScrollView->SetPosition(0, 0); + SetCaluliScrollView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + SetCaluliScrollView->SetScrollBlankSize(35); + SetCaluliScrollView->SetReboundSize(50); + SetCaluliScrollView->SetDirection(1); // 增加拖拽监听 UIView::OnDragListener *draglistener = static_cast(new TraingSetPresenter()); if (draglistener == nullptr) @@ -156,25 +162,25 @@ namespace OHOS WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::draglistener can not be nullptr!"); return nullptr; } - SetCaloriesScrollView->SetOnDragListener(draglistener); - SetCaloriesScrollView->SetTouchable(true); - SetCaloriesScrollView->SetDraggable(true); - SetCaloriesScrollView->SetVerticalScrollState(false); // 禁止垂直滑动 + SetCaluliScrollView->SetOnDragListener(draglistener); + SetCaluliScrollView->SetTouchable(true); + SetCaluliScrollView->SetDraggable(true); + SetCaluliScrollView->SetVerticalScrollState(false); // 禁止垂直滑动 /* -------------------------------------------------------------------------- */ // 初始化Lable TraingModel::GetInstance()->InitLabel(labeltitle_, 83, 50, 300, 35, "label1", "卡路里(千卡)", DEFAULT_VECTOR_FONT_FILENAME, 30); - SetCaloriesScrollView->Add(labeltitle_); + SetCaluliScrollView->Add(labeltitle_); // 初始化UIPicker InitUIPicker(calPicker_, 43, 106, 380, 240, "uiPicker"); - SetCaloriesScrollView->Add(calPicker_); + SetCaluliScrollView->Add(calPicker_); // 初始化Button - TraingModel::GetInstance()->InitButtonExt(buttonok_, 0, 366, 466, 100, BUTTONOK, STR_OK, 30); + TraingModel::GetInstance()->InitButtonExt(buttonok_, 0, 366, 466, 100, BUTTONCALULIOK, STR_OK, 30); // Set additional property buttonok_->SetImageSrc(BUTTONOK_IMAGE, BUTTONOK_IMAGE); buttonok_->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); - SetCaloriesScrollView->Add(buttonok_); + SetCaluliScrollView->Add(buttonok_); - return SetCaloriesScrollView; + return SetCaluliScrollView; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetTimeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetTimeView.cpp new file mode 100644 index 000000000..d9a31bf49 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetTimeView.cpp @@ -0,0 +1,186 @@ +/*** + * @Date: 2024-04-18 10:57:22 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-04-18 14:24:30 + * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TrainingSetTimeView.cpp + */ + +#include "traing/include/TrainingSetTimeView.h" + +#include "common/image_cache_manager.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include "components/ui_button.h" +#include "common/screen.h" +#include +#include +#include +#include "traing/include/TraingModel.h" +#include "traing/Training_UiConfig.h" +namespace OHOS +{ + + /***************************************************************************************/ + // 动态生成包含指定卡路里区间内所有卡路里数的字符串数组 + std::vector GenerateTimeValues(int minTime, int maxTime, int interval) + { + std::vector values; + for (int i = minTime; i <= maxTime; i += interval) + { + values.push_back(std::to_string(i)); + } + return values; + } + /***************************************************************************************/ + static TrainingSetTimeView *g_pTraingSetTimeView{nullptr}; + + TrainingSetTimeView::TrainingSetTimeView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingSetTimeView::TrainingSetTimeView"); + labeltitle_ = nullptr; + buttonok_ = nullptr; + calPicker_ = nullptr; + SetTimeScrollView = nullptr; + g_pTraingSetTimeView = this; + } + + TrainingSetTimeView::~TrainingSetTimeView() + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingSetTimeView::~TrainingSetTimeView"); + SetTimeScrollView->RemoveAll(); + // 删除Label + if (labeltitle_ != nullptr) + { + SetTimeScrollView->Remove(labeltitle_); + delete labeltitle_; + labeltitle_ = nullptr; + } + // 删除Button + if (buttonok_ != nullptr) + { + SetTimeScrollView->Remove(buttonok_); + delete buttonok_; + buttonok_ = nullptr; + } + + // 删除滚动选择器 + if (calPicker_ != nullptr) + { + SetTimeScrollView->Remove(calPicker_); + delete calPicker_; + calPicker_ = nullptr; + } + + // 删除容器 + if (SetTimeScrollView != nullptr) + { + SetTimeScrollView->RemoveAll(); // 移除容器中的所有组件 + delete SetTimeScrollView; + SetTimeScrollView = nullptr; + } + g_pTraingSetTimeView = nullptr; + } + + TrainingSetTimeView *TrainingSetTimeView::GetInstance() + { + + return g_pTraingSetTimeView; + } + + /* + 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 TrainingSetTimeView::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 minTime = 10; + int maxTime = 600; + int interval = 10; + std::vector TimeValues = GenerateTimeValues(minTime, maxTime, interval); + + const char **values = new const char *[TimeValues.size()]; + for (size_t i = 0; i < TimeValues.size(); i++) + { + values[i] = TimeValues[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, TimeValues.size()); + // 将 UIPicker 设置为显示 + picker->SetVisible(true); + } + + /* InitView:初始化界面*/ + UIScrollView *TrainingSetTimeView ::SetTimeViewInit() + { + /* -------------------------------------------------------------------------- */ + SetTimeScrollView = new UIScrollView(); + if (SetTimeScrollView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingSetTimeView::new SetTimeScrollView fail"); + return nullptr; + } + SetTimeScrollView->SetPosition(0, 0); + SetTimeScrollView->Resize(VERTICAL_RESOLUTION, HORIZONTAL_RESOLUTION); + SetTimeScrollView->SetScrollBlankSize(35); + SetTimeScrollView->SetReboundSize(50); + SetTimeScrollView->SetDirection(1); + // 增加拖拽监听 + UIView::OnDragListener *draglistener = static_cast(new TraingSetPresenter()); + if (draglistener == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "BloodView::draglistener can not be nullptr!"); + return nullptr; + } + SetTimeScrollView->SetOnDragListener(draglistener); + SetTimeScrollView->SetTouchable(true); + SetTimeScrollView->SetDraggable(true); + SetTimeScrollView->SetVerticalScrollState(false); // 禁止垂直滑动 + /* -------------------------------------------------------------------------- */ + // 初始化Lable + TraingModel::GetInstance()->InitLabel(labeltitle_, 83, 50, 300, 35, "label1", "时长(分钟)", DEFAULT_VECTOR_FONT_FILENAME, 30); + SetTimeScrollView->Add(labeltitle_); + + // 初始化UIPicker + InitUIPicker(calPicker_, 43, 106, 380, 240, "uiPicker"); + SetTimeScrollView->Add(calPicker_); + // 初始化Button + TraingModel::GetInstance()->InitButtonExt(buttonok_, 0, 366, 466, 100, BUTTONTIMEOK, STR_OK, 30); + // Set additional property + buttonok_->SetImageSrc(BUTTONOK_IMAGE, BUTTONOK_IMAGE); + buttonok_->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); + SetTimeScrollView->Add(buttonok_); + + return SetTimeScrollView; + } +}