From: Caisking <3449750381@qq.com> Date: Mon, 4 Dec 2023 08:59:40 +0000 (+0800) Subject: 增加训练目标设置界面 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=1f600bd0653ab28e9c98b99235f0fe0da8393ac7;p=mirrors%2FFD230.git 增加训练目标设置界面 --- diff --git a/Resource/res/Training/calories.bin b/Resource/res/Training/calories.bin index b2045151d..a46782845 100644 Binary files a/Resource/res/Training/calories.bin and b/Resource/res/Training/calories.bin differ diff --git a/code/sdk/application/wearable/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/nativeapp/CMakeLists.txt index 325abe8fc..f682930d6 100644 --- a/code/sdk/application/wearable/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/nativeapp/CMakeLists.txt @@ -250,6 +250,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingLimitPresenter.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingNomalView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingNomalPresenter.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetView.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/traing/src/TraingSetPresenter.cpp #ָ���� ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassControlView.cpp ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassCalibrationView.cpp diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h index 15d972092..9dd44e56d 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/AppViewIDs.h @@ -80,6 +80,7 @@ typedef enum : uint16_t VIEW_TRAININGMORE, // 更多训练 VIEW_TRAININGLIMIT, // 极限运动子列表 VIEW_TRAININGNOMAL, // 正常训练开始界面(除骑行,健走,跑步外) + VIEW_TRAININGSET, // 训练目标(时长,卡路里) VIEW_TRAINING_RECORD, // 训练记录 VIEW_BLOODPRESSURE, // 昨日睡眠时间 diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h index 595d963a5..26eb2a90f 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/NativeLauncher.h @@ -66,6 +66,7 @@ public: void InitTraingMoreSlice(void); void InitTraingLimitSlice(void); void InitTraingNomalSlice(void); + void InitTraingSetSlice(void); void InitUIDisplayBrightnessSlice(void); void InitBlueToothSettingSlice(void); void InitBrightnessControlSlice(void); diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h index 8e7f91ab5..458dae173 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/include/UiConfig.h @@ -43,6 +43,7 @@ namespace OHOS static constexpr const char *CARD_CONFIG_PATH = "/user/cardconfig.bin"; static constexpr const char *CLOCK_IAMGES = APP_RES_PATH "/clock/clock.bin"; + static constexpr const char *DIAL_CLOCK = APP_RES_PATH"/Dial/dogmalio.bin"; static constexpr const char *PLAYER_IAMGES = APP_RES_PATH "/player/player.bin"; static constexpr const char *COMPASS_IAMGES = APP_RES_PATH "/compass/compass.bin"; static constexpr const char *DROPDOWN_IAMGES = APP_RES_PATH "/dropdown/dropdown.bin"; diff --git a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp index 8e9fb1bbe..4919b9c0f 100644 --- a/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp +++ b/code/sdk/application/wearable/nativeapp/nativelauncher/src/NativeLauncher.cpp @@ -109,6 +109,8 @@ #include "traing/include/TraingLimitView.h" #include "traing/include/TraingNomalPresenter.h" #include "traing/include/TraingNomalView.h" +#include "traing/include/TraingSetPresenter.h" +#include "traing/include/TraingSetView.h" #include "displaybrightness/include/DisplayBrightnessPresenter.h" #include "displaybrightness/include/DisplayBrightnessView.h" #include "bluetoothofsetting/include/BlueToothOfSettingPresenter.h" @@ -233,6 +235,7 @@ static const AppViewMapper SLICE_MAPPER[] = { {VIEW_TRAININGMORE, &NativeLauncher::InitTraingMoreSlice}, //更多训练 {VIEW_TRAININGLIMIT, &NativeLauncher::InitTraingLimitSlice}, //极限训练 {VIEW_TRAININGNOMAL, &NativeLauncher::InitTraingNomalSlice}, //正常训练初始界面 + {VIEW_TRAININGSET, &NativeLauncher::InitTraingSetSlice}, //训练目标设置界面 {VIEW_DISPLAY_BRIGHTNESS,&NativeLauncher::InitUIDisplayBrightnessSlice}, //显示与亮度的实例化地址 {VIEW_CONNECT_BLUETOOTH,&NativeLauncher::InitBlueToothSettingSlice}, //蓝牙设置的实例化地址 @@ -791,6 +794,7 @@ void NativeLauncher::InitHeartRemindSlice(void) NativeAbility::GetInstance().AddSliceProxy(VIEW_HEARTRATEREMIND, heartremindview); } +//体能训练 void NativeLauncher::InitTraingSlice(void) { SliceProxy *traingview = new AbilitySliceProxy; @@ -811,6 +815,12 @@ void NativeLauncher::InitTraingNomalSlice(void) SliceProxy *traingnomalview = new AbilitySliceProxy; NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGNOMAL, traingnomalview); } +void NativeLauncher::InitTraingSetSlice(void) +{ + SliceProxy *traingsetview = new AbilitySliceProxy; + NativeAbility::GetInstance().AddSliceProxy(VIEW_TRAININGSET, traingsetview); +} + //DisplayBrightness的实例化 void NativeLauncher::InitUIDisplayBrightnessSlice(void) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/DialMalioView.h b/code/sdk/application/wearable/nativeapp/nativeui/clock/include/DialMalioView.h index d936a8ba5..138ec0fbc 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/include/DialMalioView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/include/DialMalioView.h @@ -1,3 +1,110 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: DialMalioView + * Author: + * Create: 2021-10-18 + */ +#if 0 + #ifndef DialMalio_VIEW_H + #define DialMalio_VIEW_H + + #include + #include + #include "View.h" + #include "components/ui_label.h" + #include "components/root_view.h" + #include "components/ui_view_group.h" + #include "components/ui_image_view.h" + #include "components/ui_label_button.h" + #include "components/ui_sweep_clock.h" + #include "BaseView.h" + #include "ChangeSliceListener.h" + #include "font/ui_font_bitmap.h" + #include "font/ui_font.h" + #include "graphic_config.h" + #include "HealthModel.h" + #include "ActivityModel.h" + #include "UiConfig.h" + #include "components/ui_card_page.h" + #include "animator/animator_manager.h" + #include "time.h" + #include "sys/time.h" + + namespace OHOS + { + class ClockCallback : public AnimatorCallback + { + public: + explicit ClockCallback(UISweepClock *clock) : sweepClock(clock) {} + ~ClockCallback() {} + virtual void Callback(UIView *view) + { + UNUSED(view); + struct timeval tv; + gettimeofday(&tv, NULL); + uint64_t second = tv.tv_sec; + uint64_t uSecond = tv.tv_usec; + uint64_t minute = second / 60; + uint64_t hour = minute / 60; + uint8_t realHour = static_cast(hour % 24); + uint8_t realMinute = static_cast(minute % 60); + uint16_t realMilliSecond = static_cast((second % 60) * + 1000 + + uSecond / 1000); + sweepClock->SetSweepTime12Hour(realHour, realMinute, realMilliSecond, 1); + } + + private: + UISweepClock *sweepClock{nullptr}; + }; + + class DialMalioView : public UICardPage + { + public: + DialMalioView(); + virtual ~DialMalioView(); + static DialMalioView *GetInstance(void); + bool InitView(void); + void PreLoad(void) override; + void UnLoad(void) override; + void RefreshStep(int step); + void RefreshHeartRate(int value); + void ClockAnimatorStart(void); + void ClockAnimatorStop(void); + + private: + void InitStepValue(); + bool InitLabelView(void); + bool InitCenterCircleView(void); + bool InitHandView(void); + void InitDateTime(void); + bool InitSweepClock(void); + bool LoadClockImage(Image *view, uint32_t resId); + bool LoadClockImage(UIImageView *view, uint32_t resId); + UIImageView *curFace{nullptr}; + UILabelButton *stepLabel{nullptr}; + UIButton *button1_ = nullptr; + UILabel *batteryLabel{nullptr}; + UILabel *weekLabel{nullptr}; + UILabel *heartRateLabel{nullptr}; + ClockCallback *callBack{nullptr}; + Animator *clockAnimator{nullptr}; + UISweepClock *mainSweepClock{nullptr}; + Image *secondHand{nullptr}; + Image *minuteHand{nullptr}; + Image *hourHand{nullptr}; + UIImageView *heartRate{nullptr}; + Image *hand24Hour{nullptr}; + UIImageView *weekDay{nullptr}; + UIImageView *progress{nullptr}; + Image *bigCircle{nullptr}; + Image *medCircle{nullptr}; + Image *smallCircle{nullptr}; + bool viewiInitStatus{false}; + }; + } // namespace OHOS + #endif // DialMalio_VIEW_H +#endif #ifndef DialMalioVIEW_H #define DialMalioVIEW_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/DialMalioView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/DialMalioView.cpp index 66d926040..21c8efeaa 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/clock/src/DialMalioView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/clock/src/DialMalioView.cpp @@ -1,4 +1,222 @@ +/* + * Copyright (c) CompanyNameMagicTag 2021-2021. All rights reserved. + * Description: DialMalioView + * Author: + * Create: 2021-08-14 + */ +#if 0 +#include "DialMalioView.h" +#include "MainPresenterSample.h" +#include "components/ui_label.h" +#include "wearable_log.h" +#include "ui_resource_image.h" +#include "common/image_cache_manager.h" +#include + +namespace OHOS +{ + static DialMalioView *g_pDialMalioView = nullptr; + + DialMalioView::DialMalioView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialMalioView::DialMalioView"); + g_pDialMalioView = this; + } + + DialMalioView::~DialMalioView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DialMalioView::~DialMalioView"); + if (clockAnimator != nullptr) + { + clockAnimator->Stop(); + delete clockAnimator; + clockAnimator = nullptr; + } + mainSweepClock->RemoveAll(); + g_pDialMalioView = nullptr; + } + + DialMalioView *DialMalioView::GetInstance(void) + { + return g_pDialMalioView; + } + + void DialMalioView::InitStepValue() {} + + bool DialMalioView::InitLabelView(void) {} + + bool DialMalioView::InitCenterCircleView(void) {} + + bool DialMalioView::InitHandView(void) + { + secondHand = new Image(); + if (secondHand == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "secondHand new fail"); + return false; + } + if (LoadClockImage(secondHand, CLOCK_SECONDHAND) == false) + { + return false; + } + + minuteHand = new Image(); + if (minuteHand == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "minuteHand new fail"); + return false; + } + if (LoadClockImage(minuteHand, CLOCK_MINUTEHAND) == false) + { + return false; + } + hourHand = new Image(); + if (hourHand == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "hourHand new fail"); + return false; + } + if (LoadClockImage(hourHand, CLOCK_HOURHAND) == false) + { + return false; + } + } + + bool DialMalioView::LoadClockImage(Image *view, uint32_t resId) + { + std::string file = CLOCK_IAMGES; + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; + } + + bool DialMalioView::LoadClockImage(UIImageView *view, uint32_t resId) + { + std::string file = CLOCK_IAMGES; + ImageInfo *image = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, file); + if (image == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LoadClockImage %x fail", resId); + return false; + } + view->SetSrc(image); + return true; + } + + bool DialMalioView::InitSweepClock(void) + { + curFace = new UIImageView(); + if (curFace == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace new fail"); + return false; + } + curFace->SetPosition(0, 0); + + if (LoadClockImage(curFace, CLOCK_MAIN_FACE_IMAGE) == false) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "curFace LoadClockImage CLOCK_MAIN_FACE_IMAGE fail"); + return false; + } + InitHandView(); + return true; + } + void DialMalioView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + + void DialMalioView::UnLoad(void) + { + // Main clock view is commonly used page, so we do not release it's resources inner slice. + } + bool DialMalioView::InitView(void) + { + mainSweepClock = new UISweepClock(); + if (mainSweepClock == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "mainSweepClock new fail"); + return false; + } + if (InitSweepClock() == false) + { + return false; + } + + mainSweepClock->Add(curFace); + Add(mainSweepClock); + + mainSweepClock->SetDragParentInstead(true); + mainSweepClock->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION); + + // {214, 3}: position x, y {14, 223}: center x, y + mainSweepClock->SetHandImage(UISweepClock::HandType::SECOND_HAND, *secondHand, + {221, 28}, {12, 205}); + mainSweepClock->SetHandImage(UISweepClock::HandType::MINUTE_HAND, *minuteHand, + {221, 33}, {221, 87}); + mainSweepClock->SetHandImage(UISweepClock::HandType::HOUR_HAND, *hourHand, + {221, 87}, {12, 146}); + mainSweepClock->SetInitTime24Hour(0, 0, 0); + mainSweepClock->SetWorkMode(UISweepClock::WorkMode::NORMAL); + InitDateTime(); + + callBack = new ClockCallback(mainSweepClock); + if (callBack == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "callBack new fail"); + return false; + } + clockAnimator = new Animator(callBack, mainSweepClock, 0, true); + if (clockAnimator == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "clockAnimator new fail"); + return false; + } + clockAnimator->Start(); + return true; + } + + void DialMalioView::RefreshStep(int step) {} + + void DialMalioView::RefreshHeartRate(int value) {} + + void DialMalioView::InitDateTime(void) + { + struct tm pTM; + time_t seconds; + time(&seconds); + localtime_r(&seconds, &pTM); + mainSweepClock->SetTime24Hour(pTM.tm_hour, pTM.tm_min, pTM.tm_sec); + } + + void DialMalioView::ClockAnimatorStart(void) + { + if (clockAnimator != nullptr) + { + clockAnimator->Start(); + } + } + + void DialMalioView::ClockAnimatorStop(void) + { + if (clockAnimator != nullptr) + { + clockAnimator->Stop(); + } + } + +} +#endif #include "DialMalioView.h" #include "MainClockView.h" diff --git a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp index 3c3c3d391..8a1ad7441 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/main/src/MainViewSample.cpp @@ -257,7 +257,7 @@ UICardPage *MainViewSample::InitWatchFacePage(void) return dialUserView; #endif - #if 1 + #if 0 mainClockView = new MainClockView(); if (mainClockView == nullptr) { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "MainClockView new fail"); @@ -266,7 +266,7 @@ UICardPage *MainViewSample::InitWatchFacePage(void) return mainClockView; #endif - #if 0 + #if 1 dialmalioview = new DialMalioView(); return dialmalioview; #endif @@ -335,10 +335,10 @@ void MainViewSample::AnimatorStart(int pageIndex) if (heartRateView != nullptr && pageIndex == ScreenModels::GetInstance()->GetCardPage(HEART_RATE)) { heartRateView->HeartbeatImageAnimatorStart(); } - if ((mainClockView != nullptr && pageIndex == ScreenModels::GetInstance()->GetCardPage(WATCH_FACE)) && - mainSwipeGroup->GetCurrentPageId(UISwipeView::VERTICAL) == 1) { - mainClockView->ClockAnimatorStart(); - } + // if ((mainClockView != nullptr && pageIndex == ScreenModels::GetInstance()->GetCardPage(WATCH_FACE)) && + // mainSwipeGroup->GetCurrentPageId(UISwipeView::VERTICAL) == 1) { + // mainClockView->ClockAnimatorStart(); + // } if ((dialmalioview != nullptr && pageIndex == ScreenModels::GetInstance()->GetCardPage(WATCH_FACE)) && mainSwipeGroup->GetCurrentPageId(UISwipeView::VERTICAL) == 1) { dialmalioview->ClockAnimatorStart(); @@ -353,9 +353,9 @@ void MainViewSample::AnimatorStop(void) if (mainClockView != nullptr) { mainClockView->ClockAnimatorStop(); } - if (dialmalioview != nullptr) { - dialmalioview->ClockAnimatorStop(); - } + // if (dialmalioview != nullptr) { + // dialmalioview->ClockAnimatorStop(); + // } } bool MainViewSample::IsMainView(void) diff --git a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp index b531d7d46..303fb5330 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/screensetting/src/ScreenModels.cpp @@ -169,7 +169,8 @@ bool ScreenModels::LoadAppImages(std::string file, UIImageView *view, uint32_t r void ScreenModels::PreLoadAppimages(void) { LoadAppMultiImages(PLAYER_IAMGES, PLAYER_PLAYERSMODEL_RANDOM, PLAYER_PLAYERHIGHLIGHT); - LoadAppMultiImages(CLOCK_IAMGES, CLOCK_HAND24HOUR_IMAGE_PATH, CLOCK_TUESDAY_IMAGE_PATH); + LoadAppMultiImages(DIAL_CLOCK, CLOCK_HAND24HOUR_IMAGE_PATH, CLOCK_TUESDAY_IMAGE_PATH); + //LoadAppMultiImages(CLOCK_IAMGES, CLOCK_HAND24HOUR_IMAGE_PATH, CLOCK_TUESDAY_IMAGE_PATH); LoadAppMultiImages(COMPASS_IAMGES, COMPASS_ROTATE_CENTER_IMAGE, COMPASS_COMPASS); LoadAppMultiImages(DROPDOWN_IAMGES, DROPDOWN_DROPDOWN_BLUETOOTH, DROPDOWN_DROPDOWN_BRI_SCREEN_B); LoadAppMultiImages(HEART_IAMGES, HEART_HEARTRATECOOR, HEART_HEARTRATE_TOP); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingLimitView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingLimitView.h index 26ffab6d4..604050d87 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingLimitView.h +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingLimitView.h @@ -20,14 +20,14 @@ #include "TraingLimitPresenter.h" namespace OHOS { -#define BUTTON1 "button1" // 健身 -#define BUTTON2 "button2" // 舞蹈 -#define BUTTON3 "button3" // 休闲运动 -#define BUTTON4 "button4" // 球类 -#define BUTTON5 "button5" // 水上运动 -#define BUTTON6 "button6" // 冰上运动 -#define BUTTON7 "button7" // 极限运动 -#define BUTTON8 "button8" // 其他 +#define BUTTON1 "button1" +#define BUTTON2 "button2" +#define BUTTON3 "button3" +#define BUTTON4 "button4" +#define BUTTON5 "button5" +#define BUTTON6 "button6" +#define BUTTON7 "button7" +#define BUTTON8 "button8" class TraingLimitPresenter; class TraingLimitView : public View diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetPresenter.h new file mode 100644 index 000000000..7e650aa3c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingSet_PRESENTER_H +#define _TraingSet_PRESENTER_H + +#include "Presenter.h" +#include "TraingSetView.h" + +namespace OHOS +{ + class TraingSetView; + + class TraingSetPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingSetPresenter(); + virtual ~TraingSetPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingSetPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetView.h new file mode 100644 index 000000000..a78a94198 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetView.h @@ -0,0 +1,71 @@ +#ifndef _TraingSet_VIEW_H +#define _TraingSet_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include +#include "components/ui_view_group.h" +#include "components/ui_label.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 "TraingSetPresenter.h" +namespace OHOS +{ +#define BUTTONTIME "button1" +#define BUTTONCALULI "button2" + + class TraingSetPresenter; + class TraingSetView : public View + { + + public: + TraingSetView(); + virtual ~TraingSetView(); + static TraingSetView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + void InitView(); + void DeInit(); + void InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize); + void InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId); + void InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath); + void InitList(); + void PreLoad(void); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingSetView(TraingSetView &&) = delete; + TraingSetView &operator=(TraingSetView &&) = delete; + + UIViewGroup *container_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UILabel *label5_ = nullptr; + + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + UIImageView *image3_ = nullptr; + UIImageView *image4_ = nullptr; + + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingSet_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp index fd81f3d24..f546f94a7 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalPresenter.cpp @@ -70,9 +70,9 @@ namespace OHOS bool TraingNomalPresenter::OnClick(UIView &view, const ClickEvent &event) { // 根据控件id查找是哪个控件触发了点击回调 - if (strcmp(view.GetViewId(), " ") == 0) + if (strcmp(view.GetViewId(), BUTTONSET) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); } if (strcmp(view.GetViewId(), "Remind") == 0) { diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp index 2ace50272..0ffafd017 100644 --- a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingNomalView.cpp @@ -118,7 +118,7 @@ namespace OHOS InitButton(button2_, 160, 370, 146, 35, BUTTONSET); button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);//设置为透明按键 button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - button2_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); // 设置按下时的透明度为半透明 + button2_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x80, UIButton::PRESSED); // 设置按下时的透明度为半透明 container_->Add(button1_); container_->Add(button2_); diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp new file mode 100644 index 000000000..ec9a33acc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetPresenter.cpp @@ -0,0 +1,85 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingSetPresenter.h" +// #include "TraingSetView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingSetPresenter *g_pTraingSetPresenter = nullptr; + + TraingSetPresenter::TraingSetPresenter() + { + + g_pTraingSetPresenter = this; + } + + TraingSetPresenter::~TraingSetPresenter() + { + + g_pTraingSetPresenter = nullptr; + } + + TraingSetPresenter *TraingSetPresenter::GetInstance() + { + + return g_pTraingSetPresenter; + } + + void TraingSetPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingSetPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingSetPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingSetPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingSetPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + } + UNUSED(view); + return true; + } + + bool TraingSetPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), " ") == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + } + if (strcmp(view.GetViewId(), "Remind") == 0) + { + // 模拟心率监测,等待20秒 + // std::this_thread::sleep_for(std::chrono::seconds(20)); + // NativeAbility::GetInstance().ChangeSlice(VIEW_TraingSetREMIND); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetView.cpp new file mode 100644 index 000000000..483fa1e8e --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetView.cpp @@ -0,0 +1,297 @@ + +#include "traing/include/TraingSetView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +namespace OHOS +{ + static const char *imagePath_iocn = "/user/res/Training/icon.bin"; + static const char *imagePath_time = "/user/res/Training/time.bin"; + static const char *imagePath_calories = "/user/res/Training/calories.bin"; + + static TraingSetView *g_pTraingSetView{nullptr}; + + TraingSetView::TraingSetView() + { + g_pTraingSetView = this; + } + + TraingSetView::~TraingSetView() + { + DeInit(); + g_pTraingSetView = nullptr; + } + + TraingSetView *TraingSetView::GetInstance() + { + + return g_pTraingSetView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingSetView::InitLabel(UILabel *&label, int left, int top, int width, int height, const char *viewId, const char *text, const char *fontName, int fontSize) + { + // 检查标签指针是否为空 + if (label == nullptr) + { + label = new UILabel(); + } + // 设置标签的位置和大小 + label->SetPosition(left, top); + label->Resize(width, height); + // 设置标签的视图 ID + label->SetViewId(viewId); + // 设置标签的样式 + label->SetStyle(STYLE_TEXT_FONT, fontSize); + label->SetFont(fontName, fontSize); + // 设置标签的文本和其他属性 + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(0); + // 设置标签可见 + label->SetVisible(true); + } + /* + InitButton:初始化按钮 + @param button 按钮指针 + @param left 按钮左边位置 + @param top 按钮顶部位置 + @param width 按钮宽度 + @param height 按钮高度 + @param viewId 按钮的视图 ID + */ + void TraingSetView::InitButton(UIButton *&button, int left, int top, int width, int height, const char *viewId) + { + // 设置按钮的背景颜色 + uint32_t backgroundColor = 0xff191919; // 默认背景颜色 + uint32_t pressedBackgroundColor = 0xff249115; // 按下时的背景颜色 + uint32_t pressedBorderColor = 0xff0b1928; // 按下时的边框颜色 + // 创建新按钮(如果当前按钮为空) + if (button == nullptr) + { + button = new UIButton(); + } + button->SetPosition(left, top); + button->Resize(width, height); + button->SetViewId(viewId); + button->SetStyle(STYLE_BACKGROUND_COLOR, backgroundColor); + button->SetStyleForState(STYLE_BACKGROUND_COLOR, pressedBackgroundColor, UIButton::PRESSED); + button->SetStyleForState(STYLE_BORDER_COLOR, pressedBorderColor, UIButton::PRESSED); + // 设置按钮的点击事件监听器为 TraingSetPresenter 的实例 + button->SetOnClickListener(static_cast(TraingSetPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingSetView::InitImageView(UIImageView *&imageView, int left, int top, int width, int height, const char *viewId, const char *imagePath) + { + if (imageView == nullptr) + { + imageView = new UIImageView(); + } + imageView->SetPosition(left, top); + imageView->Resize(width, height); + imageView->SetViewId(viewId); + imageView->SetSrc(imagePath); + imageView->SetVisible(true); + } + /* InitView:初始化界面*/ + void TraingSetView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Button + InitButton(button1_, 43, 120, 380, 100, BUTTONTIME); + InitButton(button2_, 43, 240, 380, 100, BUTTONTIME); + container_->Add(button1_); + container_->Add(button2_); + + // 初始化Lable + InitLabel(label1_, 173, 52, 120, 35, "label1", "极限运动", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label2_, 130, 150, 60, 35, "label2", "时长", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label3_, 270, 155, 69, 23, "label3", "30 分钟", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label4_, 130, 270, 60, 35, "label4", "卡路里", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label5_, 270, 275, 60, 35, "label5", "1000 千卡", DEFAULT_VECTOR_FONT_FILENAME, 20); + container_->Add(label1_); + container_->Add(label2_); + container_->Add(label3_); + container_->Add(label4_); + container_->Add(label5_); + + // 初始化Image + InitImageView(image1_, 70, 150, 100, 100, "image1", imagePath_time); + InitImageView(image2_, 70, 270, 100, 100, "image2", imagePath_calories); + InitImageView(image3_, 380, 160, 100, 100, "image3", imagePath_iocn); + InitImageView(image4_, 380, 280, 100, 100, "image4", imagePath_iocn); + container_->Add(image1_); + container_->Add(image2_); + container_->Add(image3_); + container_->Add(image4_); + } + /* DeInit:删除组件 */ + void TraingSetView::DeInit() + { + // 删除Label + if (label1_ != nullptr) + { + container_->Remove(label1_); + delete label1_; + label1_ = nullptr; + } + if (label2_ != nullptr) + { + container_->Remove(label2_); + delete label2_; + label2_ = nullptr; + } + if (label3_ != nullptr) + { + container_->Remove(label3_); + delete label3_; + label3_ = nullptr; + } + if (label4_ != nullptr) + { + container_->Remove(label4_); + delete label4_; + label4_ = nullptr; + } + if (label5_ != nullptr) + { + container_->Remove(label5_); + delete label5_; + label5_ = nullptr; + } + + // 删除Button + if (button1_ != nullptr) + { + container_->Remove(button1_); + delete button1_; + button1_ = nullptr; + } + if (button2_ != nullptr) + { + container_->Remove(button2_); + delete button2_; + button2_ = nullptr; + } + + // 删除Image + if (image1_ != nullptr) + { + container_->Remove(image1_); + delete image1_; + image1_ = nullptr; + } + if (image2_ != nullptr) + { + container_->Remove(image2_); + delete image2_; + image2_ = nullptr; + } + if (image3_ != nullptr) + { + container_->Remove(image3_); + delete image3_; + image3_ = nullptr; + } + if (image4_ != nullptr) + { + container_->Remove(image4_); + delete image4_; + image4_ = nullptr; + } + + // 删除容器 + if (container_ != nullptr) + { + container_->RemoveAll(); // 移除容器中的所有组件 + delete container_; + container_ = nullptr; + } + } + + void TraingSetView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingSetView::OnStart() + { + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight()); + + // 创建 draglistener 实例并设置为拖动监听器 + UIView::OnDragListener *draglistener = static_cast(TraingSetPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingSetView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingSetView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingSetView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/UiConfig.h b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/UiConfig.h index c0c5c9b38..39a3b0f5c 100644 --- a/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/UiConfig.h +++ b/code/sdk/middleware/services/gui/uikit/sample/uitest/components/ui_test_clock_dial/UiConfig.h @@ -44,6 +44,7 @@ namespace OHOS { constexpr int16_t SCREEN_VERTICAL_RESOLUTION = 454; // watch width constexpr const char *CLOCK_IAMGES = RES_PATH"/clock.bin"; + constexpr const char *DIAL_CLOCK = RES_PATH"/Dial/dogmalio.bin"; constexpr const char *PLAYER_IAMGES = RES_PATH"/player/player.bin"; constexpr const char *COMPASS_IAMGES = RES_PATH"/compass.bin"; constexpr const char *DROPDOWN_IAMGES = RES_PATH"/dropdown.bin";