From: Caisking <3449750381@qq.com> Date: Tue, 9 Apr 2024 10:36:04 +0000 (+0800) Subject: 1.增加运动计时以及数据卡片; X-Git-Tag: release_V1.2.70_20241020_135402~1200^2~11^2~1 X-Git-Url: http://git.snicker.com.cn/?a=commitdiff_plain;h=c5efd6cbae59c4fd4e107cc76b26facbcc1faab1;p=mirrors%2FFD230.git 1.增加运动计时以及数据卡片; 2.实现训练time功能 3.配置训练运动状态 --- diff --git a/code/sdk/application/wearable/fd230app/CMakeLists.txt b/code/sdk/application/wearable/fd230app/CMakeLists.txt index fca48d5ea..c4e6b861f 100644 --- a/code/sdk/application/wearable/fd230app/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230app/CMakeLists.txt @@ -491,7 +491,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/training_card/src/TraingCardView.cpp ${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/traingrecord/src/TraingRecordView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traingrecord/src/TraingRecordPresenter.cpp diff --git a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp index bbf6d1a16..f1d2c5cf2 100644 --- a/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp @@ -239,12 +239,13 @@ #include "product_adapter.h" #endif -namespace OHOS { -struct AppViewMapper +namespace OHOS { - AppViewId id; - void (NativeLauncher::*func)(void); -}; + struct AppViewMapper + { + AppViewId id; + void (NativeLauncher::*func)(void); + }; struct ViewIdToString { @@ -343,14 +344,14 @@ struct AppViewMapper #ifdef SUPPORT_ALIPAY_SEC {VIEW_MAIN_ALIPAY, &NativeLauncher::InitMainAlipaySlice}, #endif - {VIEW_SET_DESKTOP, &NativeLauncher::InitSetDesktopSlice}, - {VIEW_SET_CARD, &NativeLauncher::InitSetCardSlice}, - {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice}, - {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice}, + {VIEW_SET_DESKTOP, &NativeLauncher::InitSetDesktopSlice}, + {VIEW_SET_CARD, &NativeLauncher::InitSetCardSlice}, + {VIEW_ADD_CARD, &NativeLauncher::InitAddCardSlice}, + {VIEW_SET_DIAL, &NativeLauncher::InitSetDialSlice}, + {VIEW_MAIN_TEMP, &NativeLauncher::InitMainTempSlice}, #if 0 {VIEW_MAIN_ACTIVITY, &NativeLauncher::InitActivitySlice}, {VIEW_OFFLINEVOICE, &NativeLauncher::InitOfflineVoice}, - {VIEW_MAIN_TEMP, &NativeLauncher::InitMainTempSlice}, {VIEW_UISAMPLE, &NativeLauncher::InitUISampleSlice} #endif }; @@ -383,8 +384,8 @@ struct AppViewMapper void NativeLauncher::InitNativeLauncher() { - #ifdef JS_ENABLE - ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); +#ifdef JS_ENABLE + ACELite::ProductAdapter::SetScreenSize(HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); #endif ConfigModel::GetInstance()->Init(); // 初始化语言 @@ -403,7 +404,7 @@ struct AppViewMapper PresenterTask::GetInstance()->Init(); PlayersModel::GetInstance()->AudioInit(); ActivityModel::GetInstance()->Init(); - ScreenModels::GetInstance()->InitKvStorage(); + ScreenModels::GetInstance()->InitKvStorage(); VocassistModel::GetInstance()->Init(); HeartModel::GetInstance()->Init(); BluetoothModel::GetInstance()->Init(); diff --git a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp index a0feae8c7..45db99d87 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/applist/src/ApplistModel.cpp @@ -39,14 +39,16 @@ namespace OHOS {VIEW_MAIN_STOPWATCH, PNG_APPLIST_STOPWATCH_IMAGE, PNG_APPLIST_STOPWATCH_IMAGE, "秒表", nullptr}, {VIEW_MAIN_COUNTDOWN, PNG_APPLIST_COUNTDOWN_IMAGE, PNG_APPLIST_COUNTDOWN_IMAGE, "计时器", nullptr}, {VIEW_CONNECT_PHONE, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "连接手机", nullptr}, - {VIEW_SET_DESKTOP, PNG_APPLIST_ALARM_IMAGE, PNG_APPLIST_ALARM_IMAGE, "主题样式", nullptr}, - {VIEW_SET_CARD, PNG_APPLIST_SETTING_IMAGE, PNG_APPLIST_SETTING_IMAGE, "卡片管理", nullptr}, + {VIEW_SET_DESKTOP, PNG_SETTTING_REBOOT_IMAGE, PNG_SETTTING_REBOOT_IMAGE, "主题样式", nullptr}, + {VIEW_SET_CARD, PNG_SETTTING_SHUTDOWN_IMAGE, PNG_SETTTING_SHUTDOWN_IMAGE, "卡片管理", nullptr}, {VIEW_SET_DIAL, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "切换表盘", nullptr}, - //{VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr}, + {VIEW_MAIN_TEMP, PNG_APPLIST_TEMP_IMAGE, PNG_APPLIST_TEMP_IMAGE, "体温", nullptr}, + #ifdef SUPPORT_ALIPAY_SEC {VIEW_MAIN_ALIPAY, PNG_APPLIST_ALIPAY_IMAGE, PNG_APPLIST_ALIPAY_IMAGE, "支付宝", nullptr}, #endif #if 0 + {VIEW_LANGUAGE_SWITCH, PNG_CONNECT_PHONE_IMAGE, PNG_CONNECT_PHONE_IMAGE, "语言切换", nullptr}, {VIEW_MAIN_TEMP, PNG_APPLIST_TEMP_IMAGE, PNG_APPLIST_TEMP_IMAGE, "体温", nullptr}, {VIEW_OFFLINEVOICE, PNG_APPLIST_VOCASSIST_IMAGE, PNG_APPLIST_VOCASSIST_IMAGE, "语音助手", nullptr}, {VIEW_UISAMPLE, PNG_APPLIST_UI_SAMPLE_IMAGE, PNG_APPLIST_UI_SAMPLE_IMAGE, "示例", nullptr}, diff --git a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp index 4d50ad9af..fec1e6462 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/main/src/MainModel.cpp @@ -27,7 +27,7 @@ namespace OHOS }; const DialInfo dialInfoMap[] = { - {DIAL_CLOCK, "KUMI", PNG_SET_DIAL_CLOCK, DEFAULT_TASK_PERIOD}, + {DIAL_CLOCK, "KUMI", DEFAULT_DIALPER_PATH, DEFAULT_TASK_PERIOD}, }; MainModel::MainModel() {} 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 eb86b43d6..1b7e1c1ec 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingModel.h @@ -58,6 +58,15 @@ struct QuickTraining namespace OHOS { + // 运动状态 + enum class ExerciseState + { + General = 0, + Start, + End, + Pause, + Continue + }; class TraingModel { public: @@ -70,23 +79,26 @@ namespace OHOS bool InitButtonExt(UILabelButtonExt *&button, int left, int top, int width, int height, const char *viewId, UIResourceTextId id, int fontSize); bool InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); void InitList(); - void SetQuickTraining(QuickTraining *quickTraining); QuickTraining *GetQuickTraining() const; - /* ----------------------------------- 定时器 ---------------------------------- */ - void StartTimer(uint32_t interval); - void StopTimer(void); - char *ShowTimer(void); - + /*定时器 */ + std::string DisplayMotionDuration(); + /*设置运动项目*/ void SetSportEvent(UIResourceTextId id); + /*获取运动项目*/ UIResourceTextId GetSportEvent(); + /*设置运动状态*/ + void SetSportState(ExerciseState state); + /*获取运动状态*/ + ExerciseState GetSportState(); private: TraingModel(const TraingModel &) = delete; TraingModel &operator=(const TraingModel &) = delete; - std::string trainingTimer_; // 训练时长 - UIResourceTextId sportId_ = STR_EXTREME_SPORTS; // 训练项目 + std::string motionDuration; // 训练时长 + UIResourceTextId sportId_ = STR_EXTREME_SPORTS; // 训练项目 + ExerciseState sportstate_ = ExerciseState::General; // 训练状态 }; } 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 584fde2a6..22e87103a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingModel.cpp @@ -11,16 +11,18 @@ #include #include #include "cmsis_os.h" +#include "traing/training_card/include/TraingCardPresenter.h" -#define TIMER 0 +#define TIMER 1 #define CHECK 0 namespace OHOS { #if TIMER // 声明定时器变量 - static osTimerId_t g_timer = NULL; - static int g_trainingTimer = {0}; + static osTimerId_t g_startCounting = NULL; // 定时器 + static constexpr uint64_t MS_ONE_SECONDS = 1000; + static int g_motionTimes{0}; static constexpr int32 NUM_TEN = 10; static constexpr int16 ERROR = 0; static constexpr int16 SUCCESS = 1; @@ -256,104 +258,116 @@ namespace OHOS } #if TIMER - /* - * @brief 在这里添加定时器到期后的处理逻辑 - */ - static void TimerCallbackProc(int data) + /* 时间显示 */ + std::string TraingModel::DisplayMotionDuration() { - g_trainingTimer++; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "g_trainingTimer:%d\n", g_trainingTimer); + motionDuration.clear(); - if (ShowTimer() == nullptr) + if (g_motionTimes >= NUM_TIME_DAY) { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[Recording_TimerCallbackProc] DisplaytrainingTimer is NULL"); - return; + g_motionTimes = 0; } - // RecordGoingView::GetInstance()->GetRecordingDurationLabel()->SetText(RecordingModel::GetInstance()->DisplaytrainingTimer()); - } + int hour = g_motionTimes / NUM_TIME_HOUR; + int min = (g_motionTimes % NUM_TIME_HOUR) / NUM_TIME_MIN; + int sec = (g_motionTimes % NUM_TIME_HOUR) % NUM_TIME_MIN; - /* - * @brief 运动计时回调函数 - */ - static void TimerCallback(int data) - { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(TimerCallbackProc, data)); + std::ostringstream oss; + oss << std::setfill('0') << std::setw(2) << hour << ":" << std::setw(2) << min << ":" << std::setw(2) << sec; + + motionDuration = oss.str(); + return motionDuration; } - /** - * @brief 开启定时器函数 - * @param interval 时间间隔,单位ms - */ - void TraingModel::StartTimer(uint32_t interval) +#ifdef __cplusplus + extern "C" { - // 检查定时器是否已经存在,如果存在则返回 - if (g_timer != NULL) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingModel::Recording_StartTimer Timer already exists!!"); - return; - } - - // 创建定时器 - g_timer = osTimerNew((osTimerFunc_t)TimerCallback, osTimerPeriodic, NULL, NULL); - if (g_timer == NULL) +#endif + /* 定时器回调函数 */ + void TraingTimerCallback() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel Timer create failed!!"); - return; + g_motionTimes++; + TraingCardPresenter *gTraingCardPresenter = TraingCardPresenter::GetInstance(); + if (gTraingCardPresenter == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingTimerCallback::gTraingCardPresenter new fail"); + return; + } + gTraingCardPresenter->ModifiesTime(); } - // 将毫秒转换为系统时钟节拍数 - int tick = osMs2Tick(interval); - - // 启动定时器 - osStatus_t ret = osTimerStart(g_timer, tick); - - if (ret != osOK) + /* 开启定时器 */ + void InitTraingTimer() { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel osTimerStart failed, ret = %lx!!", ret); - if (g_timer != NULL) + if (g_startCounting != NULL) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingModel::TraingTimer already exists!!"); + return; + } + g_startCounting = osTimerNew((osTimerFunc_t)TraingTimerCallback, osTimerPeriodic, NULL, NULL); + if (g_startCounting == NULL) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::TraingTimer osTimerNew failed!!"); + return; + } + int tick = osMs2Tick(MS_ONE_SECONDS); + osStatus_t retTimer = osTimerStart(g_startCounting, tick); + if (retTimer != osOK) { - osTimerDelete(g_timer); - g_timer = NULL; + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::TraingTimer osTimerStart failed, ret = %lx!!", retTimer); + if (g_startCounting != NULL) + { + retTimer = osTimerDelete(g_startCounting); + if (retTimer != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::osTimerDelete failed, ret = %lx!!", retTimer); + return; + } + g_startCounting = NULL; + } + return; } - return; } - } - - /** - * @brief 停止定时器 - */ - void TraingModel::StopTimer() - { - // 检查定时器是否存在 - if (g_timer != NULL) + /* 关闭定时器 */ + void DisableTraingTimer() { - // 删除定时器并置为 NULL - osStatus_t ret = osTimerDelete(g_timer); - if (ret != osOK) + if (g_startCounting != NULL) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::Recording_StopTimer osTimerDelete failed, ret = %lx!!", ret); + osStatus_t ret = osTimerDelete(g_startCounting); + if (ret != osOK) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ScanTimerCallback osTimerDelete failed, ret = %lx!!", ret); + return; + } + g_startCounting = NULL; + g_motionTimes = 0; } - g_timer = NULL; - g_trainingTimer = 0; } + +#ifdef __cplusplus } - // 显示计时时间 - char *TraingModel::ShowTimer() +#endif + /*设置运动状态*/ + void TraingModel::SetSportState(ExerciseState state) { - trainingTimer.erase(); - - int hour = g_trainingTimer / NUM_TIME_HOUR; - int min = (g_trainingTimer % NUM_TIME_HOUR) / NUM_TIME_MIN; - int sec = (g_trainingTimer % NUM_TIME_HOUR) % NUM_TIME_MIN; - - std::ostringstream oss; - oss << std::setw(2) << std::setfill('0') << hour << ":" - << std::setw(2) << std::setfill('0') << min << ":" - << std::setw(2) << std::setfill('0') << sec; - - trainingTimer = oss.str(); + sportstate_ = state; + } + /*获取运动状态*/ + ExerciseState TraingModel::GetSportState() + { + return sportstate_; + } +#if 0 + // 打开传感器 + bool TraingModel::OpenDistancesSensor(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TraingModel::OpenDistancesSensor!!"); + return true; + } - return (char *)trainingTimer.c_str(); + bool TraingModel::CloseDistancesSensor(void) + { + return true; } #endif +#endif } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardPresenter.h index 2d8fcc64a..9ac2030f6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TraingCardPresenter.h @@ -1,4 +1,4 @@ -/*** +/*** * @Author: Caisking 3449750381@qq.com * @Date: 2024-03-19 17:37:18 * @LastEditors: Caisking 3449750381@qq.com @@ -12,14 +12,16 @@ #include "Presenter.h" #include "TraingCardView.h" - +#include "traing/training_card/include/TrainingControlView.h" +#include "traing/training_card/include/TrainingDataView.h" namespace OHOS { class TraingCardView; - + class TrainingControlView; + class TrainingDataView; class TraingCardPresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnClickListener, + public UIView::OnDragListener { public: TraingCardPresenter(); @@ -31,11 +33,13 @@ namespace OHOS void OnStop() override; static TraingCardPresenter *GetInstance(); + void ModifiesTime(); + private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; - //bool OnDragEnd(UIView& view, const DragEvent& event) override; + // bool OnDragEnd(UIView& view, const DragEvent& event) override; }; } // namespace OHOS 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 dfb87907a..26a577c0a 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 @@ -28,19 +28,20 @@ #include "PlayersView.h" #include "traing/training_card/include/TrainingControlView.h" -#include "traing/include/TraingDataView.h" +#include "traing/training_card/include/TrainingDataView.h" namespace OHOS { enum Control_Card { CONTROL = 0, - // DATA, + DATA, MUSIC }; class TraingCardPresenter; class TrainingControlView; + class TrainingDataView; class TraingCardView : public View { @@ -62,11 +63,8 @@ namespace OHOS void DeInit(); void InitList(); void PreLoad(void); - - // 通过函数改变 - void SetLabel(); - void SetButton(); - + + int GetCurrentPageId(); private: UIView::OnDragListener *draglistener{nullptr}; TraingCardView(TraingCardView &&) = delete; @@ -75,7 +73,7 @@ namespace OHOS UISwipeView *swipe_ = nullptr; TrainingControlView *ControlView{nullptr}; - TraingDataView *DataVIew{nullptr}; + TrainingDataView *DataVIew{nullptr}; PlayersView *MusicView{nullptr}; bool viewiInitStatus{false}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingControlView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingControlView.h index adbda5f6a..bfe13d96f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingControlView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingControlView.h @@ -42,8 +42,11 @@ namespace OHOS void PreLoad(void) override; void UnLoad(void) override; - void SetButton(); - void SetLabel(); + // 通过函数改变 + UILabelExt *GetLabel(); + UIButton *GetButton(); + + UILabelExt *GetTimeLabel(); private: UIView::OnDragListener *draglistener{nullptr}; diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDataView.h b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDataView.h index e69de29bb..44d55b7cf 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDataView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/include/TrainingDataView.h @@ -0,0 +1,73 @@ +#ifndef _TrainingData_VIEW_H +#define _TrainingData_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/TrainingDataView.h" +#include "traing/training_card/include/TraingCardPresenter.h" +namespace OHOS +{ +#define BUTTONNOTE "button1" + + class TrainingDataView : public UICardPage + { + public: + TrainingDataView(); + virtual ~TrainingDataView(); + static TrainingDataView *GetInstance(void); + + void InitView(); + void DeInit(); + + void PreLoad(void) override; + void UnLoad(void) override; + UILabelExt *GetTimeLabel(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TrainingDataView(TrainingDataView &&) = delete; + TrainingDataView &operator=(TrainingDataView &&) = delete; + + UIViewGroup *container_ = nullptr; + + UILabelExt *curtimelabel = nullptr; // 当前时间 + UILabelExt *sportlabel = nullptr; // 运动项目名称 + UILabelExt *timerlabel = nullptr; // 计时 + UILabelExt *heartlabel = nullptr; // 运动实时心率 + UILabelExt *strengthlabel = nullptr; // 运动强度 + + UIImageView *image_progress = nullptr; + UIImageView *image_arrows = nullptr; + UIImageView *image_lowIntensity = nullptr; // 低等强度 + UIImageView *image_mediumIntensity = nullptr; // 中等强度 + UIImageView *image_highIntensity = nullptr; // 高等强度 + UIImageView *image_superHighIntensity = nullptr; // 超高等强度 + + UIImageView *image_iconup = nullptr; + UIImageView *image_iconpoint = nullptr; + + UIButton *buttonNote = nullptr; // 注意事项按键 + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingData_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 9e4184338..d70b5eceb 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 @@ -13,7 +13,6 @@ namespace OHOS { - // 当前Presenter属性实例化的内存指针 static TraingCardPresenter *g_pTraingCardPresenter = nullptr; @@ -60,23 +59,68 @@ namespace OHOS bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) { - - if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) + uint8_t viewid = TraingCardView::GetInstance()->GetCurrentPageId(); + // const char *viewid = view.GetViewId(); + if (viewid == Control_Card::DATA) { - NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDETAIL); + } + return true; } UNUSED(view); - return true; + return false; } bool TraingCardPresenter::OnClick(UIView &view, const ClickEvent &event) { - // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), BUTTONSTOP) == 0) - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); - // NativeAbility::GetInstance(). - // } + // 点击暂停按键 + if (strcmp(view.GetViewId(), BUTTONSTOP) == 0) + { + // 开始状态 + if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Start) + { + TrainingControlView::GetInstance()->GetLabel()->SetText("ç»§ç»­"); + TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_CONTINUE_IMAGE, nullptr); + // 设置为暂停状态 + TraingModel::GetInstance()->SetSportState(ExerciseState::Pause); + return true; + } + // 暂停状态 + if (TraingModel::GetInstance()->GetSportState() == ExerciseState::Pause) + { + TrainingControlView::GetInstance()->GetLabel()->SetText("暂停"); + TrainingControlView::GetInstance()->GetButton()->SetImageSrc(SPORT_PAUSE_IMAGE, nullptr); + // 设置为开始状态 + TraingModel::GetInstance()->SetSportState(ExerciseState::Start); + return true; + } + } + // 点击结束按键 + if (strcmp(view.GetViewId(), BUTTONEND) == 0) + { + // 弹窗显示是否结束 + } return true; } + + // 计时器更新 + void TraingCardPresenter::ModifiesTime() + { + std ::string TimeStr = TraingModel::GetInstance()->DisplayMotionDuration(); + if (TimeStr.empty()) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TraingModel::GetInstance()->DisplayMotionDuration() nullptr"); + return; + } + if (TrainingControlView::GetInstance()->GetTimeLabel() != nullptr) + { + TrainingControlView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str()); + } + if (TrainingDataView::GetInstance()->GetTimeLabel() != nullptr) + { + TrainingDataView::GetInstance()->GetTimeLabel()->SetText(TimeStr.c_str()); + } + } } 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 fb89d3813..b3007a5d2 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 @@ -13,6 +13,15 @@ #include "components/ui_label.h" #include "components/ui_label_ext.h" #include "font/ui_font.h" + +#include "traing/include/TraingModel.h" + +extern "C" +{ + void InitTraingTimer(); + void DisableTraingTimer(); +} + namespace OHOS { static const uint16_t LABEL_FONT_SIZE = 200; @@ -24,17 +33,24 @@ namespace OHOS TraingCardView::TraingCardView() { g_pTraingCardView = this; + // 开启计时器 + InitTraingTimer(); + // 设置运动状态为开始 + TraingModel::GetInstance()->SetSportState(ExerciseState::Start); } TraingCardView::~TraingCardView() { DeInit(); g_pTraingCardView = nullptr; + // 关闭计时器 + DisableTraingTimer(); + // 设置运动状态为结束 + TraingModel::GetInstance()->SetSportState(ExerciseState::End); } TraingCardView *TraingCardView::GetInstance() { - return g_pTraingCardView; } @@ -51,12 +67,14 @@ namespace OHOS } InitControlPage(); + InitDataPage(); InitMusicPage(); swipe_->Add(ControlView); + swipe_->Add(DataVIew); swipe_->Add(MusicView); - swipe_->SetCurrentPage(Control_Card::MUSIC); + swipe_->SetCurrentPage(Control_Card::CONTROL); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "MainViewSample::InitPage over"); } @@ -76,6 +94,12 @@ namespace OHOS delete ControlView; ControlView = nullptr; } + if (DataVIew != nullptr) + { + DataVIew->RemoveAll(); + delete DataVIew; + DataVIew = nullptr; + } if (MusicView != nullptr) { MusicView->RemoveAll(); @@ -94,7 +118,17 @@ namespace OHOS } return ControlView; } - UICardPage *TraingCardView::InitDataPage(void) {} + UICardPage *TraingCardView::InitDataPage(void) + { + DataVIew = new TrainingDataView(); + DataVIew->PreLoad(); + if (DataVIew == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DataVIew new fail"); + return nullptr; + } + return DataVIew; + } UICardPage *TraingCardView::InitMusicPage(void) { MusicView = new PlayersView(); @@ -160,4 +194,8 @@ namespace OHOS return; } + int TraingCardView::GetCurrentPageId() + { + return swipe_->GetCurrentPage(); + } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingControlView.cpp b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingControlView.cpp index fbe032da7..a4e665a33 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingControlView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/traing/training_card/src/TrainingControlView.cpp @@ -67,34 +67,14 @@ namespace OHOS } /******************************************************************************************************/ - void TrainingControlView::SetLabel() + UILabelExt *TrainingControlView::GetLabel() { -#if 0 - if (TraingCardPresenter::GetInstance()->test == "ç»§ç»­") - { - labelstop->SetText("ç»§ç»­"); - } - else - { - labelstop->SetText("暂停"); - } -#endif + return labelstop; } - void TrainingControlView::SetButton() + UIButton *TrainingControlView::GetButton() { -#if 0 - if (TraingCardPresenter::GetInstance()->test == "ç»§ç»­") - { - // buttonStop->SetViewId(BUTTONCONTINUE); - buttonStop->SetImageSrc(SPORT_CONTINUE_IMAGE, nullptr); - } - if (TraingCardPresenter::GetInstance()->test == "暂停") - { - // buttonStop->SetViewId(BUTTONPAUSE); - buttonStop->SetImageSrc(SPORT_PAUSE_IMAGE, nullptr); - } -#endif + return buttonStop; } /******************************************************************************************************/ @@ -152,4 +132,9 @@ namespace OHOS } void TrainingControlView::UnLoad(void) {} + + UILabelExt *TrainingControlView::GetTimeLabel() + { + return labeltimer; + } } 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 e69de29bb..b43cdd124 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 @@ -0,0 +1,140 @@ + +#include "traing/training_card/include/TrainingDataView.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 TrainingDataView *g_pTrainingDataView{nullptr}; + + TrainingDataView::TrainingDataView() + { + SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + g_pTrainingDataView = this; + } + + TrainingDataView::~TrainingDataView() + { + RemoveAll(); + DeInit(); + g_pTrainingDataView = nullptr; + } + + TrainingDataView *TrainingDataView::GetInstance() + { + return g_pTrainingDataView; + } + + /* InitView:初始化界面*/ + void TrainingDataView ::InitView() + { + // 初始化Image + TraingModel::GetInstance()->InitImageView(image_progress, 13, 13, 440, 386, "image1", PROGRESS_IMAGE); + TraingModel::GetInstance()->InitImageView(image_arrows, 208, 297, 20, 20, "image2", ARROWS_IMAGE); + TraingModel::GetInstance()->InitImageView(image_lowIntensity, 98, 314, 270, 20, "image3", SPORT_STRENGTH_IMAGE); + TraingModel::GetInstance()->InitImageView(image_iconup, 225, 396, 16, 10, "image4", INCO_UP_IMAGE); + TraingModel::GetInstance()->InitImageView(image_iconpoint, 193, 421, 80, 20, "image5", DATA_POINT_IMAGE); + Add(image_progress); + Add(image_arrows); + Add(image_lowIntensity); + Add(image_iconup); + Add(image_iconpoint); + // 初始化Lable + TraingModel::GetInstance()->InitLabel(curtimelabel, 185, 60, 90, 35, "label1", "23:54", DEFAULT_VECTOR_FONT_FILENAME, 40); + TraingModel::GetInstance()->InitLabel(sportlabel, 158, 120, 150, 35, "label2", "跳绳运动中", DEFAULT_VECTOR_FONT_FILENAME, 30); + TraingModel::GetInstance()->InitLabel(timerlabel, 90, 175, 60, 40, "label3", "00:00:00", DEFAULT_VECTOR_FONT_FILENAME, 80); + TraingModel::GetInstance()->InitLabel(heartlabel, 150, 276, 60, 40, "label4", "144", DEFAULT_VECTOR_FONT_FILENAME, 23); + TraingModel::GetInstance()->InitLabel(strengthlabel, 167, 350, 60, 40, "label4", "中等强度", DEFAULT_VECTOR_FONT_FILENAME, 26); + Add(curtimelabel); + Add(sportlabel); + Add(timerlabel); + Add(heartlabel); + Add(strengthlabel); + // 初始化Button + TraingModel::GetInstance()->InitButton(buttonNote, 275, 350, 26, 26, BUTTONNOTE); + // Set additional property + buttonNote->SetImageSrc(NOTE_IMAGE, NOTE_IMAGE); + buttonNote->SetOnClickListener(static_cast(TraingCardPresenter::GetInstance())); + Add(buttonNote); + } + + /* DeInit:删除组件 */ + void TrainingDataView::DeInit() + { + RemoveAll(); + if (curtimelabel != nullptr) + { + curtimelabel = nullptr; + } + if (sportlabel != nullptr) + { + delete sportlabel; + sportlabel = nullptr; + } + if (timerlabel != nullptr) + { + delete timerlabel; + timerlabel = nullptr; + } + if (heartlabel != nullptr) + { + delete heartlabel; + heartlabel = nullptr; + } + if (strengthlabel != nullptr) + { + delete strengthlabel; + strengthlabel = nullptr; + } + // 删除button + if (buttonNote != nullptr) + { + delete buttonNote; + buttonNote = nullptr; + } + + // 删除Image + if (image_lowIntensity != nullptr) + { + delete image_lowIntensity; + image_lowIntensity = nullptr; + } + if (image_iconup != nullptr) + { + delete image_iconup; + image_iconup = nullptr; + } + if (image_iconpoint != nullptr) + { + delete image_iconpoint; + image_iconpoint = nullptr; + } + } + + void TrainingDataView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + + void TrainingDataView::UnLoad(void) {} + + UILabelExt *TrainingDataView::GetTimeLabel() + { + return timerlabel; + } + +}