#include "TjdUiAppBreathingPresenter.h" #include "TjdUiAppBreathingView.h" #include "power_display_service.h" #include "rtc_api.h" #include "service_hrsensor.h" #include "sql_fit.h" #include "sql_setting.h" #include "wearable_log.h" #include "TjdUiRegisterManager.h" namespace TJD { TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_BREATHING, TjdUiAppBreathingView, TjdUiAppBreathingPresenter, IMG_MENU_LIST_MENU_BREATHE, STR_ID_04); static TjdUiAppBreathingPresenter *g_pv_AppBreathingPresenter = nullptr; static bool g_pv_isExit_{true}; TjdUiAppBreathingPresenter::TjdUiAppBreathingPresenter() { g_pv_AppBreathingPresenter = this; } TjdUiAppBreathingPresenter::~TjdUiAppBreathingPresenter() { g_pv_AppBreathingPresenter = nullptr; } TjdUiAppBreathingPresenter *TjdUiAppBreathingPresenter::GetInstance(void) { return g_pv_AppBreathingPresenter; } static void OutTimeCallBackProc1(void *param) { TjdUiAppBreathingView::GetInstance()->StartAnimator(); } static void OutTimeCallBack1(void *param) { GraphicService::GetInstance()->PostGraphicEvent(std::bind(&OutTimeCallBackProc1, param)); } static void OutTimeCallBackProc2(void *param) { TjdUiAppBreathingView::GetInstance()->ChangeLabel1(); } static void OutTimeCallBack2(void *param) { GraphicService::GetInstance()->PostGraphicEvent(std::bind(&OutTimeCallBackProc2, param)); } static void OutTimeCallBackProc3(void *param) { TjdUiAppBreathingView::GetInstance()->ChangeLabel2(); } static void OutTimeCallBack3(void *param) { GraphicService::GetInstance()->PostGraphicEvent(std::bind(&OutTimeCallBackProc3, param)); } uint8_t TjdUiAppBreathingPresenter::BreathingHeartRateHandler(BreathingHeartRate action, void *param, int8_t mins) { uint8_t ret = 0; hr_api_info_t hr_api_info = {HR_SERVICE_UI_BREATHING, mins * 60 * 1000}; service_hrs_api *hrsensorInfo = tjd_service_hrs_get_ops(); struct rtc_time localTime; switch (action) { case BreathingHeartRate::Start: hrsensorInfo->open(hr_api_info); break; case BreathingHeartRate::Stop: hrsensorInfo->close(); break; case BreathingHeartRate::GetVaule: tjd_driver_rtc_get_ops()->get_rtc_time(&localTime); ret = sql_fit_get_last_hr(localTime.tm_wday); break; default: break; } return ret; } void TjdUiAppBreathingPresenter::Notify() { printf("TjdUiAppBreathingPresenter notify changeFlag1 = %d\r\n", changeFlag1); if (changeFlag1) { if (num1 == 0) { printf("start breath\r\n"); } num1++; num2++; if (num2 >= 6) { num3++; num4++; } if (num1 >= 120 * min + 6) { printf("finish breath\r\n"); BreathingHeartRateHandler(BreathingHeartRate::Stop, nullptr, min); hrnum = BreathingHeartRateHandler(BreathingHeartRate::GetVaule, nullptr, min); TjdUiAppBreathingView::GetInstance()->StopAnimator(hrnum); printf("hr =%d\r\n", hrnum); num1 = 0; num2 = 0; num3 = 0; num4 = 0; changeFlag1 = !changeFlag1; } if (num2 == 6) { OutTimeCallBack1(nullptr); hrnum = BreathingHeartRateHandler(BreathingHeartRate::Start, nullptr, min); } if (model1) { if (num3 == 12) { OutTimeCallBack2(nullptr); num3 = 0; num4 = 0; numFlag = true; } if (num4 == 8 && numFlag) { OutTimeCallBack3(nullptr); num3 = 0; numFlag = false; } } if (model2) { if (num3 == 9) { OutTimeCallBack2(nullptr); num3 = 0; num4 = 0; numFlag = true; } if (num4 == 6 && numFlag) { OutTimeCallBack3(nullptr); num3 = 0; numFlag = false; } } if (model3) { if (num3 == 6) { OutTimeCallBack2(nullptr); num3 = -1; num4 = 0; numFlag = true; } if (num4 == 6 && numFlag) { OutTimeCallBack3(nullptr); num3 = 0; numFlag = false; } } } } void TjdUiAppBreathingPresenter::OnStart() { TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE); SetPeriod(496); } void TjdUiAppBreathingPresenter::OnPause() { Presenter::OnPause(); } void TjdUiAppBreathingPresenter::OnResume() { printf("TjdUiAppBreathingPresenter onresume\r\n"); Presenter::OnResume(); } void TjdUiAppBreathingPresenter::OnStop() { TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE); } bool TjdUiAppBreathingPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { printf("TjdUiAppBreathingPresenter onclick, viewId = %s\r\n", view.GetViewId()); TjdUiAppBreathingView *breathingView = TjdUiAppBreathingView::GetInstance(); int8_t hr_num = 0; std::string viewId = view.GetViewId(); if (viewId.empty()) { return false; } if (viewId == TIMEBREATHING_ID) { breathingView->ShowView(BreathingViewIndex::BREATHING_CHOOSE_VIEW, BreathingViewIndex::BREATHING_TIME_VIEW); return true; } else if (viewId == MODELBREATHING_ID) { breathingView->ShowView(BreathingViewIndex::BREATHING_CHOOSE_VIEW, BreathingViewIndex::BREATHING_MODEL_VIEW); return true; } else if (viewId == STARTBREATHING_ID || viewId == STARTBACKGROUND_ID) { breathingView->ShowView(BreathingViewIndex::BREATHING_CHOOSE_VIEW, BreathingViewIndex::BREATHING_START_VIEW); // hr_num=breathingView->hr_breathing(); changeFlag1 = true; breathingView->StartTime(3, 0); breathingView->ChooseModel(); return true; } else if (viewId == FINISHED_ID) { breathingView->ShowView(BreathingViewIndex::BREATHING_FINISH_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); return true; } else if (viewId == TIME_LABEL1_ID) { breathingView->Addselect(1); min = 1; return true; } else if (viewId == TIME_LABEL2_ID) { breathingView->Addselect(2); min = 2; return true; } else if (viewId == TIME_LABEL3_ID) { breathingView->Addselect(3); min = 3; return true; } else if (viewId == MODEL_LABEL1_ID) { breathingView->Addselect(4); model1 = true; model2 = false; model3 = false; return true; } else if (viewId == MODEL_LABEL2_ID) { breathingView->Addselect(5); model1 = false; model2 = true; model3 = false; return true; } else if (viewId == MODEL_LABEL3_ID) { breathingView->Addselect(6); model1 = false; model2 = false; model3 = true; return true; } else { return true; } return false; } void TjdUiAppBreathingPresenter::ViewExitEvent(OHOS::UIView &view, const OHOS::DragEvent &event) { g_pv_isExit_ = true; std::string viewId_ = view.GetViewId(); printf("TjdUiAppBreathingPresenter ondragend\r\n"); TjdUiAppBreathingView *breathingView = TjdUiAppBreathingView::GetInstance(); if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_LEFT_TO_RIGHT) { if (breathingView->GetCurrentView() == BreathingViewIndex::BREATHING_TIME_VIEW) { breathingView->ShowView(BreathingViewIndex::BREATHING_TIME_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); g_pv_isExit_ = false; } if (breathingView->GetCurrentView() == BreathingViewIndex::BREATHING_MODEL_VIEW) { breathingView->ShowView(BreathingViewIndex::BREATHING_MODEL_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); g_pv_isExit_ = false; } if (breathingView->GetCurrentView() == BreathingViewIndex::BREATHING_START_VIEW) { breathingView->ShowView(BreathingViewIndex::BREATHING_START_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); breathingView->GetNum(3, 0); num1 = 0; num2 = 0; changeFlag1 = false; g_pv_isExit_ = false; } if (breathingView->GetCurrentView() == BreathingViewIndex::BREATHING_FINISH_VIEW) { breathingView->ShowView(BreathingViewIndex::BREATHING_FINISH_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); g_pv_isExit_ = false; } if (breathingView->GetCurrentView() == BreathingViewIndex::BREATHING_ANIMATOR_VIEW) { breathingView->ShowView(BreathingViewIndex::BREATHING_ANIMATOR_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); BreathingHeartRateHandler(BreathingHeartRate::Stop, nullptr, 0); breathingView->GetNum(3, 0); num1 = 0; num2 = 0; num3 = 0; num4 = 0; numFlag = false; changeFlag1 = false; g_pv_isExit_ = false; } } if (breathingView->GetCurrentView() == BreathingViewIndex::BREATHING_CHOOSE_VIEW && g_pv_isExit_) { if (event.GetDragDirection() == OHOS::DragEvent::DIRECTION_LEFT_TO_RIGHT) { OHOS::NativeAbility::GetInstance().ChangePreSlice(); } } return; } bool TjdUiAppBreathingPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { UNUSED(view); backFlag = true; uint8_t state = event.GetState(); uint16_t keyid = event.GetKeyId(); TjdUiAppBreathingView *breathView = TjdUiAppBreathingView::GetInstance(); if (event.GetState() == OHOS::InputDevice::STATE_RELEASE && event.GetKeyId() == 4165) { if (breathView->GetCurrentView() == BreathingViewIndex::BREATHING_CHOOSE_VIEW) { OHOS::NativeAbility::GetInstance().ChangePreSlice(); } if (breathView->GetCurrentView() == BreathingViewIndex::BREATHING_MODEL_VIEW && backFlag) { breathView->ShowView(BreathingViewIndex::BREATHING_MODEL_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); backFlag = false; } if (breathView->GetCurrentView() == BreathingViewIndex::BREATHING_TIME_VIEW && backFlag) { breathView->ShowView(BreathingViewIndex::BREATHING_TIME_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); backFlag = false; } if (breathView->GetCurrentView() == BreathingViewIndex::BREATHING_FINISH_VIEW && backFlag) { breathView->ShowView(BreathingViewIndex::BREATHING_FINISH_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); backFlag = false; } if (breathView->GetCurrentView() == BreathingViewIndex::BREATHING_START_VIEW && backFlag) { breathView->ShowView(BreathingViewIndex::BREATHING_START_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); breathView->GetNum(3, 0); num1 = 0; num2 = 0; changeFlag1 = false; backFlag = false; } if (breathView->GetCurrentView() == BreathingViewIndex::BREATHING_ANIMATOR_VIEW && backFlag) { breathView->ShowView(BreathingViewIndex::BREATHING_ANIMATOR_VIEW, BreathingViewIndex::BREATHING_CHOOSE_VIEW); BreathingHeartRateHandler(BreathingHeartRate::Stop, nullptr, 0); num1 = 0; num2 = 0; num3 = 0; num4 = 0; numFlag = false; changeFlag1 = false; backFlag = false; } return true; } return false; } } // namespace TJD