From: Caisking <3449750381@qq.com> Date: Mon, 4 Dec 2023 03:36:00 +0000 (+0800) Subject: 增加正常训练初始界面;优化右滑;添加资源文件 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=61daabf12634ee55900a998191f66bc0f302a7db;p=mirrors%2FFD230.git 增加正常训练初始界面;优化右滑;添加资源文件 --- diff --git a/Resource/res/Training/Go.bin b/Resource/res/Training/Go.bin new file mode 100644 index 000000000..4ae9a3879 Binary files /dev/null and b/Resource/res/Training/Go.bin differ diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index bc57c5e38..325abe8fc 100644 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -248,6 +248,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingMorePresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingLimitView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingLimitPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingNomalView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingNomalPresenter.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 676b81eb6..15d972092 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -79,6 +79,7 @@ typedef enum : uint16_t VIEW_TRAINING, // 训练 VIEW_TRAININGMORE, // 更多训练 VIEW_TRAININGLIMIT, // 极限运动子列表 + VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外) VIEW_TRAINING_RECORD, // 训练记录 VIEW_BLOODPRESSURE, // 昨日睡眠时间 diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index 1f2ba95fc..595d963a5 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -65,6 +65,7 @@ public: void InitTraingSlice(void); void InitTraingMoreSlice(void); void InitTraingLimitSlice(void); + void InitTraingNomalSlice(void); void InitUIDisplayBrightnessSlice(void); void InitBlueToothSettingSlice(void); void InitBrightnessControlSlice(void); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index 1592d61f3..8e9fb1bbe 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -107,6 +107,8 @@ #include "traing/include/TraingMoreView.h" #include "traing/include/TraingLimitPresenter.h" #include "traing/include/TraingLimitView.h" +#include "traing/include/TraingNomalPresenter.h" +#include "traing/include/TraingNomalView.h" #include "displaybrightness/include/DisplayBrightnessPresenter.h" #include "displaybrightness/include/DisplayBrightnessView.h" #include "bluetoothofsetting/include/BlueToothOfSettingPresenter.h" @@ -230,6 +232,7 @@ static const AppViewMapper SLICE_MAPPER[] = { {VIEW_TRAINING, &NativeLauncher::InitTraingSlice}, //训练 {VIEW_TRAININGMORE, &NativeLauncher::InitTraingMoreSlice}, //更多训练 {VIEW_TRAININGLIMIT, &NativeLauncher::InitTraingLimitSlice}, //极限训练 + {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice}, //正常训练初始界面 {VIEW_DISPLAY_BRIGHTNESS,&NativeLauncher::InitUIDisplayBrightnessSlice}, //显示与亮度的实例化地址 {VIEW_CONNECT_BLUETOOTH,&NativeLauncher::InitBlueToothSettingSlice}, //蓝牙设置的实例化地址 @@ -803,6 +806,11 @@ void NativeLauncher::InitTraingLimitSlice(void) SliceProxy *trainglimitview = new AbilitySliceProxy; NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGLIMIT, trainglimitview); } +void NativeLauncher::InitTraingNomalSlice(void) +{ + SliceProxy *traingnomalview = new AbilitySliceProxy; + NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGNOMAL, traingnomalview); +} //DisplayBrightness的实例化 void NativeLauncher::InitUIDisplayBrightnessSlice(void) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalPresenter.h new file mode 100644 index 000000000..9d3d9bb7b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingNomal_PRESENTER_H +#define _TraingNomal_PRESENTER_H + +#include "Presenter.h" +#include "TraingNomalView.h" + +namespace OHOS +{ + class TraingNomalView; + + class TraingNomalPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingNomalPresenter(); + virtual ~TraingNomalPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingNomalPresenter *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/TraingNomalView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalView.h new file mode 100644 index 000000000..0d6ba03fd --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalView.h @@ -0,0 +1,60 @@ +#ifndef _TraingNomal_VIEW_H +#define _TraingNomal_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 "TraingNomalPresenter.h" +namespace OHOS +{ +#define BUTTONGO "button1" +#define BUTTONSET "button2" + + class TraingNomalPresenter; + class TraingNomalView : public View + { + + public: + TraingNomalView(); + virtual ~TraingNomalView(); + static TraingNomalView *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}; + TraingNomalView(TraingNomalView &&) = delete; + TraingNomalView &operator=(TraingNomalView &&) = delete; + + UIViewGroup *container_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingNomal_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingLimitPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingLimitPresenter.cpp index 0c5da9f3b..4369a5e5c 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingLimitPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingLimitPresenter.cpp @@ -58,7 +58,8 @@ namespace OHOS bool TraingLimitPresenter::OnDrag(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE); } @@ -69,9 +70,9 @@ namespace OHOS bool TraingLimitPresenter::OnClick(UIView &view, const ClickEvent &event) { // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), " ") == 0) + if (strcmp(view.GetViewId(), BUTTON1) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); } if (strcmp(view.GetViewId(), "Remind") == 0) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingMorePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingMorePresenter.cpp index 80b3af686..44b698949 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingMorePresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingMorePresenter.cpp @@ -58,7 +58,8 @@ namespace OHOS bool TraingMorePresenter::OnDrag(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING); } diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp new file mode 100644 index 000000000..fd81f3d24 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp @@ -0,0 +1,85 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingNomalPresenter.h" +// #include "TraingNomalView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingNomalPresenter *g_pTraingNomalPresenter = nullptr; + + TraingNomalPresenter::TraingNomalPresenter() + { + + g_pTraingNomalPresenter = this; + } + + TraingNomalPresenter::~TraingNomalPresenter() + { + + g_pTraingNomalPresenter = nullptr; + } + + TraingNomalPresenter *TraingNomalPresenter::GetInstance() + { + + return g_pTraingNomalPresenter; + } + + void TraingNomalPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingNomalPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingNomalPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingNomalPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingNomalPresenter::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_TRAININGMORE); + } + UNUSED(view); + return true; + } + + bool TraingNomalPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), " ") == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + if (strcmp(view.GetViewId(), "Remind") == 0) + { + // 模拟心率监测,等待20秒 + // std::this_thread::sleep_for(std::chrono::seconds(20)); + // NativeAbility::GetInstance().ChangeSlice(VIEW_TraingNomalREMIND); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp new file mode 100644 index 000000000..2ace50272 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp @@ -0,0 +1,206 @@ + +#include "traing/include/TraingNomalView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +namespace OHOS +{ + + static TraingNomalView *g_pTraingNomalView{nullptr}; + + TraingNomalView::TraingNomalView() + { + g_pTraingNomalView = this; + } + + TraingNomalView::~TraingNomalView() + { + DeInit(); + g_pTraingNomalView = nullptr; + } + + TraingNomalView *TraingNomalView::GetInstance() + { + + return g_pTraingNomalView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingNomalView::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 TraingNomalView::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); + // 设置按钮的点击事件监听器为 TraingNomalPresenter 的实例 + button->SetOnClickListener(static_cast(TraingNomalPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* InitView:初始化界面*/ + void TraingNomalView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Lable + InitLabel(label1_, 137, 52, 195, 35, "label1", "高空弹跳/蹦极", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label1_); + InitLabel(label2_, 160, 370, 146, 35, "label2", "设定目标 >", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label2_); + // 初始化Button + InitButton(button1_, 133, 133, 200, 200, BUTTONGO); + // Set additional property + char *button1defaultImgSrc = "/user/res/Training/Go.bin"; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + + InitButton(button2_, 160, 370, 146, 35, BUTTONSET); + button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);//设置为透明按键 + button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + button2_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); // 设置按下时的透明度为半透明 + + container_->Add(button1_); + container_->Add(button2_); + } + /* DeInit:删除组件*/ + void TraingNomalView::DeInit() + { + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (button1_ != nullptr) + { + delete button1_; + button1_ = nullptr; + } + if (button2_ != nullptr) + { + delete button2_; + button2_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + + void TraingNomalView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingNomalView::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(TraingNomalPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingNomalView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingNomalView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingNomalView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingPresenter.cpp index 27334e7b1..fb84c41bf 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingPresenter.cpp @@ -5,7 +5,7 @@ #include #include #include "traing/include/TraingPresenter.h" -//#include "TraingView.h" +// #include "TraingView.h" namespace OHOS { @@ -58,7 +58,8 @@ namespace OHOS bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event) { - if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) { NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); } @@ -76,8 +77,8 @@ namespace OHOS if (strcmp(view.GetViewId(), "Remind") == 0) { // 模拟心率监测,等待20秒 - //std::this_thread::sleep_for(std::chrono::seconds(20)); - //NativeAbility::GetInstance().ChangeSlice(VIEW_TraingREMIND); + // std::this_thread::sleep_for(std::chrono::seconds(20)); + // NativeAbility::GetInstance().ChangeSlice(VIEW_TraingREMIND); } return true; }