mcu_hi3321_watch/tjd/ui/app/stopwatch/TjdUiAppStopwatchPresenter.cpp
2025-05-26 20:15:20 +08:00

233 lines
8.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "TjdUiAppStopwatchPresenter.h"
#include "TjdUiAppStopwatchView.h"
#include "common/key_code.h"
#include "sys_config.h"
#include "wearable_log.h"
#include "TjdUiRegisterManager.h"
#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_STOPWATCH, TjdUiAppStopwatchView, TjdUiAppStopwatchPresenter, IMG_MENU_LIST_MENU_STOPWATCH, STR_ID_13);
#define DRAG_EXIT_DISTANCE 180
static TjdUiAppStopwatchPresenter *g_pv_AppStopwatchPresenter = nullptr;
TjdUiAppStopwatchPresenter::TjdUiAppStopwatchPresenter() { g_pv_AppStopwatchPresenter = this; }
TjdUiAppStopwatchPresenter::~TjdUiAppStopwatchPresenter() { g_pv_AppStopwatchPresenter = nullptr; }
TjdUiAppStopwatchPresenter *TjdUiAppStopwatchPresenter::GetInstance(void) { return g_pv_AppStopwatchPresenter; }
void TjdUiAppStopwatchPresenter::Notify()
{
if (boolFlag1) {
TjdUiAppStopwatchView::GetInstance()->UpdateStopwatchTime();
}
}
void TjdUiAppStopwatchPresenter::OnStart()
{
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
}
void TjdUiAppStopwatchPresenter::OnPause() { Presenter::OnPause(); }
void TjdUiAppStopwatchPresenter::OnResume() { Presenter::OnResume(); }
void TjdUiAppStopwatchPresenter::OnStop()
{
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
}
void TjdUiAppStopwatchPresenter::StowatchStartClickEvent() // button id: STOPWATCH_START_ID
{
TjdUiAppStopwatchView *stopwatchView = TjdUiAppStopwatchView::GetInstance();
if (!stopwatchView)
return;
stopwatchView->ShowView(StopwatchViewIndex::STOPWATCH_START_VIEW, StopwatchViewIndex::STOPWATCH_CARRY_VIEW);
stopwatchView->CoumtNumInit();
listNum = 0;
theNum = 1; // 页面1
boolFlag1 = true; // 时间开始
}
void TjdUiAppStopwatchPresenter::StowatchPause1ClickEvent() // button id: STOPWATCH_PAUSE_ID_1
{
TjdUiAppStopwatchView *stopwatchView = TjdUiAppStopwatchView::GetInstance();
if (!stopwatchView)
return;
stopwatchView->ChangestatusPause();
stopwatchView->SaveStopwatchTime();
theNum = 2;
boolFlag1 = false;
}
void TjdUiAppStopwatchPresenter::StowatchPause2ClickEvent() // button id: STOPWATCH_PAUSE_ID_2
{
TjdUiAppStopwatchView *stopwatchView = TjdUiAppStopwatchView::GetInstance();
if (!stopwatchView)
return;
stopwatchView->ChangestatusPause_();
stopwatchView->SaveStopwatchTime();
theNum = 4;
boolFlag1 = false;
}
void TjdUiAppStopwatchPresenter::StowatchListClickEvent() // button id: STOPWATCH_LIST_ID
{
TjdUiAppStopwatchView *stopwatchView = TjdUiAppStopwatchView::GetInstance();
if (!stopwatchView)
return;
if (listNum > 0) {
stopwatchView->StopAiainAnimator(0); // 大于0的时候不重复动画开始
} else {
stopwatchView->StopAiainAnimator(1); // listNum=0的时候播放动画
static_print_info("TjdUiAppStopwatchPresenter 111::%s", __func__);
}
theNum = 3;
stopwatchView->StartAnimator();
stopwatchView->ShowList();
stopwatchView->Invalidate();
listNum++;
if (listNum == 20) {
stopwatchView->SetStopWatchListOpa(76);
}
}
void TjdUiAppStopwatchPresenter::StowatchResumeClickEvent() // button id: STOPWATCH_RESUME_ID
{
TjdUiAppStopwatchView *stopwatchView = TjdUiAppStopwatchView::GetInstance();
if (!stopwatchView)
return;
stopwatchView->ChangestatusResume();
if (listNum >= 1) {
theNum = 3;
} else {
theNum = 1;
}
boolFlag1 = true;
}
bool TjdUiAppStopwatchPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
{
printf("TjdUiAppStopwatchPresenter OnClick viewId:%s\r\n", view.GetViewId());
TjdUiAppStopwatchView *stopwatchView1 = TjdUiAppStopwatchView::GetInstance();
std::string viewId = view.GetViewId();
if (viewId.empty()) {
return false;
}
if (viewId == STOPWATCH_START_ID) {
StowatchStartClickEvent();
} else if (viewId == STOPWATCH_PAUSE_ID_1) {
StowatchPause1ClickEvent();
} else if (viewId == STOPWATCH_PAUSE_ID_2) {
StowatchPause2ClickEvent();
} else if (viewId == STOPWATCH_LIST_ID && listNum < 20) {
StowatchListClickEvent();
} else if (viewId == STOPWATCH_CLEAR_ID) {
stopwatchView1->ShowView(StopwatchViewIndex::STOPWATCH_CARRY_VIEW, StopwatchViewIndex::STOPWATCH_START_VIEW);
stopwatchView1->ChangestatusClear();
stopwatchView1->StopTimer(); // 停止Label移动的定时器
stopwatchView1->SetStopWatchListOpa(255);
} else if (viewId == STOPWATCH_RESUME_ID) {
StowatchResumeClickEvent();
}
return false;
}
bool TjdUiAppStopwatchPresenter::OnDragEnd(OHOS::UIView &view, const OHOS::DragEvent &event)
{
backFlag3 = true;
return TjdUiScreenDragListener::OnDragEnd(view, event);
}
void TjdUiAppStopwatchPresenter::ViewExitEvent()
{
static_print_info("TjdUiAppStopwatchPresenter::%s", __func__);
TjdUiAppStopwatchView *stopwatchView2 = TjdUiAppStopwatchView::GetInstance();
if (stopwatchView2->GetCurrentView() == StopwatchViewIndex::STOPWATCH_START_VIEW) {
stopwatchView2->ChangeAnimator();
OHOS::NativeAbility::GetInstance().ChangePreSlice();
}
if (stopwatchView2->GetCurrentView() == StopwatchViewIndex::STOPWATCH_CARRY_VIEW && theNum == 1) {
stopwatchView2->ChangestatusPause();
stopwatchView2->SaveStopwatchTime();
theNum = 2;
boolFlag1 = false;
backFlag3 = false;
}
if (stopwatchView2->GetCurrentView() == StopwatchViewIndex::STOPWATCH_CARRY_VIEW && theNum == 2 && backFlag3) {
stopwatchView2->ShowView(StopwatchViewIndex::STOPWATCH_CARRY_VIEW, StopwatchViewIndex::STOPWATCH_START_VIEW);
stopwatchView2->ChangestatusClear();
backFlag3 = false;
}
if (stopwatchView2->GetCurrentView() == StopwatchViewIndex::STOPWATCH_CARRY_VIEW && theNum == 3) {
stopwatchView2->ChangestatusPause_();
stopwatchView2->SaveStopwatchTime();
theNum = 4;
boolFlag1 = false;
backFlag3 = false;
}
if (stopwatchView2->GetCurrentView() == StopwatchViewIndex::STOPWATCH_CARRY_VIEW && theNum == 4 && backFlag3) {
stopwatchView2->ShowView(StopwatchViewIndex::STOPWATCH_CARRY_VIEW, StopwatchViewIndex::STOPWATCH_START_VIEW);
stopwatchView2->ChangestatusClear();
stopwatchView2->StopTimer();
backFlag3 = false;
}
stopwatchView2->SetStopWatchListOpa(255);
}
bool TjdUiAppStopwatchPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
{
static_print_info("TjdUiAppStopwatchPresenter::%s", __func__);
backFlag2 = true;
UNUSED(view);
uint8_t state2 = event.GetState();
uint16_t keyid = event.GetKeyId();
TjdUiAppStopwatchView *stopwatchView3 = TjdUiAppStopwatchView::GetInstance();
printf("TjdUiAppStopwatchPresenter OnKeyAct state:%d keyid:%dGetCurrentView()=%d\r\n", state2, keyid,
stopwatchView3->GetCurrentView());
if (event.GetState() == OHOS::InputDevice::STATE_RELEASE &&
event.GetKeyId() == static_cast<uint16_t>(OHOS::ZliteKeyCode::ZLITE_KEY_TJD_RIGHTUP)) {
if (stopwatchView3->GetCurrentView() == StopwatchViewIndex::STOPWATCH_START_VIEW) {
if (stopwatchView3->GetStopWatchStart1Visible()) {
StowatchStartClickEvent();
}
} else if (stopwatchView3->GetCurrentView() == StopwatchViewIndex::STOPWATCH_CARRY_VIEW) {
if (stopwatchView3->GetStopWatchPause1Visible()) {
StowatchPause1ClickEvent();
} else if (stopwatchView3->GetStopWatchResumeVisible()) {
StowatchResumeClickEvent();
} else if (stopwatchView3->GetStopWatchPause2Visible()) {
StowatchPause2ClickEvent();
}
}
} else if (event.GetState() == OHOS::InputDevice::STATE_RELEASE &&
event.GetKeyId() == static_cast<uint16_t>(OHOS::ZliteKeyCode::ZLITE_KEY_TJD_LEFT) &&
!stopwatchView3->GetStopWatchResumeVisible() && listNum < 20) {
StowatchListClickEvent();
}
return false;
}
} // namespace TJD