#include "TjdUiAppSleepPresenter.h" #include "NativeAbility.h" #include "TjdUiAppSleepView.h" #include "TjdUiRegisterManager.h" #include "dock/input_device.h" #include "sys_config.h" #include using namespace OHOS; #define ENABLE_PRINT_INFO 1 #if ENABLE_PRINT_INFO #define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制 #define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开 #define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开 #define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印 #else #define static_print_info(...) #define static_print_warn(...) #define static_print_error(...) #define static_print_debug(...) #endif namespace TJD { TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_SLEEP, TjdUiAppSleepView, TjdUiAppSleepPresenter, IMG_MENU_LIST_MENU_SLEEP, STR_ID_02); // clang-format off #define DRAG_EXIT_DISTANCE 170 // clang-format on static TjdUiAppSleepPresenter *g_pv_AppSleepPresenter = nullptr; TjdUiAppSleepPresenter::TjdUiAppSleepPresenter() { g_pv_AppSleepPresenter = this; model = &TjdUiAppSleepModel::GetInstance(); } TjdUiAppSleepPresenter::~TjdUiAppSleepPresenter() { g_pv_AppSleepPresenter = nullptr; } TjdUiAppSleepPresenter *TjdUiAppSleepPresenter::GetInstance(void) { return g_pv_AppSleepPresenter; } void TjdUiAppSleepPresenter::OnStart() { static_print_info("[TjdUiAppSleepPresenter]::%s", __func__); TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE); } void TjdUiAppSleepPresenter::OnResume() { static_print_info("[TjdUiAppSleepPresenter]::%s", __func__); Presenter::OnResume(); UpdateView(); if (view_->GetSwipeView()) { view_->GetSwipeView()->RequestFocus(); view_->GetSwipeView()->SetRotateFactor(1.0); } } void TjdUiAppSleepPresenter::OnPause() { static_print_info("[TjdUiAppSleepPresenter]::%s", __func__); Presenter::OnPause(); if (view_->GetSwipeView()) { view_->GetSwipeView()->ClearFocus(); } } void TjdUiAppSleepPresenter::OnStop() { static_print_info("[TjdUiAppSleepPresenter]::%s", __func__); TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE); } bool TjdUiAppSleepPresenter::OnKeyAct(UIView &view, const KeyEvent &event) { if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } ExitSleepView(); return false; } void TjdUiAppSleepPresenter::ExitSleepView(void) { NativeAbility::GetInstance().ChangePreSlice(); } void TjdUiAppSleepPresenter::UpdateView(void) { uint8_t wakeupPersent; uint8_t blinkPersent; uint8_t deepPersent; uint8_t lightPersent; uint16_t deepTime; uint16_t lightTime; uint16_t wakeupTime; uint16_t blinkTime; blinkTime = model->GetBlinkTime(); wakeupTime = model->GetWakeupTime(); deepTime = model->GetDeepSleepTime(); lightTime = model->GetLightSleepTime(); totalSleepTime = model->GetTotalSleepTime(); // blinkTime = 45; // 假值:眨眼时间 // wakeupTime = 15; // 假值:清醒时间 // deepTime = 150; // 假值:深睡时间 // lightTime = 90; // 假值:浅睡时间 // totalSleepTime = 300; // 总时间 if (totalSleepTime == 0) { deepPersent = 0; lightPersent = 0; wakeupPersent = 0; blinkPersent = 0; } else { deepPersent = (deepTime / (float)totalSleepTime) * 100; lightPersent = (lightTime / (float)totalSleepTime) * 100; blinkPersent = (blinkTime / (float)totalSleepTime) * 100; wakeupPersent = 100 - deepPersent - lightPersent - blinkPersent; } uint8_t valid_day = 0; uint32_t sum_time = 0; for (int i = 0; i < 7; i++) { uint16_t blinkTime = model->GetBlinkSleepTimeArray()[i]; uint16_t wakeupTime = model->GetWakeupSleepTimeArray()[i]; uint16_t lightTime = model->GetLightSleepTimeArray()[i]; uint16_t deepTime = model->GetDeepSleepTimeArray()[i]; totalSleepTimeArray[i] = model->GetTotalSleepTimeArray()[i]; maxWeekSleepTime = maxWeekSleepTime > totalSleepTimeArray[i] ? maxWeekSleepTime : totalSleepTimeArray[i]; if (totalSleepTimeArray[i]) { valid_day++; sum_time += totalSleepTimeArray[i]; } } view_->UpdateData(TOTAL_TIME, model->GenerateTimeString(totalSleepTime).c_str()); view_->UpdateData(BLINK_TIME, model->GenerateTimeString(blinkTime).c_str()); view_->UpdateData(WAKEUP_TIME, model->GenerateTimeString(wakeupTime).c_str()); view_->UpdateData(DEEP_TIME, model->GenerateTimeString(deepTime).c_str()); view_->UpdateData(LIGHT_TIME, model->GenerateTimeString(lightTime).c_str()); if (deepPersent == 0) view_->UpdateData(DEEP_PERSENT, (std::string("--") + "%").c_str()); else view_->UpdateData(DEEP_PERSENT, (std::to_string(deepPersent) + "%").c_str()); if (lightPersent == 0) view_->UpdateData(LIGHT_PERSENT, (std::string("--") + "%").c_str()); else view_->UpdateData(LIGHT_PERSENT, (std::to_string(lightPersent) + "%").c_str()); if (blinkPersent == 0) view_->UpdateData(BLINK_PERSENT, (std::string("--") + "%").c_str()); else view_->UpdateData(BLINK_PERSENT, (std::to_string(blinkPersent) + "%").c_str()); if (wakeupPersent == 0) view_->UpdateData(WAKEUP_PERSENT, (std::string("--") + "%").c_str()); else view_->UpdateData(WAKEUP_PERSENT, (std::to_string(wakeupPersent) + "%").c_str()); view_->UpdateData(BLINK_SLIDER, (blinkPersent > 98) ? 98 : ((blinkPersent < 2) ? 2 : blinkPersent)); view_->UpdateData(WAKEUP_SLIDER, (wakeupPersent > 98) ? 98 : ((wakeupPersent < 2) ? 2 : wakeupPersent)); view_->UpdateData(DEEP_SLIDER, (deepPersent > 98) ? 98 : ((deepPersent < 2) ? 2 : deepPersent)); view_->UpdateData(LIGHT_SLIDER, (lightPersent > 98) ? 98 : ((lightPersent < 2) ? 2 : lightPersent)); if (valid_day == 0) return; averageWeekSleepTime = sum_time / valid_day; view_->UpdateData(AVERAGE_TIME, model->GenerateTimeString(averageWeekSleepTime).c_str()); view_->UpdateData(BLINK_CHART, model->GetBlinkSleepTimeArray(), maxWeekSleepTime); view_->UpdateData(WAKEUP_CHART, model->GetWakeupSleepTimeArray(), maxWeekSleepTime); view_->UpdateData(LIGHT_CHART, model->GetLightSleepTimeArray(), maxWeekSleepTime); view_->UpdateData(DEEP_CHART, model->GetDeepSleepTimeArray(), maxWeekSleepTime); static_print_debug("UpdateView end"); } } // namespace TJD