From: Caisking <3449750381@qq.com> Date: Wed, 10 Apr 2024 07:26:50 +0000 (+0800) Subject: 增加训练详细数据卡片;心率血氧数据实现动态管理 X-Git-Tag: release_V1.2.70_20241020_135402~1200^2~6 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=ee825df25c8eb3e674fd4bb561450e497ff5fffa;p=mirrors%2FFD230.git 增加训练详细数据卡片;心率血氧数据实现动态管理 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index b6847b9b1..dbd97e527 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -493,6 +493,7 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TraingCardPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TrainingControlView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TrainingDataView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TrainingDetailView.cpp #训练记录 ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordView.cpp diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/defult_health.json b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/defult_health.json index 50b82dbb8..77e0e542a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/defult_health.json +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/defult_health.json @@ -1,46 +1,22 @@ { "spo2_latest_data": { - "oxygen_value": 98, - "timestamp": 1646769855 + "oxygen_value": 0, + "timestamp": 0 }, "spo2_data_list": [ { - "oxygen_value": 95, - "timestamp": 1646769823 - }, - { - "oxygen_value": 97, - "timestamp": 1646769844 - }, - { - "oxygen_value": 96, - "timestamp": 1646769849 - }, - { - "oxygen_value": 98, - "timestamp": 1646769855 + "oxygen_value": 0, + "timestamp": 0 } ], "heart_latest_data": { - "heart_value": 88, - "timestamp": 1646769855 + "heart_value": 0, + "timestamp": 0 }, "heart_data_list": [ { - "heart_value": 95, - "timestamp": 1646769823 - }, - { - "heart_value": 57, - "timestamp": 1646769844 - }, - { - "heart_value": 86, - "timestamp": 1646769849 - }, - { - "heart_value": 88, - "timestamp": 1646769855 + "heart_value": 0, + "timestamp": 0 } ] } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp index f1bd27ebd..8f46c7e3e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.cpp @@ -3,9 +3,13 @@ #include #include "wearable_log.h" #include "cJSON.h" +#include +#include namespace OHOS { static HealthService *g_pHealthService = nullptr; + static constexpr const char *HEALTH_JSON_PATH = "/user/userdata/health/"; + cJSON *root = NULL; HealthService::HealthService() { @@ -23,7 +27,89 @@ namespace OHOS static HealthService instance; return &instance; } + /* --------------------------------- 文件IO操作 --------------------------------- */ + /*创建文件夹*/ + bool HealthService::CreateHealthFolder() + { + struct stat info; + if (stat(HEALTH_JSON_PATH, &info) != 0) + { + if (mkdir(HEALTH_JSON_PATH, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) + { + return false; // Failed to create folder + } + } + return true; + } + /*获取日期*/ + std::string GetCurrentDate() + { + time_t now = time(0); + tm *ltm = localtime(&now); + char date[20]; + strftime(date, sizeof(date), "%Y%m%d", ltm); + return std::string(date); + } + /*生成文件*/ + std::string GetJsonFilePath() + { + std::string currentDate = GetCurrentDate(); + return std::string(HEALTH_JSON_PATH) + currentDate + ".json"; + } + bool HealthService::LoadJsonData() + { + // 创建健康数据文件夹 + if (!CreateHealthFolder()) + { + return false; + } + // 获取当天日期对应的JSON文件路径 + std::string jsonFilePath = GetJsonFilePath(); + std::ifstream inFile(jsonFilePath); + if (!inFile.is_open()) + { + // 如果文件不存在,则创建一个包含默认值的JSON文件 + cJSON *defaultJson = cJSON_Parse("{\ + \"spo2_latest_data\": {\ + \"oxygen_value\": 0, \ + \"timestamp\": 0 \ + }, \ + \"spo2_data_list\": [\ + {\ + \"oxygen_value\": 0, \ + \"timestamp\": 0 \ + }\ + ], \ + \"heart_latest_data\": {\ + \"heart_value\": 0, \ + \"timestamp\": 0 \ + }, \ + \"heart_data_list\": [\ + {\ + \"heart_value\": 0, \ + \"timestamp\": 0 \ + }\ + ]\ + }"); + std::ofstream outFile(jsonFilePath); + if (!outFile.is_open()) + { + return false; // 无法创建文件 + } + char *defaultJsonString = cJSON_Print(defaultJson); + outFile << defaultJsonString; // 写入包含默认值的JSON对象 + outFile.close(); + cJSON_Delete(defaultJson); + inFile.open(jsonFilePath); // 重新打开文件 + } + // 读取JSON文件内容 + std::string jsonDataString((std::istreambuf_iterator(inFile)), std::istreambuf_iterator()); + const char *jsonData = jsonDataString.c_str(); + root = cJSON_Parse(jsonData); + return true; + } +#if 0 bool HealthService::LoadJsonData() { std::ifstream inFile(HEALTH_JSON_PATH); @@ -36,7 +122,7 @@ namespace OHOS root = cJSON_Parse(jsonData); return true; } - +#endif BloodOxygenData *HealthService::ReadBloodOxygenData() { LoadJsonData(); @@ -47,7 +133,6 @@ namespace OHOS cJSON_Delete(root); return data; } - bool HealthService::UpdateBloodOxygenData(const BloodOxygenData &data) { LoadJsonData(); @@ -130,7 +215,8 @@ namespace OHOS bool HealthService::UpdateJsonData() { - std::ofstream outFile(HEALTH_JSON_PATH); + std::string jsonFilePath = GetJsonFilePath(); + std::ofstream outFile(jsonFilePath); if (!outFile.is_open()) { return false; diff --git a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h index a23c39955..d6175d759 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h +++ b/code/sdk/application/wearable/fd230app/nativeui/heart_blood/health_service/health_service.h @@ -43,6 +43,7 @@ namespace OHOS HealthService(); ~HealthService(); static HealthService *GetInstance(void); + bool CreateHealthFolder(); bool LoadJsonData(); // 加载json BloodOxygenData *ReadBloodOxygenData(); // 读取血氧数据 bool UpdateBloodOxygenData(const BloodOxygenData &data); // 更新血氧数据 @@ -50,8 +51,6 @@ namespace OHOS HeartPoints *ReadHeartRateDataList(); // 读取心率列表 bool UpdateHeartRateData(const HeartRateData &data); // 更新心率数据 bool UpdateJsonData(); // 更新json - private: - static constexpr const char *HEALTH_JSON_PATH = "/user/userdata/health.json"; }; } #endif // HEALTH_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp index 5a77f25c1..427cf9fad 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainViewSample.cpp @@ -25,7 +25,7 @@ namespace OHOS CardId id; UICardPage *(MainViewSample::*func)(void); }; - //严格按照Id对应 + // 严格按照Id对应 static const MainViewMapper CardMapper[] = { {WATCH_FACE, &MainViewSample::InitWatchFacePage}, {HEART_RATE, &MainViewSample::InitHeartRatePage}, @@ -255,6 +255,7 @@ namespace OHOS dropDownView->SetViewId("dropDownView"); dropDownView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); dropDownView->SetStyle(STYLE_BACKGROUND_OPA, OPA_TRANSPARENT); + /* -------------------------------------------------------------------------- */ messageView = new MessageCardView(); if (messageView == nullptr) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp index 4c5a733aa..b9ed27711 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp @@ -218,7 +218,7 @@ namespace OHOS button_exit = new UIButton(); } button_exit->SetPosition(204, 350); // widget's left position and top position - button_exit->Resize(60, 60); // widget's width and height + button_exit->Resize(100, 100); // widget's width and height button_exit->SetViewId("button_exit"); // Set style button_exit->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); button_exit->SetStyle(STYLE_BACKGROUND_OPA, 0x00); @@ -226,7 +226,7 @@ namespace OHOS // Set additional property char *button1defaultImgSrc = "/user/res/Save_Ele/finger.bin"; char *button1triggeredImgSrc = nullptr; - button_exit->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + button_exit->SetImageSrc(button1defaultImgSrc, button1defaultImgSrc); button_exit->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); // Add the CallBack about events 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 f4c0623c1..d4c345a08 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -475,7 +475,7 @@ namespace OHOS } /* 开启定时器 */ - void InitTraingTimer() + void InitTimer(void) { if (g_startCounting != NULL) { @@ -503,11 +503,12 @@ namespace OHOS } g_startCounting = NULL; } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "InitTimer!"); return; } } /* 关闭定时器 */ - void DisableTraingTimer() + void DisableTimer(void) { if (g_startCounting != NULL) { @@ -519,6 +520,39 @@ namespace OHOS } g_startCounting = NULL; g_motionTimes = 0; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DisableTimer!"); + } + } + /* 暂停定时器 */ + void PauseTimer(void) + { + // 检查定时器是否存在 + if (g_startCounting != NULL) + { + // 暂停定时器,但不删除它 + osStatus_t ret = osTimerStop(g_startCounting); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StopWatch_PauseTimer osTimerStop failed, ret = %lx!!", ret); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "PauseTimer!"); + } + } + + /*恢复定时器*/ + void ResumeTimer(void) + { + // 检查定时器是否存在 + if (g_startCounting != NULL) + { + int tick = osMs2Tick(MS_ONE_SECONDS); + // 恢复定时器 + osStatus_t ret = osTimerStart(g_startCounting, tick); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResumeTimer osTimerStart failed, ret = %lx!!", ret); + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ResumeTimer!"); } } 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 26a577c0a..7253a0827 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 @@ -29,6 +29,7 @@ #include "PlayersView.h" #include "traing/training_card/include/TrainingControlView.h" #include "traing/training_card/include/TrainingDataView.h" +#include "traing/training_card/include/TrainingDetailView.h" namespace OHOS { @@ -42,6 +43,7 @@ namespace OHOS class TraingCardPresenter; class TrainingControlView; class TrainingDataView; + class TrainingDetailView; class TraingCardView : public View { @@ -58,22 +60,25 @@ namespace OHOS UICardPage *InitControlPage(void); UICardPage *InitDataPage(void); UICardPage *InitMusicPage(void); + UICardPage *InitDetailPage(void); void InitView(); void DeInit(); void InitList(); void PreLoad(void); - - int GetCurrentPageId(); + + int GetCurrentPage(); + private: UIView::OnDragListener *draglistener{nullptr}; TraingCardView(TraingCardView &&) = delete; TraingCardView &operator=(TraingCardView &&) = delete; - UISwipeView *swipe_ = nullptr; + UICrossView *swipe_ = nullptr; TrainingControlView *ControlView{nullptr}; TrainingDataView *DataVIew{nullptr}; + TrainingDetailView *DetailView{nullptr}; PlayersView *MusicView{nullptr}; bool viewiInitStatus{false}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDetailView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDetailView.h new file mode 100644 index 000000000..874f788b5 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDetailView.h @@ -0,0 +1,72 @@ +#ifndef _TrainingDetail_VIEW_H +#define _TrainingDetail_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +#include "components/ui_image_animator.h" +#include "components/ui_label_button_ext.h" +#include "components/ui_chart.h" +#include "components/ui_list.h" +#include "components/icon_adapter.h" +#include "wearable_log.h" +#include "ohos_types.h" +#include "components/ui_card_page.h" +#include "traing/include/TraingModel.h" +#include "traing/Training_UiConfig.h" + +#include "traing/include/TraingModel.h" +#include "traing/Training_UiConfig.h" + +#include "traing/training_card/include/TrainingDetailView.h" +#include "traing/training_card/include/TraingCardPresenter.h" +namespace OHOS +{ + + class TrainingDetailView : public UICardPage + { + public: + TrainingDetailView(); + virtual ~TrainingDetailView(); + static TrainingDetailView *GetInstance(void); + + void InitView(); + void DeInit(); + + void PreLoad(void) override; + void UnLoad(void) override; + // UILabelExt *GetTimeLabel(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TrainingDetailView(TrainingDetailView &&) = delete; + TrainingDetailView &operator=(TrainingDetailView &&) = delete; + + UIViewGroup *container_ = nullptr; + + UILabelExt *u_heartlabel = nullptr; + UILabelExt *u_milelabel = nullptr; + UILabelExt *u_stepslabel = nullptr; + UILabelExt *u_calorielabel = nullptr; + UILabelExt *heartlabel = nullptr; + UILabelExt *milelabel = nullptr; + UILabelExt *steplabel = nullptr; + UILabelExt *calorielabel = nullptr; + + UIImageView *heartimage = nullptr; + UIImageView *mileimage = nullptr; + UIImageView *stepimage = nullptr; + UIImageView *calorieimage = nullptr; + UIImageView *lineimage1_ = nullptr; + UIImageView *lineimage2_ = nullptr; + UIImageView *lineimage3_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingDetail_PRESENTER_H 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 2787f0efc..c5ec9eff1 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 @@ -10,7 +10,13 @@ #include #include "traing/training_card/include/TraingCardPresenter.h" // #include "TraingCardView.h" - +extern "C" +{ + void InitTimer(); + void DisableTimer(); + void PauseTimer(); + void ResumeTimer(); +} namespace OHOS { // 当前Presenter属性实例化的内存指针 @@ -59,18 +65,18 @@ namespace OHOS bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) { - uint8_t viewid = TraingCardView::GetInstance()->GetCurrentPageId(); - // const char *viewid = view.GetViewId(); - if (viewid == Control_Card::DATA) - { - if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) - { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDETAIL); - } - return true; - } + // uint8_t viewid = TraingCardView::GetInstance()->GetCurrentPage(); + // // const char *viewid = view.GetViewId(); + // if (viewid == Control_Card::DATA) + // { + // if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDETAIL); + // } + // return true; + // } UNUSED(view); - return false; + return true; } bool TraingCardPresenter::OnClick(UIView &view, const ClickEvent &event) @@ -82,18 +88,22 @@ namespace OHOS if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Start) { TrainingControlView::GetInstance()->GetLabel()->SetText("ç»§ç»­"); - TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_CONTINUE_IMAGE, nullptr); + TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_CONTINUE_IMAGE, SPORT_CONTINUE_IMAGE); // 设置为暂停状态 TraingModel::GetInstance()->SetSportState(ExerciseState::Pause); + // 暂停计时器 + PauseTimer(); return true; } // 暂停状态 if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Pause) { TrainingControlView::GetInstance()->GetLabel()->SetText("暂停"); - TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_PAUSE_IMAGE, nullptr); + TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_PAUSE_IMAGE, SPORT_PAUSE_IMAGE); // 设置为开始状态 TraingModel::GetInstance()->SetSportState(ExerciseState::Start); + // 恢复计时器 + ResumeTimer(); return true; } } @@ -105,7 +115,7 @@ namespace OHOS return true; } - // 计时器更新 + // 计时器更新timer void TraingCardPresenter::ModifiesTime() { std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); 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 b3007a5d2..660402863 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 @@ -18,8 +18,8 @@ extern "C" { - void InitTraingTimer(); - void DisableTraingTimer(); + void InitTimer(); + void DisableTimer(); } namespace OHOS @@ -34,7 +34,7 @@ namespace OHOS { g_pTraingCardView = this; // 开启计时器 - InitTraingTimer(); + InitTimer(); // 设置运动状态为开始 TraingModel::GetInstance()->SetSportState(ExerciseState::Start); } @@ -44,7 +44,7 @@ namespace OHOS DeInit(); g_pTraingCardView = nullptr; // 关闭计时器 - DisableTraingTimer(); + DisableTimer(); // 设置运动状态为结束 TraingModel::GetInstance()->SetSportState(ExerciseState::End); } @@ -61,7 +61,7 @@ namespace OHOS if (swipe_ == nullptr) { - swipe_ = new UISwipeView(); + swipe_ = new UICrossView(); swipe_->SetPosition(0, 0, 466, 466); swipe_->SetStyle(STYLE_BACKGROUND_OPA, 0); } @@ -69,12 +69,16 @@ namespace OHOS InitControlPage(); InitDataPage(); InitMusicPage(); + InitDetailPage(); - swipe_->Add(ControlView); - swipe_->Add(DataVIew); - swipe_->Add(MusicView); + swipe_->HorAdd(ControlView); + swipe_->HorAdd(DataVIew); + swipe_->HorAdd(MusicView); + // swipe_->HorAdd(DetailView); - swipe_->SetCurrentPage(Control_Card::CONTROL); + swipe_->VerAdd(DetailView, UICrossView::VPage::DOWN_PAGE); + + swipe_->SetHorCurrentPage(Control_Card::CONTROL); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); } @@ -100,6 +104,12 @@ namespace OHOS delete DataVIew; DataVIew = nullptr; } + if (DetailView != nullptr) + { + DetailView->RemoveAll(); + delete DetailView; + DetailView = nullptr; + } if (MusicView != nullptr) { MusicView->RemoveAll(); @@ -140,7 +150,18 @@ namespace OHOS } return MusicView; } - + UICardPage *TraingCardView::InitDetailPage() + { + DetailView = new TrainingDetailView(); + DetailView->PreLoad(); + DetailView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + if (DetailView == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DetailView new fail"); + return nullptr; + } + return DetailView; + } void TraingCardView::PreLoad(void) { if (!viewiInitStatus) @@ -148,10 +169,11 @@ namespace OHOS InitView(); viewiInitStatus = true; } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingCardView PreLoad"); } void TraingCardView::OnStart() { - swipe_ = new UISwipeView(); + swipe_ = new UICrossView(); if (swipe_ == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "swipe_ new fail"); @@ -194,8 +216,8 @@ namespace OHOS return; } - int TraingCardView::GetCurrentPageId() + int TraingCardView::GetCurrentPage() { - return swipe_->GetCurrentPage(); + return swipe_->GetCurrentPageId(0); // 获取水平页面 } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDataView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDataView.cpp index 02f93db63..b61bf673f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDataView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDataView.cpp @@ -66,6 +66,9 @@ namespace OHOS buttonNote->SetImageSrc(NOTE_IMAGE, NOTE_IMAGE); buttonNote->SetOnClickListener(static_cast(TraingCardPresenter::GetInstance())); Add(buttonNote); + + //增加上拉卡片 + SetCoverable(true); } /* DeInit:删除组件 */ diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDetailView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDetailView.cpp new file mode 100644 index 000000000..b7bbdc4d5 --- /dev/null +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingDetailView.cpp @@ -0,0 +1,177 @@ + +#include "traing/training_card/include/TrainingDetailView.h" +#include "traing/training_card/include/TraingCardView.h" + +#include "common/image_cache_manager.h" +#include "components/ui_label_ext.h" +#include "language/font/ui_resource_string.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +#include "traing/include/TraingModel.h" +#include "traing/Training_UiConfig.h" + +namespace OHOS +{ + + static TrainingDetailView *g_pTrainingDetailView{nullptr}; + + TrainingDetailView::TrainingDetailView() + { + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pTrainingDetailView = this; + } + TrainingDetailView::~TrainingDetailView() + { + RemoveAll(); + DeInit(); + g_pTrainingDetailView = nullptr; + } + + TrainingDetailView *TrainingDetailView::GetInstance() + { + return g_pTrainingDetailView; + } + + /* InitView:初始化界面*/ + void TrainingDetailView ::InitView() + { + // 初始化Image + TraingModel::GetInstance()->InitImageView(heartimage, 134, 58, 30, 30, "image1", HEARTRATE_30_IMAGE); + TraingModel::GetInstance()->InitImageView(mileimage, 44, 189, 30, 30, "image2", MILEAGE_30_IMAGE); + TraingModel::GetInstance()->InitImageView(stepimage, 297, 189, 30, 30, "image3", STEP_30_IMAGE); + TraingModel::GetInstance()->InitImageView(calorieimage, 129, 335, 30, 30, "image4", CALORIES_30_IMAGE); + TraingModel::GetInstance()->InitImageView(lineimage1_, 0, 160, 10, 466, "image5", LINE_1_IMAGE); + TraingModel::GetInstance()->InitImageView(lineimage2_, 233, 193, 80, 20, "image5", LINE_2_IMAGE); + TraingModel::GetInstance()->InitImageView(lineimage3_, 0, 306, 10, 466, "image5", LINE_1_IMAGE); + Add(heartimage); + Add(mileimage); + Add(stepimage); + Add(calorieimage); + Add(lineimage1_); + Add(lineimage2_); + Add(lineimage3_); + // 初始化Lable + TraingModel::GetInstance()->InitLabel(u_heartlabel, 174, 60, 90, 35, "label1", "心率(次/分)", DEFAULT_VECTOR_FONT_FILENAME, 26); + TraingModel::GetInstance()->InitLabel(u_milelabel, 80, 190, 60, 40, "label2", "距离(公里)", DEFAULT_VECTOR_FONT_FILENAME, 26); + TraingModel::GetInstance()->InitLabel(u_stepslabel, 332, 189, 60, 40, "label3", "步数", DEFAULT_VECTOR_FONT_FILENAME, 26); + TraingModel::GetInstance()->InitLabel(u_calorielabel, 167, 336, 60, 40, "label4", "卡路里(千卡)", DEFAULT_VECTOR_FONT_FILENAME, 26); + TraingModel::GetInstance()->InitLabel(heartlabel, 202, 94, 60, 40, "label5", "144", DEFAULT_VECTOR_FONT_FILENAME, 40); + TraingModel::GetInstance()->InitLabel(milelabel, 76, 233, 60, 40, "label6", "13.21", DEFAULT_VECTOR_FONT_FILENAME, 40); + TraingModel::GetInstance()->InitLabel(steplabel, 300, 233, 60, 40, "label7", "28312", DEFAULT_VECTOR_FONT_FILENAME, 40); + TraingModel::GetInstance()->InitLabel(calorielabel, 175, 376, 60, 40, "label8", "210.03", DEFAULT_VECTOR_FONT_FILENAME, 40); + Add(u_heartlabel); + Add(u_milelabel); + Add(u_stepslabel); + Add(u_calorielabel); + Add(heartlabel); + Add(milelabel); + Add(steplabel); + Add(calorielabel); + + SetTouchable(true); + SetIntercept(true); + } + /* DeInit:删除组件 */ + void TrainingDetailView::DeInit() + { + RemoveAll(); + if (u_heartlabel != nullptr) + { + delete u_heartlabel; + u_heartlabel = nullptr; + } + if (u_milelabel != nullptr) + { + delete u_milelabel; + u_milelabel = nullptr; + } + if (u_stepslabel != nullptr) + { + delete u_stepslabel; + u_stepslabel = nullptr; + } + if (u_calorielabel != nullptr) + { + delete u_calorielabel; + u_calorielabel = nullptr; + } + if (heartlabel != nullptr) + { + delete heartlabel; + heartlabel = nullptr; + } + if (milelabel != nullptr) + { + delete milelabel; + milelabel = nullptr; + } + if (steplabel != nullptr) + { + delete steplabel; + steplabel = nullptr; + } + if (calorielabel != nullptr) + { + delete calorielabel; + calorielabel = nullptr; + } + + // 删除Image + if (heartimage != nullptr) + { + delete heartimage; + heartimage = nullptr; + } + if (mileimage != nullptr) + { + delete mileimage; + mileimage = nullptr; + } + if (stepimage != nullptr) + { + delete stepimage; + stepimage = nullptr; + } + if (calorieimage != nullptr) + { + delete calorieimage; + calorieimage = nullptr; + } + if (lineimage1_ != nullptr) + { + delete lineimage1_; + lineimage1_ = nullptr; + } + if (lineimage2_ != nullptr) + { + delete lineimage2_; + lineimage2_ = nullptr; + } + if (lineimage3_ != nullptr) + { + delete lineimage3_; + lineimage3_ = nullptr; + } + } + + void TrainingDetailView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TrainingDetailView"); + } + + void TrainingDetailView::UnLoad(void) {} + /* + UILabelExt *TrainingDetailView::GetTimeLabel() + { + return timerlabel; + } + */ + +} diff --git a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c index 2eb18f0e6..bdbc0ca8d 100644 --- a/code/sdk/drivers/peripheral/cywee/service/cywee_service.c +++ b/code/sdk/drivers/peripheral/cywee/service/cywee_service.c @@ -69,8 +69,8 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen PRINT("CYWEE_MSG_TYPE_NORMAL_UPDATE"); PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", c_result_t.activity_mode,c_result_t.steps,c_result_t.distance,c_result_t.calories,c_result_t.step_frequency, - c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_NORMAL_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_NORMAL_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; //跑步机模式 @@ -78,8 +78,8 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen PRINT("CYWEE_MSG_TYPE_TREADMILL_UPDATE"); PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", c_result_t.activity_mode,c_result_t.steps,c_result_t.distance,c_result_t.calories,c_result_t.step_frequency, - c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_TREADMILL_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_TREADMILL_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; //户外跑步模式 @@ -87,8 +87,8 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen PRINT("CYWEE_MSG_TYPE_OUTDOOR_RUNNING_UPDATE"); PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", c_result_t.activity_mode,c_result_t.steps,c_result_t.distance,c_result_t.calories,c_result_t.step_frequency, - c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_OUTDOOR_RUNNING_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; //室内跑步模式 @@ -96,8 +96,8 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen PRINT("CYWEE_MSG_TYPE_INDOOR_RUNNING_UPDATE"); PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", c_result_t.activity_mode,c_result_t.steps,c_result_t.distance,c_result_t.calories,c_result_t.step_frequency, - c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_INDOOR_RUNNING_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_INDOOR_RUNNING_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; //防误触计步模式 @@ -105,32 +105,32 @@ void cywee_msg_callback(uint8_t msg_type, uint8_t *msg_data, int32_t msg_datalen PRINT("CYWEE_MSG_TYPE_FITNESS_PEDOMETERR_UPDATE"); PRINT("activit_mode[%d], steps[%d], distance[%d], calories[%d], step frequency[%d], step length[%d], pace[%d], BMR calories[%d], is_pause[%d],len[%d]\n", c_result_t.activity_mode,c_result_t.steps,c_result_t.distance,c_result_t.calories,c_result_t.step_frequency, - c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.step_length,c_result_t.pace,c_result_t.BMR_calories,c_result_t.is_pause,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_FITNESS_PEDOMETERR_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; //自由运动模式 case CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE: PRINT("CYWEE_MSG_TYPE_FREE_TRAINING_UPDATE"); PRINT("activit_mode[%d], calories[%d], duration[%d],len[%d]\n", - c_result_t.activity_mode,c_result_t.calories,c_result_t.duration,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_FREE_TRAINING_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.activity_mode,c_result_t.calories,c_result_t.duration,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_FREE_TRAINING_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; //长时间动作侦测模式 case CYWEE_MSG_TYPE_AR_ALERT_UPDATE: PRINT("CYWEE_MSG_TYPE_AR_ALERT_UPDATE"); PRINT("activit_mode[%d], ar alert type[%d], len[%d]\n", - c_result_t.activity_mode,c_result_t.ar_alert_type,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_AR_ALERT_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.activity_mode,c_result_t.ar_alert_type,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_AR_ALERT_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; //额外信息 case CYWEE_MSG_TYPE_EXTRA_INFO_UPDATE: PRINT("CYWEE_MSG_TYPE_EXTRA_INFO_UPDATE"); PRINT("average step frequency[%d], average step length[%d], average pace[%d], max step frequency[%d], max pace[%d]\n", - c_result_t.avg_step_freq,c_result_t.avg_step_len,c_result_t.avg_pace,c_result_t.max_step_freq,c_result_t.max_pace,sizeof(c_result_t)); - CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_result_t,sizeof(c_result_t)); + c_result_t.avg_step_freq,c_result_t.avg_step_len,c_result_t.avg_pace,c_result_t.max_step_freq,c_result_t.max_pace,sizeof(cywee_result_t)); + CustomEventPublish(TOPIC_EVENT_EXTRA_INFO_UPDATE,&c_result_t,sizeof(cywee_result_t)); break; default: PRINT("Unknown sensor message type");