From: Caisking <3449750381@qq.com> Date: Tue, 13 Aug 2024 08:05:26 +0000 (+0800) Subject: 设置目标界面增加选择目标显示 X-Git-Tag: release_V1.2.70_20241020_135402~673^2~4 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=07d7a07ff7586b02e848307660900a9e41b6a4ee;p=mirrors%2FFD230.git 设置目标界面增加选择目标显示 --- 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 6bf035a06..83ce2fe66 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -152,7 +152,7 @@ namespace OHOS Distance, Calories, Duration, - STEP, + Steps, UNKNOW, }; @@ -237,108 +237,72 @@ namespace OHOS /*定时器 */ std::string DisplayMotionDuration(); - /*设置运动类型*/ - void SetSportType(Exercisetype type); - /*获取运动类型图片*/ - std::string GetSportType(Exercisetype sporttype); - std::string GetSportIcon(Exercisetype sporttype); - /*设置运动项目*/ - void SetSportEvent(UIResourceTextId id); - /*获取运动项目*/ - UIResourceTextId GetSportEvent(); - /*获取运动项目Id*/ - ExerciseClass GetSportId(); - /*设置运动状态*/ - void SetSportState(ExerciseState state); - /*获取运动状态*/ - ExerciseState GetSportState(); - /*解析传输过来的数据*/ - void AnalysisData(cywee_activity_result_t *cyweeInfo); - /*解析运动额外数据*/ - void AnalysisExtraData(cywee_activity_result_extre_info_t *cyweeInfo); - /*获取训练数据*/ - SportData *GetSportdata(); - /*设置训练数据[为训练记录准备]*/ - void SetSportdata(SportData *data); - /*获取运动卡路里*/ - int GetCal(); - /*解析时间戳*/ - std::string AnalysisTimestamp(uint64_t timestamp); - /*获取运动总时长*/ - std::string GetTrainingTime(); - /*设置训练目标类型以及训练目标*/ - void SetSportTag(ExerciseTag tagtpye, int tag); - /*获取训练目标*/ - int GetSportTag(); - /*获取项目目标类型*/ - ExerciseTag GetSportTagtype(); - /*设置训练强度*/ - void SetIntensity(int heart); - /*获取训练强度STR*/ - UIResourceTextId GetIntensity(); - /*获取对应的训练目标的值*/ - int GetSportTagData(); - /*获取训练目标完成百分比*/ - int GetGoaldegree(); - /*保存数据*/ - bool SaveSportData(); - /*设置运动开始方式*/ - void SetSportOpenWay(bool way); - /*设置运动是否开始*/ - void SetSportOpenState(bool state); - /*获取运动是否开始*/ - bool GetSportOpenState(); - /*获取训练量是否达标*/ - bool GetMomentum(); - /*发送实时数据*/ - void SendLiveData(); - /*打印数据*/ - void printTrainingData(const Trainingdata &data); - - std::string GetStartTiemStr(); - std::string GetEndTiemStr(); - - /*平均心率计算*/ - int CalculateAverageHeartRate(int newHeartRate); - /*显示心率计算*/ - int CalculateFilteredHeartRate(int newHeartRate); - - int Averageheartrate(int newHeartRate); - - /*保存训练记录到json文件*/ - bool CheckDataJson(); - bool SaveDataToJson(SportData *data); - std::vector LoadDataFormJson(); - - /*打印函数*/ - void printf_data(SportData *data); - /*获取协议Id*/ - int GetBleSportId(Exercisetype sporttype, UIResourceTextId id); - /*获取训练类Id*/ - UIResourceTextId GetSportTypeId(Exercisetype type); - - /*重新初始化训练配置*/ - void ResetSharedTrainingData(); - /*设置训练开始与结束*/ - void SetTimestamp(); - /*设置开始时间*/ - void SetStartDateTime(); - /*设置结束时间*/ - void SetEndTime(); - /*获取日期*/ - bool GetFormattedDate(std::string &dateOutput, const char *errorMsg); - /*获取时间*/ - bool GetFormattedTime(std::string &timeOutput, const char *errorMsg); - /*保存数据*/ - void RecordSportData(); - - /*进入训练方式*/ - void SetEntryType(ENTEYTYPE type); - ENTEYTYPE GetEntryType(); - - /*判断是否为特殊运动*/ - void IsSpecialSport(UIResourceTextId sportId_); - bool GetIsSpecial(); + + // 训练存储相关配置 + bool CheckDataJson(); /*判断json文件是否存在*/ + bool SaveDataToJson(SportData *data); /*保存训练记录到json文件*/ + std::vector LoadDataFormJson(); /*加载json文件*/ + void RecordSportData(); /*保存数据*/ + + // 训练数据相关配置 + void AnalysisData(cywee_activity_result_t *cyweeInfo); /*解析传输过来的数据*/ + void AnalysisExtraData(cywee_activity_result_extre_info_t *cyweeInfo); /*解析运动额外数据*/ + SportData *GetSportdata(); /*获取训练数据*/ + void SetIntensity(int heart); /*设置训练强度*/ + UIResourceTextId GetIntensity(); /*获取训练强度STR*/ + bool SaveSportData(); /*保存数据*/ + void SendLiveData(); /*发送实时数据*/ + int CalculateAverageHeartRate(int newHeartRate); /*平均心率计算*/ + int CalculateFilteredHeartRate(int newHeartRate); /*显示心率计算*/ + int Averageheartrate(int newHeartRate); /*平均心率窗口数*/ + void SetSportdata(SportData *data); /*设置训练数据[为训练记录准备]*/ + int GetCal(); /*获取运动卡路里*/ + + // 训练状态相关配置 + void SetEntryType(ENTEYTYPE type); /*设置进入训练方式*/ + ENTEYTYPE GetEntryType(); /*获取训练进入方式*/ + void SetSportOpenWay(bool way); /*设置运动开始方式*/ + void SetSportOpenState(bool state); /*设置运动是否开始*/ + bool GetSportOpenState(); /*获取运动是否开始*/ + bool GetMomentum(); /*获取训练量是否达标*/ + void SetSportState(ExerciseState state); /*设置运动状态*/ + ExerciseState GetSportState(); /*获取运动状态*/ + void ResetSharedTrainingData(); /*重新初始化训练配置*/ + + // 训练时间相关配置 + std::string AnalysisTimestamp(uint64_t timestamp); /*解析时间戳*/ + std::string GetTrainingTime(); /*获取运动总时长*/ + std::string GetStartTiemStr(); /*获取开始时间Str*/ + std::string GetEndTiemStr(); /*获取结束时间Str*/ + void SetTimestamp(); /*设置训练开始与结束*/ + void SetStartDateTime(); /*设置开始时间*/ + void SetEndTime(); /*设置结束时间*/ + bool GetFormattedDate(std::string &dateOutput, const char *errorMsg); /*获取日期*/ + bool GetFormattedTime(std::string &timeOutput, const char *errorMsg); /*获取时间*/ + + // 训练项相关配置 + void IsSpecialSport(UIResourceTextId sportId_); /*判断是否为特殊训练*/ + bool GetIsSpecial(); /*获取是否为特殊训练*/ + void SetSportEvent(UIResourceTextId id); /*设置运动项目*/ + UIResourceTextId GetSportEvent(); /*获取运动项目*/ + ExerciseClass GetSportId(); /*获取运动项目Id*/ + int GetBleSportId(Exercisetype sporttype, UIResourceTextId id); /*获取协议Id*/ + UIResourceTextId GetSportTypeId(Exercisetype type); /*获取训练类Id*/ + void SetSportType(Exercisetype type); /*设置运动类型*/ + std::string GetSportType(Exercisetype sporttype); /*获取训练类型type图片*/ + std::string GetSportIcon(Exercisetype sporttype); /*获取训练类型icon图片*/ + + // 训练目标相关配置 + void SetSportTag(ExerciseTag tagtpye, int tag); /*设置训练目标类型以及训练目标*/ + int GetSportTag(); /*获取训练目标*/ + ExerciseTag GetSportTagtype(); /*获取项目目标类型*/ + int GetSportTagData(); /*获取对应的训练目标的值*/ + int GetGoaldegree(); /*获取训练目标完成百分比*/ + std::string GetTagStr(); /*获取训练目标Str*/ + + // 打印配置 + void printTrainingData(const Trainingdata &data); /*打印数据*/ + void printf_data(SportData *data); /*打印函数*/ private: TraingModel(const TraingModel &) = delete; @@ -353,9 +317,6 @@ namespace OHOS ENTEYTYPE entey_type = ENTEYTYPE::MAIN_ENTER; // 进入方式 bool isspecialsport_{false}; - - // int currentdata = 0; // 当前目标配置 - int sportTag_ = 0; // 训练目标 int freq = 0; // 训练发送数据频率 diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h index edbe7dc9a..54f04d687 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingSetView.h @@ -65,7 +65,8 @@ namespace OHOS bool ChangeSetDurationView(int16_t thisview); bool ClickFunc(int16_t interface); void ChangeView(int16_t hideView, int16_t showView); - + void BonusdataView(); // 配置额外数据 + void SetCurrentViewId(int viewId) { CurrentViewId = viewId; 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 dabde6acc..ae2dd7370 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -307,6 +307,7 @@ namespace OHOS void TraingModel::SetSportEvent(UIResourceTextId id) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " SetSportType %d", sportId_); + IsSpecialSport(id); // 设置特殊性 sportId_ = id; } /*获取运动Id*/ @@ -368,7 +369,57 @@ namespace OHOS { return isspecialsport_; } + /*获取目标字符串*/ + std::string TraingModel::GetTagStr() + { + /* + 通用目标配置: 时长、卡路里 + 不通用目标配置: 步数、距离 + + 如果配置项是特殊目标 + -> 普通训练: 无训练目标 + -> 特殊训练: 有训练目标 + */ + + std::string tagStr; + + switch (sportTagType_) + { + case ExerciseTag::Duration: + tagStr = std::to_string(sportTag_) + " min"; // 时长目标 + break; + + case ExerciseTag::Calories: + tagStr = std::to_string(sportTag_) + " kcal"; // 卡路里目标 + break; + + case ExerciseTag::Steps: + case ExerciseTag::Distance: + if (isspecialsport_) // 检查是否为特殊训练 + { + // 只在特殊训练模式下使用步数和距离目标 + if (sportTagType_ == ExerciseTag::Steps) + { + tagStr = std::to_string(sportTag_) + " steps"; // 步数目标 + } + else + { + tagStr = std::to_string(sportTag_) + " km"; // 距离目标 + } + } + else + { + tagStr = ""; // 普通训练下不使用目标 + } + break; + default: + tagStr = ""; // 未知目标类型 + break; + } + + return tagStr; + } /*设置运动状态*/ void TraingModel::SetSportState(ExerciseState state) { @@ -455,8 +506,8 @@ namespace OHOS int maxHeartRate = ConfigModel::GetInstance()->get_configData_int(ConfigModel::CONFIGMODEL_ITEM_TRAINING_HEART_MAX); if (sportdata->heart >= maxHeartRate) { - uapi_set_screen_on_api(); // 亮屏检测 - if(true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) + uapi_set_screen_on_api(); // 亮屏检测 + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) { ui_api_vibrate_once_func(); } @@ -473,7 +524,7 @@ namespace OHOS { // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "currentdata%d", currentdata); uapi_set_screen_on_api(); // 亮屏检测 - if(true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) + if (true != OHOS::ConfigModel::GetInstance()->GetDnotdisturb()) { ui_api_vibrate_once_func(); } @@ -652,9 +703,11 @@ namespace OHOS Startstate = false; Endstate = true; +#if 0 // 重置训练目标 [发生在训练前] sportTag_ = 0; sportTagType_ = ExerciseTag::UNKNOW; +#endif WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "结束运动"); } @@ -944,6 +997,7 @@ namespace OHOS break; } } + /*获取当前的目标值*/ int TraingModel::GetSportTagData() { if (sportdata->tag) @@ -960,7 +1014,7 @@ namespace OHOS case ExerciseTag::Distance: return sportdata->distance; break; - case ExerciseTag::STEP: + case ExerciseTag::Steps: return sportdata->steps; break; default: diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalView.cpp index aba06113a..859377788 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalView.cpp @@ -45,6 +45,7 @@ namespace OHOS } UIResourceTextId sport_id = TraingModel::GetInstance()->GetSportEvent(); + // 初始化Lable InitLabelExt(sporttitle_, 137, 52, 200, 80, "label1", sport_id, DEFAULT_VECTOR_FONT_FILENAME, 30); container_->Add(sporttitle_); @@ -55,6 +56,10 @@ namespace OHOS // 显示设置目标 InitButtonExt(buttonSet_, 160, 370, 150, 50, BUTTONSET, STR_SET_GOALS, 30); + if (TraingModel::GetInstance()->GetTagStr() != "") + { + buttonSet_->SetText((TraingModel::GetInstance()->GetTagStr()).c_str()); + } buttonSet_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); // 设置为透明按键 buttonSet_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); buttonSet_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x80, UIButton::PRESSED); // 设置按下时的透明度为半透明 @@ -83,7 +88,6 @@ namespace OHOS delete buttonSet_; buttonSet_ = nullptr; } - } void TraingNomalView::PreLoad(void) @@ -130,7 +134,10 @@ namespace OHOS } // 更新训练目标 [考虑 通用目标 特殊目标] - void TraingNomalView::UpdateTraingTag() {} + void TraingNomalView::UpdateTraingTag() + { + // buttonSet_->SetText(); + } void TraingNomalView::OnSetUpView() { @@ -152,7 +159,7 @@ namespace OHOS RootView::GetInstance()->RemoveAll(); RootView::GetInstance()->ClearOnKeyActListener(); - //FocusManager::GetInstance()->ClearFocus(); + // FocusManager::GetInstance()->ClearFocus(); return; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp index 676be20fa..fea9365b1 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetPresenter.cpp @@ -191,7 +191,6 @@ namespace OHOS */ ExerciseTag TraingSetPresenter::GetExerciseTagFromCard(int cardID) { - ; switch (cardID) { case SET_DURATION: @@ -201,7 +200,7 @@ namespace OHOS case SET_DISTANCE: return ExerciseTag::Distance; case SET_STEPS: - return ExerciseTag::STEP; + return ExerciseTag::Steps; default: return ExerciseTag::UNKNOW; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp index 58abcb75d..65e487708 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingSetView.cpp @@ -32,7 +32,30 @@ namespace OHOS { return g_pTraingSetView; } + /*增加额外配置项*/ + void TraingSetView ::BonusdataView() + { + InitButton(butDistance, 43, 360, 380, 100, BUTTONDISTANCE); + InitButton(butSteps, 43, 480, 380, 100, BUTTONSTEPS); + butDistance->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); + butSteps->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); + group->Add(butDistance); + group->Add(butSteps); + InitLabelExt(labelDistance, 100, 390, 150, 35, "label3", STR_DISTANCE, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(labelSteps, 100, 510, 150, 35, "label5", STR_STEP_NUMBER, DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(labelDistance); + group->Add(labelSteps); + + InitImageView(imagedistance, 70, 390, 100, 100, "image5", MILEAGE_IMAGE); + InitImageView(imagesteps, 70, 510, 100, 100, "image6", WALKING_IMAGE); + InitImageView(imagicon3, 380, 400, 100, 100, "image3", ICON_IMAGE); + InitImageView(imagicon4, 380, 520, 100, 100, "image4", ICON_IMAGE); + group->Add(imagedistance); + group->Add(imagesteps); + group->Add(imagicon3); + group->Add(imagicon4); + } /* InitView:初始化界面*/ void TraingSetView ::InitView() { @@ -42,56 +65,33 @@ namespace OHOS group->SetPosition(0, 0, 466, 466); group->SetStyle(STYLE_BACKGROUND_OPA, 0); } + // 初始化Lable + UIResourceTextId sportid = TraingModel::GetInstance()->GetSportEvent(); + InitLabelExt(labeltitle, 83, 50, 300, 35, "label1", sportid, DEFAULT_VECTOR_FONT_FILENAME, 30); + group->Add(labeltitle); + // 初始化Button InitButton(butTime, 43, 120, 380, 100, BUTTONTIME); InitButton(butKcal, 43, 240, 380, 100, BUTTONCALULI); butTime->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); butKcal->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); - - InitButton(butDistance, 43, 360, 380, 100, BUTTONDISTANCE); - InitButton(butSteps, 43, 480, 380, 100, BUTTONSTEPS); - butDistance->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); - butSteps->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); - group->Add(butTime); group->Add(butKcal); - group->Add(butDistance); - group->Add(butSteps); - // 初始化Lable - UIResourceTextId sportid = TraingModel::GetInstance()->GetSportEvent(); - InitLabelExt(labeltitle, 83, 50, 300, 35, "label1", sportid, DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabelExt(labelTime, 100, 150, 150, 35, "label2", STR_DURATION, DEFAULT_VECTOR_FONT_FILENAME, 30); InitLabelExt(labelKcal, 100, 270, 150, 35, "label4", STR_CALORIE, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitLabelExt(labelDistance, 100, 390, 150, 35, "label3", STR_DISTANCE, DEFAULT_VECTOR_FONT_FILENAME, 30); - InitLabelExt(labelSteps, 100, 510, 150, 35, "label5", STR_STEP_NUMBER, DEFAULT_VECTOR_FONT_FILENAME, 30); - - group->Add(labeltitle); group->Add(labelTime); group->Add(labelKcal); - group->Add(labelDistance); - group->Add(labelSteps); // 初始化Image InitImageView(imagetime, 70, 150, 100, 100, "image1", TIME_IMAGE); InitImageView(imagcal, 70, 270, 100, 100, "image2", CALORIES_IMAGE); - InitImageView(imagedistance, 70, 390, 100, 100, "image5", MILEAGE_IMAGE); - InitImageView(imagesteps, 70, 510, 100, 100, "image6", WALKING_IMAGE); - InitImageView(imagicon1, 380, 160, 100, 100, "image3", ICON_IMAGE); InitImageView(imagicon2, 380, 280, 100, 100, "image4", ICON_IMAGE); - InitImageView(imagicon3, 380, 400, 100, 100, "image3", ICON_IMAGE); - InitImageView(imagicon4, 380, 520, 100, 100, "image4", ICON_IMAGE); - group->Add(imagetime); group->Add(imagcal); - group->Add(imagedistance); - group->Add(imagesteps); - group->Add(imagicon1); group->Add(imagicon2); - group->Add(imagicon3); - group->Add(imagicon4); } /* DeInit:删除组件 */ void TraingSetView::DeInit() @@ -410,6 +410,12 @@ namespace OHOS group->SetDraggable(true); PreLoad(); + + if (TraingModel::GetInstance()->GetIsSpecial()) + { + BonusdataView(); + } + SetKeyActListener(); // RootView::GetInstance()->Add(SetTagScrollView[SET_VIEW]); // SetCurrentViewId(SET_VIEW); // 设置当前页面ID @@ -438,10 +444,9 @@ namespace OHOS { View::OnStop(); - group->RemoveAll(); RootView::GetInstance()->ClearOnKeyActListener(); - //FocusManager::GetInstance()->ClearFocus(); + // FocusManager::GetInstance()->ClearFocus(); RootView::GetInstance()->RemoveAll(); return; } 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 fa9f8acdd..2ba20c01f 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 @@ -475,7 +475,7 @@ namespace OHOS tagString = tagString + "km"; break; } - case ExerciseTag::STEP: + case ExerciseTag::Steps: break; default: break;