/*---------------------------------------------------------------------------- * Copyright (c) TJD Technologies Co., Ltd. 2024. All rights reserved. * * Description: * * Author: wuchangxin * * Create: 2024-8-24 *--------------------------------------------------------------------------*/ #include "TjdUiAppTimerView.h" #include "TjdUiImageIds.h" #include "TjdUiMemManage.h" #include "TjdUiMultiLanguageExt.h" #include "TjdUiUtils.h" #include "animator/animator_manager.h" #include "color.h" #include "common/image_cache_manager.h" #include "gfx_utils/color.h" #include "graphic_service.h" #include "hal_tick.h" #include "motor.h" #include "rtc_api.h" #include "sys_config.h" #include "ui_screennotify.h" #include "ui_view.h" #include #include #include using namespace OHOS; namespace TJD { #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 #define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_timer.bin" static uint32_t g_comeback_dial_interval = 5; static TjdUiAppTimerView *g_pv_TimerView = nullptr; static TimerRunningView *g_pv_TimerRunningView = nullptr; static OHOS::GraphicTimer *countDownTimer_ = nullptr; static TimerCustomSettingiew *g_pv_TimerCustomSettingiew = nullptr; static bool TimerIsRunning = false; // 计时器是否正在运行 static uint8_t g_TimerPickerIndex = 0; // 计时器选择器索引 bool GetTimerStatus() { return TimerIsRunning; } TimerViewIndex TjdUiAppTimerView::currentViewIndex_ = TIMER_VIEW_MAX; // clang-format off static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; } static void InitLabel(OHOS::UILabel &label, uint8_t size, int16_t x, int16_t y, const char *text) { label.SetFont(TJD_VECTOR_FONT_FILENAME, size); label.SetText(text); label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); label.SetPosition(x, y); } static void InitLabelExt(OHOS::UILabelExt &label, uint8_t size, int16_t x, int16_t y, uint16_t textId) { label.SetFont(TJD_VECTOR_FONT_FILENAME, size); label.SetTextId(textId); label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE); label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); label.SetPosition(x, y); } static void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text) { label.SetFont(TJD_VECTOR_FONT_FILENAME, size); // 上板子改字体!!!!!!!! label.SetText(text); label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); label.SetPosition(HorizontalCenter(label.GetWidth(), target), y); } static void InitLabelExtHorCenter(OHOS::UILabelExt &label, uint8_t size, int16_t y, int16_t target, uint16_t textId) { label.SetFont(TJD_VECTOR_FONT_FILENAME, size); // 上板子改字体!!!!!!!! label.SetTextId(textId); label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); label.SetPosition(HorizontalCenter(label.GetWidth(), target), y); } TimerPickerInfo g_timerPickerInfo[] = { {"1", STR_ID_129}, {"3", STR_ID_129}, {"5", STR_ID_129}, {"10", STR_ID_129}, {"15", STR_ID_129}, {"20", STR_ID_129}, {"1", STR_ID_551}, {"2", STR_ID_551}, }; uint16_t unitId[] = {STR_ID_281, STR_ID_129, STR_ID_559}; // clang-format on TjdUiAppTimerView::TjdUiAppTimerView() { g_pv_TimerView = this; } TjdUiAppTimerView::~TjdUiAppTimerView() { printf("TjdUiAppTimerView::~TjdUiAppTimerView\n"); g_TimerPickerIndex = 0; // 主界面退出清零 g_pv_TimerView = nullptr; } TjdUiAppTimerView *TjdUiAppTimerView::GetInstance(void) { return g_pv_TimerView; } #pragma region == == = 主监听器 == == = static void TimerIsRunningTimerCallBack(void *arg) { TimerViewOnListener *timerViewOnListener = static_cast(arg); auto timerRunningView = TimerRunningView::GetInstance(); timerRunningView->GetRemindLabel()->SetVisible(false); timerRunningView->GetCountDownLabel()->SetVisible(true); timerRunningView->Invalidate(); if (timerIsRunningTimer_ != nullptr) { timerIsRunningTimer_->Stop(); delete timerIsRunningTimer_; timerIsRunningTimer_ = nullptr; } } bool TimerViewOnListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { static_print_info("TimerViewOnListener::OnClick"); auto timerRunningView = TimerRunningView::GetInstance(); auto timerView = TjdUiAppTimerView::GetInstance(); if (view.GetViewId() == "imgRefresh_") { if (timerRunningView->touchTimerIndex_ < MAX_TIMER) { timerRunningView->InitView(); } else { TimerInfo curTime = TimerCustomSettingiew::GetInstance()->GetPickerSelectedTime(); timerRunningView->InitView(curTime); } countDownTimer_->Start(); TimerIsRunning = true; timerRunningView->lastTime = OHOS::HALTick::GetInstance().GetTime(); } else if (view.GetViewId() == "imgCancel_") { if (TimerIsRunning) { timerRunningView->GetCountDownLabel()->SetVisible(false); timerRunningView->GetRemindLabel()->SetVisible(true); timerRunningView->Invalidate(); uint64_t firstTimerTick = OHOS::HALTick::GetInstance().GetTime(); uint64_t curTimerTick = firstTimerTick; timerRunningView->CreateRunningTimer(); } else { timerView->ShowView(TIMER_MAIN_VIEW); // showView } } else if (view.GetViewId() == "PauseOrContinueBox_") { OHOS::UICheckBox *checkBox = static_cast(&view); if (checkBox->GetState() == OHOS::UICheckBox::SELECTED) { countDownTimer_->Stop(); TimerIsRunning = false; } else { countDownTimer_->Start(); timerRunningView->lastTime = OHOS::HALTick::GetInstance().GetTime(); } } else if (view.GetViewId() == "customBg_") { timerView->ShowView(TIMER_CUSTOM_SETTING_VIEW); // showView } else if (view.GetViewId() == "customImgConfirm_") { TimerInfo curTime = TimerCustomSettingiew::GetInstance()->GetPickerSelectedTime(); printf("curTime.hours:%d, curTime.minutes:%d, curTime.seconds:%d\n", curTime.hours, curTime.minutes, curTime.seconds); if (curTime.hours == 0 && curTime.minutes == 0 && curTime.seconds == 0) return true; timerView->ShowView(TIMER_RUNNING_VIEW); // showView timerRunningView->touchTimerIndex_ = view.GetViewIndex(); timerRunningView->InitView(curTime); countDownTimer_->Start(); TimerIsRunning = true; timerRunningView->lastTime = OHOS::HALTick::GetInstance().GetTime(); } else if (view.GetViewId() == "customImgCancel_") { timerView->ShowView(TIMER_MAIN_VIEW); // showView } return true; } #pragma endregion bool TimerUIScrollView::OnDragStartEvent(const OHOS::DragEvent &event) { if (TjdUiAppTimerView::currentViewIndex_ != TIMER_MAIN_VIEW) { return true; } isOnStart_ = true; return OHOS::UIScrollViewNested::OnDragStartEvent(event); } bool TimerUIScrollView::OnDragEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } if (TjdUiAppTimerView::currentViewIndex_ != TIMER_MAIN_VIEW) { return true; } return OHOS::UIScrollViewNested::OnDragEvent(event); } bool TimerUIScrollView::OnDragEndEvent(const OHOS::DragEvent &event) { if (!isOnStart_) { return true; } isOnStart_ = false; if (TjdUiAppTimerView::currentViewIndex_ != TIMER_MAIN_VIEW) { return true; } return OHOS::UIScrollViewNested::OnDragEndEvent(event); } void TjdUiAppTimerView::OnStart() { static_print_info("TjdUiAppTimerView::OnStart"); View::OnStart(); OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(IMAGE_BIN_PATH); if (mainView_ == nullptr) { mainView_ = new TimerUIScrollView(); } mainView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); // mainView_->SetOnDragListener(&TjdUiAppTimerPresenter::GetInstance()); viewManager_[TIMER_MAIN_VIEW] = new TimerMainView(); viewManager_[TIMER_RUNNING_VIEW] = new TimerRunningView(); viewManager_[TIMER_RUNNING_VIEW]->HideView(); mainView_->Add(viewManager_[TIMER_MAIN_VIEW]); mainView_->Add(viewManager_[TIMER_RUNNING_VIEW]); AddViewToRootContainer(mainView_); ShowView(TIMER_MAIN_VIEW); } void TjdUiAppTimerView::InitTargetView(TimerViewIndex index) { if (viewManager_[index] != nullptr) { return; } // clang-format off switch (index) { case TIMER_MAIN_VIEW: viewManager_[index] = new TimerMainView(); break; case TIMER_RUNNING_VIEW: viewManager_[index] = new TimerRunningView(); break; case TIMER_CUSTOM_SETTING_VIEW: viewManager_[index] = new TimerCustomSettingiew(); break; default: break; } // clang-format on if (viewManager_[index] == nullptr) { return; } viewManager_[index]->SetPosition(0, 0); viewManager_[index]->SetVisible(false); mainView_->Add(viewManager_[index]); } void TjdUiAppTimerView::ShowView(TimerViewIndex showIndex) { if (showIndex < 0 || showIndex >= TIMER_VIEW_MAX) { return; } InitTargetView(showIndex); if (currentViewIndex_ >= 0 && currentViewIndex_ < TIMER_VIEW_MAX && viewManager_[currentViewIndex_] != nullptr) { viewManager_[currentViewIndex_]->HideView(); } if (viewManager_[showIndex] != nullptr) { viewManager_[showIndex]->ShowView(); } currentViewIndex_ = showIndex; } void TjdUiAppTimerView::OnStop() { printf("TjdUiAppTimerView::OnStop\n"); tjd_driver_motor_user_stop(); OHOS::FocusManager::GetInstance()->ClearFocus(); OHOS::RootView::GetInstance()->Remove(mainView_); if (mainView_ != nullptr) { mainView_->RemoveAll(); delete mainView_; mainView_ = nullptr; } for (uint8_t i = 0; i < TIMER_VIEW_MAX; i++) { if (viewManager_[i] != nullptr) { printf("TjdUiAppTimerView::OnStop delete viewManager_[%d]\n", i); viewManager_[i]->RemoveAll(); delete viewManager_[i]; viewManager_[i] = nullptr; } } OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH); } #pragma region == = 计时器主界面 == = bool TimerPickerOnListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event) { static_print_info("TimerPickerOnListener::OnClick"); TjdUiAppTimerView::GetInstance()->ShowView(TIMER_RUNNING_VIEW); TimerRunningView::GetInstance()->touchTimerIndex_ = view.GetViewIndex(); TimerRunningView::GetInstance()->InitView(); countDownTimer_->Start(); TimerIsRunning = true; TimerRunningView::GetInstance()->lastTime = OHOS::HALTick::GetInstance().GetTime(); return true; } TimerPicker::TimerPicker(TimerPickerInfo &info) { Resize(150, 150); SetTouchable(true); SetOnClickListener(&timerPickerOnListener); SetViewIndex(g_TimerPickerIndex++); auto image = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_BJ, IMAGE_BIN_PATH); timerPickerBg_.SetPosition(0, 0); timerPickerBg_.SetSrc(image); unit_.SetFont(TJD_VECTOR_FONT_FILENAME, 25); // 上板子改字体!!!!!!!! unit_.SetTextId(info.textId); unit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); unit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); unit_.SetPosition(HorizontalCenter(unit_.GetWidth(), 150), 87); unit_.SetTextColor(Color::GetColorFromRGBA(0x9f, 0x9f, 0x9f, 0xff)); InitLabelHorCenter(time_, 50, 28, 150, info.time); Add(&timerPickerBg_); Add(&time_); Add(&unit_); } TimerMainView::TimerMainView() { printf("TimerMainView::TimerMainView g_TimerPickerIndex = %d\n", g_TimerPickerIndex); uint8_t temp = 0; uint8_t column = 0; SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); SetTouchable(true); SetThrowDrag(true); SetSwipeACCLevel(10); // 0-255 SetDragACCLevel(15); // 5: drag acceleration SetScrollBlankSize(30); SetReboundSize(30); // 100: // SetRotateFactor(-10); SetRotateThreshold(4); SetYScrollBarVisible(true); if (OHOS::PageTransitionMgr::GetInstance().GetTopSlideBackImage() == nullptr) { SetOnDragListener(&TjdUiAppTimerPresenter::GetInstance()); } mainViewTitle_.SetFont(TJD_VECTOR_FONT_FILENAME, 28); // 上板子改字体!!!!!!!! mainViewTitle_.SetTextId(STR_ID_12); mainViewTitle_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); mainViewTitle_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); mainViewTitle_.SetPosition(HorizontalCenter(mainViewTitle_.GetWidth(), 466), 19); for (uint8_t i = 0; i < MAX_TIMER; i++) { if (temp > 1) { temp = 0; column++; } timerPicker_[i] = new TimerPicker(g_timerPickerInfo[i]); timerPicker_[i]->SetPosition(60 + temp * 190, 100 + column * 189); Add(timerPicker_[i]); temp++; } customBg_.SetPosition(49, 856, 368, 80); customBg_.SetStyle(STYLE_BACKGROUND_COLOR, 0xff006cf2); customBg_.SetStyle(STYLE_BORDER_RADIUS, 40); customBg_.SetViewId("customBg_"); customBg_.SetTouchable(true); customBg_.SetOnClickListener(&timerMainViewListener); // InitLabelHorCenter(customLabel_, 34, 872, 466, "自定义"); customLabel_.SetFont(TJD_VECTOR_FONT_FILENAME, 34); // 上板子改字体!!!!!!!! customLabel_.SetTextId(STR_ID_280); customLabel_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); customLabel_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); customLabel_.SetPosition(HorizontalCenter(customLabel_.GetWidth(), 466), 872); mainViewBg_.SetPosition(0, 956, 466, 92); Add(&mainViewTitle_); Add(&customBg_); Add(&customLabel_); Add(&mainViewBg_); } void TimerMainView::ShowView() { SetVisible(true); TjdUiUtils::ViewRequestFocus(*this); } TimerMainView::~TimerMainView() { RemoveAll(); printf("TimerMainView::~TimerMainView g_TimerPickerIndex = %d\n", g_TimerPickerIndex); for (uint8_t i = 0; i < MAX_TIMER; i++) { if (timerPicker_[i] != nullptr) { printf("TimerMainView::~TimerMainView delete timerPicker_[%d]\n", i); delete timerPicker_[i]; timerPicker_[i] = nullptr; } } } #pragma endregion //===计时器主界面=== #pragma region == = 计时器运行界面 == = static void TimerCallBack(void *arg) { GraphicService::GetInstance()->PostGraphicEvent(std::bind( [](void *arg) { auto timerRunningView = TimerRunningView::GetInstance(); TimerIsRunning = true; uint64_t curTimerTick = OHOS::HALTick::GetInstance().GetTime(); if (curTimerTick - (timerRunningView->lastTime) >= 1000) { std::string timeStr = timerRunningView->GetCountDownLabel()->GetText(); TimerInfo curTime = timerRunningView->ExtractTime(timeStr); uint64_t Value = curTime.hours * 60 * 60 + curTime.minutes * 60 + curTime.seconds - 1; timerRunningView->UpdateInfo(Value); timerRunningView->lastTime = curTimerTick; } }, arg)); } TimerRunningView::TimerRunningView() { g_pv_TimerRunningView = this; SetPosition(0, 0, 466, 466); SetTouchable(true); SetOnDragListener(&TjdUiAppTimerPresenter::GetInstance()); // InitLabelHorCenter(targetLabel_, 30, 139, 466, "1 分钟"); targetLabel_.SetFont(TJD_VECTOR_FONT_FILENAME, 30); // 上板子改字体!!!!!!!! std::string str = "1 " + std::string(FontGlobalManager::GetInstance()->GetText(STR_ID_129)); targetLabel_.SetText(str.c_str()); targetLabel_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); targetLabel_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); targetLabel_.SetPosition(HorizontalCenter(targetLabel_.GetWidth(), 466), 139); targetLabel_.SetTextColor(Color::GetColorFromRGBA(0x9d, 0x9d, 0x9d, 0xff)); targetLabel_.SetVisible(false); countDownLabel_.SetFont(TJD_DIN_MEDIUM_FONT_FILENAME, 72); // 上板子改字体!!!!!!!! countDownLabel_.SetText("00:00:00"); countDownLabel_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); countDownLabel_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); countDownLabel_.SetPosition(HorizontalCenter(countDownLabel_.GetWidth(), 466), 184); countDownLabel_.SetVisible(false); // InitLabelHorCenter(remindLabel_, 32, 196, 466, "计时中不可退出"); remindLabel_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); // 上板子改字体!!!!!!!! remindLabel_.SetTextId(STR_ID_558); // remindLabel_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT); remindLabel_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); remindLabel_.SetPosition(0, 196, 466, 43); remindLabel_.SetTextColor(Color::GetColorFromRGBA(0xF3, 0x1B, 0x1B, 0xff)); remindLabel_.SetVisible(false); // InitLabelHorCenter(endingLabel_, 38, 174, 466, "结束"); InitLabelExtHorCenter(endingLabel_, 38, 174, 466, STR_ID_285); endingLabel_.SetVisible(false); countDownProgress_.SetPosition(5, 5); countDownProgress_.Resize(456, 456); countDownProgress_.SetStyle(STYLE_BACKGROUND_OPA, 0x00); countDownProgress_.SetCapType(OHOS::CapType::CAP_ROUND); countDownProgress_.SetTouchable(false); countDownProgress_.SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); countDownProgress_.SetBackgroundStyle(STYLE_LINE_COLOR, 0xff262626); countDownProgress_.SetBackgroundStyle(STYLE_LINE_WIDTH, 10); countDownProgress_.SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6); countDownProgress_.SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000); countDownProgress_.SetForegroundStyle(STYLE_LINE_COLOR, 0xff006CF2); countDownProgress_.SetForegroundStyle(STYLE_LINE_WIDTH, 10); countDownProgress_.SetCenterPosition(228, 228); countDownProgress_.SetRadius(228); countDownProgress_.SetEndAngle(359); countDownProgress_.SetValue(20); auto image = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_CANCEL, IMAGE_BIN_PATH); imgCancel_.SetPosition(103, 281, 92, 92); imgCancel_.SetSrc(image); imgCancel_.SetViewId("imgCancel_"); imgCancel_.SetTouchable(true); imgCancel_.SetOnClickListener(&timerRunningViewOnListener); auto selectImage = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_CONTINUE, IMAGE_BIN_PATH); auto unSelectImage = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_PAUSE, IMAGE_BIN_PATH); PauseOrContinueBox_.SetPosition(271, 281, 92, 92); PauseOrContinueBox_.SetState(UICheckBox::UNSELECTED); PauseOrContinueBox_.SetViewId("PauseOrContinueBox_"); PauseOrContinueBox_.SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); PauseOrContinueBox_.SetImages(selectImage, unSelectImage); PauseOrContinueBox_.SetOnClickListener(&timerRunningViewOnListener); image = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_REFRESH, IMAGE_BIN_PATH); imgRefresh_.SetPosition(271, 281, 92, 92); imgRefresh_.SetSrc(image); imgRefresh_.SetViewId("imgRefresh_"); imgRefresh_.SetTouchable(true); imgRefresh_.SetOnClickListener(&timerRunningViewOnListener); imgRefresh_.SetVisible(false); if (countDownTimer_ == nullptr) { countDownTimer_ = new OHOS::GraphicTimer(100, TimerCallBack, nullptr, true); } Add(&targetLabel_); Add(&remindLabel_); Add(&endingLabel_); Add(&countDownLabel_); Add(&countDownProgress_); Add(&imgCancel_); Add(&PauseOrContinueBox_); Add(&imgRefresh_); } void TimerRunningView::ShowView() { set_back_to_home_interval(0xFFFFFFFF); SetVisible(true); } void TimerRunningView::HideView() { set_back_to_home_interval(g_comeback_dial_interval); SetVisible(false); } void TimerRunningView::CreateRunningTimer() { if (timerIsRunningTimer_ == nullptr) { timerIsRunningTimer_ = new OHOS::GraphicTimer(1000, TimerIsRunningTimerCallBack, this, false); } timerIsRunningTimer_->Start(); } TimerInfo TimerRunningView::ExtractTime(const std::string &timeStr) { std::istringstream stream(timeStr); TimerInfo curTime; int hours, minutes, seconds; char colon1, colon2; stream >> hours >> colon1 >> minutes >> colon2 >> seconds; curTime.hours = hours; curTime.minutes = minutes; curTime.seconds = seconds; return curTime; } void TimerRunningView::InitView() { uint64_t value = 0; TimerInfo curTime = {0, 0, 0}; uint8_t time = std::stoi(std::string(g_timerPickerInfo[touchTimerIndex_].time)); char timeStr[10] = {0}; std::string string = std::string(g_timerPickerInfo[touchTimerIndex_].time) + std::string(FontGlobalManager::GetInstance()->GetText(g_timerPickerInfo[touchTimerIndex_].textId)); InitLabelHorCenter(targetLabel_, 24, 134, 466, string.c_str()); targetLabel_.SetVisible(true); endingLabel_.SetVisible(false); PauseOrContinueBox_.SetState(UICheckBox::UNSELECTED); switch (touchTimerIndex_) { case 0 ... 5: memset(timeStr, 0, sizeof(timeStr)); sprintf(timeStr, "%02d:%02d:%02d", 0, time, 0); countDownLabel_.SetText(timeStr); break; case 6 ... 7: memset(timeStr, 0, sizeof(timeStr)); sprintf(timeStr, "%02d:%02d:%02d", time, 0, 0); countDownLabel_.SetText(timeStr); default: break; } if (!TimerIsRunning) { countDownLabel_.SetVisible(true); } curTime = ExtractTime(std::string(timeStr)); value = curTime.hours * 60 * 60 + curTime.minutes * 60 + curTime.seconds; countDownProgress_.SetRange(value, 0); countDownProgress_.SetValue(value); PauseOrContinueBox_.SetVisible(true); imgRefresh_.SetVisible(false); } void TimerRunningView::InitView(TimerInfo &curTime) { uint64_t value = 0; char timeStr[20] = {0}; if (curTime.hours != 0) { if (curTime.minutes == 0 && curTime.seconds == 0) sprintf(timeStr, "%d %s", curTime.hours, FontGlobalManager::GetInstance()->GetText(unitId[0])); else sprintf(timeStr, "%d%s%d%s%d%s", curTime.hours, FontGlobalManager::GetInstance()->GetText(unitId[0]), curTime.minutes, FontGlobalManager::GetInstance()->GetText(unitId[1]), curTime.seconds, FontGlobalManager::GetInstance()->GetText(unitId[2])); } else if (curTime.hours == 0 && curTime.minutes != 0) { if (curTime.seconds) sprintf(timeStr, "%d%s%d%s", curTime.minutes, FontGlobalManager::GetInstance()->GetText(unitId[1]), curTime.seconds, FontGlobalManager::GetInstance()->GetText(unitId[2])); else sprintf(timeStr, "%d %s", curTime.minutes, FontGlobalManager::GetInstance()->GetText(unitId[1])); } else { sprintf(timeStr, "%d %s", curTime.seconds, FontGlobalManager::GetInstance()->GetText(unitId[2])); } InitLabelHorCenter(targetLabel_, 24, 134, 466, timeStr); targetLabel_.SetVisible(true); memset(timeStr, 0, sizeof(timeStr)); sprintf(timeStr, "%02d:%02d:%02d", curTime.hours, curTime.minutes, curTime.seconds); countDownLabel_.SetText(timeStr); endingLabel_.SetVisible(false); PauseOrContinueBox_.SetState(UICheckBox::UNSELECTED); if (!TimerIsRunning) { countDownLabel_.SetVisible(true); } value = curTime.hours * 3600 + curTime.minutes * 60 + curTime.seconds; countDownProgress_.SetRange(value, 0); countDownProgress_.SetValue(value); PauseOrContinueBox_.SetVisible(true); imgRefresh_.SetVisible(false); } void TimerRunningView::UpdateInfo(uint64_t Value) { if (Value == 0) { countDownTimer_->Stop(); TimerIsRunning = false; countDownLabel_.SetVisible(false); endingLabel_.SetVisible(true); PauseOrContinueBox_.SetVisible(false); imgRefresh_.SetVisible(true); set_back_to_home_interval(g_comeback_dial_interval); motor_param_t motorParam = {.cycle1_on = 500, .cycle1_off = 500, .cycle1_cnt = 3, .duty = 100}; tjd_driver_motor_user_start(&motorParam); } int hour = Value / 3600; int minute = (Value % 3600) / 60; int second = Value % 60; std::stringstream ss; ss << std::setw(2) << std::setfill('0') << hour << ":" << std::setw(2) << std::setfill('0') << minute << ":" << std::setw(2) << std::setfill('0') << second; countDownLabel_.SetText(ss.str().c_str()); second--; countDownProgress_.SetValue(Value--); } TimerRunningView *TimerRunningView::GetInstance() { return g_pv_TimerRunningView; } TimerRunningView::~TimerRunningView() { g_pv_TimerRunningView = nullptr; RemoveAll(); }; #pragma endregion //===计时器运行界面=== #pragma region == = 计时器自定义设置界面 == = bool TimerCustomSettingiew::PickerSelectListener::OnPress(UIView &view, const OHOS::PressEvent &event) { dynamic_cast(view.GetParent())->SelectPicker(dynamic_cast(&view)); return false; } bool TimerCustomSettingiew::PickerSelectListener::OnCancel(UIView &view, const OHOS::CancelEvent &event) { dynamic_cast(view.GetParent())->SelectPicker(dynamic_cast(&view)); return false; } TimerCustomSettingiew::TimerCustomSettingiew() { g_pv_TimerCustomSettingiew = this; SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION); SetTouchable(true); SetOnDragListener(&TjdUiAppTimerPresenter::GetInstance()); auto image = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_TIME, IMAGE_BIN_PATH); for (uint8_t i = 0; i < 2; i++) { imgTimeGap_[i].SetPosition(152 + i * 150, 198, 10, 30); imgTimeGap_[i].SetSrc(image); Add(&imgTimeGap_[i]); } // InitLabelExt(hourUnit_, 32, 67, 99, STR_ID_281);时 hourUnit_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); hourUnit_.SetTextId(STR_ID_281); // hourUnit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE); hourUnit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); hourUnit_.SetPosition(17, 99, 122, 43); hourUnit_.SetVisible(false); // InitLabelExt(minuteUnit_, 32, 198, 99, STR_ID_129);分 minuteUnit_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); minuteUnit_.SetTextId(STR_ID_129); // minuteUnit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE); minuteUnit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); minuteUnit_.SetPosition(166, 99, 122, 43); minuteUnit_.SetVisible(false); // InitLabelExt(secUnit_, 32, 369, 99, STR_ID_559);秒 secUnit_.SetFont(TJD_VECTOR_FONT_FILENAME, 32); secUnit_.SetTextId(STR_ID_559); // secUnit_.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_MARQUEE); secUnit_.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER); secUnit_.SetPosition(319, 99, 122, 43); secUnit_.SetVisible(false); hourPicker_.SetPosition(17, 141); hourPicker_.Resize(122, 134); hourPicker_.SetStyle(OHOS::STYLE_BORDER_WIDTH, 4); hourPicker_.SetStyle(OHOS::STYLE_BORDER_RADIUS, 26); hourPicker_.SetStyle(OHOS::STYLE_BORDER_COLOR, 0xff262626); hourPicker_.SetHighlightFont(TJD_VECTOR_FONT_FILENAME, 70); hourPicker_.SetItemHeight(142 + 60); hourPicker_.SetTextColor(OHOS::Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff), OHOS::Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); hourPicker_.SetViewId("HourPicker"); hourPicker_.SetValues(static_cast(0), static_cast(99)); hourPicker_.SetLoopState(true); hourPicker_.SetDragACCLevel(15); hourPicker_.SetSwipeACCLevel(10); hourPicker_.SetOnTouchListener(&pickerSelectListener_); hourPicker_.SetRotateFactor(1.8f); minutePicker_.SetPosition(166, 141); minutePicker_.Resize(122, 134); minutePicker_.SetStyle(OHOS::STYLE_BORDER_WIDTH, 4); minutePicker_.SetStyle(OHOS::STYLE_BORDER_RADIUS, 26); minutePicker_.SetStyle(OHOS::STYLE_BORDER_COLOR, 0xff262626); minutePicker_.SetHighlightFont(TJD_VECTOR_FONT_FILENAME, 70); minutePicker_.SetItemHeight(142 + 60); minutePicker_.SetTextColor(OHOS::Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff), OHOS::Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); minutePicker_.SetViewId("MinutePicker"); minutePicker_.SetValues(static_cast(0), static_cast(59)); minutePicker_.SetLoopState(true); minutePicker_.SetDragACCLevel(15); minutePicker_.SetSwipeACCLevel(10); minutePicker_.SetOnTouchListener(&pickerSelectListener_); minutePicker_.SetRotateFactor(1.8f); secPicker_.SetPosition(319, 141); secPicker_.Resize(122, 134); secPicker_.SetStyle(OHOS::STYLE_BORDER_WIDTH, 4); secPicker_.SetStyle(OHOS::STYLE_BORDER_RADIUS, 26); secPicker_.SetStyle(OHOS::STYLE_BORDER_COLOR, 0xff262626); secPicker_.SetHighlightFont(TJD_VECTOR_FONT_FILENAME, 70); secPicker_.SetItemHeight(142 + 60); secPicker_.SetTextColor(OHOS::Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff), OHOS::Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); secPicker_.SetViewId("SecPicker"); secPicker_.SetValues(static_cast(0), static_cast(59)); secPicker_.SetLoopState(true); secPicker_.SetDragACCLevel(15); secPicker_.SetSwipeACCLevel(10); secPicker_.SetOnTouchListener(&pickerSelectListener_); secPicker_.SetRotateFactor(1.8f); image = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_CONFIRM, IMAGE_BIN_PATH); imgConfirm_.SetPosition(271, 326, 92, 92); imgConfirm_.SetSrc(image); imgConfirm_.SetViewId("customImgConfirm_"); imgConfirm_.SetViewIndex(MAX_TIMER); imgConfirm_.SetTouchable(true); imgConfirm_.SetOnClickListener(&CustomSettingViewOnListener); image = OHOS::ImageCacheManager::GetInstance().LoadOneInMultiRes(IMG_TIMER_CANCEL, IMAGE_BIN_PATH); imgCancel_.SetPosition(103, 326, 92, 92); imgCancel_.SetSrc(image); imgCancel_.SetViewId("customImgCancel_"); imgCancel_.SetViewIndex(MAX_TIMER); imgCancel_.SetTouchable(true); imgCancel_.SetOnClickListener(&CustomSettingViewOnListener); Add(&imgConfirm_); Add(&imgCancel_); Add(&hourPicker_); Add(&minutePicker_); Add(&secPicker_); Add(&hourUnit_); Add(&minuteUnit_); Add(&secUnit_); } void TimerCustomSettingiew::ShowView() { SetVisible(true); } void TimerCustomSettingiew::HideView() { SetVisible(false); } TimerCustomSettingiew *TimerCustomSettingiew::GetInstance(void) { return g_pv_TimerCustomSettingiew; } TimerCustomSettingiew::~TimerCustomSettingiew() { g_pv_TimerCustomSettingiew = nullptr; RemoveAll(); // if (lastPicker_ != nullptr) { // delete lastPicker_; // lastPicker_ = nullptr; // } } void TimerCustomSettingiew::SelectPicker(OHOS::UIPicker *selectPicker) { if (selectPicker == lastPicker_) { return; } if (lastPicker_ != nullptr) { lastPicker_->SetStyle(OHOS::STYLE_BORDER_COLOR, 0xff262626); lastPicker_->Invalidate(); } selectPicker->SetStyle(OHOS::STYLE_BORDER_COLOR, 0xff006CF2); selectPicker->Invalidate(); hourUnit_.SetVisible(false); minuteUnit_.SetVisible(false); secUnit_.SetVisible(false); if (selectPicker->GetViewId() == "HourPicker") { hourUnit_.SetVisible(true); TjdUiUtils::ViewRequestFocus(hourPicker_); } else if (selectPicker->GetViewId() == "MinutePicker") { minuteUnit_.SetVisible(true); TjdUiUtils::ViewRequestFocus(minutePicker_); } else if (selectPicker->GetViewId() == "SecPicker") { secUnit_.SetVisible(true); TjdUiUtils::ViewRequestFocus(secPicker_); } lastPicker_ = selectPicker; } #pragma endregion //===计时器自定义设置界面=== } // namespace TJD