#include "TjdUiAppCalendarPresenter.h" #include "NativeAbility.h" #include "TjdUiAppCalendarModel.h" #include "TjdUiAppCalendarView.h" #include "dock/input_device.h" #include "graphic_service.h" #include "sys_config.h" #include "TjdUiRegisterManager.h" namespace TJD { TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_CALENDAR, TjdUiAppCalendarView, TjdUiAppCalendarPresenter, IMG_MENU_LIST_MENU_CALENDAR, STR_ID_16); #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 static TjdUiAppCalendarPresenter *g_pv_AppCalendarPresenter = nullptr; TjdUiAppCalendarPresenter::TjdUiAppCalendarPresenter() { g_pv_AppCalendarPresenter = this; } TjdUiAppCalendarPresenter::~TjdUiAppCalendarPresenter() { g_pv_AppCalendarPresenter = nullptr; } TjdUiAppCalendarPresenter &TjdUiAppCalendarPresenter::GetInstance(void) { return *g_pv_AppCalendarPresenter; } void TjdUiAppCalendarPresenter::OnStart() { TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);} void TjdUiAppCalendarPresenter::OnStop() { TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE); } void TjdUiAppCalendarPresenter::OnPause() { Presenter::OnPause(); } void TjdUiAppCalendarPresenter::OnResume() { Presenter::OnResume(); } bool TjdUiAppCalendarPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { static_print_debug("CalendarOnClickListener::OnClick"); uint16_t year = 0; uint8_t month = 0; std::string dateString = (char *)(CalendarView::GetInstance()->GetDateLabel()->GetText()); // 查找点号的位置 size_t dotPos = dateString.find('.'); if (dotPos != std::string::npos) { // 提取年份和月份 std::string yearStr = dateString.substr(0, dotPos); std::string monthStr = dateString.substr(dotPos + 1); year = std::stoi(yearStr); month = std::stoi(monthStr); } CalendarView::CurrentDateInfo curDateInfo = CalendarView::GetInstance()->GetCurrentDateInfo(); auto touchX = event.GetCurrentPos().x; auto leftThird = 1 * 466 / 3; auto rightThird = 2 * 466 / 3; if (touchX < leftThird) { month--; if (month == 0) { month = 12; year--; } CalendarView::GetInstance()->UpdateInfo(curDateInfo, month, year); } else if (touchX > rightThird) { month++; if (month == 13) { month = 1; year++; } CalendarView::GetInstance()->UpdateInfo(curDateInfo, month, year); } TjdUiAppCalendarView::GetInstance()->GetMainView()->Invalidate(); return true; } void TjdUiAppCalendarPresenter::ViewExitEvent(bool isSwipe) { OHOS::NativeAbility::GetInstance().ChangePreSlice(); } bool TjdUiAppCalendarPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event) { if(!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)) { return true; } ViewExitEvent(false); return true; } void TjdUiAppCalendarPresenter::OnClickTrans(OHOS::UIView &view) {} } // namespace TJD