From 61daabf12634ee55900a998191f66bc0f302a7db Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Mon, 4 Dec 2023 11:36:00 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=AD=A3=E5=B8=B8=E8=AE=AD?= =?utf8?q?=E7=BB=83=E5=88=9D=E5=A7=8B=E7=95=8C=E9=9D=A2=EF=BC=9B=E4=BC=98?= =?utf8?q?=E5=8C=96=E5=8F=B3=E6=BB=91=EF=BC=9B=E6=B7=BB=E5=8A=A0=E8=B5=84?= =?utf8?q?=E6=BA=90=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Resource/res/Training/Go.bin | Bin 0 -> 27224 bytes .../wearable/nativeapp/CMakeLists.txt | 2 + .../nativelauncher/include/AppViewIDs.h | 1 + .../nativelauncher/include/NativeLauncher.h | 1 + .../nativelauncher/src/NativeLauncher.cpp | 8 + .../traing/include/TraingNomalPresenter.h | 33 +++ .../nativeui/traing/include/TraingNomalView.h | 60 +++++ .../traing/src/TraingLimitPresenter.cpp | 7 +- .../traing/src/TraingMorePresenter.cpp | 3 +- .../traing/src/TraingNomalPresenter.cpp | 85 ++++++++ .../nativeui/traing/src/TraingNomalView.cpp | 206 ++++++++++++++++++ .../nativeui/traing/src/TraingPresenter.cpp | 9 +- 12 files changed, 407 insertions(+), 8 deletions(-) create mode 100644 Resource/res/Training/Go.bin create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalPresenter.h create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingNomalView.h create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp create mode 100644 code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp diff --git a/Resource/res/Training/Go.bin b/Resource/res/Training/Go.bin new file mode 100644 index 0000000000000000000000000000000000000000..4ae9a3879e9f3024f73b1e2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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; } -- 2.17.1