* @Date: 2024-04-15 10:55:58
* @LastEditors: Caisking 3449750381@qq.com
* @LastEditTime: 2024-04-16 17:33:11
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingPresenter.cpp
+ * @FilePath:
+ * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingPresenter.cpp
*/
#include "AppViewIDs.h"
-#include "components/ui_label_ext.h"
-#include "ui_resource_string.h"
-#include "NativeAbility.h"
#include "KeyInputListener.h"
-#include "custom_utils.h"
+#include "NativeAbility.h"
#include "common/key_code.h"
+#include "components/ui_label_ext.h"
+#include "custom_utils.h"
+#include "ui_resource_string.h"
-#include <iostream>
-#include <chrono>
-#include <thread>
-#include "traing/include/TraingPresenter.h"
#include "traing/include/TraingModel.h"
+#include "traing/include/TraingPresenter.h"
#include "uicomponents/UIComponents.h"
+#include <chrono>
+#include <iostream>
+#include <thread>
// #include "TraingView.h"
+#include "NativeRegisterManager.h"
#include "gfx_utils/mem_check.h"
-namespace OHOS
-{
+namespace OHOS {
+REGIST_MENU_PRO(VIEW_TRAINING, TraingView, TraingPresenter,
+ PNG_APPLIST_TRAINING_IMAGE_BIG, PNG_APPLIST_TRAINING_IMAGE,
+ PNG_APPLIST_TRAINING_IMAGE, "运动", STR_TRAINING);
- // 当前Presenter属性实例化的内存指针
- static TraingPresenter *g_pTraingPresenter = nullptr;
+// 当前Presenter属性实例化的内存指针
+static TraingPresenter *g_pTraingPresenter = nullptr;
- TraingPresenter::TraingPresenter()
- {
- g_pTraingPresenter = this;
+TraingPresenter::TraingPresenter() {
+ g_pTraingPresenter = this;
#ifdef MEM_CHECK
- MemCheck::GetInstance()->EnableLeakCheck(true);
+ MemCheck::GetInstance()->EnableLeakCheck(true);
#endif
- }
+}
- TraingPresenter::~TraingPresenter()
- {
- g_pTraingPresenter = nullptr;
+TraingPresenter::~TraingPresenter() {
+ g_pTraingPresenter = nullptr;
#ifdef MEM_CHECK
- MemCheck::GetInstance()->EnableLeakCheck(false);
+ MemCheck::GetInstance()->EnableLeakCheck(false);
#endif
- }
+}
- TraingPresenter *TraingPresenter::GetInstance()
- {
- return g_pTraingPresenter;
- }
+TraingPresenter *TraingPresenter::GetInstance() { return g_pTraingPresenter; }
- void TraingPresenter::OnStart()
- {
- Presenter<TraingView>::OnStart();
- }
+void TraingPresenter::OnStart() { Presenter<TraingView>::OnStart(); }
- void TraingPresenter::OnPause(void)
- {
- Presenter<TraingView>::OnPause();
- }
+void TraingPresenter::OnPause(void) { Presenter<TraingView>::OnPause(); }
- void TraingPresenter::OnResume(void)
- {
- Presenter<TraingView>::OnResume();
- }
+void TraingPresenter::OnResume(void) { Presenter<TraingView>::OnResume(); }
- void TraingPresenter::OnStop(void)
- {
- Presenter<TraingView>::OnStop();
- }
- // 回退函数 [ Slice 的 traingview {右滑只能回到applist}]
- void TraingPresenter::NavigateBack()
- {
- NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS);
- NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素
- }
- bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event)
- {
- return true;
- }
- bool TraingPresenter::OnDragEnd(UIView &view, const DragEvent &event)
- {
- UNUSED(view);
- if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
- NavigateBack();
- return true;
- }
+void TraingPresenter::OnStop(void) { Presenter<TraingView>::OnStop(); }
+// 回退函数 [ Slice 的 traingview {右滑只能回到applist}]
+void TraingPresenter::NavigateBack() {
+ NativeAbility::GetInstance().ChangeSlice(
+ VIEW_APPLIST, TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+ NativeAbility::GetInstance().ClearSliceIdStack(); // 清空所有SLiceId栈元素
+}
+bool TraingPresenter::OnDrag(UIView &view, const DragEvent &event) {
+ return true;
+}
+bool TraingPresenter::OnDragEnd(UIView &view, const DragEvent &event) {
+ UNUSED(view);
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)
+ NavigateBack();
+ return true;
+}
- bool TraingPresenter::OnClick(UIView &view, const ClickEvent &event)
- {
- if (strcmp(view.GetViewId(), BUTTON1) == 0)
- {
- NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
- TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING);
- }
- if (strcmp(view.GetViewId(), BUTTON3) == 0)
- {
- NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
- TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING);
- }
- if (strcmp(view.GetViewId(), BUTTONMORE) == 0)
- {
- NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE);
- }
- if (strcmp(view.GetViewId(), BUTTON2) == 0) {
- NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
- TraingModel::GetInstance()->SetSportEvent(
- STR_EXERCISE_FREETRAINING); //修改为自由训练
- }
- TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS);
- return true;
- }
+bool TraingPresenter::OnClick(UIView &view, const ClickEvent &event) {
+ if (strcmp(view.GetViewId(), BUTTON1) == 0) {
+ NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
+ TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORWALKING);
+ }
+ if (strcmp(view.GetViewId(), BUTTON3) == 0) {
+ NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
+ TraingModel::GetInstance()->SetSportEvent(STR_EXERCISE_OUTDOORRUNNING);
+ }
+ if (strcmp(view.GetViewId(), BUTTONMORE) == 0) {
+ NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGMORE);
+ }
+ if (strcmp(view.GetViewId(), BUTTON2) == 0) {
+ NativeAbility::GetInstance().EnterSlice(VIEW_TRAININGNOMAL);
+ TraingModel::GetInstance()->SetSportEvent(
+ STR_EXERCISE_FREETRAINING); //修改为自由训练
+ }
+ TraingModel::GetInstance()->SetSportType(Exercisetype::FITNESS);
+ return true;
+}
- // 增加按键事件
- bool TraingPresenter::OnKeyAct(UIView &view, const KeyEvent &event)
- {
- unsigned short keyID = event.GetKeyId();
- unsigned short keyState = event.GetState();
- // 如果是power键,且是亮屏状态,按键释放就返回上一级
- if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) &&
- keyState == 1 && uapi_get_screen_state() == 0)
- NavigateBack();
+// 增加按键事件
+bool TraingPresenter::OnKeyAct(UIView &view, const KeyEvent &event) {
+ unsigned short keyID = event.GetKeyId();
+ unsigned short keyState = event.GetState();
+ // 如果是power键,且是亮屏状态,按键释放就返回上一级
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) &&
+ keyState == 1 && uapi_get_screen_state() == 0)
+ NavigateBack();
- return true;
- }
+ return true;
}
+} // namespace OHOS