From 445ca391c32476da2518f056d2eb3c8f88c280bd Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 13 Apr 2024 14:13:19 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E5=BC=80=E5=A7=8B=E7=BB=93?= =?utf8?q?=E6=9D=9F=E8=AE=AD=E7=BB=83=E6=97=B6=E9=97=B4=E6=88=B3=E6=89=93?= =?utf8?q?=E5=8D=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../nativeui/traing/include/TraingModel.h | 10 ++++- .../nativeui/traing/src/TraingModel.cpp | 38 +++++++++++++++++++ .../training_card/include/TraingCardView.h | 2 +- .../training_card/src/TraingCardPresenter.cpp | 32 ++++++++++++++-- .../training_card/src/TraingCardView.cpp | 11 +++--- .../msg_center/src/msg_center_customer.cpp | 3 +- 6 files changed, 82 insertions(+), 14 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h index 94d410510..8da6adffc 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -41,6 +41,7 @@ #include "displaybrightness/include/DisplayBrightnessModel.h" #include +#include struct QuickTraining { @@ -149,8 +150,8 @@ namespace OHOS }; struct SportData { - uint32 starttime; // 开始时间时间戳 - uint32 endtime; // 结束时间时间戳 + uint64 starttime; // 开始时间时间戳 + uint64 endtime; // 结束时间时间戳 int goaldegree; // 目标完成度 int calories; // 训练卡路里 int duration; // 训练时长 @@ -198,6 +199,10 @@ namespace OHOS SportData *GetSportdata(); /*获取运动卡路里*/ int GetCal(); + /*设置时间戳*/ + void SetTimestamp(); + /*解析时间戳*/ + std::string AnalysisTimestamp(uint64_t timestamp); private: TraingModel(const TraingModel &) = delete; @@ -206,6 +211,7 @@ namespace OHOS std::string motionDuration; // 训练时长 UIResourceTextId sportId_ = STR_EXTREME_SPORTS; // 训练项目 ExerciseState sportstate_ = ExerciseState::General; // 训练状态 + /*std::unique_ptr sportdata;*/ // 使用 std::unique_ptr 管理 SportData 对象 }; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp index 8890dc464..5264620b1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -16,11 +16,14 @@ #include "broadcast_feature.h" #include "broadcast_service.h" #include "samgr_lite.h" +#include +#include #define TIMER 1 #define CHECK 0 #define HARD_OFF 1 #define TRAINING_PATH "user/userdata/sportdata/" +extern "C" errcode_t uapi_get_timestampe_ms(uint64_t *tm); #ifdef __cplusplus extern "C" @@ -427,6 +430,8 @@ namespace OHOS ExerciseClass TraingModel::GetSportType() { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " GetSportType %d", sportId_); + // 设置结构体里面的运动类型 + sportdata->sportId = sportId_; switch (sportId_) { // 室外跑步 @@ -486,6 +491,39 @@ namespace OHOS { return sportdata->calories; } + /*设置时间戳*/ + void TraingModel::SetTimestamp() + { + // std::lock_guard lock(mutex); // 使用互斥锁确保线程安全 + uint64_t time; + uapi_get_timestampe_ms(&time); + ExerciseState currentState = GetSportState(); // 获取当前运动状态 + + if (currentState == ExerciseState::Start) + { + sportdata->starttime = time; + } + else if (currentState == ExerciseState::End) + { + sportdata->endtime = time; + } + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SetTimestamp [%d %lu]", currentState, time); + } + /*解析时间戳 返回例如:13:00:22*/ + std::string TraingModel::AnalysisTimestamp(uint64_t timestamp) + { + // 将时间戳转换为小时、分钟、秒 + int hours = timestamp / 3600000; // 1小时 = 3600000毫秒 + int minutes = (timestamp % 3600000) / 60000; // 1分钟 = 60000毫秒 + int seconds = (timestamp % 60000) / 1000; // 1秒 = 1000毫秒 + + // 格式化输出为 HH:MM:SS + std::stringstream ss; + ss << std::setfill('0') << std::setw(2) << hours << ":" << std::setw(2) << minutes << ":" << std::setw(2) << seconds; + + return ss.str(); + } /* -------------------------------------------------------------------------- */ #if TIMER /* 时间显示 */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h index bc893f975..98ff79110 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardView.h @@ -74,7 +74,7 @@ namespace OHOS void SetEndViewStatus(bool status); void ShowEndView(); - void RefreshEndView(); + bool RefreshEndView(); UIView *GetTraingCrad(); int GetCurrentPage(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp index e9366d6cb..87be72ba7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardPresenter.cpp @@ -204,7 +204,7 @@ namespace OHOS if (strcmp(view.GetViewId(), BUTTONSTOP) == 0) { // 开始状态 - if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Start) + if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Start || TraingModel::GetInstance()->GetSportState() == ExerciseState::Continue) { TrainingControlView::GetInstance()->GetLabel()->SetText("继续"); TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_CONTINUE_IMAGE, SPORT_CONTINUE_IMAGE); @@ -221,8 +221,8 @@ namespace OHOS { TrainingControlView::GetInstance()->GetLabel()->SetText("暂停"); TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_PAUSE_IMAGE, SPORT_PAUSE_IMAGE); - // 设置为开始状态 - TraingModel::GetInstance()->SetSportState(ExerciseState::Start); + // 设置为继续状态 + TraingModel::GetInstance()->SetSportState(ExerciseState::Continue); // 恢复计时器 ResumeTimer(); // 恢复运动库 @@ -241,8 +241,32 @@ namespace OHOS // 退出按键 if (strcmp(view.GetViewId(), BUTTONEXIT) == 0) { + TraingModel::GetInstance()->SetSportState(ExerciseState::End); ControlSensor(ExerciseState::End); - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGWIN); + if (TraingCardView::GetInstance()->RefreshEndView()) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGWIN); + } + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGMORE); + } +#if 0 + // 在点击事件中打印 SportData 对象之前,确保结束时间戳已经被设置 + if (TraingModel::GetInstance()->GetSportdata()->endtime == 0 && TraingModel::GetInstance()->GetSportState() == ExerciseState::End) + { + PRINT("RESET ENDTIMESTAMP\r\n"); + TraingModel::GetInstance()->SetTimestamp(); // 如果结束时间戳为0且当前为结束状态,再次调用 SetTimestamp 设置结束时间戳 + } + // 打印 SportData 中的数据 + SportData *sportData = TraingModel::GetInstance()->GetSportdata(); + + std::string formattedStartTime = TraingModel::GetInstance()->AnalysisTimestamp(sportData->starttime); + std::string formattedEndTime = TraingModel::GetInstance()->AnalysisTimestamp(sportData->endtime); + std::string formattedTimeRange = formattedStartTime + "-" + formattedEndTime; + + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "【SportData - StartTime: [%lu], EndTime: [%lu] %s】", sportData->starttime, sportData->endtime, formattedTimeRange.c_str()); +#endif } // 返回按键 if (strcmp(view.GetViewId(), BUTTONBACK) == 0) diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp index 8857a4119..d8cffaf48 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TraingCardView.cpp @@ -38,8 +38,7 @@ namespace OHOS InitTimer(); // 设置运动状态为开始 TraingModel::GetInstance()->SetSportState(ExerciseState::Start); - // 设置常亮 - ScreenAlwaysOnCtr(true); + TraingModel::GetInstance()->SetTimestamp(); } TraingCardView::~TraingCardView() @@ -50,8 +49,7 @@ namespace OHOS DisableTimer(); // 设置运动状态为结束 TraingModel::GetInstance()->SetSportState(ExerciseState::End); - // 设置为正常 - ScreenAlwaysOnCtr(false); + TraingModel::GetInstance()->SetTimestamp(); } TraingCardView *TraingCardView::GetInstance() @@ -121,7 +119,7 @@ namespace OHOS delete MusicView; MusicView = nullptr; } - if (MusicView != nullptr) + if (endView != nullptr) { endView->RemoveAll(); delete endView; @@ -286,7 +284,7 @@ namespace OHOS return; } /*获取运动量结束弹窗界面刷新*/ - void TraingCardView::RefreshEndView() + bool TraingCardView::RefreshEndView() { // 获取训练卡路里判断运动量 int caldata = TraingModel::GetInstance()->GetCal(); @@ -306,6 +304,7 @@ namespace OHOS endtitle->SetTextId(STR_LOOK_OUT); notelabel->SetTextId(STR_INSUFFICIENT_EXERCISE_AMOUNT); } + return momentumFlag; } /*获取卡片View单例*/ UIView *TraingCardView::GetTraingCrad() diff --git a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp index 53c69a28c..f3756e7b0 100755 --- a/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp +++ b/code/sdk/application/wearable/service/msg_center/src/msg_center_customer.cpp @@ -126,6 +126,7 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_FINISHED); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_PHONE_TO_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_HFP_WATCH_TO_PHONE); +#ifdef CYWEE_SPORT MsgCenterSubscribeTopic(TOPIC_EVENT_NORMAL_UPDATE); MsgCenterSubscribeTopic(TOPIC_EVENT_TREADMILL_UPDATE); MsgCenterSubscribeTopic(TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE); @@ -134,6 +135,7 @@ void MsgCenterSubscribe() MsgCenterSubscribeTopic(TOPIC_EVENT_FREE_TRAINING_UPDATE); MsgCenterSubscribeTopic(TOPIC_EVENT_AR_ALERT_UPDATE); MsgCenterSubscribeTopic(TOPIC_EVENT_EXTRA_INFO_UPDATE); +#endif #ifdef SUPPORT_CHARGER_PLUG_DETECTION_NOTIFICATION MsgCenterSubscribeTopic(TOPIC_EVENT_CHARGE_PLUG); MsgCenterSubscribeTopic(TOPIC_EVENT_CHARGE_UNPLUG); @@ -166,7 +168,6 @@ void MsgCenterSubscribe() #endif MsgCenterSubscribeTopic(TOPIC_EVENT_FIND_WATCH); MsgCenterSubscribeTopic(TOPIC_EVENT_CANCEL_FIND_WATCH); - } static OHOS::UIViewGroup* showAlarmNotify(void) -- 2.17.1