311 lines
13 KiB
C++
311 lines
13 KiB
C++
#include "TjdUiAppSportPresenter.h"
|
|
#include "NativeAbility.h"
|
|
#include "TjdUiAppIds.h"
|
|
#include "TjdUiAppSportAdapter.h"
|
|
#include "TjdUiAppSportPage.h"
|
|
#include "TjdUiAppSportView.h"
|
|
#include "TjdUiMsgCenter.h"
|
|
#include "TjdUiRegisterManager.h"
|
|
#include "broadcast_feature.h"
|
|
#include "dock/input_device.h"
|
|
#include "graphic_service.h"
|
|
#include "notification_manager.h"
|
|
#include "service_sport.h"
|
|
#include "sys_config.h"
|
|
#include <string>
|
|
|
|
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_SPORT, TjdUiAppSportView, TjdUiAppSportPresenter, IMG_MENU_LIST_MENU_SPORT,
|
|
STR_ID_05);
|
|
|
|
static TjdUiAppSportPresenter *g_pv_AppSportPresenter = nullptr;
|
|
UIViewGroup *g_messageSportView = nullptr;
|
|
static OHOS::RootView::OnKeyActListener *tmpSportOnKeyListener = nullptr;
|
|
bool returnToDial = false;
|
|
|
|
TjdUiAppSportPresenter::TjdUiAppSportPresenter() { g_pv_AppSportPresenter = this; }
|
|
|
|
TjdUiAppSportPresenter::~TjdUiAppSportPresenter() { g_pv_AppSportPresenter = nullptr; }
|
|
|
|
TjdUiAppSportPresenter *TjdUiAppSportPresenter::GetInstance(void) { return g_pv_AppSportPresenter; }
|
|
|
|
// void TjdUiAppSportPresenter::SetCurrentSportingData()
|
|
// {
|
|
// static_print_info("lines = %d ,func = %s\n",__LINE__,__FUNCTION__);
|
|
// lastSportingData = TjdUiAppSportModel::GetInstance()->GetSqlSportData();
|
|
// }
|
|
|
|
void TjdUiAppSportPresenter::OnStart()
|
|
{
|
|
static_print_info("TjdUiAppSportPresenter::OnStart");
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
TjdUiAppSportView *sportView = TjdUiAppSportView::GetInstance();
|
|
|
|
if (returnToDial) {
|
|
sportView->ShowTargetView(SportViewManager::SPORTING_VIEW);
|
|
returnToDial = false;
|
|
} else {
|
|
if (getmotion_recognition_entry() >> 4) {
|
|
uint8_t sportType = (getmotion_recognition_entry() & 0x0F);
|
|
sportView->ChooseSportItem(static_cast<SportTypeIndex>(sportType));
|
|
} else
|
|
sportView->ShowTargetView(SportViewManager::SPORT_LIST_VIEW);
|
|
}
|
|
}
|
|
|
|
void TjdUiAppSportPresenter::OnResume() { OHOS::Presenter<TjdUiAppSportView>::OnResume(); }
|
|
|
|
void TjdUiAppSportPresenter::OnStop()
|
|
{
|
|
static_print_info("TjdUiAppSportPresenter::OnStop");
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
bool TjdUiAppSportPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
static_print_info("TjdUiAppSportPresenter::OnKeyAct");
|
|
static_print_info("event.GetKeyId() = %d\n", event.GetKeyId());
|
|
if (event.GetKeyId() == 4165 && TjdUiAppSportView::currentViewIndex_ == GPS_VIEW) {
|
|
if (event.GetState() == OHOS::InputDevice::STATE_RELEASE) {
|
|
TjdUiAppSportView::GetInstance()->ShowTargetView(COUNT_DOWN_VIEW);
|
|
return true;
|
|
}
|
|
} else if (event.GetKeyId() == 4165 && TjdUiAppSportView::currentViewIndex_ != SPORTING_VIEW) {
|
|
if (event.GetState() == OHOS::InputDevice::STATE_RELEASE) {
|
|
ExitSportView();
|
|
return true;
|
|
}
|
|
} else if (event.GetKeyId() == 4165 && TjdUiAppSportView::currentViewIndex_ == SPORTING_VIEW) {
|
|
if (event.GetState() == OHOS::InputDevice::STATE_RELEASE) {
|
|
returnToDial = true;
|
|
NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MAIN);
|
|
return true;
|
|
}
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void TjdUiAppSportPresenter::OnSwipe(UISwipeView &view)
|
|
{
|
|
static_print_info("=======SportItemListListener::OnClick========\n");
|
|
}
|
|
|
|
bool TjdUiAppSportPresenter::OnLongPress(OHOS::UIView &view, const OHOS::LongPressEvent &event) { return false; }
|
|
|
|
bool TjdUiAppSportPresenter::OnPress(OHOS::UIView &view, const OHOS::PressEvent &event) { return false; }
|
|
|
|
bool TjdUiAppSportPresenter::OnRelease(UIView &view, const OHOS::ReleaseEvent &event) { return false; }
|
|
|
|
bool TjdUiAppSportPresenter::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
static_print_info("===TjdUiAppSportPresenter::OnClick\n");
|
|
std::string touchId = view.GetViewId();
|
|
if (touchId == "sport_list_edit") {
|
|
TjdUiAppSportView::GetInstance()->ShowTargetView(SportViewManager::SPORT_EDIT_VIEW);
|
|
return true;
|
|
}
|
|
return true;
|
|
}
|
|
|
|
bool SportItemListListener::OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event)
|
|
{
|
|
static_print_info("===SportItemListListener::OnClick\n");
|
|
// static_print_info("HALTick::GetInstance().GetTime() === %d",HALTick::GetInstance().GetTime());
|
|
// static_print_info("SportItemListListener::OnClick cxin is clicked=====%s!!!!!!!!!!\n",view.GetViewId());
|
|
// view.GetChildById("moreIcon");
|
|
|
|
return false;
|
|
}
|
|
|
|
extern OHOS::GraphicTimer *GetSportingTime();
|
|
void TjdUiAppSportPresenter::ExitSportView(void)
|
|
{
|
|
static_print_info("TjdUiAppSportPresenter::ExitSportView\n");
|
|
auto sportView = TjdUiAppSportView::GetInstance();
|
|
switch (TjdUiAppSportView::currentViewIndex_) {
|
|
case SPORT_LIST_VIEW:
|
|
OHOS::FocusManager::GetInstance()->ClearFocus();
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
break;
|
|
case COUNT_DOWN_VIEW:
|
|
case GPS_VIEW:
|
|
// case SPORTING_VIEW:
|
|
case SPORT_END_NODATA_VIEW:
|
|
case SPORT_END_DATA_VIEW:
|
|
case SPORT_GOAL_SELECT_VIEW:
|
|
case SPORT_EDIT_VIEW:
|
|
sportView->ShowTargetView(SPORT_LIST_VIEW);
|
|
break;
|
|
case SPORT_GOAL_DISTANCES_VIEW:
|
|
case SPORT_GOAL_TIME_VIEW:
|
|
case SPORT_GOAL_CALORIES_VIEW:
|
|
case SPORT_GOAL_FREE_TRAINING_VIEW:
|
|
sportView->ShowTargetView(SPORT_GOAL_SELECT_VIEW);
|
|
break;
|
|
case SPORT_REMIND_SELECT_VIEW:
|
|
printf("lastViewIndex_ = %d", TjdUiAppSportView::lastViewIndex_);
|
|
sportView->ShowTargetView(TjdUiAppSportView::lastViewIndex_);
|
|
break;
|
|
case DISTANCE_GOAL_SELECT_VIEW:
|
|
sportView->ShowTargetView(SPORT_GOAL_DISTANCES_VIEW);
|
|
break;
|
|
case TIME_GOAL_SELECT_VIEW:
|
|
sportView->ShowTargetView(SPORT_GOAL_TIME_VIEW);
|
|
break;
|
|
case CALORIES_GOAL_SELECT_VIEW:
|
|
sportView->ShowTargetView(SPORT_GOAL_CALORIES_VIEW);
|
|
break;
|
|
case HEART_RATE_PICK_VIEW:
|
|
case TIME_PICK_VIEW:
|
|
case DISTANCE_PICK_VIEW:
|
|
sportView->ShowTargetView(SPORT_REMIND_SELECT_VIEW);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
void TjdUiAppSportPresenter::StartJumpTimer(SportViewManager jumpView)
|
|
{
|
|
if (jumpTimerId_ == nullptr) {
|
|
jumpTimerId_ = osTimerNew(
|
|
[](void *arg) {
|
|
SportViewManager jumpView = static_cast<SportViewManager>(reinterpret_cast<intptr_t>(arg));
|
|
GraphicService::GetInstance()->PostGraphicEvent([jumpView]() {
|
|
TjdUiAppSportView *view = TjdUiAppSportView::GetInstance();
|
|
if (view == nullptr) {
|
|
return;
|
|
}
|
|
// view->ShowView(jumpView);
|
|
});
|
|
},
|
|
osTimerOnce, reinterpret_cast<void *>(static_cast<intptr_t>(jumpView)), nullptr);
|
|
if (jumpTimerId_ == nullptr) {
|
|
static_print_info("TjdUiAppAlipayModel::AlipayStartBind Create timer fail.");
|
|
return;
|
|
}
|
|
}
|
|
|
|
int ret = osTimerStart(jumpTimerId_, 2000);
|
|
|
|
if (ret != 0) {
|
|
static_print_info("TjdUiAppAlipayModel::AlipayStartBind Start timer fail");
|
|
return;
|
|
}
|
|
}
|
|
|
|
#pragma region 弹窗消息处理
|
|
void TjdUiSportMessageProc(const Topic topic, Request *req) // 时间目标设置弹窗消息处理
|
|
{
|
|
static_print_info("====((Reminder *)(req->data))->msgType = %d\n", (*(Reminder **)(req->data))->msgType);
|
|
uint8_t msgType = (*(Reminder **)(req->data))->msgType;
|
|
uint8_t msgData = (*(Reminder **)(req->data))->value;
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TjdUiMsgCenterGetPriority(topic));
|
|
OHOS::NotificationManager::GetInstance()->ShowNotify(
|
|
[msgType, msgData]() -> OHOS::UIViewGroup * {
|
|
if (g_messageSportView == nullptr) {
|
|
static_print_info("TjdUiShutdownMsgCenterMessageProc");
|
|
if (msgType < SPORT_POPUP_TYPE_END_30_MIN_REMIND) {
|
|
std::string popupText;
|
|
uint32_t hour = 0;
|
|
uint32_t minute = 0;
|
|
switch (msgType) {
|
|
case SPORT_POPUP_MSG_TYPE_DISTANCE:
|
|
popupText = g_pv_SportGoal[TjdUiAppSportView::currentIconIndex_].distGoal;
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_TIME:
|
|
popupText = g_pv_SportGoal[TjdUiAppSportView::currentIconIndex_].timeGoal;
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_CALORIES:
|
|
popupText = g_pv_SportGoal[TjdUiAppSportView::currentIconIndex_].caloriesGoal;
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_PER_DISTANCE:
|
|
popupText = std::to_string(msgData);
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_PER_TIME:
|
|
hour = msgData / 3600;
|
|
minute = (msgData % 3600) / 60;
|
|
popupText = std::to_string(hour) + " H " + std::to_string(minute) + "min";
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_PER_HEARTRATE_TYPE_1:
|
|
popupText = "139-150次/分";
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_PER_HEARTRATE_TYPE_2:
|
|
popupText = "151-162次/分";
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_PER_HEARTRATE_TYPE_3:
|
|
popupText = "163-174次/分";
|
|
break;
|
|
case SPORT_POPUP_MSG_TYPE_PER_HEARTRATE_TYPE_4:
|
|
popupText = "175 bpm";
|
|
break;
|
|
default:
|
|
printf("msgType = %d", msgType);
|
|
break;
|
|
}
|
|
|
|
printf("msgType = %d, popupText = %s\n", msgType, popupText.c_str());
|
|
g_messageSportView =
|
|
new SportPopupWindow(static_cast<PopupMsgType>(msgType), (char *)popupText.c_str());
|
|
} else {
|
|
uint8_t time_stamp = msgData;
|
|
auto sportView = TjdUiAppSportView::GetInstance();
|
|
switch (msgType) {
|
|
case SPORT_POPUP_TYPE_END_30_MIN_REMIND:
|
|
case SPORT_POPUP_TYPE__END_50_MIN_REMIND:
|
|
case SPORT_POPUP_TYPE__END_60_MIN_REMIND:
|
|
case SPORT_POPUP_TYPE__END_65_MIN_REMIND:
|
|
g_messageSportView = new SportFinishRemindView(time_stamp);
|
|
break;
|
|
case SPORT_POPUP_TYPE__END_70_MIN_REMIND:
|
|
sportView->ShowTargetView(SPORT_END_DATA_VIEW);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
g_pv_AppSportPresenter = new TjdUiAppSportPresenter();
|
|
tmpSportOnKeyListener = OHOS::RootView::GetInstance()->GetOnKeyActListener();
|
|
OHOS::RootView::GetInstance()->SetOnKeyActListener(tmpSportOnKeyListener);
|
|
}
|
|
OHOS::NotificationManager::GetInstance()->RegisterNotifyCleanupFunction([]() {
|
|
OHOS::NotificationManager::GetInstance()->SetNotifyPriority(TJD_UI_PRIO_LOWEST);
|
|
static_print_info("TjdUiShutdownMsgCenterMessageProc RegisterNotifyCleanupFunction");
|
|
if (tmpSportOnKeyListener != nullptr) {
|
|
OHOS::RootView::GetInstance()->SetOnKeyActListener(tmpSportOnKeyListener);
|
|
}
|
|
delete g_messageSportView;
|
|
delete g_pv_AppSportPresenter;
|
|
g_messageSportView = nullptr;
|
|
g_pv_AppSportPresenter = nullptr;
|
|
RunPopOutPageCallback();
|
|
});
|
|
return g_messageSportView;
|
|
},
|
|
static_cast<uint16_t>(topic), true
|
|
|
|
);
|
|
}
|
|
|
|
#pragma endregion
|
|
|
|
} // namespace TJD
|