From: Caisking <3449750381@qq.com> Date: Tue, 12 Dec 2023 06:27:27 +0000 (+0800) Subject: 提交 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=422991a93d12c09c8f5c46468c223d8404cc775e;p=mirrors%2FFD230.git 提交 --- diff --git a/Resource/res/Training/Go_2.bin b/Resource/res/Training/Go_2.bin new file mode 100644 index 000000000..ec87acf4c Binary files /dev/null and b/Resource/res/Training/Go_2.bin differ diff --git a/Resource/res/Training/Line 1.bin b/Resource/res/Training/Line 1.bin new file mode 100644 index 000000000..f04c971b6 Binary files /dev/null and b/Resource/res/Training/Line 1.bin differ diff --git a/Resource/res/Training/Line 2.bin b/Resource/res/Training/Line 2.bin new file mode 100644 index 000000000..635cb2c34 Binary files /dev/null and b/Resource/res/Training/Line 2.bin differ diff --git a/Resource/res/Training/Line 3.bin b/Resource/res/Training/Line 3.bin new file mode 100644 index 000000000..f435d9c14 Binary files /dev/null and b/Resource/res/Training/Line 3.bin differ diff --git a/Resource/res/Training/Line 4.bin b/Resource/res/Training/Line 4.bin new file mode 100644 index 000000000..b56c169d2 Binary files /dev/null and b/Resource/res/Training/Line 4.bin differ diff --git a/Resource/res/Training/Line.bin b/Resource/res/Training/Line.bin new file mode 100644 index 000000000..9ba40f7ef Binary files /dev/null and b/Resource/res/Training/Line.bin differ diff --git a/Resource/res/Training/Walking_54.bin b/Resource/res/Training/Walking_54.bin new file mode 100644 index 000000000..0c977057b Binary files /dev/null and b/Resource/res/Training/Walking_54.bin differ diff --git a/Resource/res/Training/arrows.bin b/Resource/res/Training/arrows.bin new file mode 100644 index 000000000..797a64a25 Binary files /dev/null and b/Resource/res/Training/arrows.bin differ diff --git a/Resource/res/Training/black_piont.bin b/Resource/res/Training/black_piont.bin new file mode 100644 index 000000000..a9bc0b8c9 Binary files /dev/null and b/Resource/res/Training/black_piont.bin differ diff --git a/Resource/res/Training/bubble.bin b/Resource/res/Training/bubble.bin new file mode 100644 index 000000000..268046d4c Binary files /dev/null and b/Resource/res/Training/bubble.bin differ diff --git a/Resource/res/Training/bubble_piont.bin b/Resource/res/Training/bubble_piont.bin new file mode 100644 index 000000000..818a9abd0 Binary files /dev/null and b/Resource/res/Training/bubble_piont.bin differ diff --git a/Resource/res/Training/calories_30.bin b/Resource/res/Training/calories_30.bin new file mode 100644 index 000000000..8674a596f Binary files /dev/null and b/Resource/res/Training/calories_30.bin differ diff --git a/Resource/res/Training/control_point.bin b/Resource/res/Training/control_point.bin new file mode 100644 index 000000000..199c0f137 Binary files /dev/null and b/Resource/res/Training/control_point.bin differ diff --git a/Resource/res/Training/data_point.bin b/Resource/res/Training/data_point.bin new file mode 100644 index 000000000..0cd66a165 Binary files /dev/null and b/Resource/res/Training/data_point.bin differ diff --git a/Resource/res/Training/heartrate_30.bin b/Resource/res/Training/heartrate_30.bin new file mode 100644 index 000000000..1697c6bc7 Binary files /dev/null and b/Resource/res/Training/heartrate_30.bin differ diff --git a/Resource/res/Training/inco_up.bin b/Resource/res/Training/inco_up.bin new file mode 100644 index 000000000..d81048b08 Binary files /dev/null and b/Resource/res/Training/inco_up.bin differ diff --git a/Resource/res/Training/inco_up_40.bin b/Resource/res/Training/inco_up_40.bin new file mode 100644 index 000000000..96f896968 Binary files /dev/null and b/Resource/res/Training/inco_up_40.bin differ diff --git a/Resource/res/Training/mileage_30.bin b/Resource/res/Training/mileage_30.bin new file mode 100644 index 000000000..76237bd30 Binary files /dev/null and b/Resource/res/Training/mileage_30.bin differ diff --git a/Resource/res/Training/no.bin b/Resource/res/Training/no.bin new file mode 100644 index 000000000..fb89e49c2 Binary files /dev/null and b/Resource/res/Training/no.bin differ diff --git a/Resource/res/Training/note.bin b/Resource/res/Training/note.bin new file mode 100644 index 000000000..48ab51d86 Binary files /dev/null and b/Resource/res/Training/note.bin differ diff --git a/Resource/res/Training/path.bin b/Resource/res/Training/path.bin new file mode 100644 index 000000000..ab6c2a848 Binary files /dev/null and b/Resource/res/Training/path.bin differ diff --git a/Resource/res/Training/progress.bin b/Resource/res/Training/progress.bin new file mode 100644 index 000000000..2d456e0c8 Binary files /dev/null and b/Resource/res/Training/progress.bin differ diff --git a/Resource/res/Training/sport-strength.bin b/Resource/res/Training/sport-strength.bin new file mode 100644 index 000000000..2f682a0bd Binary files /dev/null and b/Resource/res/Training/sport-strength.bin differ diff --git a/Resource/res/Training/step_30.bin b/Resource/res/Training/step_30.bin new file mode 100644 index 000000000..98998f919 Binary files /dev/null and b/Resource/res/Training/step_30.bin differ diff --git a/Resource/res/Training/warning.bin b/Resource/res/Training/warning.bin new file mode 100644 index 000000000..7301e2834 Binary files /dev/null and b/Resource/res/Training/warning.bin differ diff --git a/Resource/res/Training/yes.bin b/Resource/res/Training/yes.bin new file mode 100644 index 000000000..2e1463050 Binary files /dev/null and b/Resource/res/Training/yes.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_END.bin b/Resource/res/countdown/COUNTDOWM_END.bin new file mode 100644 index 000000000..85ed573cf Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_END.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_FIVE_MINUTE.bin b/Resource/res/countdown/COUNTDOWM_FIVE_MINUTE.bin new file mode 100644 index 000000000..7dd2cf845 Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_FIVE_MINUTE.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_ONE_MINUTE.bin b/Resource/res/countdown/COUNTDOWM_ONE_MINUTE.bin new file mode 100644 index 000000000..d0efbc507 Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_ONE_MINUTE.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_PAUSE.bin b/Resource/res/countdown/COUNTDOWM_PAUSE.bin new file mode 100644 index 000000000..87c18748a Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_PAUSE.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_PLAY.bin b/Resource/res/countdown/COUNTDOWM_PLAY.bin new file mode 100644 index 000000000..97b64f812 Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_PLAY.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_RESET.bin b/Resource/res/countdown/COUNTDOWM_RESET.bin new file mode 100644 index 000000000..2d3105e7d Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_RESET.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_TEN_MINUTE.bin b/Resource/res/countdown/COUNTDOWM_TEN_MINUTE.bin new file mode 100644 index 000000000..7a2e1029f Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_TEN_MINUTE.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_THIRTY_MINUTE.bin b/Resource/res/countdown/COUNTDOWM_THIRTY_MINUTE.bin new file mode 100644 index 000000000..ba69e921b Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_THIRTY_MINUTE.bin differ diff --git a/Resource/res/countdown/COUNTDOWM_VECTOR.bin b/Resource/res/countdown/COUNTDOWM_VECTOR.bin new file mode 100644 index 000000000..40be9d194 Binary files /dev/null and b/Resource/res/countdown/COUNTDOWM_VECTOR.bin differ diff --git a/Resource/res/countdown/COUNTDOWN_ATTENTION.bin b/Resource/res/countdown/COUNTDOWN_ATTENTION.bin new file mode 100644 index 000000000..b8120b857 Binary files /dev/null and b/Resource/res/countdown/COUNTDOWN_ATTENTION.bin differ diff --git a/Resource/res/countdown/COUNTDOWN_BUTTON.bin b/Resource/res/countdown/COUNTDOWN_BUTTON.bin new file mode 100644 index 000000000..5f89b6371 Binary files /dev/null and b/Resource/res/countdown/COUNTDOWN_BUTTON.bin differ diff --git a/Resource/res/countdown/COUNTDOWN_COLONE.bin b/Resource/res/countdown/COUNTDOWN_COLONE.bin new file mode 100644 index 000000000..f3d90d91f Binary files /dev/null and b/Resource/res/countdown/COUNTDOWN_COLONE.bin differ diff --git a/Resource/res/stopwatch/STOPWATCH_MARK.bin b/Resource/res/stopwatch/STOPWATCH_MARK.bin new file mode 100644 index 000000000..482ef15ca Binary files /dev/null and b/Resource/res/stopwatch/STOPWATCH_MARK.bin differ diff --git a/Resource/res/stopwatch/STOPWATH_RESET1.bin b/Resource/res/stopwatch/STOPWATH_RESET1.bin new file mode 100644 index 000000000..66a43d7fd Binary files /dev/null and b/Resource/res/stopwatch/STOPWATH_RESET1.bin differ diff --git a/Resource/res/stopwatch/STOPWATH_RESET2.bin b/Resource/res/stopwatch/STOPWATH_RESET2.bin new file mode 100644 index 000000000..2730fd954 Binary files /dev/null and b/Resource/res/stopwatch/STOPWATH_RESET2.bin differ diff --git a/Resource/res/weather/WEATHER_BACKGROUND.bin b/Resource/res/weather/WEATHER_BACKGROUND.bin new file mode 100644 index 000000000..143df271c Binary files /dev/null and b/Resource/res/weather/WEATHER_BACKGROUND.bin differ diff --git a/Resource/res/weather/WEATHER_CLEAR-SUNNY.bin b/Resource/res/weather/WEATHER_CLEAR-SUNNY.bin new file mode 100644 index 000000000..150f9023d Binary files /dev/null and b/Resource/res/weather/WEATHER_CLEAR-SUNNY.bin differ diff --git a/Resource/res/weather/WEATHER_DUSTSTORM.bin b/Resource/res/weather/WEATHER_DUSTSTORM.bin new file mode 100644 index 000000000..f1a9c607e Binary files /dev/null and b/Resource/res/weather/WEATHER_DUSTSTORM.bin differ diff --git a/Resource/res/weather/WEATHER_FOGGY.bin b/Resource/res/weather/WEATHER_FOGGY.bin new file mode 100644 index 000000000..b16fc33fe Binary files /dev/null and b/Resource/res/weather/WEATHER_FOGGY.bin differ diff --git a/Resource/res/weather/WEATHER_HAZE.bin b/Resource/res/weather/WEATHER_HAZE.bin new file mode 100644 index 000000000..a77f3a7ad Binary files /dev/null and b/Resource/res/weather/WEATHER_HAZE.bin differ diff --git a/Resource/res/weather/WEATHER_HUMIDITY.bin b/Resource/res/weather/WEATHER_HUMIDITY.bin new file mode 100644 index 000000000..678ff935d Binary files /dev/null and b/Resource/res/weather/WEATHER_HUMIDITY.bin differ diff --git a/Resource/res/weather/WEATHER_OVERCAST.bin b/Resource/res/weather/WEATHER_OVERCAST.bin new file mode 100644 index 000000000..e888f9c85 Binary files /dev/null and b/Resource/res/weather/WEATHER_OVERCAST.bin differ diff --git a/Resource/res/weather/WEATHER_RAIN.bin b/Resource/res/weather/WEATHER_RAIN.bin new file mode 100644 index 000000000..ede837596 Binary files /dev/null and b/Resource/res/weather/WEATHER_RAIN.bin differ diff --git a/Resource/res/weather/WEATHER_SNOW.bin b/Resource/res/weather/WEATHER_SNOW.bin new file mode 100644 index 000000000..27d521ee2 Binary files /dev/null and b/Resource/res/weather/WEATHER_SNOW.bin differ diff --git a/Resource/res/weather/WEATHER_SUNNY-CLOUNDY.bin b/Resource/res/weather/WEATHER_SUNNY-CLOUNDY.bin new file mode 100644 index 000000000..4460e9254 Binary files /dev/null and b/Resource/res/weather/WEATHER_SUNNY-CLOUNDY.bin differ diff --git a/Resource/res/weather/WEATHER_SUNNY.bin b/Resource/res/weather/WEATHER_SUNNY.bin new file mode 100644 index 000000000..75c954299 Binary files /dev/null and b/Resource/res/weather/WEATHER_SUNNY.bin differ diff --git a/Resource/res/weather/WEATHER_UVI.bin b/Resource/res/weather/WEATHER_UVI.bin new file mode 100644 index 000000000..9a1e8cee2 Binary files /dev/null and b/Resource/res/weather/WEATHER_UVI.bin differ diff --git a/Resource/res/weather/WEATHER_WINDSPEED.bin b/Resource/res/weather/WEATHER_WINDSPEED.bin new file mode 100644 index 000000000..1b02cdeb4 Binary files /dev/null and b/Resource/res/weather/WEATHER_WINDSPEED.bin differ diff --git a/Resource/res/weather/weather_clear-cloudy.bin b/Resource/res/weather/weather_clear-cloudy.bin new file mode 100644 index 000000000..96d16533d Binary files /dev/null and b/Resource/res/weather/weather_clear-cloudy.bin differ diff --git a/Resource/res/weather/weather_sunny-cloudy.bin b/Resource/res/weather/weather_sunny-cloudy.bin new file mode 100644 index 000000000..b3eae3b41 Binary files /dev/null and b/Resource/res/weather/weather_sunny-cloudy.bin differ diff --git a/Resource/res/weather/weather_thundershower.bin b/Resource/res/weather/weather_thundershower.bin new file mode 100644 index 000000000..148c18b45 Binary files /dev/null and b/Resource/res/weather/weather_thundershower.bin differ diff --git a/Resource/res/weather/weather_unknown.bin b/Resource/res/weather/weather_unknown.bin new file mode 100644 index 000000000..50b0ff892 Binary files /dev/null and b/Resource/res/weather/weather_unknown.bin differ diff --git a/build/.cmake/api/v1/query/client-vscode/query.json b/build/.cmake/api/v1/query/client-vscode/query.json new file mode 100644 index 000000000..82bb96424 --- /dev/null +++ b/build/.cmake/api/v1/query/client-vscode/query.json @@ -0,0 +1 @@ +{"requests":[{"kind":"cache","version":2},{"kind":"codemodel","version":2},{"kind":"toolchains","version":1},{"kind":"cmakeFiles","version":1}]} \ No newline at end of file diff --git a/build/CMakeCache.txt b/build/CMakeCache.txt new file mode 100644 index 000000000..675df3f5b --- /dev/null +++ b/build/CMakeCache.txt @@ -0,0 +1,65 @@ +# This is the CMakeCache file. +# For build in directory: /home/luozheng/FD230/build +# It was generated by CMake: /usr/bin/cmake +# You can edit this file to change values found and used by cmake. +# If you do not want to change any of the values, simply exit the editor. +# If you do want to change a value, simply edit, save, and exit the editor. +# The syntax for the file is as follows: +# KEY:TYPE=VALUE +# KEY is the name of a variable in the cache. +# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!. +# VALUE is the current value for the KEY. + +######################## +# EXTERNAL cache entries +######################## + +//No help, variable specified on the command line. +CMAKE_BUILD_TYPE:STRING=Debug + +//No help, variable specified on the command line. +CMAKE_CXX_COMPILER:FILEPATH=/mnt/d/tool/mingw64/bin/g++.exe + +//No help, variable specified on the command line. +CMAKE_C_COMPILER:FILEPATH=/mnt/d/tool/mingw64/bin/gcc.exe + +//No help, variable specified on the command line. +CMAKE_EXPORT_COMPILE_COMMANDS:BOOL=TRUE + + +######################## +# INTERNAL cache entries +######################## + +//This is the directory where this CMakeCache.txt was created +CMAKE_CACHEFILE_DIR:INTERNAL=/home/luozheng/FD230/build +//Major version of cmake used to create the current loaded cache +CMAKE_CACHE_MAJOR_VERSION:INTERNAL=3 +//Minor version of cmake used to create the current loaded cache +CMAKE_CACHE_MINOR_VERSION:INTERNAL=16 +//Patch version of cmake used to create the current loaded cache +CMAKE_CACHE_PATCH_VERSION:INTERNAL=3 +//Path to CMake executable. +CMAKE_COMMAND:INTERNAL=/usr/bin/cmake +//Path to cpack program executable. +CMAKE_CPACK_COMMAND:INTERNAL=/usr/bin/cpack +//Path to ctest program executable. +CMAKE_CTEST_COMMAND:INTERNAL=/usr/bin/ctest +//Name of external makefile project generator. +CMAKE_EXTRA_GENERATOR:INTERNAL= +//Name of generator. +CMAKE_GENERATOR:INTERNAL=Ninja +//Generator instance identifier. +CMAKE_GENERATOR_INSTANCE:INTERNAL= +//Name of generator platform. +CMAKE_GENERATOR_PLATFORM:INTERNAL= +//Name of generator toolset. +CMAKE_GENERATOR_TOOLSET:INTERNAL= +//Source directory with the top level CMakeLists.txt file for this +// project +CMAKE_HOME_DIRECTORY:INTERNAL=/home/luozheng/FD230/code/sdk +//number of local generators +CMAKE_NUMBER_OF_MAKEFILES:INTERNAL=1 +//Path to CMake installation. +CMAKE_ROOT:INTERNAL=/usr/share/cmake-3.16 + diff --git a/build/CMakeFiles/cmake.check_cache b/build/CMakeFiles/cmake.check_cache new file mode 100644 index 000000000..56c437b9b --- /dev/null +++ b/build/CMakeFiles/cmake.check_cache @@ -0,0 +1 @@ +# This file is generated by cmake for dependency checking of the CMakeCache.txt file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownModel.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownModel.h new file mode 100644 index 000000000..59161b8b7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownModel.h @@ -0,0 +1,25 @@ +#ifndef COUNTDOWN_MODEL_H +#define COUNTDOWN_MODEL_H + +#include +#include + +namespace OHOS +{ + class CountDownModel + { + public: + static std::shared_ptr GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存 + ~CountDownModel() {} + void SetCountDownTime(const std::string &countdowntime); // 设置倒计时时间 + std::string GetCountDownTime(void); // 获取倒计时时间 + void SetRingTime(const std::string &ringtime); // 设置响铃时间 + std::string GetRingTime(void); // 获取响铃时间 + + private: + CountDownModel() {} + std::string RingTime{"00:00:00"}; // 响铃时间 + std::string CountTime{"00:00:00"}; // 倒计时时间 + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeConfigPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeConfigPresenter.h new file mode 100644 index 000000000..fdecd4f09 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeConfigPresenter.h @@ -0,0 +1,40 @@ +#ifndef COUNTDOWN_TIME_CONFIG_PRESENTER_H +#define COUNTDOWN_TIME_CONFIG_PRESENTER_H + +#include "Presenter.h" +#include "CountDownTimeConfigView.h" +#include "components/ui_time_picker.h" +#include "components/ui_label.h" +/*倒计时时间配置*/ +namespace OHOS +{ + class CountDownTimeConfigView; + + class CountDownTimeConfigPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + UITimePicker::SelectedListener + { + public: + CountDownTimeConfigPresenter(); + virtual ~CountDownTimeConfigPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static CountDownTimeConfigPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + void OnTimePickerStoped(UITimePicker &picker) override; + + static std::string countdowntime; + static std::string ringtime; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeConfigView.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeConfigView.h new file mode 100644 index 000000000..67e47cb60 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeConfigView.h @@ -0,0 +1,47 @@ +#ifndef COUNTDOWN_TIME_CONFIG_VIEW_H +#define COUNTDOWN_TIME_CONFIG_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_time_picker.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +/*倒计时时间配置*/ +namespace OHOS +{ + static const char *ColoneImagesPath = "/user/res/countdown/COUNTDOWN_COLONE.bin"; // 冒号图片 + static const char *start_countdown_button_imagePath = "/user/res/countdown/COUNTDOWM_PAUSE.bin"; // 开始倒计时按钮图片 + static const char *start_countdown_button_viewid = "start_countdown"; // 开始倒计时按钮视图id + class CountDownTimeConfigPresenter; + class CountDownTimeConfigView : public View + { + public: + CountDownTimeConfigView(); + virtual ~CountDownTimeConfigView(); + static CountDownTimeConfigView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UITimePicker *timePicker = nullptr; + UIImageView *image1 = nullptr; + UIImageView *image2 = nullptr; + UIButton *start_countdown_button = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif // CountDownTimeConfig_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeNotNullPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeNotNullPresenter.h new file mode 100644 index 000000000..c49fc694c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeNotNullPresenter.h @@ -0,0 +1,34 @@ +#ifndef COUNTDOWN_TIME_NOT_NULL_PRESENTER_H +#define COUNTDOWN_TIME_NOT_NULL_PRESENTER_H + +#include "Presenter.h" +#include "CountDownTimeNotNullView.h" + +/*倒计时时间不能为0*/ +namespace OHOS +{ + class CountDownTimeNotNullView; + + class CountDownTimeNotNullPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + CountDownTimeNotNullPresenter(); + virtual ~CountDownTimeNotNullPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static CountDownTimeNotNullPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeNotNullView.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeNotNullView.h new file mode 100644 index 000000000..bbfbf50f3 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/CountDownTimeNotNullView.h @@ -0,0 +1,47 @@ +#ifndef COUNTDOWN_TIME_NOT_NULL_VIEW_H +#define COUNTDOWN_TIME_NOT_NULL_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" + +/*倒计时时间不能为0*/ +namespace OHOS +{ + static const char *RETURN_NUTTON_VIEWID = "ReturnButton"; // 点击该按钮后回到倒计时设置界面 + static const char *imagepath1 = "/user/res/countdown/COUNTDOWN_ATTENTION.bin"; + static const char *imagepath2 = "/user/res/countdown/COUNTDOWN_BUTTON.bin"; + class CountDownTimeNotNullPresenter; + class CountDownTimeNotNullView : public View + { + + public: + CountDownTimeNotNullView(); + virtual ~CountDownTimeNotNullView(); + static CountDownTimeNotNullView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UIImageView *image1_ = nullptr; + UILabel *label2_ = nullptr; + UIButton *button1_ = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/MainCountDownPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/MainCountDownPresenter.h new file mode 100644 index 000000000..d81b459e8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/MainCountDownPresenter.h @@ -0,0 +1,34 @@ +#ifndef MAIN_COUNTDOWN_PRESENTER_H +#define MAIN_COUNTDOWN_PRESENTER_H + +#include "Presenter.h" +#include "MainCountDownView.h" + +/*倒计时的主界面*/ +namespace OHOS +{ + class MainCountDownView; + + class MainCountDownPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + MainCountDownPresenter(); + virtual ~MainCountDownPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static MainCountDownPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // MainCountDown_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/MainCountDownView.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/MainCountDownView.h new file mode 100644 index 000000000..aa2914ae3 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/MainCountDownView.h @@ -0,0 +1,63 @@ +#ifndef MAIN_COUNTDOWN_VIEW_H +#define MAIN_COUNTDOWN_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_label_button.h" +#include "components/ui_button.h" +/*倒计时的主界面*/ +namespace OHOS +{ +#define CountDownImageSrc "/user/res/countdown/" + + // 图片路径 + static const char *COUNTDOWN_ONE_MINUTE_IMAGE = CountDownImageSrc "COUNTDOWM_ONE_MINUTE.bin"; // 1分钟 image + static const char *COUNTDOWN_FIVE_MINUTE_IMAGE = CountDownImageSrc "COUNTDOWM_FIVE_MINUTE.bin"; // 5分钟 image + static const char *COUNTDOWN_TEN_MINUTE_IMAGE = CountDownImageSrc "COUNTDOWM_TEN_MINUTE.bin"; // 10分钟 image + static const char *COUNTDOWN_THIRTY_MINUTE_IMAGE = CountDownImageSrc "COUNTDOWM_THIRTY_MINUTE.bin"; // 30分钟 image + + // 视图ID + static const char *COUNTDOWN_LABELBUTTON_VIEWID = "COUNTDOWN_LABELBUTTON"; // 自定义时间ID + static const char *COUNTDOWN_ONE_MINUTE_BUTTON_VIEWID = "COUNTDOWN_ONE_MINUTE_BUTTON"; // 1分钟 + static const char *COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID = "COUNTDOWN_FIVE_MINUTE_BUTTON"; // 5分钟 + static const char *COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID = "COUNTDOWN_TEN_MINUTE_BUTTON"; // 10分钟 + static const char *COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID = "COUNTDOWN_THIRTY_MINUTE_BUTTON"; // 30 分钟 +} +namespace OHOS +{ + class MainCountDownPresenter; + class MainCountDownView : public View + { + + public: + MainCountDownView(); + virtual ~MainCountDownView(); + static MainCountDownView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIView::OnDragListener *draglistener{nullptr}; + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UILabelButton *COUNTDOWN_LABELBUTTON = nullptr; + UIButton *COUNTDOWN_TEN_MINUTE_BUTTON = nullptr; + UIButton *COUNTDOWN_FIVE_MINUTE_BUTTON = nullptr; + UIButton *COUNTDOWN_THIRTY_MINUTE_BUTTON = nullptr; + UIButton *COUNTDOWN_ONE_MINUTE_BUTTON = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif // MainCountDown_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/StartCountDownPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/StartCountDownPresenter.h new file mode 100644 index 000000000..689075728 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/StartCountDownPresenter.h @@ -0,0 +1,42 @@ +#ifndef START_COUNTDOWN_PRESENTER_H +#define START_COUNTDOWN_PRESENTER_H + +#include "Presenter.h" +#include "StartCountDownView.h" +#include "components/ui_checkbox.h" +#include "components/ui_toggle_button.h" + +/*开始倒计时*/ +namespace OHOS +{ + class StartCountDownView; + class StartCountDownPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener, + public UICheckBox::OnChangeListener + { + public: + StartCountDownPresenter(); + virtual ~StartCountDownPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static StartCountDownPresenter *GetInstance(); + void SetToggleButton(UIToggleButton *togglebutton) + { + m_togglebutton = togglebutton; + } + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnChange(UICheckBox::UICheckBoxState state) override; + UIToggleButton *m_togglebutton{nullptr}; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/StartCountDownView.h b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/StartCountDownView.h new file mode 100644 index 000000000..559ac7186 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/include/StartCountDownView.h @@ -0,0 +1,55 @@ +#ifndef START_COUNTDOWN_VIEW_H +#define START_COUNTDOWN_VIEW_H + +#include "BaseView.h" +#include "View.h" + +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +#include "components/ui_button.h" +#include "components/ui_checkbox.h" + +/*开始倒计时*/ +namespace OHOS +{ + static const char *EndButton_ImagePath = "/user/res/countdown/COUNTDOWM_END.bin"; // 结束返回按钮图片 + static const char *CountDown_Play_ImagePath = "/user/res/countdown/COUNTDOWM_PLAY.bin"; // 开始倒计时image + static const char *CountDown_PAUSE_ImagePath = "/user/res/countdown/COUNTDOWM_PAUSE.bin"; // 暂停倒计时image + static const char *VectorImagesPath = "/user/res/countdown/COUNTDOWM_VECTOR.bin"; + static const char *PlayOrPauseToggleButton_ViewID = "PlayOrPauseToggleButton"; // 暂停和开始toggleButton视图id + static const char *EndButton_ViewID = "endbutton"; // 结束返回按钮视图id + class StartCountDownPresenter; + class StartCountDownView : public View + { + + public: + StartCountDownView(); + virtual ~StartCountDownView(); + static StartCountDownView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *showCountDownTimelabel = nullptr; + UILabel *label3_ = nullptr; + UIImageView *image = nullptr; + UIToggleButton *play_or_pause_toggleButton = nullptr; + UIButton *endbutton = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownModel.cpp new file mode 100644 index 000000000..f5e758821 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownModel.cpp @@ -0,0 +1,75 @@ +#include "countdown/include/CountDownModel.h" +#include +#include +#include +namespace OHOS +{ + /* -------------------------------------------------------------------------- */ + struct Time + { + int hour; + int minute; + int second; + }; + // 解析时间字符串并返回 Time 结构体 + Time ParseTimeString(const std::string &timeString) + { + Time time; + + std::stringstream ss(timeString); + char delimiter; + + ss >> time.hour >> delimiter >> time.minute >> delimiter >> time.second; + + return time; + } + // 格式化时间:确保它是 “hh:mm:ss” 格式 + std::string FormatTime(int hours, int minutes, int seconds) + { + std::ostringstream oss; + oss << std::setw(2) << std::setfill('0') << hours << ":" + << std::setw(2) << std::setfill('0') << minutes << ":" + << std::setw(2) << std::setfill('0') << seconds; + + return oss.str(); + } + /* -------------------------------------------------------------------------- */ + // 定义了 GetInstance() 方法来获取 CountDownModel 的实例,确保只有一个全局实例存在。 + std::shared_ptr CountDownModel::GetInstance() + { + static std::shared_ptr instance(new CountDownModel()); + return instance; + } + + // 设置倒计时时间 + void CountDownModel::SetCountDownTime(const std::string &countdowntime) + { + CountTime = countdowntime; + } + + // 获取倒计时时间 + std::string CountDownModel::GetCountDownTime(void) + { + return CountTime; + } + + // 设置响铃时间 + void CountDownModel::SetRingTime(const std::string &ringtime) + { + Time time = ParseTimeString(ringtime); + if (time.hour == 0) // 如果倒计时时间小于一小时就只显示分钟和秒 + { + std::string rt = ringtime.substr(3, 5); //"00:05:00":从第3个位置开始截图5个字符 ,substr不会修改原来的字符串 + RingTime = rt; + return; + } + RingTime = ringtime; + } + + // 获取响铃时间 + std::string CountDownModel::GetRingTime(void) + { + return RingTime; + } + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeConfigPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeConfigPresenter.cpp new file mode 100644 index 000000000..9a14b3ce6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeConfigPresenter.cpp @@ -0,0 +1,94 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "countdown/include/CountDownTimeConfigPresenter.h" +#include "countdown/include/CountDownModel.h" +/*倒计时时间配置*/ +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static CountDownTimeConfigPresenter *g_pCountDownTimeConfigPresenter = nullptr; + std::string CountDownTimeConfigPresenter::countdowntime{"00:00:00"}; + std::string CountDownTimeConfigPresenter::ringtime{nullptr}; + CountDownTimeConfigPresenter::CountDownTimeConfigPresenter() + { + + g_pCountDownTimeConfigPresenter = this; + } + + CountDownTimeConfigPresenter::~CountDownTimeConfigPresenter() + { + + g_pCountDownTimeConfigPresenter = nullptr; + } + + CountDownTimeConfigPresenter *CountDownTimeConfigPresenter::GetInstance() + { + + return g_pCountDownTimeConfigPresenter; + } + + void CountDownTimeConfigPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void CountDownTimeConfigPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void CountDownTimeConfigPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void CountDownTimeConfigPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool CountDownTimeConfigPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_COUNTDOWN); + } + return true; + } + + bool CountDownTimeConfigPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), start_countdown_button_viewid) == 0) + { + if (strcmp(CountDownModel::GetInstance()->GetCountDownTime().c_str(), "00:00:00") == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_COUNTDOWN_TIME_NOT_NULL); + return true; + } + else + { + NativeAbility::GetInstance().ChangeSlice(VIEW_START_COUNTDOWN); + return true; + } + return false; + } + return false; + } + + void CountDownTimeConfigPresenter::OnTimePickerStoped(UITimePicker &picker) + { + countdowntime = picker.GetSelectValue(); //倒计时时间 + ringtime = countdowntime; //响铃时间 + CountDownModel::GetInstance()->SetCountDownTime(countdowntime); // 设置倒计时时间 + CountDownModel::GetInstance()->SetRingTime(ringtime); // 设置响铃时间 + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeConfigView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeConfigView.cpp new file mode 100644 index 000000000..336034ff1 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeConfigView.cpp @@ -0,0 +1,226 @@ +#include "countdown/include/CountDownTimeConfigView.h" +#include "countdown/include/CountDownTimeConfigPresenter.h" +#include "countdown/include/CountDownModel.h" +#include "UiConfig.h" + +/*倒计时时间配置*/ +namespace OHOS +{ + + static CountDownTimeConfigView *g_pCountDownTimeConfigView{nullptr}; + + CountDownTimeConfigView::CountDownTimeConfigView() + { + + g_pCountDownTimeConfigView = this; + } + + CountDownTimeConfigView::~CountDownTimeConfigView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pCountDownTimeConfigView = nullptr; + } + + CountDownTimeConfigView *CountDownTimeConfigView::GetInstance() + { + + return g_pCountDownTimeConfigView; + } + + void CountDownTimeConfigView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView1_->SetHorizontalScrollState(false); + scrollView1_->SetVerticalScrollState(false); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(189, 52); + label1_->Resize(90, 35); + label1_->SetViewId("label"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + // Set additional property + label1_->SetText("倒计时"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add TimePicker to App + if (timePicker == nullptr) + { + timePicker = new UITimePicker(); + } + timePicker->SetPosition(74, 121); + timePicker->Resize(320, 180); + timePicker->SetViewId("timePicker1"); + timePicker->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + timePicker->SetStyle(STYLE_BORDER_RADIUS, 51); + // Set additional property + timePicker->SetItemHeight(60); // 设置时间选择器中每个项目的高度。 + timePicker->EnableSecond(true); // 设置在时间选择器中启用秒。 + timePicker->SetSelected(CountDownModel::GetInstance()->GetCountDownTime().c_str()); // 设置时间选择器中当前选择的时间。 + timePicker->SetTextColor(Color::GetColorFromRGBA(0xcc, 0xcc, 0xcc, 0xff), Color::GetColorFromRGBA(0xff, 0xa8, 0x00, 0xff)); // 设置时间选择器中的文本颜色。 + timePicker->SetLoopState(UITimePicker::PickerType::PICKER_HOUR, true); // 设置是否开启循环 :时 + timePicker->SetLoopState(UITimePicker::PickerType::PICKER_MIN, true); // 设置是否开启循环:分 + timePicker->SetLoopState(UITimePicker::PickerType::PICKER_SEC, true); // 设置是否开启循环:秒 + timePicker->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, 60); // 设置突出显示文本的字体名称和大小。 + timePicker->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, 30); // 设置背景文本的字体名称和大小。 + UITimePicker::SelectedListener *selectTimeListener = + (UITimePicker::SelectedListener *)OHOS::CountDownTimeConfigPresenter::GetInstance(); + timePicker->RegisterSelectedListener(selectTimeListener); + // Add to scrollView1 + scrollView1_->Add(timePicker); + timePicker->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (image1 == nullptr) + { + image1 = new UIImageView(); + } + image1->SetPosition(175, 200); + image1->Resize(18, 79); + image1->SetViewId("image1"); + image1->SetSrc(ColoneImagesPath); + // Add to scrollView1 + scrollView1_->Add(image1); + image1->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add ImageView to App + if (image2 == nullptr) + { + image2 = new UIImageView(); + } + image2->SetPosition(280, 200); + image2->Resize(18, 79); + image2->SetViewId("image2"); + image2->SetSrc(ColoneImagesPath); + scrollView1_->Add(image2); + image2->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (start_countdown_button == nullptr) + { + start_countdown_button = new UIButton(); + } + start_countdown_button->SetPosition(183, 321); + start_countdown_button->Resize(100, 100); + start_countdown_button->SetViewId(start_countdown_button_viewid); + start_countdown_button->SetStyle(STYLE_BORDER_RADIUS, 52); + start_countdown_button->SetImageSrc(start_countdown_button_imagePath, nullptr); + start_countdown_button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffa800, UIButton::PRESSED); + start_countdown_button->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + start_countdown_button->SetStyleForState(STYLE_BORDER_RADIUS, 52, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *start_countdown_button_Click = static_cast(CountDownTimeConfigPresenter::GetInstance()); + start_countdown_button->SetOnClickListener(start_countdown_button_Click); + // Add to scrollView1 + scrollView1_->Add(start_countdown_button); + start_countdown_button->SetVisible(true); + } + + void CountDownTimeConfigView::DeInitView() + { + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (timePicker != nullptr) + { + delete timePicker; + timePicker = nullptr; + } + if (image1 != nullptr) + { + delete image1; + image1 = nullptr; + } + if (image2 != nullptr) + { + delete image2; + image2 = nullptr; + } + if (start_countdown_button != nullptr) + { + delete start_countdown_button; + start_countdown_button = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + void CountDownTimeConfigView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + + void CountDownTimeConfigView::OnStart() + { + // container_容器属性 new + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + // container_容器属性 扩展 + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetTouchable(true); + container_->SetDraggable(true); + UIView::OnDragListener *DragListener = static_cast(CountDownTimeConfigPresenter::GetInstance()); + container_->SetOnDragListener(DragListener); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void CountDownTimeConfigView::OnSetUpView() + { + View::OnSetUpView(); + Draw(); + } + + void CountDownTimeConfigView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void CountDownTimeConfigView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeNotNullPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeNotNullPresenter.cpp new file mode 100644 index 000000000..008a9f429 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeNotNullPresenter.cpp @@ -0,0 +1,71 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "countdown/include/CountDownTimeNotNullPresenter.h" + +/*倒计时时间不能为0*/ +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static CountDownTimeNotNullPresenter *g_pCountDownTimeNotNullPresenter = nullptr; + + CountDownTimeNotNullPresenter::CountDownTimeNotNullPresenter() + { + + g_pCountDownTimeNotNullPresenter = this; + } + + CountDownTimeNotNullPresenter::~CountDownTimeNotNullPresenter() + { + + g_pCountDownTimeNotNullPresenter = nullptr; + } + + CountDownTimeNotNullPresenter *CountDownTimeNotNullPresenter::GetInstance() + { + + return g_pCountDownTimeNotNullPresenter; + } + + void CountDownTimeNotNullPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void CountDownTimeNotNullPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void CountDownTimeNotNullPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void CountDownTimeNotNullPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool CountDownTimeNotNullPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + + bool CountDownTimeNotNullPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), RETURN_NUTTON_VIEWID) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_COUNTDOWN_TIME_CONFIG); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeNotNullView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeNotNullView.cpp new file mode 100644 index 000000000..b687cf1dc --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/CountDownTimeNotNullView.cpp @@ -0,0 +1,198 @@ +#include "countdown/include/CountDownTimeNotNullView.h" +#include "countdown/include/CountDownTimeNotNullPresenter.h" +#include "UiConfig.h" + +/*倒计时时间不能为0*/ +namespace OHOS +{ + + static CountDownTimeNotNullView *g_pCountDownTimeNotNullView{nullptr}; + + CountDownTimeNotNullView::CountDownTimeNotNullView() + { + + g_pCountDownTimeNotNullView = this; + } + + CountDownTimeNotNullView::~CountDownTimeNotNullView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pCountDownTimeNotNullView = nullptr; + } + + CountDownTimeNotNullView *CountDownTimeNotNullView::GetInstance() + { + + return g_pCountDownTimeNotNullView; + } + + void CountDownTimeNotNullView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(188, 52); + label1_->Resize(90, 35); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + label1_->SetText("倒计时"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add ImageView to App + if (image1_ == nullptr) + { + image1_ = new UIImageView(); + } + image1_->SetPosition(193, 121); + image1_->Resize(80, 80); + image1_->SetViewId("image1"); + image1_->SetStyle(STYLE_BORDER_RADIUS, 100); + image1_->SetSrc(imagepath1); + // Add to scrollView1 + scrollView1_->Add(image1_); + image1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label2_ == nullptr) + { + label2_ = new UILabel(); + } + label2_->SetPosition(98, 253); + label2_->Resize(270, 35); + label2_->SetViewId("label2"); + label2_->SetStyle(STYLE_TEXT_FONT, 30); + label2_->SetStyle(STYLE_LINE_HEIGHT, 35); + label2_->SetText("请先设置好倒计时间"); + label2_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label2_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label2_->SetRollSpeed(0); + label2_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label2_); + label2_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (button1_ == nullptr) + { + button1_ = new UIButton(); + } + button1_->SetPosition(0, 366); + button1_->Resize(466, 100); + button1_->SetViewId(RETURN_NUTTON_VIEWID); + button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + button1_->SetStyle(STYLE_BORDER_RADIUS, 100); + button1_->SetImageSrc(imagepath2, nullptr); + button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button1Click = static_cast(CountDownTimeNotNullPresenter::GetInstance()); + button1_->SetOnClickListener(button1Click); + // Add to scrollView1 + scrollView1_->Add(button1_); + button1_->SetVisible(true); + } + + void CountDownTimeNotNullView::DeInitView() + { + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (image1_ != nullptr) + { + delete image1_; + image1_ = nullptr; + } + if (label2_ != nullptr) + { + delete label2_; + label2_ = nullptr; + } + if (button1_ != nullptr) + { + delete button1_; + button1_ = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + void CountDownTimeNotNullView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void CountDownTimeNotNullView::OnStart() + { + // container_容器属性 new + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + // container_容器属性 扩展 + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetTouchable(true); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void CountDownTimeNotNullView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void CountDownTimeNotNullView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void CountDownTimeNotNullView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/MainCountDownPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/MainCountDownPresenter.cpp new file mode 100644 index 000000000..c853b4311 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/MainCountDownPresenter.cpp @@ -0,0 +1,114 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "countdown/include/MainCountDownPresenter.h" +#include "countdown/include/CountDownModel.h" +/*倒计时的主界面*/ + +namespace OHOS +{ + using namespace std; + string OneMinuteTime = "00:01:00"; // 1分钟 + string FiveMinuteTime = "00:05:00"; // 5分钟 + string TenMinuteTime = "00:10:00"; // 10分钟 + string ThirtyMinuteTime = "00:30:00"; // 30分钟 +} + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static MainCountDownPresenter *g_pMainCountDownPresenter = nullptr; + + MainCountDownPresenter::MainCountDownPresenter() + { + + g_pMainCountDownPresenter = this; + } + + MainCountDownPresenter::~MainCountDownPresenter() + { + + g_pMainCountDownPresenter = nullptr; + } + + MainCountDownPresenter *MainCountDownPresenter::GetInstance() + { + + return g_pMainCountDownPresenter; + } + + void MainCountDownPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void MainCountDownPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainCountDownPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void MainCountDownPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool MainCountDownPresenter::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_APPLIST); + } + return true; + } + + bool MainCountDownPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), COUNTDOWN_LABELBUTTON_VIEWID) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_COUNTDOWN_TIME_CONFIG); + return true; + } + else if (strcmp(view.GetViewId(), COUNTDOWN_ONE_MINUTE_BUTTON_VIEWID) == 0) + { + CountDownModel::GetInstance()->SetCountDownTime(OneMinuteTime); + CountDownModel::GetInstance()->SetRingTime(OneMinuteTime); + NativeAbility::GetInstance().ChangeSlice(VIEW_START_COUNTDOWN); + return true; + } + else if (strcmp(view.GetViewId(), COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID) == 0) + { + CountDownModel::GetInstance()->SetCountDownTime(FiveMinuteTime); + CountDownModel::GetInstance()->SetRingTime(FiveMinuteTime); + NativeAbility::GetInstance().ChangeSlice(VIEW_START_COUNTDOWN); + return true; + } + else if (strcmp(view.GetViewId(), COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID) == 0) + { + CountDownModel::GetInstance()->SetCountDownTime(TenMinuteTime); + CountDownModel::GetInstance()->SetRingTime(TenMinuteTime); + NativeAbility::GetInstance().ChangeSlice(VIEW_START_COUNTDOWN); + return true; + } + else if (strcmp(view.GetViewId(), COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID) == 0) + { + CountDownModel::GetInstance()->SetCountDownTime(ThirtyMinuteTime); + CountDownModel::GetInstance()->SetRingTime(ThirtyMinuteTime); + NativeAbility::GetInstance().ChangeSlice(VIEW_START_COUNTDOWN); + return true; + } + return false; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/MainCountDownView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/MainCountDownView.cpp new file mode 100644 index 000000000..73c3eb422 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/MainCountDownView.cpp @@ -0,0 +1,277 @@ +#include "countdown/include/MainCountDownView.h" +#include "countdown/include/MainCountDownPresenter.h" + +/*倒计时的主界面*/ +namespace OHOS +{ +#define VISIBLE_XBAR(visible) + + static MainCountDownView *g_pMainCountDownView{nullptr}; + + MainCountDownView::MainCountDownView() + { + g_pMainCountDownView = this; + } + + MainCountDownView::~MainCountDownView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pMainCountDownView = nullptr; + } + + MainCountDownView *MainCountDownView::GetInstance() + { + + return g_pMainCountDownView; + } + + void MainCountDownView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView1_->SetReboundSize(100); // 设置回弹大小 + scrollView1_->SetHorizontalScrollState(false); // 设置横向不可以滚动 + scrollView1_->SetScrollBlankSize(50); // 设置高位50可滑动空白区域 + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(189, 55); + label1_->Resize(90, 35); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + label1_->SetText("倒计时"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (COUNTDOWN_LABELBUTTON == nullptr) + { + COUNTDOWN_LABELBUTTON = new UILabelButton(); + } + COUNTDOWN_LABELBUTTON->SetPosition(43, 130); + COUNTDOWN_LABELBUTTON->Resize(380, 100); + COUNTDOWN_LABELBUTTON->SetViewId(COUNTDOWN_LABELBUTTON_VIEWID); + COUNTDOWN_LABELBUTTON->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + COUNTDOWN_LABELBUTTON->SetStyle(STYLE_BORDER_RADIUS, 100); + // Set additional property + COUNTDOWN_LABELBUTTON->SetText("自定义时间"); + COUNTDOWN_LABELBUTTON->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + COUNTDOWN_LABELBUTTON->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffa800, UIButton::PRESSED); + COUNTDOWN_LABELBUTTON->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + COUNTDOWN_LABELBUTTON->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + // Add the CallBack about events + UIView::OnClickListener *labelButton1Click = static_cast(MainCountDownPresenter::GetInstance()); + COUNTDOWN_LABELBUTTON->SetOnClickListener(labelButton1Click); + // Add to scrollView1 + scrollView1_->Add(COUNTDOWN_LABELBUTTON); + COUNTDOWN_LABELBUTTON->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (COUNTDOWN_ONE_MINUTE_BUTTON == nullptr) + { + COUNTDOWN_ONE_MINUTE_BUTTON = new UIButton(); + } + COUNTDOWN_ONE_MINUTE_BUTTON->SetPosition(43, 254); + COUNTDOWN_ONE_MINUTE_BUTTON->Resize(180, 180); + COUNTDOWN_ONE_MINUTE_BUTTON->SetViewId(COUNTDOWN_ONE_MINUTE_BUTTON_VIEWID); + COUNTDOWN_ONE_MINUTE_BUTTON->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + COUNTDOWN_ONE_MINUTE_BUTTON->SetStyle(STYLE_BORDER_RADIUS, 100); + COUNTDOWN_ONE_MINUTE_BUTTON->SetImageSrc(COUNTDOWN_ONE_MINUTE_IMAGE, nullptr); + COUNTDOWN_ONE_MINUTE_BUTTON->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffa800, UIButton::PRESSED); + COUNTDOWN_ONE_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + COUNTDOWN_ONE_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button3Click = static_cast(MainCountDownPresenter::GetInstance()); + COUNTDOWN_ONE_MINUTE_BUTTON->SetOnClickListener(button3Click); + // Add to scrollView1 + scrollView1_->Add(COUNTDOWN_ONE_MINUTE_BUTTON); + COUNTDOWN_ONE_MINUTE_BUTTON->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (COUNTDOWN_FIVE_MINUTE_BUTTON == nullptr) + { + COUNTDOWN_FIVE_MINUTE_BUTTON = new UIButton(); + } + COUNTDOWN_FIVE_MINUTE_BUTTON->SetPosition(243, 254); + COUNTDOWN_FIVE_MINUTE_BUTTON->Resize(180, 180); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetViewId(COUNTDOWN_FIVE_MINUTE_BUTTON_VIEWID); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetStyle(STYLE_BORDER_RADIUS, 100); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetImageSrc(COUNTDOWN_FIVE_MINUTE_IMAGE, nullptr); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffa800, UIButton::PRESSED); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button5Click = static_cast(MainCountDownPresenter::GetInstance()); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetOnClickListener(button5Click); + // Add to scrollView1 + scrollView1_->Add(COUNTDOWN_FIVE_MINUTE_BUTTON); + COUNTDOWN_FIVE_MINUTE_BUTTON->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (COUNTDOWN_TEN_MINUTE_BUTTON == nullptr) + { + COUNTDOWN_TEN_MINUTE_BUTTON = new UIButton(); + } + COUNTDOWN_TEN_MINUTE_BUTTON->SetPosition(43, 454); + COUNTDOWN_TEN_MINUTE_BUTTON->Resize(180, 180); + COUNTDOWN_TEN_MINUTE_BUTTON->SetViewId(COUNTDOWN_TEN_MINUTE_BUTTON_VIEWID); + COUNTDOWN_TEN_MINUTE_BUTTON->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + COUNTDOWN_TEN_MINUTE_BUTTON->SetStyle(STYLE_BORDER_RADIUS, 100); + COUNTDOWN_TEN_MINUTE_BUTTON->SetImageSrc(COUNTDOWN_TEN_MINUTE_IMAGE, nullptr); + COUNTDOWN_TEN_MINUTE_BUTTON->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffa800, UIButton::PRESSED); + COUNTDOWN_TEN_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + COUNTDOWN_TEN_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button7Click = static_cast(MainCountDownPresenter::GetInstance()); + COUNTDOWN_TEN_MINUTE_BUTTON->SetOnClickListener(button7Click); + // Add to scrollView1 + scrollView1_->Add(COUNTDOWN_TEN_MINUTE_BUTTON); + COUNTDOWN_TEN_MINUTE_BUTTON->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (COUNTDOWN_THIRTY_MINUTE_BUTTON == nullptr) + { + COUNTDOWN_THIRTY_MINUTE_BUTTON = new UIButton(); + } + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetPosition(243, 454); + COUNTDOWN_THIRTY_MINUTE_BUTTON->Resize(180, 180); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetViewId(COUNTDOWN_THIRTY_MINUTE_BUTTON_VIEWID); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetStyle(STYLE_BORDER_RADIUS, 100); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetImageSrc(COUNTDOWN_THIRTY_MINUTE_IMAGE, nullptr); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffa800, UIButton::PRESSED); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button1Click = static_cast(MainCountDownPresenter::GetInstance()); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetOnClickListener(button1Click); + // Add to scrollView1 + scrollView1_->Add(COUNTDOWN_THIRTY_MINUTE_BUTTON); + COUNTDOWN_THIRTY_MINUTE_BUTTON->SetVisible(true); + /* -------------------------------------------------------------------------- */ + } + + void MainCountDownView::DeInitView() + { + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (COUNTDOWN_LABELBUTTON != nullptr) + { + delete COUNTDOWN_LABELBUTTON; + COUNTDOWN_LABELBUTTON = nullptr; + } + if (COUNTDOWN_TEN_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_TEN_MINUTE_BUTTON; + COUNTDOWN_TEN_MINUTE_BUTTON = nullptr; + } + if (COUNTDOWN_FIVE_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_FIVE_MINUTE_BUTTON; + COUNTDOWN_FIVE_MINUTE_BUTTON = nullptr; + } + if (COUNTDOWN_THIRTY_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_THIRTY_MINUTE_BUTTON; + COUNTDOWN_THIRTY_MINUTE_BUTTON = nullptr; + } + if (COUNTDOWN_ONE_MINUTE_BUTTON != nullptr) + { + delete COUNTDOWN_ONE_MINUTE_BUTTON; + COUNTDOWN_ONE_MINUTE_BUTTON = nullptr; + } + if (draglistener != nullptr) + { + delete draglistener; + draglistener = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + void MainCountDownView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void MainCountDownView::OnStart() + { + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight()); + draglistener = static_cast(MainCountDownPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + container_->SetTouchable(true); + container_->SetDraggable(true); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void MainCountDownView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void MainCountDownView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void MainCountDownView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/StartCountDownPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/StartCountDownPresenter.cpp new file mode 100644 index 000000000..f4aa4759c --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/StartCountDownPresenter.cpp @@ -0,0 +1,84 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "countdown/include/StartCountDownPresenter.h" +#include "countdown/include/CountDownModel.h" +/*开始倒计时*/ +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static StartCountDownPresenter *g_pStartCountDownPresenter = nullptr; + + StartCountDownPresenter::StartCountDownPresenter() + { + + g_pStartCountDownPresenter = this; + } + + StartCountDownPresenter::~StartCountDownPresenter() + { + + g_pStartCountDownPresenter = nullptr; + } + + StartCountDownPresenter *StartCountDownPresenter::GetInstance() + { + + return g_pStartCountDownPresenter; + } + + void StartCountDownPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void StartCountDownPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void StartCountDownPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void StartCountDownPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool StartCountDownPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + + bool StartCountDownPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), EndButton_ViewID) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_COUNTDOWN); //退出时把倒计时时间设置为0 + CountDownModel::GetInstance()->SetCountDownTime("00:00:00"); + CountDownModel::GetInstance()->SetRingTime(""); + } + return true; + } + bool StartCountDownPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + if(state == UICheckBox::UICheckBoxState::SELECTED) + { + printf("start countdown...\n"); //开启定时器 + } + else + { + printf("countdown pause...\n");//结束定时器 + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/StartCountDownView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/StartCountDownView.cpp new file mode 100644 index 000000000..475f94b7b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/countdown/src/StartCountDownView.cpp @@ -0,0 +1,252 @@ +#include "countdown/include/StartCountDownView.h" +#include "countdown/include/StartCountDownPresenter.h" +#include "countdown/include/CountDownModel.h" +#include "UiConfig.h" + +/*开始倒计时*/ +namespace OHOS +{ + + static StartCountDownView *g_pStartCountDownView{nullptr}; + + StartCountDownView::StartCountDownView() + { + + g_pStartCountDownView = this; + } + + StartCountDownView::~StartCountDownView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pStartCountDownView = nullptr; + } + + StartCountDownView *StartCountDownView::GetInstance() + { + + return g_pStartCountDownView; + } + + void StartCountDownView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(189, 52); + label1_->Resize(90, 35); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + // Set additional property + label1_->SetText("倒计时"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to scrollView1 + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (showCountDownTimelabel == nullptr) + { + showCountDownTimelabel = new UILabel(); + } + showCountDownTimelabel->SetPosition(63, 138); + showCountDownTimelabel->Resize(200, 60); + showCountDownTimelabel->SetViewId("showCountDownTimelabel");//用来显示倒计时时间 + showCountDownTimelabel->SetStyle(STYLE_TEXT_FONT, 80); + showCountDownTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94); + // Set additional property + showCountDownTimelabel->SetText(CountDownModel::GetInstance()->GetCountDownTime().c_str()); + showCountDownTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + showCountDownTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showCountDownTimelabel->SetRollSpeed(0); + showCountDownTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 80); + + // Add to scrollView1 + scrollView1_->Add(showCountDownTimelabel); + showCountDownTimelabel->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add ImageView to App + if (image == nullptr) + { + image = new UIImageView(); + } + image->SetPosition(174, 247); + image->Resize(28, 28); + image->SetViewId("image"); + image->SetSrc(VectorImagesPath); + // Add to scrollView1 + scrollView1_->Add(image); + image->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label3_ == nullptr) + { + label3_ = new UILabel(); + } + label3_->SetPosition(209, 241); + label3_->Resize(81, 41); + label3_->SetViewId("label3"); + label3_->SetStyle(STYLE_TEXT_FONT, 35); + label3_->SetStyle(STYLE_LINE_HEIGHT, 41); + + // Set additional property + label3_->SetText(CountDownModel::GetInstance()->GetRingTime().c_str()); + label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label3_->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff)); + label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label3_->SetRollSpeed(0); + label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 35); + + // Add to scrollView1 + scrollView1_->Add(label3_); + label3_->SetVisible(true); + + // Add ToggleButton to App + if (play_or_pause_toggleButton == nullptr) + { + play_or_pause_toggleButton = new UIToggleButton(); + } + play_or_pause_toggleButton->SetPosition(248, 321); + play_or_pause_toggleButton->Resize(100, 100); + play_or_pause_toggleButton->SetViewId(PlayOrPauseToggleButton_ViewID); + play_or_pause_toggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + play_or_pause_toggleButton->SetStyle(STYLE_BORDER_RADIUS, 100); + play_or_pause_toggleButton->SetImages(CountDown_Play_ImagePath, CountDown_PAUSE_ImagePath); + UICheckBox::OnChangeListener *ToggleButtonChange = static_cast(StartCountDownPresenter::GetInstance()); + StartCountDownPresenter::GetInstance()->SetToggleButton(play_or_pause_toggleButton); + play_or_pause_toggleButton->SetOnChangeListener(ToggleButtonChange); + scrollView1_->Add(play_or_pause_toggleButton); + play_or_pause_toggleButton->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (endbutton == nullptr) + { + endbutton = new UIButton(); + } + endbutton->SetPosition(118, 321); + endbutton->Resize(100, 100); + endbutton->SetViewId(EndButton_ViewID); + endbutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + endbutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + endbutton->SetStyle(STYLE_BORDER_RADIUS, 100); + endbutton->SetImageSrc(EndButton_ImagePath, nullptr); + endbutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffffa800, UIButton::PRESSED); + endbutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + endbutton->SetStyleForState(STYLE_BORDER_RADIUS, 100, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *buttonClick = static_cast(StartCountDownPresenter::GetInstance()); + endbutton->SetOnClickListener(buttonClick); + // Add to scrollView1 + scrollView1_->Add(endbutton); + endbutton->SetVisible(true); + } + + void StartCountDownView::DeInitView() + { + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (showCountDownTimelabel != nullptr) + { + delete showCountDownTimelabel; + showCountDownTimelabel = nullptr; + } + if (image != nullptr) + { + delete image; + image = nullptr; + } + if (label3_ != nullptr) + { + delete label3_; + label3_ = nullptr; + } + if (play_or_pause_toggleButton != nullptr) + { + delete play_or_pause_toggleButton; + play_or_pause_toggleButton = nullptr; + } + if (endbutton != nullptr) + { + delete endbutton; + endbutton = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + } + void StartCountDownView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void StartCountDownView::OnStart() + { + // container_容器属性 new + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + // container_容器属性 扩展 + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetTouchable(true); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void StartCountDownView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void StartCountDownView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void StartCountDownView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h new file mode 100644 index 000000000..bdfbb26a6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchPresenter.h @@ -0,0 +1,31 @@ +#ifndef MAIN_STOPWATCH_PRESENTER_H +#define MAIN_STOPWATCH_PRESENTER_H + +#include "Presenter.h" +#include "MainStopWatchView.h" +#include "components/ui_checkbox.h" +/*秒表主视图*/ +namespace OHOS +{ + class MainStopWatchView; + class MainStopWatchPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + MainStopWatchPresenter(); + virtual ~MainStopWatchPresenter(); + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static MainStopWatchPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h new file mode 100644 index 000000000..2d6176c69 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/MainStopWatchView.h @@ -0,0 +1,56 @@ +#ifndef MAIN_STOPWATCH_VIEW_H +#define MAIN_STOPWATCH_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_checkbox.h" +#include "components/ui_button.h" +/*秒表主视图*/ +namespace OHOS +{ + + static const char *checkBox1selectedImg = "/user/res/countdown/COUNTDOWM_PLAY.bin"; // 播放 + static const char *checkBox1unSelectedImg = "/user/res/countdown/COUNTDOWM_PAUSE.bin"; // 暂停 + static const char *ResetOrMarkButtonImg_Reset1 = "/user/res/stopwatch/STOPWATH_RESET1.bin"; // 重置_灰色 图片 + static const char *ResetOrMarkButtonImg_Reset2 = "/user/res/stopwatch/STOPWATH_RESET2.bin"; // 重置_白色 图片 + static const char *ResetOrMarkButtonImg_Mark = "/user/res/stopwatch/STOPWATCH_MARK.bin"; // 标记 图片 + static const char *PlayOrPausecheckBoxVIEWID = "PlayOrPausecheckBox"; // 播放或暂停复选框视图ID + static const char *ResetOrMarkButton_RESET1_VIEWID = "ResetOrMarkButtonReset1"; // ResetOrMarkButtonReset1 + static const char *ResetOrMarkButton_RESET2_VIEWID = "ResetOrMarkButtonReset2"; // ResetOrMarkButtonReset2 + static const char *ResetOrMarkButton_MARK_VIEWID = "ResetOrMarkButtonMark"; // ResetOrMarkButtonMark + class MainStopWatchPresenter; + class MainStopWatchView : public View + { + + public: + MainStopWatchView(); + virtual ~MainStopWatchView(); + static MainStopWatchView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *showTimelabel = nullptr; // 用来显示计时时间 + UICheckBox *PlayOrPausecheckBox = nullptr; // 播放或暂停复选框 + UIButton *ResetOrMarkbutton = nullptr; // 重置或标记按钮 + UIView::OnDragListener *draglistener{nullptr}; + UICheckBox::OnChangeListener *PlayOrPausecheckBoxChangeListener{nullptr}; + UIView::OnClickListener *ResetOrMarkbuttonClick{nullptr}; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchModel.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchModel.h new file mode 100644 index 000000000..66baa6de1 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchModel.h @@ -0,0 +1,31 @@ +#ifndef STOP_WATCH_MODEL_H +#define STOP_WATCH_MODEL_H + +#include +#include +#include + +namespace OHOS +{ + class StopWatchModel + { + public: + static std::shared_ptr GetInstance(); // shared_ptr:当没有引用指向这个实例时会自动释放内存 + ~StopWatchModel() {} + char *DisplayMotionDuration(); + + private: + // 将构造函数、拷贝构造函数和赋值操作符私有化 + StopWatchModel() = default; + StopWatchModel(const StopWatchModel &) = delete; + StopWatchModel &operator=(const StopWatchModel &) = delete; + + private: + static int oneDaySec; // 一天的秒数 + static int oneHourSec; // 一个小时的秒数 + static int oneMinuteSec; // 一分钟秒数 + }; + +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitPresenter.h new file mode 100644 index 000000000..0d548cdad --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitPresenter.h @@ -0,0 +1,34 @@ +#ifndef STOPWATCH_RECORD_CYCLE_TO_LIMIT_PRESENTER_H +#define STOPWATCH_RECORD_CYCLE_TO_LIMIT_PRESENTER_H + +#include "Presenter.h" +#include "StopWatchRecordCycleToLimitView.h" + +/*弹窗视图:到达最高圈数99时弹出*/ +namespace OHOS +{ + class StopWatchRecordCycleToLimitView; + + class StopWatchRecordCycleToLimitPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + StopWatchRecordCycleToLimitPresenter(); + virtual ~StopWatchRecordCycleToLimitPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static StopWatchRecordCycleToLimitPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h new file mode 100644 index 000000000..f69f36111 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordCycleToLimitView.h @@ -0,0 +1,43 @@ +#ifndef STOPWATCH_RECORD_CYCLE_TO_LIMIT_VIEW_H +#define STOPWATCH_RECORD_CYCLE_TO_LIMIT_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +/*弹窗视图:到达最高圈数99时弹出*/ +namespace OHOS +{ + class StopWatchRecordCycleToLimitPresenter; + class StopWatchRecordCycleToLimitView : public View + { + + public: + StopWatchRecordCycleToLimitView(); + virtual ~StopWatchRecordCycleToLimitView(); + static StopWatchRecordCycleToLimitView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UIImageView *image1_ = nullptr; + UILabel *label3_ = nullptr; + UIButton *button1_ = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitPresenter.h new file mode 100644 index 000000000..6a158dda9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitPresenter.h @@ -0,0 +1,32 @@ +#ifndef STOPWATCH_RECORD_TIME_TO_LIMIT_PRESENTER_H +#define STOPWATCH_RECORD_TIME_TO_LIMIT_PRESENTER_H + +#include "Presenter.h" +#include "StopWatchRecordTimeToLimitView.h" +/*弹窗视图:到达最高时间99:59.99时弹出*/ +namespace OHOS +{ + class StopWatchRecordTimeToLimitView; + class StopWatchRecordTimeToLimitPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + StopWatchRecordTimeToLimitPresenter(); + virtual ~StopWatchRecordTimeToLimitPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static StopWatchRecordTimeToLimitPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h new file mode 100644 index 000000000..9667176c6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/include/StopWatchRecordTimeToLimitView.h @@ -0,0 +1,43 @@ +#ifndef STOPWATCH_RECORD_TIME_TO_LIMIT_VIEW_H +#define STOPWATCH_RECORD_TIME_TO_LIMIT_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_button.h" +/*弹窗视图:到达最高时间99:59.99时弹出*/ +namespace OHOS +{ + class StopWatchRecordTimeToLimitPresenter; + class StopWatchRecordTimeToLimitView : public View + { + + public: + StopWatchRecordTimeToLimitView(); + virtual ~StopWatchRecordTimeToLimitView(); + static StopWatchRecordTimeToLimitView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UIImageView *image1_ = nullptr; + UILabel *label3_ = nullptr; + UIButton *button1_ = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp new file mode 100644 index 000000000..8cd78aa7a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchPresenter.cpp @@ -0,0 +1,70 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "stopwatch/include/MainStopWatchPresenter.h" +/*秒表主视图*/ +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static MainStopWatchPresenter *g_pMainStopWatchPresenter = nullptr; + + MainStopWatchPresenter::MainStopWatchPresenter() + { + + g_pMainStopWatchPresenter = this; + } + + MainStopWatchPresenter::~MainStopWatchPresenter() + { + + g_pMainStopWatchPresenter = nullptr; + } + + MainStopWatchPresenter *MainStopWatchPresenter::GetInstance() + { + + return g_pMainStopWatchPresenter; + } + + void MainStopWatchPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void MainStopWatchPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainStopWatchPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void MainStopWatchPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool MainStopWatchPresenter::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_APPLIST); + } + return true; + } + + bool MainStopWatchPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp new file mode 100644 index 000000000..29c080bd9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/MainStopWatchView.cpp @@ -0,0 +1,289 @@ +#include "stopwatch/include/MainStopWatchView.h" +#include "stopwatch/include/MainStopWatchPresenter.h" +#include "UiConfig.h" +#include "NativeAbility.h" +#include "AppViewIDs.h" +/*秒表主视图*/ +namespace OHOS +{ + /*点击该复选框会播放或暂停计时*/ + class PlayOrPausecheckBoxOnChangeListener : public UICheckBox::OnChangeListener + { + public: + PlayOrPausecheckBoxOnChangeListener(UICheckBox *checkbox, UIButton *button) + { + m_checkbox = checkbox; + m_button = button; + } + bool OnChange(UICheckBox::UICheckBoxState state) override + { + if (state == UICheckBox::UICheckBoxState::SELECTED) + { + m_button->SetViewId(ResetOrMarkButton_MARK_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Mark, nullptr); + m_button->Invalidate(); // 图片重新赋值要刷新该区域 + } + else + { + m_button->SetViewId(ResetOrMarkButton_RESET2_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Reset2, nullptr); + m_button->Invalidate(); + } + return true; + } + + private: + UICheckBox *m_checkbox{nullptr}; + UIButton *m_button{nullptr}; + }; + int flag = 0; + /*标记或重置时间按钮监听*/ + class ResetOrMarkbuttonOnClickListener : public UIView::OnClickListener + { + public: + ResetOrMarkbuttonOnClickListener(UIButton *button) + { + m_button = button; + } + + bool OnClick(UIView &view, const ClickEvent &event) override + { + if (strcmp(view.GetViewId(), ResetOrMarkButton_MARK_VIEWID) == 0) + { + printf("mark!\n"); + if (flag == 0) + { + flag = 1; + NativeAbility::GetInstance().ChangeSlice(VIEW_STOPWATCH_RECORD_CYCLE_TO_LIMIT); + } + else + { + flag = 0; + NativeAbility::GetInstance().ChangeSlice(VIEW_STOPWATCH_RECORD_TIME_TO_LIMIT); + } + } + else if (strcmp(view.GetViewId(), ResetOrMarkButton_RESET2_VIEWID) == 0) + { + printf("Reset2!\n"); + m_button->SetViewId(ResetOrMarkButton_RESET1_VIEWID); + m_button->SetImageSrc(ResetOrMarkButtonImg_Reset1, ResetOrMarkButtonImg_Reset1); + m_button->Invalidate(); + } + return true; + } + UIButton *m_button{nullptr}; + }; +} +namespace OHOS +{ + + static MainStopWatchView *g_pMainStopWatchView{nullptr}; + + MainStopWatchView::MainStopWatchView() + { + + g_pMainStopWatchView = this; + } + + MainStopWatchView::~MainStopWatchView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pMainStopWatchView = nullptr; + } + + MainStopWatchView *MainStopWatchView::GetInstance() + { + + return g_pMainStopWatchView; + } + + void MainStopWatchView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(203, 52); + label1_->Resize(60, 35); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + label1_->SetText("秒表"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (showTimelabel == nullptr) + { + showTimelabel = new UILabel(); + } + showTimelabel->SetPosition(63, 160); + showTimelabel->Resize(200, 60); + showTimelabel->SetViewId("showTimelabel"); + showTimelabel->SetStyle(STYLE_TEXT_FONT, 80); + showTimelabel->SetStyle(STYLE_LINE_HEIGHT, 94); + showTimelabel->SetText("00:00.00"); + showTimelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + showTimelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + showTimelabel->SetRollSpeed(0); + showTimelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 80); + scrollView1_->Add(showTimelabel); + showTimelabel->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add CheckBox to App + if (PlayOrPausecheckBox == nullptr) + { + PlayOrPausecheckBox = new UICheckBox(); + } + PlayOrPausecheckBox->SetPosition(118, 321); + PlayOrPausecheckBox->Resize(100, 100); + PlayOrPausecheckBox->SetViewId(PlayOrPausecheckBoxVIEWID); + PlayOrPausecheckBox->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + PlayOrPausecheckBox->SetStyle(STYLE_BORDER_RADIUS, 51); + PlayOrPausecheckBox->SetImages(checkBox1selectedImg, checkBox1unSelectedImg); + // Add to scrollView1 + scrollView1_->Add(PlayOrPausecheckBox); + PlayOrPausecheckBox->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (ResetOrMarkbutton == nullptr) + { + ResetOrMarkbutton = new UIButton(); + } + ResetOrMarkbutton->SetPosition(248, 321); + ResetOrMarkbutton->Resize(100, 100); + ResetOrMarkbutton->SetViewId(ResetOrMarkButton_RESET1_VIEWID); + ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + ResetOrMarkbutton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + ResetOrMarkbutton->SetImageSrc(ResetOrMarkButtonImg_Reset1, nullptr); + ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + ResetOrMarkbutton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + ResetOrMarkbutton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + scrollView1_->Add(ResetOrMarkbutton); + ResetOrMarkbutton->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add the CallBack about events + PlayOrPausecheckBoxChangeListener = static_cast(new PlayOrPausecheckBoxOnChangeListener(PlayOrPausecheckBox, ResetOrMarkbutton)); + PlayOrPausecheckBox->SetOnChangeListener(PlayOrPausecheckBoxChangeListener); + ResetOrMarkbuttonClick = static_cast(new ResetOrMarkbuttonOnClickListener(ResetOrMarkbutton)); + ResetOrMarkbutton->SetOnClickListener(ResetOrMarkbuttonClick); + } + + void MainStopWatchView::DeInitView() + { + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (showTimelabel != nullptr) + { + delete showTimelabel; + showTimelabel = nullptr; + } + if (PlayOrPausecheckBox != nullptr) + { + delete PlayOrPausecheckBox; + PlayOrPausecheckBox = nullptr; + } + if (ResetOrMarkbutton != nullptr) + { + delete ResetOrMarkbutton; + ResetOrMarkbutton = nullptr; + } + if (draglistener != nullptr) + { + delete draglistener; + draglistener = nullptr; + } + if (PlayOrPausecheckBoxChangeListener != nullptr) + { + delete PlayOrPausecheckBoxChangeListener; + PlayOrPausecheckBoxChangeListener = nullptr; + } + if (ResetOrMarkbuttonClick != nullptr) + { + delete ResetOrMarkbuttonClick; + ResetOrMarkbuttonClick = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + void MainStopWatchView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void MainStopWatchView::OnStart() + { + // container_容器属性 new + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + // container_容器属性 扩展 + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + draglistener = static_cast(MainStopWatchPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + container_->SetTouchable(true); + container_->SetDraggable(true); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void MainStopWatchView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void MainStopWatchView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void MainStopWatchView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp new file mode 100644 index 000000000..bb4f2be89 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchModel.cpp @@ -0,0 +1,21 @@ +#include "stopwatch/include/StopWatchModel.h" +#include "cmsis_os2.h" +#include "cmsis_os.h" + +namespace OHOS +{ + int StopWatchModel::oneDaySec = 86400; // 一天的秒数 + int StopWatchModel::oneHourSec = 3600; // 一个小时的秒数 + int StopWatchModel::oneMinuteSec = 60; // 一分钟秒数 + + std::shared_ptr StopWatchModel::GetInstance() // shared_ptr:当没有引用指向这个实例时会自动释放内存 + { + static std::shared_ptr instance(new StopWatchModel()); + return instance; + } + + /* 时间显示 */ + char *StopWatchModel::DisplayMotionDuration() + { + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitPresenter.cpp new file mode 100644 index 000000000..730c2c9e1 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitPresenter.cpp @@ -0,0 +1,70 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "stopwatch/include/StopWatchRecordCycleToLimitPresenter.h" + +/*弹窗视图:到达最高圈数99时弹出*/ +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static StopWatchRecordCycleToLimitPresenter *g_pStopWatchRecordCycleToLimitPresenter = nullptr; + + StopWatchRecordCycleToLimitPresenter::StopWatchRecordCycleToLimitPresenter() + { + + g_pStopWatchRecordCycleToLimitPresenter = this; + } + + StopWatchRecordCycleToLimitPresenter::~StopWatchRecordCycleToLimitPresenter() + { + + g_pStopWatchRecordCycleToLimitPresenter = nullptr; + } + + StopWatchRecordCycleToLimitPresenter *StopWatchRecordCycleToLimitPresenter::GetInstance() + { + + return g_pStopWatchRecordCycleToLimitPresenter; + } + + void StopWatchRecordCycleToLimitPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void StopWatchRecordCycleToLimitPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void StopWatchRecordCycleToLimitPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void StopWatchRecordCycleToLimitPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool StopWatchRecordCycleToLimitPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + + bool StopWatchRecordCycleToLimitPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), "ReturnButton") == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_STOPWATCH); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp new file mode 100644 index 000000000..9862deb5f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordCycleToLimitView.cpp @@ -0,0 +1,195 @@ +#include "stopwatch/include/StopWatchRecordCycleToLimitView.h" +#include "stopwatch/include/StopWatchRecordCycleToLimitPresenter.h" +#include "UiConfig.h" +/*弹窗视图:到达最高圈数99时弹出*/ +namespace OHOS +{ + + static StopWatchRecordCycleToLimitView *g_pStopWatchRecordCycleToLimitView{nullptr}; + + StopWatchRecordCycleToLimitView::StopWatchRecordCycleToLimitView() + { + + g_pStopWatchRecordCycleToLimitView = this; + } + + StopWatchRecordCycleToLimitView::~StopWatchRecordCycleToLimitView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pStopWatchRecordCycleToLimitView = nullptr; + } + + StopWatchRecordCycleToLimitView *StopWatchRecordCycleToLimitView::GetInstance() + { + + return g_pStopWatchRecordCycleToLimitView; + } + + void StopWatchRecordCycleToLimitView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(203, 52); + label1_->Resize(60, 35); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + label1_->SetText("秒表"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (image1_ == nullptr) + { + image1_ = new UIImageView(); + } + image1_->SetPosition(193, 121); + image1_->Resize(100, 100); + image1_->SetViewId("image1"); + image1_->SetStyle(STYLE_BORDER_RADIUS, 100); + char *image1imagesPath = "/user/res/countdown/COUNTDOWN_ATTENTION.bin"; + image1_->SetSrc(image1imagesPath); + scrollView1_->Add(image1_); + image1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label3_ == nullptr) + { + label3_ = new UILabel(); + } + label3_->SetPosition(83, 253); + label3_->Resize(300, 35); + label3_->SetViewId("label3"); + label3_->SetStyle(STYLE_TEXT_FONT, 30); + label3_->SetStyle(STYLE_LINE_HEIGHT, 35); + label3_->SetText("当前已达到了最高圈数"); + label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label3_->SetRollSpeed(0); + label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to scrollView1 + scrollView1_->Add(label3_); + label3_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (button1_ == nullptr) + { + button1_ = new UIButton(); + } + button1_->SetPosition(0, 366); + button1_->Resize(466, 100); + button1_->SetViewId("ReturnButton"); + button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin"; + button1_->SetImageSrc(button1defaultImgSrc, nullptr); + button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + + // Add the CallBack about events + UIView::OnClickListener *button1Click = static_cast(StopWatchRecordCycleToLimitPresenter::GetInstance()); + button1_->SetOnClickListener(button1Click); + // Add to scrollView1 + scrollView1_->Add(button1_); + button1_->SetVisible(true); + } + + void StopWatchRecordCycleToLimitView::DeInitView() + { + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (image1_ != nullptr) + { + delete image1_; + image1_ = nullptr; + } + if (label3_ != nullptr) + { + delete label3_; + label3_ = nullptr; + } + if (button1_ != nullptr) + { + delete button1_; + button1_ = nullptr; + } + } + void StopWatchRecordCycleToLimitView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void StopWatchRecordCycleToLimitView::OnStart() + { + // container_容器属性 new + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + // container_容器属性 扩展 + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetTouchable(true); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void StopWatchRecordCycleToLimitView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void StopWatchRecordCycleToLimitView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void StopWatchRecordCycleToLimitView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitPresenter.cpp new file mode 100644 index 000000000..d58558f76 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitPresenter.cpp @@ -0,0 +1,70 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "stopwatch/include/StopWatchRecordTimeToLimitPresenter.h" + +/*弹窗视图:到达最高时间99:59.99时弹出*/ +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static StopWatchRecordTimeToLimitPresenter *g_pStopWatchRecordTimeToLimitPresenter = nullptr; + + StopWatchRecordTimeToLimitPresenter::StopWatchRecordTimeToLimitPresenter() + { + + g_pStopWatchRecordTimeToLimitPresenter = this; + } + + StopWatchRecordTimeToLimitPresenter::~StopWatchRecordTimeToLimitPresenter() + { + + g_pStopWatchRecordTimeToLimitPresenter = nullptr; + } + + StopWatchRecordTimeToLimitPresenter *StopWatchRecordTimeToLimitPresenter::GetInstance() + { + + return g_pStopWatchRecordTimeToLimitPresenter; + } + + void StopWatchRecordTimeToLimitPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void StopWatchRecordTimeToLimitPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void StopWatchRecordTimeToLimitPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void StopWatchRecordTimeToLimitPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool StopWatchRecordTimeToLimitPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + + bool StopWatchRecordTimeToLimitPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), "ReturnButton") == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN_STOPWATCH); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp new file mode 100644 index 000000000..2fb5b9624 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/stopwatch/src/StopWatchRecordTimeToLimitView.cpp @@ -0,0 +1,165 @@ +#include "stopwatch/include/StopWatchRecordTimeToLimitView.h" +#include "stopwatch/include/StopWatchRecordTimeToLimitPresenter.h" + +#include "UiConfig.h" + +/*弹窗视图:到达最高时间99:59.99时弹出*/ +namespace OHOS +{ + + static StopWatchRecordTimeToLimitView *g_pStopWatchRecordTimeToLimitView{nullptr}; + + StopWatchRecordTimeToLimitView::StopWatchRecordTimeToLimitView() + { + + g_pStopWatchRecordTimeToLimitView = this; + } + + StopWatchRecordTimeToLimitView::~StopWatchRecordTimeToLimitView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pStopWatchRecordTimeToLimitView = nullptr; + } + + StopWatchRecordTimeToLimitView *StopWatchRecordTimeToLimitView::GetInstance() + { + + return g_pStopWatchRecordTimeToLimitView; + } + + void StopWatchRecordTimeToLimitView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(203, 52); + label1_->Resize(60, 35); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + label1_->SetText("秒表"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (image1_ == nullptr) + { + image1_ = new UIImageView(); + } + image1_->SetPosition(193, 121); + image1_->Resize(100, 100); + image1_->SetViewId("image1"); + image1_->SetStyle(STYLE_BORDER_RADIUS, 100); + char *image1imagesPath = "/user/res/countdown/COUNTDOWN_ATTENTION.bin"; + image1_->SetSrc(image1imagesPath); + scrollView1_->Add(image1_); + image1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Label to App + if (label3_ == nullptr) + { + label3_ = new UILabel(); + } + label3_->SetPosition(53, 235); + label3_->Resize(300, 35); + label3_->SetViewId("label3"); + label3_->SetStyle(STYLE_TEXT_FONT, 30); + label3_->SetStyle(STYLE_LINE_HEIGHT, 35); + label3_->SetText("当前已达到了最长时间\n表秒自动暂停,请重新开始"); + label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label3_->SetRollSpeed(0); + label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + // Add to scrollView1 + scrollView1_->Add(label3_); + label3_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add Button to App + if (button1_ == nullptr) + { + button1_ = new UIButton(); + } + button1_->SetPosition(0, 366); + button1_->Resize(466, 100); + button1_->SetViewId("ReturnButton"); + button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff); + button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + char *button1defaultImgSrc = "/user/res/countdown/COUNTDOWN_BUTTON.bin"; + button1_->SetImageSrc(button1defaultImgSrc, nullptr); + button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xfffbfbfb, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED); + button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); + // Add the CallBack about events + UIView::OnClickListener *button1Click = static_cast(StopWatchRecordTimeToLimitPresenter::GetInstance()); + button1_->SetOnClickListener(button1Click); + // Add to scrollView1 + scrollView1_->Add(button1_); + button1_->SetVisible(true); + } + + void StopWatchRecordTimeToLimitView::DeInitView() + { + } + void StopWatchRecordTimeToLimitView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void StopWatchRecordTimeToLimitView::OnStart() + { + // container_容器属性 new + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + // container_容器属性 扩展 + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetTouchable(true); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void StopWatchRecordTimeToLimitView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void StopWatchRecordTimeToLimitView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void StopWatchRecordTimeToLimitView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingCardPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingCardPresenter.h new file mode 100644 index 000000000..d011868a8 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingCardPresenter.h @@ -0,0 +1,32 @@ +#ifndef _TraingCard_PRESENTER_H +#define _TraingCard_PRESENTER_H + +#include "Presenter.h" +#include "TraingCardView.h" + +namespace OHOS +{ + class TraingCardView; + + class TraingCardPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingCardPresenter(); + virtual ~TraingCardPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static TraingCardPresenter *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/TraingCardView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingCardView.h new file mode 100644 index 000000000..bdf142e10 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingCardView.h @@ -0,0 +1,63 @@ +#ifndef _TraingCard_VIEW_H +#define _TraingCard_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 "components/ui_swipe_view.h" + +#include "TraingCardPresenter.h" +namespace OHOS +{ + class TraingCardPresenter; + class TraingCardView : public View + { + + public: + TraingCardView(); + virtual ~TraingCardView(); + static TraingCardView *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); + + // 通过函数改变 + void SetLabel(); + void SetButton(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingCardView(TraingCardView &&) = delete; + TraingCardView &operator=(TraingCardView &&) = delete; + + UISwipeView *swipe_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingCard_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingControlPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingControlPresenter.h new file mode 100644 index 000000000..c1ebbfd72 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingControlPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingControl_PRESENTER_H +#define _TraingControl_PRESENTER_H + +#include "Presenter.h" +#include "TraingControlView.h" + +namespace OHOS +{ + class TraingControlView; + + class TraingControlPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingControlPresenter(); + virtual ~TraingControlPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + std::string test = "暂停"; + static TraingControlPresenter *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/TraingControlView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingControlView.h new file mode 100644 index 000000000..e96e78183 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingControlView.h @@ -0,0 +1,76 @@ +#ifndef _TraingControl_VIEW_H +#define _TraingControl_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 "TraingControlPresenter.h" +namespace OHOS +{ +#define BUTTONSTOP "button1" +#define BUTTONPAUSE "button2" +#define BUTTONCONTINUE "button3" + +#define BUTTON_PAUSE_IMG_SRC "/user/res/Training/sport-pause.bin" +#define BUTTON_STOP_IMG_SRC "/user/res/Training/sport-stop.bin" +#define BUTTON_CONTINUE_IMG_SRC "/user/res/Training/sport-continue.bin" + + class TraingControlPresenter; + class TraingControlView : public View + { + + public: + TraingControlView(); + virtual ~TraingControlView(); + static TraingControlView *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); + + //通过函数改变 + void SetLabel(); + void SetButton(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingControlView(TraingControlView &&) = delete; + TraingControlView &operator=(TraingControlView &&) = delete; + + UIViewGroup *container_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + + UIImageView *image1_ = nullptr; + + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingControl_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDataPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDataPresenter.h new file mode 100644 index 000000000..256325ee3 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDataPresenter.h @@ -0,0 +1,32 @@ +#ifndef _TraingData_PRESENTER_H +#define _TraingData_PRESENTER_H + +#include "Presenter.h" +#include "TraingDataView.h" + +namespace OHOS +{ + class TraingDataView; + + class TraingDataPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingDataPresenter(); + virtual ~TraingDataPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static TraingDataPresenter *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/TraingDataView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDataView.h new file mode 100644 index 000000000..c782f9480 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDataView.h @@ -0,0 +1,75 @@ +#ifndef _TraingData_VIEW_H +#define _TraingData_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 "TraingDataPresenter.h" +namespace OHOS +{ +#define BUTTONNOTE "button1" + + + class TraingDataPresenter; + class TraingDataView : public View + { + + public: + TraingDataView(); + virtual ~TraingDataView(); + static TraingDataView *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); + + // 通过函数改变 + void SetLabel(); + void SetButton(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingDataView(TraingDataView &&) = delete; + TraingDataView &operator=(TraingDataView &&) = 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; + UIImageView *image5_ = nullptr; + UIImageView *image6_ = nullptr; + + UIButton *button1_ = nullptr; + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingData_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDetailPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDetailPresenter.h new file mode 100644 index 000000000..351c7e398 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDetailPresenter.h @@ -0,0 +1,32 @@ +#ifndef _TraingDetail_PRESENTER_H +#define _TraingDetail_PRESENTER_H + +#include "Presenter.h" +#include "TraingDetailView.h" + +namespace OHOS +{ + class TraingDetailView; + + class TraingDetailPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingDetailPresenter(); + virtual ~TraingDetailPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static TraingDetailPresenter *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/TraingDetailView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDetailView.h new file mode 100644 index 000000000..735c9975a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingDetailView.h @@ -0,0 +1,75 @@ +#ifndef _TraingDetail_VIEW_H +#define _TraingDetail_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 "TraingDetailPresenter.h" +namespace OHOS +{ + class TraingDetailPresenter; + class TraingDetailView : public View + { + + public: + TraingDetailView(); + virtual ~TraingDetailView(); + static TraingDetailView *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); + + // 通过函数改变 + void SetLabel(); + void SetButton(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingDetailView(TraingDetailView &&) = delete; + TraingDetailView &operator=(TraingDetailView &&) = delete; + + UIViewGroup *container_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UILabel *label5_ = nullptr; + UILabel *label6_ = nullptr; + UILabel *label7_ = nullptr; + UILabel *label8_ = nullptr; + + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + UIImageView *image3_ = nullptr; + UIImageView *image4_ = nullptr; + UIImageView *image5_ = nullptr; + UIImageView *image6_ = nullptr; + UIImageView *image7_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingDetail_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEnddataPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEnddataPresenter.h new file mode 100644 index 000000000..c7877fb81 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEnddataPresenter.h @@ -0,0 +1,32 @@ +#ifndef _TraingEnddata_PRESENTER_H +#define _TraingEnddata_PRESENTER_H + +#include "Presenter.h" +#include "TraingEnddataView.h" + +namespace OHOS +{ + class TraingEnddataView; + + class TraingEnddataPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingEnddataPresenter(); + virtual ~TraingEnddataPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static TraingEnddataPresenter *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/TraingEnddataView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEnddataView.h new file mode 100644 index 000000000..56c9294ba --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEnddataView.h @@ -0,0 +1,95 @@ +#ifndef _TraingEnddata_VIEW_H +#define _TraingEnddata_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 "TraingEnddataPresenter.h" +namespace OHOS +{ +#define BUTTONBACK "button1" + + class TraingEnddataPresenter; + class TraingEnddataView : public View + { + + public: + TraingEnddataView(); + virtual ~TraingEnddataView(); + static TraingEnddataView *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); + + // 通过函数改变 + void SetLabel(); + void SetButton(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingEnddataView(TraingEnddataView &&) = delete; + TraingEnddataView &operator=(TraingEnddataView &&) = delete; + + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UILabel *label5_ = nullptr; + UILabel *label6_ = nullptr; + UILabel *label7_ = nullptr; + UILabel *label8_ = nullptr; + UILabel *label9_ = nullptr; + UILabel *label10_ = nullptr; + UILabel *label11_ = nullptr; + UILabel *label12_ = nullptr; + UILabel *label13_ = nullptr; + UILabel *label14_ = nullptr; + UILabel *label15_ = nullptr; + UILabel *label16_ = nullptr; + UILabel *label17_ = nullptr; + UILabel *label18_ = nullptr; + UILabel *label19_ = nullptr; + + UIButton *button1_ = nullptr; + + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + UIImageView *image3_ = nullptr; + UIImageView *image4_ = nullptr; + UIImageView *image5_ = nullptr; + UIImageView *image6_ = nullptr; + UIImageView *image7_ = nullptr; + UIImageView *image8_ = nullptr; + UIImageView *image9_ = nullptr; + UIImageView *image10_ = nullptr; + UIImageView *image11_ = nullptr; + + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingEnddata_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEndnotePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEndnotePresenter.h new file mode 100644 index 000000000..428b3d038 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEndnotePresenter.h @@ -0,0 +1,32 @@ +#ifndef _TraingEndnote_PRESENTER_H +#define _TraingEndnote_PRESENTER_H + +#include "Presenter.h" +#include "TraingEndnoteView.h" + +namespace OHOS +{ + class TraingEndnoteView; + + class TraingEndnotePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingEndnotePresenter(); + virtual ~TraingEndnotePresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + static TraingEndnotePresenter *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/TraingEndnoteView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEndnoteView.h new file mode 100644 index 000000000..243b52157 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingEndnoteView.h @@ -0,0 +1,66 @@ +#ifndef _TraingEndnote_VIEW_H +#define _TraingEndnote_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 "TraingEndnotePresenter.h" +namespace OHOS +{ +#define BUTTONNO "button1" +#define BUTTONYES "button2" + + class TraingEndnotePresenter; + class TraingEndnoteView : public View + { + + public: + TraingEndnoteView(); + virtual ~TraingEndnoteView(); + static TraingEndnoteView *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); + + // 通过函数改变 + void SetLabel(); + void SetButton(); + + private: + UIView::OnDragListener *draglistener{nullptr}; + TraingEndnoteView(TraingEndnoteView &&) = delete; + TraingEndnoteView &operator=(TraingEndnoteView &&) = delete; + + UIViewGroup *container_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingEndnote_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSPresenter.h new file mode 100644 index 000000000..aa6055eec --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingGPS_PRESENTER_H +#define _TraingGPS_PRESENTER_H + +#include "Presenter.h" +#include "TraingGPSView.h" + +namespace OHOS +{ + class TraingGPSView; + + class TraingGPSPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingGPSPresenter(); + virtual ~TraingGPSPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingGPSPresenter *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/TraingGPSView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSView.h new file mode 100644 index 000000000..4fa461646 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSView.h @@ -0,0 +1,64 @@ +#ifndef _TraingGPS_VIEW_H +#define _TraingGPS_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 "TraingGPSPresenter.h" +namespace OHOS +{ +#define BUTTONGO "button1" +#define BUTTONSET "button2" + + class TraingGPSPresenter; + class TraingGPSView : public View + { + + public: + TraingGPSView(); + virtual ~TraingGPSView(); + static TraingGPSView *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}; + TraingGPSView(TraingGPSView &&) = delete; + TraingGPSView &operator=(TraingGPSView &&) = delete; + + UIViewGroup *container_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingGPS_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSlackPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSlackPresenter.h new file mode 100644 index 000000000..21713d7ac --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSlackPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingGPSlack_PRESENTER_H +#define _TraingGPSlack_PRESENTER_H + +#include "Presenter.h" +#include "TraingGPSlackView.h" + +namespace OHOS +{ + class TraingGPSlackView; + + class TraingGPSlackPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingGPSlackPresenter(); + virtual ~TraingGPSlackPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingGPSlackPresenter *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/TraingGPSlackView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSlackView.h new file mode 100644 index 000000000..c96f41e18 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSlackView.h @@ -0,0 +1,64 @@ +#ifndef _TraingGPSlack_VIEW_H +#define _TraingGPSlack_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 "TraingGPSlackPresenter.h" +namespace OHOS +{ +#define BUTTONGO "button1" +#define BUTTONSET "button2" + + class TraingGPSlackPresenter; + class TraingGPSlackView : public View + { + + public: + TraingGPSlackView(); + virtual ~TraingGPSlackView(); + static TraingGPSlackView *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}; + TraingGPSlackView(TraingGPSlackView &&) = delete; + TraingGPSlackView &operator=(TraingGPSlackView &&) = delete; + + UIViewGroup *container_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingGPSlack_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSnotePresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSnotePresenter.h new file mode 100644 index 000000000..cbaf8eafa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSnotePresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingGPSnote_PRESENTER_H +#define _TraingGPSnote_PRESENTER_H + +#include "Presenter.h" +#include "TraingGPSnoteView.h" + +namespace OHOS +{ + class TraingGPSnoteView; + + class TraingGPSnotePresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingGPSnotePresenter(); + virtual ~TraingGPSnotePresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingGPSnotePresenter *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/TraingGPSnoteView.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSnoteView.h new file mode 100644 index 000000000..555f4c4ca --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingGPSnoteView.h @@ -0,0 +1,68 @@ +#ifndef _TraingGPSnote_VIEW_H +#define _TraingGPSnote_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 "TraingGPSnotePresenter.h" +namespace OHOS +{ +#define BUTTONBACK "button1" +#define BUTTONGO "button2" + + class TraingGPSnotePresenter; + class TraingGPSnoteView : public View + { + + public: + TraingGPSnoteView(); + virtual ~TraingGPSnoteView(); + static TraingGPSnoteView *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}; + TraingGPSnoteView(TraingGPSnoteView &&) = delete; + TraingGPSnoteView &operator=(TraingGPSnoteView &&) = delete; + + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + + UIButton *button1_ = nullptr; + UIButton *button2_ = nullptr; + + UIImageView *image1_ = nullptr; + UIImageView *image2_ = nullptr; + bool viewiInitStatus{false}; + }; +} // namespace OHOS +#endif // TraingGPSnote_PRESENTER_H diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetCaluliPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetCaluliPresenter.h new file mode 100644 index 000000000..5706845a7 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/include/TraingSetCaluliPresenter.h @@ -0,0 +1,33 @@ +#ifndef _TraingSetCaluli_PRESENTER_H +#define _TraingSetCaluli_PRESENTER_H + +#include "Presenter.h" +#include "TraingSetCaluliView.h" + +namespace OHOS +{ + class TraingSetCaluliView; + + class TraingSetCaluliPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + TraingSetCaluliPresenter(); + virtual ~TraingSetCaluliPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static TraingSetCaluliPresenter *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/src/TraingCardPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingCardPresenter.cpp new file mode 100644 index 000000000..cac32c0ac --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingCardPresenter.cpp @@ -0,0 +1,79 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingCardPresenter.h" +// #include "TraingCardView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingCardPresenter *g_pTraingCardPresenter = nullptr; + + TraingCardPresenter::TraingCardPresenter() + { + + g_pTraingCardPresenter = this; + } + + TraingCardPresenter::~TraingCardPresenter() + { + + g_pTraingCardPresenter = nullptr; + } + + TraingCardPresenter *TraingCardPresenter::GetInstance() + { + + return g_pTraingCardPresenter; + } + + void TraingCardPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingCardPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingCardPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingCardPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingCardPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + } + UNUSED(view); + return true; + } + + bool TraingCardPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), BUTTONSTOP) == 0) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + // NativeAbility::GetInstance(). + // } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingCardView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingCardView.cpp new file mode 100644 index 000000000..422454bac --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingCardView.cpp @@ -0,0 +1,224 @@ + +#include "traing/include/TraingCardView.h" +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" + +#include "common/screen.h" +#include "components/ui_digital_clock.h" +#include "components/ui_label.h" +#include "font/ui_font.h" +namespace OHOS +{ + static const uint16_t LABEL_FONT_SIZE = 200; + static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6; + static const uint32_t CARD_PAGE_COLOR = 0xffd0d0d0; + + static TraingCardView *g_pTraingCardView{nullptr}; + + TraingCardView::TraingCardView() + { + g_pTraingCardView = this; + } + + TraingCardView::~TraingCardView() + { + DeInit(); + g_pTraingCardView = nullptr; + } + + TraingCardView *TraingCardView::GetInstance() + { + + return g_pTraingCardView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingCardView::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->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x43, 0xff)); + label->SetRollSpeed(0); + // 设置标签可见 + label->SetVisible(true); + } + /* + InitButton:初始化按钮 + @param button 按钮指针 + @param left 按钮左边位置 + @param top 按钮顶部位置 + @param width 按钮宽度 + @param height 按钮高度 + @param viewId 按钮的视图 ID + */ + void TraingCardView::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); + // 设置按钮的点击事件监听器为 TraingCardPresenter 的实例 + button->SetOnClickListener(static_cast(TraingCardPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingCardView::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 TraingCardView ::InitView() + { + if (swipe_ == nullptr) + { + swipe_ = new UISwipeView(UISwipeView::HORIZONTAL); + swipe_->SetPosition(0, 0, 466, 466); + swipe_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Lable + InitLabel(label1_, 0, 55, 466, 466, "label1", "训练", DEFAULT_VECTOR_FONT_FILENAME, 200); + InitLabel(label2_, 0, 55, 466, 466, "label2", "暂停", DEFAULT_VECTOR_FONT_FILENAME, 200); + InitLabel(label3_, 0, 55, 466, 466, "label3", "结束", DEFAULT_VECTOR_FONT_FILENAME, 200); + + swipe_->Add(label1_); + swipe_->Add(label2_); + swipe_->Add(label3_); + } + + /* DeInit:删除组件 */ + void TraingCardView::DeInit() + { + UIView *view = static_cast(swipe_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete swipe_; + swipe_ = nullptr; + } + + void TraingCardView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingCardView::OnStart() + { + swipe_ = new UISwipeView(UISwipeView::HORIZONTAL); + if (swipe_ == nullptr) + { + return; + } + swipe_->SetPosition(0, 0); + swipe_->SetWidth(Screen::GetInstance().GetWidth()); + swipe_->SetHeight(Screen::GetInstance().GetHeight()); + + // 创建 draglistener 实例并设置为拖动监听器 + UIView::OnDragListener *draglistener = static_cast(TraingCardPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + swipe_->SetOnDragListener(draglistener); + + swipe_->SetTouchable(true); + swipe_->SetDraggable(true); + swipe_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); + swipe_->SetStyle(STYLE_BACKGROUND_OPA, OPA_OPAQUE); + swipe_->SetBlankSize(0); + swipe_->SetReboundSize(200); // 200: rebound size + swipe_->SetElastic(true); + + PreLoad(); + RootView::GetInstance()->Add(swipe_); + } + + void TraingCardView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingCardView::OnTearDownView() + { + View::OnTearDownView(); + return; + } + + void TraingCardView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } + +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingControlPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingControlPresenter.cpp new file mode 100644 index 000000000..f6e3394c9 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingControlPresenter.cpp @@ -0,0 +1,91 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingControlPresenter.h" +// #include "TraingControlView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingControlPresenter *g_pTraingControlPresenter = nullptr; + + TraingControlPresenter::TraingControlPresenter() + { + + g_pTraingControlPresenter = this; + } + + TraingControlPresenter::~TraingControlPresenter() + { + + g_pTraingControlPresenter = nullptr; + } + + TraingControlPresenter *TraingControlPresenter::GetInstance() + { + + return g_pTraingControlPresenter; + } + + void TraingControlPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingControlPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingControlPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingControlPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingControlPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDATA); + } + UNUSED(view); + return true; + } + + bool TraingControlPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONSTOP) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDNOTE); + } + + printf("********* test:%s\n", test.c_str()); + if (strcmp(view.GetViewId(), BUTTONPAUSE) == 0) + { + // 改变lable文字,button背景图片 + // test如果等于继续那就变为暂停,反之; + test == "ç»§ç»­" ? test = "暂停" : test = "ç»§ç»­"; + TraingControlView::GetInstance()->SetLabel(); + TraingControlView::GetInstance()->SetButton(); + } + printf("********* test:%s\n", test.c_str()); + // TraingControlView::GetInstance()->InitView(); + + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingControlView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingControlView.cpp new file mode 100644 index 000000000..70123e696 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingControlView.cpp @@ -0,0 +1,301 @@ + +#include "traing/include/TraingControlView.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_point = "/user/res/Training/control_point.bin"; + + static TraingControlView *g_pTraingControlView{nullptr}; + + TraingControlView::TraingControlView() + { + g_pTraingControlView = this; + } + + TraingControlView::~TraingControlView() + { + DeInit(); + g_pTraingControlView = nullptr; + } + + TraingControlView *TraingControlView::GetInstance() + { + + return g_pTraingControlView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingControlView::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 TraingControlView::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); + // 设置按钮的点击事件监听器为 TraingControlPresenter 的实例 + button->SetOnClickListener(static_cast(TraingControlPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingControlView::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 TraingControlView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Button + InitButton(button1_, 100, 202, 100, 100, BUTTONSTOP); + // Set additional property + char *button1defaultImgSrc = BUTTON_STOP_IMG_SRC; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + container_->Add(button1_); + + InitButton(button2_, 255, 202, 100, 100, BUTTONPAUSE); + // Set additional property + char *button2defaultImgSrc = BUTTON_PAUSE_IMG_SRC; + char *button2triggeredImgSrc = nullptr; + button2_->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc); + container_->Add(button2_); + + // 初始化Lable + InitLabel(label1_, 188, 52, 90, 35, "label1", "训练中", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label2_, 98, 110, 60, 35, "label2", "00:00:00", DEFAULT_VECTOR_FONT_FILENAME, 65); + InitLabel(label3_, 125, 324, 60, 40, "label3", "结束", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label4_, 280, 324, 60, 40, "label4", "暂停", DEFAULT_VECTOR_FONT_FILENAME, 20); + container_->Add(label1_); + container_->Add(label2_); + container_->Add(label3_); + container_->Add(label4_); + + // 初始化Image + InitImageView(image1_, 193, 421, 80, 20, "image1", imagePath_point); + container_->Add(image1_); + } + + /******************************************************************************************************/ + void TraingControlView::SetLabel() + { + if (TraingControlPresenter::GetInstance()->test == "ç»§ç»­") + { + label4_->SetText("ç»§ç»­"); + } + else + { + label4_->SetText("暂停"); + } + } + + void TraingControlView::SetButton() + { + if (TraingControlPresenter::GetInstance()->test == "ç»§ç»­") + { + //button2_->SetViewId(BUTTONCONTINUE); + button2_->SetImageSrc(BUTTON_CONTINUE_IMG_SRC, nullptr); + } + if (TraingControlPresenter::GetInstance()->test == "暂停") + { + //button2_->SetViewId(BUTTONPAUSE); + button2_->SetImageSrc(BUTTON_PAUSE_IMG_SRC, nullptr); + } + } + /******************************************************************************************************/ + + /* DeInit:删除组件 */ + void TraingControlView::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; + } + + // 删除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 (container_ != nullptr) + { + container_->RemoveAll(); // 移除容器中的所有组件 + delete container_; + container_ = nullptr; + } + } + + void TraingControlView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingControlView::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(TraingControlPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingControlView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingControlView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingControlView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDataPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDataPresenter.cpp new file mode 100644 index 000000000..3e72cdd72 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDataPresenter.cpp @@ -0,0 +1,83 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingDataPresenter.h" +// #include "TraingDataView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingDataPresenter *g_pTraingDataPresenter = nullptr; + + TraingDataPresenter::TraingDataPresenter() + { + + g_pTraingDataPresenter = this; + } + + TraingDataPresenter::~TraingDataPresenter() + { + + g_pTraingDataPresenter = nullptr; + } + + TraingDataPresenter *TraingDataPresenter::GetInstance() + { + + return g_pTraingDataPresenter; + } + + void TraingDataPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingDataPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingDataPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingDataPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingDataPresenter::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_TRAININGCONTROL); + } + if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDETAIL); + } + UNUSED(view); + return true; + } + + bool TraingDataPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONNOTE) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGNOMAL); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDataView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDataView.cpp new file mode 100644 index 000000000..8a184e79b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDataView.cpp @@ -0,0 +1,237 @@ + +#include "traing/include/TraingDataView.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_point = "/user/res/Training/data_point.bin"; + static const char *imagePath_progress = "/user/res/Training/progress.bin"; + static const char *imagePath_incoup = "/user/res/Training/inco_up.bin"; + static const char *imagePath_arrows = "/user/res/Training/arrows.bin"; + static const char *imagePath_strength = "/user/res/Training/sport-strength.bin"; + static const char *imagePath_note = "/user/res/Training/note.bin"; + + static TraingDataView *g_pTraingDataView{nullptr}; + + TraingDataView::TraingDataView() + { + g_pTraingDataView = this; + } + + TraingDataView::~TraingDataView() + { + DeInit(); + g_pTraingDataView = nullptr; + } + + TraingDataView *TraingDataView::GetInstance() + { + + return g_pTraingDataView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingDataView::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 TraingDataView::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); + // 设置按钮的点击事件监听器为 TraingDataPresenter 的实例 + button->SetOnClickListener(static_cast(TraingDataPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingDataView::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 TraingDataView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Image + InitImageView(image1_, 13, 13, 440, 386, "image1", imagePath_progress); + InitImageView(image2_, 208, 297, 20, 20, "image2", imagePath_arrows); + InitImageView(image3_, 98, 314, 270, 20, "image3", imagePath_strength); + InitImageView(image4_, 225, 396, 16, 10, "image4", imagePath_incoup); + InitImageView(image5_, 193, 421, 80, 20, "image5", imagePath_point); + container_->Add(image1_); + container_->Add(image2_); + container_->Add(image3_); + container_->Add(image4_); + container_->Add(image5_); + // 初始化Lable + InitLabel(label1_, 185, 60, 90, 35, "label1", "23:54", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitLabel(label2_, 158, 120, 150, 35, "label2", "跳绳运动中", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label3_, 90, 175, 60, 40, "label3", "00:31:26", DEFAULT_VECTOR_FONT_FILENAME, 80); + InitLabel(label4_, 150, 276, 60, 40, "label4", "144", DEFAULT_VECTOR_FONT_FILENAME, 23); + InitLabel(label5_, 167, 350, 60, 40, "label4", "中等强度", DEFAULT_VECTOR_FONT_FILENAME, 26); + container_->Add(label1_); + container_->Add(label2_); + container_->Add(label3_); + container_->Add(label4_); + container_->Add(label5_); + // 初始化Button + InitButton(button1_, 275, 350, 26, 26, BUTTONNOTE); + // Set additional property + static const char *button1defaultImgSrc = imagePath_note; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + container_->Add(button1_); + } + + /* DeInit:删除组件 */ + void TraingDataView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingDataView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingDataView::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(TraingDataPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingDataView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingDataView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingDataView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDetailPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDetailPresenter.cpp new file mode 100644 index 000000000..f473ff119 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDetailPresenter.cpp @@ -0,0 +1,74 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingDetailPresenter.h" +// #include "TraingDetailView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingDetailPresenter *g_pTraingDetailPresenter = nullptr; + + TraingDetailPresenter::TraingDetailPresenter() + { + + g_pTraingDetailPresenter = this; + } + + TraingDetailPresenter::~TraingDetailPresenter() + { + + g_pTraingDetailPresenter = nullptr; + } + + TraingDetailPresenter *TraingDetailPresenter::GetInstance() + { + + return g_pTraingDetailPresenter; + } + + void TraingDetailPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingDetailPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingDetailPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingDetailPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingDetailPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDATA); + } + UNUSED(view); + return true; + } + + bool TraingDetailPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDetailView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDetailView.cpp new file mode 100644 index 000000000..2f086718f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingDetailView.cpp @@ -0,0 +1,240 @@ + +#include "traing/include/TraingDetailView.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_heartrate = "/user/res/Training/heartrat_30.bin"; + static const char *imagePath_mileage = "/user/res/Training/mileage_30.bin"; + static const char *imagePath_step = "/user/res/Training/step_30.bin"; + static const char *imagePath_calories = "/user/res/Training/calories_30.bin"; + static const char *imagePath_line1 = "/user/res/Training/Line 1.bin"; + static const char *imagePath_line2 = "/user/res/Training/Line 2.bin"; + + static TraingDetailView *g_pTraingDetailView{nullptr}; + + TraingDetailView::TraingDetailView() + { + g_pTraingDetailView = this; + } + + TraingDetailView::~TraingDetailView() + { + DeInit(); + g_pTraingDetailView = nullptr; + } + + TraingDetailView *TraingDetailView::GetInstance() + { + + return g_pTraingDetailView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingDetailView::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 TraingDetailView::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); + // 设置按钮的点击事件监听器为 TraingDetailPresenter 的实例 + button->SetOnClickListener(static_cast(TraingDetailPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingDetailView::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 TraingDetailView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Image + InitImageView(image1_, 134, 58, 30, 30, "image1", imagePath_heartrate); + InitImageView(image2_, 44, 189, 30, 30, "image2", imagePath_mileage); + InitImageView(image3_, 297, 189, 30, 30, "image3", imagePath_step); + InitImageView(image4_, 129, 335, 30, 30, "image4", imagePath_calories); + InitImageView(image5_, 0, 160, 10, 466, "image5", imagePath_line1); + InitImageView(image6_, 233, 193, 80, 20, "image5", imagePath_line2); + InitImageView(image7_, 0, 306, 10, 466, "image5", imagePath_line1); + container_->Add(image1_); + container_->Add(image2_); + container_->Add(image3_); + container_->Add(image4_); + container_->Add(image5_); + container_->Add(image6_); + container_->Add(image7_); + // 初始化Lable + InitLabel(label1_, 174, 60, 90, 35, "label1", "心率(次/分)", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label2_, 80, 190, 60, 40, "label2", "距离(公里)", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label3_, 332, 189, 60, 40, "label3", "步数", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label4_, 167, 336, 60, 40, "label4", "卡路里(千卡)", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label5_, 202, 94, 60, 40, "label5", "144", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitLabel(label6_, 76, 233, 60, 40, "label6", "13.21", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitLabel(label7_, 300, 233, 60, 40, "label7", "28312", DEFAULT_VECTOR_FONT_FILENAME, 40); + InitLabel(label8_, 175, 376, 60, 40, "label8", "210.03", DEFAULT_VECTOR_FONT_FILENAME, 40); + container_->Add(label1_); + container_->Add(label2_); + container_->Add(label3_); + container_->Add(label4_); + container_->Add(label5_); + container_->Add(label6_); + container_->Add(label7_); + container_->Add(label8_); + } + + /* DeInit:删除组件 */ + void TraingDetailView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingDetailView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingDetailView::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(TraingDetailPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingDetailView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingDetailView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingDetailView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEnddataPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEnddataPresenter.cpp new file mode 100644 index 000000000..e1fd4f542 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEnddataPresenter.cpp @@ -0,0 +1,79 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingEnddataPresenter.h" +// #include "TraingEnddataView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingEnddataPresenter *g_pTraingEnddataPresenter = nullptr; + + TraingEnddataPresenter::TraingEnddataPresenter() + { + + g_pTraingEnddataPresenter = this; + } + + TraingEnddataPresenter::~TraingEnddataPresenter() + { + + g_pTraingEnddataPresenter = nullptr; + } + + TraingEnddataPresenter *TraingEnddataPresenter::GetInstance() + { + + return g_pTraingEnddataPresenter; + } + + void TraingEnddataPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingEnddataPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingEnddataPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingEnddataPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingEnddataPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + // if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDATA); + // } + UNUSED(view); + return true; + } + + bool TraingEnddataPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONBACK) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAINING); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEnddataView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEnddataView.cpp new file mode 100644 index 000000000..db4f86561 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEnddataView.cpp @@ -0,0 +1,319 @@ + +#include "traing/include/TraingEnddataView.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_path = "/user/res/Training/path.bin"; + static const char *imagePath_bubble = "/user/res/Training/bubble.bin"; + static const char *imagePath_bubblepiont = "/user/res/Training/bubble_piont.bin"; + static const char *imagePath_Line = "/user/res/Training/Line.bin"; + static const char *imagePath_spot = "/user/res/Training/Walking_54.bin"; + static const char *imagePath_incoup = "/user/res/Training/inco_up_40.bin"; + + static TraingEnddataView *g_pTraingEnddataView{nullptr}; + + TraingEnddataView::TraingEnddataView() + { + g_pTraingEnddataView = this; + } + + TraingEnddataView::~TraingEnddataView() + { + DeInit(); + g_pTraingEnddataView = nullptr; + } + + TraingEnddataView *TraingEnddataView::GetInstance() + { + + return g_pTraingEnddataView; + } + + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingEnddataView::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); + label1_->SetTextColor(Color::GetColorFromRGBA(0x22, 0x9d, 0xd3, 0xff)); + 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 TraingEnddataView::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); + // 设置按钮的点击事件监听器为 TraingEnddataPresenter 的实例 + button->SetOnClickListener(static_cast(TraingEnddataPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingEnddataView::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 TraingEnddataView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); // widget's left position and top position + scrollView1_->Resize(466, 466); // widget's width and height + scrollView1_->SetViewId("scrollView1"); // Set style + scrollView1_->SetReboundSize(100); + scrollView1_->SetScrollBlankSize(35); + scrollView1_->SetHorizontalScrollState(false); + // Add to rootView + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + + // 初始化Image + InitImageView(image1_, 200, 131, 80, 48, "image1", imagePath_bubble); + InitImageView(image2_, 230, 183, 20, 20, "image2", imagePath_bubblepiont); + InitImageView(image3_, 96, 118, 271, 233, "image3", imagePath_path); + InitImageView(image4_, 212, 402, 40, 40, "image4", imagePath_incoup); + InitImageView(image5_, 80, 470, 54, 80, "image5", imagePath_spot); + InitImageView(image6_, 97, 552, 80, 20, "image6", imagePath_Line); + InitImageView(image8_, 97, 682, 80, 20, "image6", imagePath_Line); + InitImageView(image9_, 97, 812, 80, 20, "image6", imagePath_Line); + InitImageView(image10_, 97, 942, 80, 20, "image6", imagePath_Line); + InitImageView(image11_, 97, 1072, 80, 20, "image6", imagePath_Line); + + scrollView1_->Add(image3_); + scrollView1_->Add(image6_); + scrollView1_->Add(image8_); + scrollView1_->Add(image9_); + scrollView1_->Add(image10_); + scrollView1_->Add(image11_); + scrollView1_->Add(image1_); + scrollView1_->Add(image2_); + scrollView1_->Add(image4_); + scrollView1_->Add(image5_); + + // 初始化button + InitButton(button1_, 42, 1319, 380, 100, BUTTONBACK); + scrollView1_->Add(button1_); + + // 初始化Lable + InitLabel(label1_, 188, 52, 90, 35, "label1", "健身类", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label2_, 220, 140, 60, 40, "label2", "达标", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label3_, 114, 252, 60, 40, "label3", "终", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label4_, 172, 284, 60, 40, "label4", "èµ·", DEFAULT_VECTOR_FONT_FILENAME, 20); + InitLabel(label5_, 155, 372, 60, 40, "label5", "距离:8.3KM", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label6_, 146, 478, 60, 40, "label6", "健走", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label7_, 146, 517, 60, 40, "label7", "13:00:22-15:00:12", DEFAULT_VECTOR_FONT_FILENAME, 28); + + InitLabel(label8_, 146, 590, 60, 40, "label8", "目标完成度", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label9_, 146, 720, 60, 40, "label9", "训练时长", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label10_, 146, 850, 60, 40, "label10", "距离(ç±³)", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label11_, 146, 980, 60, 40, "label11", "平均心率(次/分)", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label12_, 146, 1110, 60, 40, "label2", "训练强度", DEFAULT_VECTOR_FONT_FILENAME, 26); + InitLabel(label18_, 155, 1232, 60, 40, "label8", "更多数据请前往手机\nAPP“小希爱玩”查看", DEFAULT_VECTOR_FONT_FILENAME, 26); + + label7_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + label8_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + label9_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + label10_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + label11_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + label12_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + label18_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x7f)); + + InitLabel(label13_, 146, 626, 60, 40, "label18", "226%", DEFAULT_VECTOR_FONT_FILENAME, 40); + label13_->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + InitLabel(label14_, 146, 756, 60, 40, "label14", "05:45:46", DEFAULT_VECTOR_FONT_FILENAME, 40); + label14_->SetTextColor(Color::GetColorFromRGBA(0xff, 0x8a, 0x36, 0xff)); + InitLabel(label15_, 146, 886, 60, 40, "label15", "8,301", DEFAULT_VECTOR_FONT_FILENAME, 40); + label15_->SetTextColor(Color::GetColorFromRGBA(0x36, 0x4a, 0xff, 0xff)); + InitLabel(label16_, 146, 1016, 60, 40, "label16", "144", DEFAULT_VECTOR_FONT_FILENAME, 40); + label16_->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); + InitLabel(label17_, 146, 1146, 60, 40, "label17", "中等强度", DEFAULT_VECTOR_FONT_FILENAME, 40); + label17_->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff)); + InitLabel(label19_, 201, 1348, 60, 40, "label19", "关闭", DEFAULT_VECTOR_FONT_FILENAME, 31); + + scrollView1_->Add(label1_); + scrollView1_->Add(label2_); + scrollView1_->Add(label3_); + scrollView1_->Add(label4_); + scrollView1_->Add(label5_); + scrollView1_->Add(label6_); + scrollView1_->Add(label7_); + scrollView1_->Add(label8_); + scrollView1_->Add(label9_); + scrollView1_->Add(label10_); + scrollView1_->Add(label11_); + scrollView1_->Add(label12_); + scrollView1_->Add(label13_); + scrollView1_->Add(label14_); + scrollView1_->Add(label15_); + scrollView1_->Add(label16_); + scrollView1_->Add(label17_); + scrollView1_->Add(label18_); + scrollView1_->Add(label19_); + + // Add ImageView to App + if (image7_ == nullptr) + { + image7_ = new UIImageView(); + } + image7_->SetPosition(188, 1460); // widget's left position and top position + image7_->Resize(100, 100); // widget's width and height + image7_->SetViewId("image7"); // Set style + // Add to rootView + scrollView1_->Add(image7_); + image7_->SetVisible(true); + } + + /* DeInit:删除组件 */ + void TraingEnddataView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingEnddataView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingEnddataView::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(TraingEnddataPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingEnddataView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingEnddataView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingEnddataView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEndnotePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEndnotePresenter.cpp new file mode 100644 index 000000000..2c4920bc0 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEndnotePresenter.cpp @@ -0,0 +1,83 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingEndnotePresenter.h" +// #include "TraingEndnoteView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingEndnotePresenter *g_pTraingEndnotePresenter = nullptr; + + TraingEndnotePresenter::TraingEndnotePresenter() + { + + g_pTraingEndnotePresenter = this; + } + + TraingEndnotePresenter::~TraingEndnotePresenter() + { + + g_pTraingEndnotePresenter = nullptr; + } + + TraingEndnotePresenter *TraingEndnotePresenter::GetInstance() + { + + return g_pTraingEndnotePresenter; + } + + void TraingEndnotePresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingEndnotePresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingEndnotePresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingEndnotePresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingEndnotePresenter::OnDrag(UIView &view, const DragEvent &event) + { + + // if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) + // { + // NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGDATA); + // } + UNUSED(view); + return true; + } + + bool TraingEndnotePresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONNO) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCONTROL); + } + if (strcmp(view.GetViewId(), BUTTONYES) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGENDDATA); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEndnoteView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEndnoteView.cpp new file mode 100644 index 000000000..e2c1d810b --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingEndnoteView.cpp @@ -0,0 +1,225 @@ + +#include "traing/include/TraingEndnoteView.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_no = "/user/res/Training/no.bin"; + static const char *imagePath_yes = "/user/res/Training/yes.bin"; + + static TraingEndnoteView *g_pTraingEndnoteView{nullptr}; + + TraingEndnoteView::TraingEndnoteView() + { + g_pTraingEndnoteView = this; + } + + TraingEndnoteView::~TraingEndnoteView() + { + DeInit(); + g_pTraingEndnoteView = nullptr; + } + + TraingEndnoteView *TraingEndnoteView::GetInstance() + { + + return g_pTraingEndnoteView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingEndnoteView::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 TraingEndnoteView::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); + // 设置按钮的点击事件监听器为 TraingEndnotePresenter 的实例 + button->SetOnClickListener(static_cast(TraingEndnotePresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingEndnoteView::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 TraingEndnoteView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Lable + InitLabel(label1_, 173, 52, 90, 35, "label1", "结束运动", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label2_, 116, 187, 60, 40, "label2", "是否结束本次运动", DEFAULT_VECTOR_FONT_FILENAME, 26); + + container_->Add(label1_); + container_->Add(label2_); + + InitButton(button1_, 111, 299, 100, 100, BUTTONNO); + // Set additional property + const char *button1defaultImgSrc = imagePath_no; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + + InitButton(button2_, 256, 299, 100, 100, BUTTONYES); + // Set additional property + const char *button2defaultImgSrc = imagePath_yes; + char *button2triggeredImgSrc = nullptr; + button2_->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc); + + container_->Add(button1_); + container_->Add(button2_); + } + + /* DeInit:删除组件 */ + void TraingEndnoteView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingEndnoteView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingEndnoteView::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(TraingEndnotePresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingEndnoteView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingEndnoteView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingEndnoteView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSPresenter.cpp new file mode 100644 index 000000000..589c89252 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSPresenter.cpp @@ -0,0 +1,84 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingGPSPresenter.h" +// #include "TraingGPSView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingGPSPresenter *g_pTraingGPSPresenter = nullptr; + + TraingGPSPresenter::TraingGPSPresenter() + { + + g_pTraingGPSPresenter = this; + } + + TraingGPSPresenter::~TraingGPSPresenter() + { + + g_pTraingGPSPresenter = nullptr; + } + + TraingGPSPresenter *TraingGPSPresenter::GetInstance() + { + + return g_pTraingGPSPresenter; + } + + void TraingGPSPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingGPSPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingGPSPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingGPSPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingGPSPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + UNUSED(view); + return true; + } + + bool TraingGPSPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONSET) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + } + if (strcmp(view.GetViewId(), BUTTONGO) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCONTROL); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSView.cpp new file mode 100644 index 000000000..46d4807c6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSView.cpp @@ -0,0 +1,231 @@ + +#include "traing/include/TraingGPSView.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_heartrate = "/user/res/Training/heartrate_1.bin"; + static const char *imagePath_GPS = "/user/res/Training/GPS_1.bin"; + static TraingGPSView *g_pTraingGPSView{nullptr}; + + TraingGPSView::TraingGPSView() + { + g_pTraingGPSView = this; + } + + TraingGPSView::~TraingGPSView() + { + DeInit(); + g_pTraingGPSView = nullptr; + } + + TraingGPSView *TraingGPSView::GetInstance() + { + + return g_pTraingGPSView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingGPSView::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 TraingGPSView::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); + // 设置按钮的点击事件监听器为 TraingGPSPresenter 的实例 + button->SetOnClickListener(static_cast(TraingGPSPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingGPSView::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 TraingGPSView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Lable + InitLabel(label1_, 203, 52, 195, 35, "label1", "骑行", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label1_); + InitLabel(label2_, 160, 370, 146, 35, "label2", "设定目标 >", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label2_); + InitLabel(label3_, 41, 237, 54, 41, "lable3", "144", DEFAULT_VECTOR_FONT_FILENAME, 35); + container_->Add(label3_); + InitLabel(label4_, 361, 237, 54, 41, "lable4", "GPS", DEFAULT_VECTOR_FONT_FILENAME, 35); + container_->Add(label4_); + // 初始化image + InitImageView(image1_, 48, 193, 40, 40, "image1", imagePath_heartrate); + InitImageView(image2_, 375, 193, 40, 40, "image2", imagePath_GPS); + container_->Add(image1_); + container_->Add(image2_); + // 初始化Button + InitButton(button1_, 133, 133, 200, 200, BUTTONGO); + // Set additional property + char *button1defaultImgSrc = "/user/res/Training/Go.bin"; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + + InitButton(button2_, 160, 370, 146, 35, BUTTONSET); + button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); // 设置为透明按键 + button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + button2_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x80, UIButton::PRESSED); // 设置按下时的透明度为半透明 + + container_->Add(button1_); + container_->Add(button2_); + } + /* DeInit:删除组件*/ + void TraingGPSView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingGPSView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingGPSView::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(TraingGPSPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingGPSView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingGPSView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingGPSView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackPresenter.cpp new file mode 100644 index 000000000..8cf922caa --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackPresenter.cpp @@ -0,0 +1,84 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingGPSlackPresenter.h" +// #include "TraingGPSlackView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingGPSlackPresenter *g_pTraingGPSlackPresenter = nullptr; + + TraingGPSlackPresenter::TraingGPSlackPresenter() + { + + g_pTraingGPSlackPresenter = this; + } + + TraingGPSlackPresenter::~TraingGPSlackPresenter() + { + + g_pTraingGPSlackPresenter = nullptr; + } + + TraingGPSlackPresenter *TraingGPSlackPresenter::GetInstance() + { + + return g_pTraingGPSlackPresenter; + } + + void TraingGPSlackPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingGPSlackPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingGPSlackPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingGPSlackPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingGPSlackPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + UNUSED(view); + return true; + } + + bool TraingGPSlackPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONSET) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + } + if (strcmp(view.GetViewId(), BUTTONGO) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGGPSNOTE); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackView.cpp new file mode 100644 index 000000000..383e6a654 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSlackView.cpp @@ -0,0 +1,231 @@ + +#include "traing/include/TraingGPSlackView.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_heartrate = "/user/res/Training/heartrate_2.bin"; + static const char *imagePath_GPS = "/user/res/Training/GPS_2.bin"; + static TraingGPSlackView *g_pTraingGPSlackView{nullptr}; + + TraingGPSlackView::TraingGPSlackView() + { + g_pTraingGPSlackView = this; + } + + TraingGPSlackView::~TraingGPSlackView() + { + DeInit(); + g_pTraingGPSlackView = nullptr; + } + + TraingGPSlackView *TraingGPSlackView::GetInstance() + { + + return g_pTraingGPSlackView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingGPSlackView::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 TraingGPSlackView::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); + // 设置按钮的点击事件监听器为 TraingGPSlackPresenter 的实例 + button->SetOnClickListener(static_cast(TraingGPSlackPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingGPSlackView::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 TraingGPSlackView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // 初始化Lable + InitLabel(label1_, 203, 52, 195, 35, "label1", "骑行", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label1_); + InitLabel(label2_, 160, 370, 146, 35, "label2", "设定目标 >", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label2_); + InitLabel(label3_, 41, 237, 54, 41, "lable3", "--", DEFAULT_VECTOR_FONT_FILENAME, 35); + container_->Add(label3_); + InitLabel(label4_, 361, 237, 54, 41, "lable4", "--", DEFAULT_VECTOR_FONT_FILENAME, 35); + container_->Add(label4_); + // 初始化image + InitImageView(image1_, 48, 193, 40, 40, "image1", imagePath_heartrate); + InitImageView(image2_, 375, 193, 40, 40, "image2", imagePath_GPS); + container_->Add(image1_); + container_->Add(image2_); + // 初始化Button + InitButton(button1_, 133, 133, 200, 200, BUTTONGO); + // Set additional property + char *button1defaultImgSrc = "/user/res/Training/Go_2.bin"; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + + InitButton(button2_, 160, 370, 146, 35, BUTTONSET); + button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); // 设置为透明按键 + button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + button2_->SetStyleForState(STYLE_BACKGROUND_OPA, 0x80, UIButton::PRESSED); // 设置按下时的透明度为半透明 + + container_->Add(button1_); + container_->Add(button2_); + } + /* DeInit:删除组件*/ + void TraingGPSlackView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingGPSlackView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingGPSlackView::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(TraingGPSlackPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingGPSlackView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingGPSlackView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingGPSlackView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnotePresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnotePresenter.cpp new file mode 100644 index 000000000..3c125e321 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnotePresenter.cpp @@ -0,0 +1,84 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingGPSnotePresenter.h" +// #include "TraingGPSnoteView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingGPSnotePresenter *g_pTraingGPSnotePresenter = nullptr; + + TraingGPSnotePresenter::TraingGPSnotePresenter() + { + + g_pTraingGPSnotePresenter = this; + } + + TraingGPSnotePresenter::~TraingGPSnotePresenter() + { + + g_pTraingGPSnotePresenter = nullptr; + } + + TraingGPSnotePresenter *TraingGPSnotePresenter::GetInstance() + { + + return g_pTraingGPSnotePresenter; + } + + void TraingGPSnotePresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingGPSnotePresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingGPSnotePresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingGPSnotePresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingGPSnotePresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 40) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); + } + UNUSED(view); + return true; + } + + bool TraingGPSnotePresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONBACK) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGGPS); + } + if (strcmp(view.GetViewId(), BUTTONGO) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGCONTROL); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnoteView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnoteView.cpp new file mode 100644 index 000000000..4be1e949a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingGPSnoteView.cpp @@ -0,0 +1,254 @@ + +#include "traing/include/TraingGPSnoteView.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_warning = "/user/res/Training/warning.bin"; + + static TraingGPSnoteView *g_pTraingGPSnoteView{nullptr}; + + TraingGPSnoteView::TraingGPSnoteView() + { + g_pTraingGPSnoteView = this; + } + + TraingGPSnoteView::~TraingGPSnoteView() + { + DeInit(); + g_pTraingGPSnoteView = nullptr; + } + + TraingGPSnoteView *TraingGPSnoteView::GetInstance() + { + + return g_pTraingGPSnoteView; + } + + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingGPSnoteView::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); + label1_->SetTextColor(Color::GetColorFromRGBA(0x22, 0x9d, 0xd3, 0xff)); + 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 TraingGPSnoteView::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); + // 设置按钮的点击事件监听器为 TraingGPSnotePresenter 的实例 + button->SetOnClickListener(static_cast(TraingGPSnotePresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitImageView:初始化图片 + @param imageView 图片指针 + @param left 图片左边位置 + @param top 图片顶部位置 + @param width 图片宽度 + @param height 图片高度 + @param viewId 图片的视图 ID + @param imagePath 图片路径 + */ + void TraingGPSnoteView::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 TraingGPSnoteView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); // widget's left position and top position + scrollView1_->Resize(466, 466); // widget's width and height + scrollView1_->SetViewId("scrollView1"); // Set style + scrollView1_->SetReboundSize(100); + scrollView1_->SetScrollBlankSize(52); + scrollView1_->SetHorizontalScrollState(false); + // Add to rootView + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + + // 初始化Image + InitImageView(image1_, 193, 111, 80, 80, "image1", imagePath_warning); + scrollView1_->Add(image1_); + + // 初始化button + InitButton(button1_, 118, 334, 230, 80, BUTTONBACK); + button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c); + scrollView1_->Add(button1_); + + InitButton(button2_, 118, 434, 230, 80, BUTTONBACK); + scrollView1_->Add(button2_); + + // 初始化Lable + InitLabel(label1_, 160, 52, 90, 35, "label1", "GPS未准备", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label2_, 33, 215, 60, 40, "label2", "GPS仍在定位,建议等待定位\n完成后再开始训练", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label3_, 181, 357, 60, 40, "label3", "继续等待", DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabel(label4_, 181, 457, 60, 40, "label4", "直接开始", DEFAULT_VECTOR_FONT_FILENAME, 30); + + scrollView1_->Add(label1_); + scrollView1_->Add(label2_); + scrollView1_->Add(label3_); + scrollView1_->Add(label4_); + + // Add ImageView to App + if (image2_ == nullptr) + { + image2_ = new UIImageView(); + } + image2_->SetPosition(181, 500); // widget's left position and top position + image2_->Resize(100, 100); // widget's width and height + image2_->SetViewId("image7"); // Set style + // Add to rootView + scrollView1_->Add(image2_); + image2_->SetVisible(true); + } + + /* DeInit:删除组件 */ + void TraingGPSnoteView::DeInit() + { + UIView *view = static_cast(container_)->GetChildrenHead(); + while (view != nullptr) + { + UIView *tempView = view; + view = view->GetNextSibling(); + if (tempView->GetParent()) + { + static_cast(tempView->GetParent())->Remove(tempView); + } + delete tempView; + } + delete container_; + container_ = nullptr; + } + + void TraingGPSnoteView::PreLoad(void) + { + if (!viewiInitStatus) + { + InitView(); + viewiInitStatus = true; + } + } + void TraingGPSnoteView::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(TraingGPSnotePresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingGPSnoteView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingGPSnoteView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingGPSnoteView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliPresenter.cpp new file mode 100644 index 000000000..089837178 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliPresenter.cpp @@ -0,0 +1,79 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include +#include +#include +#include "traing/include/TraingSetCaluliPresenter.h" +// #include "TraingSetCaluliView.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static TraingSetCaluliPresenter *g_pTraingSetCaluliPresenter = nullptr; + + TraingSetCaluliPresenter::TraingSetCaluliPresenter() + { + + g_pTraingSetCaluliPresenter = this; + } + + TraingSetCaluliPresenter::~TraingSetCaluliPresenter() + { + + g_pTraingSetCaluliPresenter = nullptr; + } + + TraingSetCaluliPresenter *TraingSetCaluliPresenter::GetInstance() + { + + return g_pTraingSetCaluliPresenter; + } + + void TraingSetCaluliPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void TraingSetCaluliPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void TraingSetCaluliPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void TraingSetCaluliPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool TraingSetCaluliPresenter::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_TRAININGSET); + // } + UNUSED(view); + return true; + } + + bool TraingSetCaluliPresenter::OnClick(UIView &view, const ClickEvent &event) + { + // 根据控件id查找是哪个控件触发了点击回调 + if (strcmp(view.GetViewId(), BUTTONOK) == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_TRAININGSET); + } + return true; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliView.cpp new file mode 100644 index 000000000..5d5ff2a63 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/traing/src/TraingSetCaluliView.cpp @@ -0,0 +1,280 @@ + +#include "traing/include/TraingSetCaluliView.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" +#include +#include "components/ui_button.h" +#include "common/screen.h" +#include +#include +#include + +namespace OHOS +{ + + /***************************************************************************************/ + // 动态生成包含指定卡路里区间内所有卡路里数的字符串数组 + std::vector GenerateCaluliValues(int minTime, int maxTime, int interval) + { + std::vector values; + for (int i = minTime; i <= maxTime; i += interval) + { + values.push_back(std::to_string(i) + " 千卡"); + } + return values; + } + /***************************************************************************************/ + static TraingSetCaluliView *g_pTraingSetCaluliView{nullptr}; + + TraingSetCaluliView::TraingSetCaluliView() + { + g_pTraingSetCaluliView = this; + } + + TraingSetCaluliView::~TraingSetCaluliView() + { + DeInit(); + g_pTraingSetCaluliView = nullptr; + } + + TraingSetCaluliView *TraingSetCaluliView::GetInstance() + { + + return g_pTraingSetCaluliView; + } + /* + InitLabel:初始化标签 + @param label 标签指针 + @param left 标签左边位置 + @param top 标签顶部位置 + @param width 标签宽度 + @param height 标签高度 + @param viewId 标签的视图 ID + @param text 标签显示的文本 + @param fontName 字体名称 + @param fontSize 字体大小 + */ + void TraingSetCaluliView::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 TraingSetCaluliView::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); + // 设置按钮的点击事件监听器为 TraingSetCaluliPresenter 的实例 + button->SetOnClickListener(static_cast(TraingSetCaluliPresenter::GetInstance())); + // 设置按钮可见 + button->SetVisible(true); + } + /* + InitUIPicker: 初始化UIPicker组件 + @param picker: 指向UIPicker的指针 + @param x: UIPicker的左边位置 + @param y: UIPicker的顶部位置 + @param width: UIPicker的宽度 + @param height: UIPicker的高度 + @param viewId: UIPicker的视图 ID + @param values: 选项数组 + @param count: 选项数量 + @param backgroundFontSize: 普通文本大小 + @highlightFontSize: 高光文本大小 + */ + void TraingSetCaluliView::InitUIPicker(UIPicker *&picker, int x, int y, int width, int height, const char *viewId) + { + // 文本大小 + constexpr uint8_t BACKGROUND_FONT = 40; + constexpr uint8_t HIGHTLIGHT_FONT = 60; + // 获取value数组 + int minCaluli = 100; + int maxCaluli = 1000; + int interval = 100; + std::vector caluliValues = GenerateCaluliValues(minCaluli, maxCaluli, interval); + + const char **values = new const char *[caluliValues.size()]; + for (size_t i = 0; i < caluliValues.size(); i++) + { + values[i] = caluliValues[i].c_str(); + } + // 创建 UIPicker + if (picker == nullptr) + { + picker = new UIPicker(); + } + + // 设置 UIPicker 的位置和大小 + picker->SetPosition(x, y); + picker->Resize(width, height); + // 设置 UIPicker 的 ViewId + picker->SetViewId(viewId); + // 设置 UIPicker 的属性 + picker->SetItemHeight(70); + picker->SetLoopState(true); + picker->SetTextColor(Color::GetColorFromRGBA(0x66, 0x66, 0x66, 0xff), Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff)); + picker->SetBackgroundFont(DEFAULT_VECTOR_FONT_FILENAME, BACKGROUND_FONT); // 设置普通文本大小 + picker->SetHighlightFont(DEFAULT_VECTOR_FONT_FILENAME, HIGHTLIGHT_FONT); // 设置高光文本大小 + picker->SetValues(values, caluliValues.size()); + // 将 UIPicker 设置为显示 + picker->SetVisible(true); + } + + /* InitView:初始化界面*/ + void TraingSetCaluliView ::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + } + // 初始化Lable + InitLabel(label1_, 173, 52, 120, 35, "label1", "卡路里设定", DEFAULT_VECTOR_FONT_FILENAME, 30); + container_->Add(label1_); + + // 初始化UIPicker + InitUIPicker(uiPicker1_, 43, 106, 380, 240, "uiPicker1"); + container_->Add(uiPicker1_); + // 初始化Button + InitButton(button1_, 0, 366, 466, 100, BUTTONOK); + // Set additional property + char *button1defaultImgSrc = "/user/res/Training/buttonok.bin"; + char *button1triggeredImgSrc = nullptr; + button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); + container_->Add(button1_); + } + /* DeInit:删除组件 */ + void TraingSetCaluliView::DeInit() + { + // 删除Label + if (label1_ != nullptr) + { + container_->Remove(label1_); + delete label1_; + label1_ = nullptr; + } + // 删除Button + if (button1_ != nullptr) + { + container_->Remove(button1_); + delete button1_; + button1_ = nullptr; + } + + // 删除Image + + // 删除滚动选择器 + if (uiPicker1_ != nullptr) + { + container_->Remove(uiPicker1_); + delete uiPicker1_; + uiPicker1_ = nullptr; + } + + // 删除容器 + if (container_ != nullptr) + { + container_->RemoveAll(); // 移除容器中的所有组件 + delete container_; + container_ = nullptr; + } + } + + void TraingSetCaluliView::PreLoad(void) + { + if (!viewiInitStatus) + { + //printf("init traingsetcaluliview\n"); + InitView(); + viewiInitStatus = true; + } + } + void TraingSetCaluliView::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(TraingSetCaluliPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + + container_->SetTouchable(true); + container_->SetDraggable(true); + + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void TraingSetCaluliView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void TraingSetCaluliView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void TraingSetCaluliView::OnStop() + { + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/FutureWeatherPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/FutureWeatherPresenter.h new file mode 100644 index 000000000..645130639 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/FutureWeatherPresenter.h @@ -0,0 +1,34 @@ +#ifndef FUTURE_WEATHER_PRESENTER_H +#define FUTURE_WEATHER_PRESENTER_H + +#include "Presenter.h" + +#include "FutureWeatherView.h" + +namespace OHOS +{ + class FutureWeatherView; + + class FutureWeatherPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + FutureWeatherPresenter(); + virtual ~FutureWeatherPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static FutureWeatherPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // FutureWeather_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/FutureWeatherView.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/FutureWeatherView.h new file mode 100644 index 000000000..d4ba47d16 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/FutureWeatherView.h @@ -0,0 +1,66 @@ +#ifndef FUTURE_WEATHER_VIEW_H +#define FUTURE_WEATHER_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_list.h" +#include "components/icon_adapter.h" + +namespace OHOS +{ +#define weather_src "/user/res/weather/" +static const char *weather65x65[] = +{ +weather_src"weather_sunny.bin", //晴天 +weather_src"weather_clear-cloudy.bin", //多云 +weather_src"weather_rain.bin", //阵雨 +weather_src"weather_thundershower.bin", +weather_src"weather_foggy.bin", +weather_src"weather_unknown.bin", +weather_src"weather_overcast.bin", +weather_src"weather_clear-sunny.bin", +weather_src"weather_duststorm.bin", +weather_src"weather_haze.bin", +weather_src"weather_snow.bin", +weather_src"weather_sunny-cloudy.bin", +}; + + +} + +namespace OHOS +{ + class FutureWeatherPresenter; + class FutureWeatherView : public View + { + + public: + FutureWeatherView(); + virtual ~FutureWeatherView(); + static FutureWeatherView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIView::OnDragListener *draglistener{nullptr}; + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UIList *list = nullptr; + IconAdapter *listadapter = nullptr; + List *listdata = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif // FutureWeather_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/GetWeatherDataErrorPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/GetWeatherDataErrorPresenter.h new file mode 100644 index 000000000..2bda7b5ee --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/GetWeatherDataErrorPresenter.h @@ -0,0 +1,33 @@ +#ifndef Get_WEATHER_DATA_ERROR_PRESENTER_H +#define Get_WEATHER_DATA_ERROR_PRESENTER_H + +#include "Presenter.h" +#include "GetWeatherDataErrorView.h" + +namespace OHOS +{ + class GetWeatherDataErrorView; + + class GetWeatherDataErrorPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + GetWeatherDataErrorPresenter(); + virtual ~GetWeatherDataErrorPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static GetWeatherDataErrorPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // GetWeatherDataError_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h new file mode 100644 index 000000000..b22d63314 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/GetWeatherDataErrorView.h @@ -0,0 +1,40 @@ +#ifndef Get_WEATHER_DATA_ERROR_VIEW_H +#define Get_WEATHER_DATA_ERROR_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +namespace OHOS +{ + class GetWeatherDataErrorPresenter; + class GetWeatherDataErrorView : public View + { + + public: + GetWeatherDataErrorView(); + virtual ~GetWeatherDataErrorView(); + static GetWeatherDataErrorView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIView::OnDragListener *draglistener{nullptr}; + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UIImageView *image1_ = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif // GetWeatherDataError_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/MainWeatherPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/MainWeatherPresenter.h new file mode 100644 index 000000000..70bbd4ec2 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/MainWeatherPresenter.h @@ -0,0 +1,34 @@ +#ifndef MAIN_WEATHER_PRESENTER_H +#define MAIN_WEATHER_PRESENTER_H + +#include "Presenter.h" +#include "MainWeatherView.h" + +/*主天气视图*/ +namespace OHOS +{ + class MainWeatherView; + + class MainWeatherPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + MainWeatherPresenter(); + virtual ~MainWeatherPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static MainWeatherPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // MainWeather_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/MainWeatherView.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/MainWeatherView.h new file mode 100644 index 000000000..b7da48150 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/MainWeatherView.h @@ -0,0 +1,83 @@ +#ifndef MAIN_WEATHER_VIEW_H +#define MAIN_WEATHER_VIEW_H + +#include "BaseView.h" +#include "View.h" + +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_view.h" +#include "components/ui_image_animator.h" +#include + +namespace OHOS +{ +#define weather_src "/user/res/weather/" + static const char *background = weather_src "WEATHER_BACKGROUND.bin"; + static const char *weather130x130[] = + { + weather_src "WEATHER_CLEAR-CLOUDY.bin", + weather_src "WEATHER_CLEAR-SUNNY.bin", + weather_src "WEATHER_DUSTSTORM.bin", + weather_src "WEATHER_FOGGY.bin", + weather_src "WEATHER_HAZE.bin", + weather_src "WEATHER_OVERCAST.bin", + weather_src "WEATHER_RAIN.bin", + weather_src "WEATHER_SNOW.bin", + weather_src "WEATHER_SUNNY.bin", + weather_src "WEATHER_SUNNY-CLOUNDY.bin", + weather_src "WEATHER_THUNDERSHOWER.bin", + weather_src "WEATHER_UNKNOWN.bin"}; +} + +namespace OHOS +{ + class MainWeatherPresenter; + class MainWeatherView : public View + { + + public: + MainWeatherView(); + virtual ~MainWeatherView(); + static MainWeatherView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + UILabel *InitLabel(int x, int y, const char *text, const char *id, int textfont, int lineheight); + void PreLoad(void); + + private: + std::string GetTime(); + std::string GetWeatherImage(); + std::string GetWeatherTemperature(); + std::string GetWeatherDescription(); + std::string GetWeatherArea(); + std::string GetWeatherMaxAndMinTemperature(); + + std::string Time; // 时间 + std::string WeatherImag; // 天气图片 + std::string Temperature; // 温度 + std::string WeatherDescription; // 天气描述 + std::string WeatherArea; // 天气地区 + std::string MaxandMinTemperature; // 最高与最低气温 + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label1_ = nullptr; + UILabel *label2_ = nullptr; + UIImageView *image1_ = nullptr; + UILabel *label3_ = nullptr; + UILabel *label4_ = nullptr; + UILabel *label5_ = nullptr; + UIImageAnimatorView *imageAnimator1_ = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/WeatherReportPresenter.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/WeatherReportPresenter.h new file mode 100644 index 000000000..a6049260a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/WeatherReportPresenter.h @@ -0,0 +1,33 @@ +#ifndef WEATHER_REPORT_PRESENTER_H +#define WEATHER_REPORT_PRESENTER_H + +#include "Presenter.h" +#include "WeatherReportView.h" + +namespace OHOS +{ + class WeatherReportView; + + class WeatherReportPresenter : public Presenter, + public UIView::OnClickListener, + public UIView::OnDragListener + { + public: + WeatherReportPresenter(); + virtual ~WeatherReportPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static WeatherReportPresenter *GetInstance(); + + private: + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + }; +} // namespace OHOS + +#endif // WeatherReport_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/include/WeatherReportView.h b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/WeatherReportView.h new file mode 100644 index 000000000..31c90825f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/include/WeatherReportView.h @@ -0,0 +1,48 @@ +#ifndef WEATHER_REPORT_VIEW_H +#define WEATHER_REPORT_VIEW_H + +#include "BaseView.h" +#include "View.h" +#include "components/ui_view_group.h" +#include "components/ui_scroll_view.h" +#include "components/ui_label.h" +#include "components/ui_image_animator.h" +namespace OHOS +{ + class WeatherReportPresenter; + class WeatherReportView : public View + { + + public: + WeatherReportView(); + virtual ~WeatherReportView(); + static WeatherReportView *GetInstance(void); + + void OnStart() override; + void OnSetUpView() override; + void OnTearDownView() override; + void OnStop() override; + + private: + void InitView(void); + void DeInitView(void); + void PreLoad(void); + + private: + UIViewGroup *container_ = nullptr; + UIScrollView *scrollView1_ = nullptr; + UILabel *label5_ = nullptr; + UIImageAnimatorView *imageAnimator3_ = nullptr; + UIImageAnimatorView *imageAnimator2_ = nullptr; + UIImageAnimatorView *imageAnimator1_ = nullptr; + UIImageAnimatorView *imageAnimator = nullptr; + UILabel *label6_ = nullptr; + UILabel *label7_ = nullptr; + UILabel *label8_ = nullptr; + UILabel *label9_ = nullptr; + UILabel *label10_ = nullptr; + UILabel *label11_ = nullptr; + bool viewInitStatus{false}; + }; +} // namespace OHOS +#endif // WeatherReport_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/FutureWeatherPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/FutureWeatherPresenter.cpp new file mode 100644 index 000000000..8c2d22b4a --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/FutureWeatherPresenter.cpp @@ -0,0 +1,72 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include "weather/include/FutureWeatherPresenter.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static FutureWeatherPresenter *g_pFutureWeatherPresenter = nullptr; + + FutureWeatherPresenter::FutureWeatherPresenter() + { + + g_pFutureWeatherPresenter = this; + } + + FutureWeatherPresenter::~FutureWeatherPresenter() + { + + g_pFutureWeatherPresenter = nullptr; + } + + FutureWeatherPresenter *FutureWeatherPresenter::GetInstance() + { + + return g_pFutureWeatherPresenter; + } + + void FutureWeatherPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void FutureWeatherPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void FutureWeatherPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void FutureWeatherPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool FutureWeatherPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM && + (event.GetDeltaY() > 20) && (event.GetDeltaY() > (2 * MATH_ABS(event.GetDeltaX())))) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_WEATHER_REPORT); // 未来天气界面从上往下滑进入气象报告界面 + } + return true; + } + + bool FutureWeatherPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), 控件ID) == 0) + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/FutureWeatherView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/FutureWeatherView.cpp new file mode 100644 index 000000000..1c94715b4 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/FutureWeatherView.cpp @@ -0,0 +1,199 @@ +#include "weather/include/FutureWeatherView.h" +#include "weather/include/FutureWeatherPresenter.h" + +#include "common/image_cache_manager.h" +#include "UiConfig.h" +#include "ui_resource_image.h" + +namespace OHOS +{ + + static FutureWeatherView *g_pFutureWeatherView{nullptr}; + + FutureWeatherView::FutureWeatherView() + { + + g_pFutureWeatherView = this; + } + + FutureWeatherView::~FutureWeatherView() + { + DeInitView(); + g_pFutureWeatherView = nullptr; + } + + FutureWeatherView *FutureWeatherView::GetInstance() + { + + return g_pFutureWeatherView; + } + + void FutureWeatherView::InitView() + { + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); // widget's left position and top position + scrollView1_->Resize(466, 466); // widget's width and height + scrollView1_->SetViewId("scrollView1"); // Set style + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView1_->SetReboundSize(50); // 设置回弹大小 + scrollView1_->SetScrollBarCenter({200, 200}); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(179, 52); + label1_->Resize(108, 35); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + label1_->SetText("未来7天"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + scrollView1_->Add(label1_); + label1_->SetVisible(true); + + if (list == nullptr) + { + list = new UIList(); + } + list->SetPosition(65, 140); + list->Resize(354, 520); + list->SetViewId("list1"); + list->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + list->SetReboundSize(50); // 设置回弹值 + if (listdata == nullptr) + { + listdata = new List(); + } + IconItemNode *list3data1 = new IconItemNode(); + list3data1->imagePath = "/user/res/weather/weather_sunny.bin"; + list3data1->txt = "周一 晴天 18°/24°"; + listdata->PushBack(list3data1); + + IconItemNode *list3data2 = new IconItemNode(); + list3data2->imagePath = "/user/res/weather/weather_clear-cloudy.bin"; + list3data2->txt = "周二 多云 19°/24°"; + listdata->PushBack(list3data2); + + IconItemNode *list3data3 = new IconItemNode(); + list3data3->imagePath = "/user/res/weather/weather_rain.bin"; + list3data3->txt = " 周三 阵雨 -11°/-12°"; + listdata->PushBack(list3data3); + + IconItemNode *list3data4 = new IconItemNode(); + list3data4->imagePath = "/user/res/weather/weather_sunny.bin"; + list3data4->txt = "周四 晴天 18°/22°"; + listdata->PushBack(list3data4); + + IconItemNode *list3data5 = new IconItemNode(); + list3data5->imagePath = "/user/res/weather/weather_foggy.bin"; + list3data5->txt = "周五 阴天 16°/20°"; + listdata->PushBack(list3data5); + + IconItemNode *list3data6 = new IconItemNode(); + list3data6->imagePath = "/user/res/weather/weather_thundershower.bin"; + list3data6->txt = " 周六 雷阵雨 10°/15°"; + listdata->PushBack(list3data6); + + IconItemNode *list3data7 = new IconItemNode(); + list3data7->imagePath = "/user/res/weather/weather_overcast.bin"; + list3data7->txt = "周日 阴 20°/24°"; + listdata->PushBack(list3data7); + if (listadapter == nullptr) + { + listadapter = new IconAdapter(); + } + listadapter->SetItemSize(355, 65); + listadapter->SetImageSize(65, 65); + listadapter->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + listadapter->SetData(listdata); + list->SetAdapter(listadapter); + + // Add to scrollView1 + scrollView1_->Add(list); + list->SetVisible(true); + } + + void FutureWeatherView::DeInitView() + { + if (viewInitStatus == true) + { + delete label1_; + label1_ = nullptr; + + delete list; + list = nullptr; + + delete listadapter; + listadapter = nullptr; + + delete draglistener; + draglistener = nullptr; + + listdata->Clear(); + delete listdata; + listdata = nullptr; + + delete scrollView1_; + scrollView1_ = nullptr; + + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + + void FutureWeatherView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void FutureWeatherView::OnStart() + { + View::OnStart(); + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->Resize(466, 466); + container_->SetTouchable(true); + container_->SetDraggable(true); + draglistener = static_cast(FutureWeatherPresenter::GetInstance()); + container_->SetOnDragListener(draglistener); + } + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void FutureWeatherView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void FutureWeatherView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void FutureWeatherView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/GetWeatherDataErrorPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/GetWeatherDataErrorPresenter.cpp new file mode 100644 index 000000000..6fffd0098 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/GetWeatherDataErrorPresenter.cpp @@ -0,0 +1,71 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "weather/include/GetWeatherDataErrorPresenter.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static GetWeatherDataErrorPresenter *g_pGetWeatherDataErrorPresenter = nullptr; + + GetWeatherDataErrorPresenter::GetWeatherDataErrorPresenter() + { + + g_pGetWeatherDataErrorPresenter = this; + } + + GetWeatherDataErrorPresenter::~GetWeatherDataErrorPresenter() + { + + g_pGetWeatherDataErrorPresenter = nullptr; + } + + GetWeatherDataErrorPresenter *GetWeatherDataErrorPresenter::GetInstance() + { + + return g_pGetWeatherDataErrorPresenter; + } + + void GetWeatherDataErrorPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void GetWeatherDataErrorPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void GetWeatherDataErrorPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void GetWeatherDataErrorPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool GetWeatherDataErrorPresenter::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_WEATHER); + } + return true; + } + + bool GetWeatherDataErrorPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), 控件ID) == 0) + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp new file mode 100644 index 000000000..6279185f6 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/GetWeatherDataErrorView.cpp @@ -0,0 +1,161 @@ +#include "weather/include/GetWeatherDataErrorView.h" +#include "weather/include/GetWeatherDataErrorPresenter.h" +#include "UiConfig.h" + +/* 天气获取数据失败后会调用该视图*/ +namespace OHOS +{ + + static GetWeatherDataErrorView *g_pGetWeatherDataErrorView{nullptr}; + + GetWeatherDataErrorView::GetWeatherDataErrorView() + { + + g_pGetWeatherDataErrorView = this; + } + + GetWeatherDataErrorView::~GetWeatherDataErrorView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pGetWeatherDataErrorView = nullptr; + } + + GetWeatherDataErrorView *GetWeatherDataErrorView::GetInstance() + { + + return g_pGetWeatherDataErrorView; + } + + void GetWeatherDataErrorView::InitView() + { + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + + // Add Label to App + if (label1_ == nullptr) + { + label1_ = new UILabel(); + } + label1_->SetPosition(113, 268); + label1_->Resize(240, 70); + label1_->SetViewId("label1"); + label1_->SetStyle(STYLE_TEXT_FONT, 30); + label1_->SetStyle(STYLE_LINE_HEIGHT, 35); + + // Set additional property + label1_->SetText("未获取到天气信息\n请前往APP更新"); + label1_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label1_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label1_->SetRollSpeed(0); + label1_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + // Add to scrollView1 + scrollView1_->Add(label1_); + label1_->SetVisible(true); + + // Add ImageView to App + if (image1_ == nullptr) + { + image1_ = new UIImageView(); + } + image1_->SetPosition(168, 127); + image1_->Resize(130, 130); + image1_->SetViewId("image1"); + image1_->SetSrc("/user/res/weather/WEATHER_UNKNOWN.bin"); + + // Add to scrollView1 + scrollView1_->Add(image1_); + image1_->SetVisible(true); + } + + void GetWeatherDataErrorView::DeInitView() + { + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (image1_ != nullptr) + { + delete image1_; + image1_ = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + + void GetWeatherDataErrorView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void GetWeatherDataErrorView::OnStart() + { + container_ = new UIViewGroup(); + if (container_ == nullptr) + { + return; + } + // container_容器属性 扩展 + container_->SetPosition(0, 0); + container_->SetWidth(Screen::GetInstance().GetWidth()); + container_->SetHeight(Screen::GetInstance().GetHeight()); + + draglistener = static_cast(GetWeatherDataErrorPresenter::GetInstance()); + if (draglistener == nullptr) + { + return; + } + container_->SetOnDragListener(draglistener); + container_->SetTouchable(true); + container_->SetDraggable(true); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void GetWeatherDataErrorView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void GetWeatherDataErrorView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void GetWeatherDataErrorView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp new file mode 100644 index 000000000..d065faf1f --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/MainWeatherPresenter.cpp @@ -0,0 +1,76 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "weather/include/MainWeatherPresenter.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static MainWeatherPresenter *g_pMainWeatherPresenter = nullptr; + + MainWeatherPresenter::MainWeatherPresenter() + { + + g_pMainWeatherPresenter = this; + } + + MainWeatherPresenter::~MainWeatherPresenter() + { + + g_pMainWeatherPresenter = nullptr; + } + + MainWeatherPresenter *MainWeatherPresenter::GetInstance() + { + + return g_pMainWeatherPresenter; + } + + void MainWeatherPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void MainWeatherPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void MainWeatherPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void MainWeatherPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool MainWeatherPresenter::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_APPLIST); + return true; + } + else if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_WEATHER_REPORT); // 主天气界面从下往上滑进入气象报告界面 + return true; + } + return false; + } + + bool MainWeatherPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), 控件ID) == 0) + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/MainWeatherView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/MainWeatherView.cpp new file mode 100644 index 000000000..9ca4e8109 --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/MainWeatherView.cpp @@ -0,0 +1,283 @@ +#include "weather/include/MainWeatherView.h" +#include "weather/include/MainWeatherPresenter.h" +#include "UiConfig.h" +/* +当至天气界面时,主动获取最新天气数据。 +(此操作静默将进行,获取到则立刻更新显示,获取不到则重试 +重试3次无果结束更新) +在加载该视图时,需要加载:1时间,2天气图片,3温度,4天气描述,5,地点,6,温度范围 +*/ + +namespace OHOS +{ + static ImageAnimatorInfo g_imageAnimator1Info[2] = { + {PNG_ANIMATOR1_IMAGE, {213, 400}, 40, 40, IMG_SRC_FILE_PATH}, + {PNG_ANIMATOR2_IMAGE, {213, 400}, 40, 40, IMG_SRC_FILE_PATH}, + }; + static MainWeatherView *g_pMainWeatherView{nullptr}; + + MainWeatherView::MainWeatherView() + { + Time = GetTime(); + WeatherImag = GetWeatherImage(); + Temperature = GetWeatherTemperature(); + WeatherDescription = GetWeatherDescription(); + WeatherArea = GetWeatherArea(); + MaxandMinTemperature = GetWeatherMaxAndMinTemperature(); + g_pMainWeatherView = this; + } + + MainWeatherView::~MainWeatherView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pMainWeatherView = nullptr; + } + + MainWeatherView *MainWeatherView::GetInstance() + { + return g_pMainWeatherView; + } + + // 获取时间 + std::string MainWeatherView::GetTime() + { + srand(time(0)); + std::string area[] = {"23:54", "12:00", "7:25"}; + int num = rand() % (sizeof(area) / sizeof(area[0])); + return area[num]; + } + + // 获取天气图片 + std::string MainWeatherView::GetWeatherImage() + { + int size = sizeof(weather130x130) / sizeof(weather130x130[0]); + return weather130x130[rand() % size]; + } + // 获取温度 + + std::string MainWeatherView::GetWeatherTemperature() + { + // 使用系统时间作为种子 + srand(time(0)); + int temperature = rand() % 50; + return std::to_string(temperature) + "°"; + } + // 获取天气描述 + + std::string MainWeatherView::GetWeatherDescription() + { + srand(time(0)); + std::string area[] = {"晴", "雨夹雪", "雷阵雨伴有冰雹"}; + int num = rand() % (sizeof(area) / sizeof(area[0])); + return area[num]; + } + // 获取天气地区 + + std::string MainWeatherView::GetWeatherArea() + { + srand(time(0)); + std::string area[] = {"北京市东城区", "深圳市福田区", "那然色布斯台音布拉格市那然色布斯台音努如"}; + int num = rand() % (sizeof(area) / sizeof(area[0])); + return area[num]; + } + // 获取最高气温和最低气温 + + std::string MainWeatherView::GetWeatherMaxAndMinTemperature() + { + // 使用系统时间作为种子 + srand(time(0)); + // 生成随机数 + int maxtemperature = 20 + rand() % 40; // 最高气温:20°~60° + int mintemperature = -5 + rand() % 20; + std::string MaxandMinTemperature = "最高" + std::to_string(maxtemperature) + "°" + " " + "最低" + std::to_string(mintemperature) + "°"; + return MaxandMinTemperature; + } + + // 初始化标签 + UILabel *MainWeatherView::InitLabel(int x, int y, const char *text, const char *id, int textfont, int lineheight) + { + UILabel *label = new UILabel(); + label->SetPosition(x, y); + label->Resize(200, 30); + label->SetViewId(id); + label->SetStyle(STYLE_TEXT_FONT, textfont); + label->SetStyle(STYLE_LINE_HEIGHT, lineheight); + label->SetText(text); + label->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label->SetRollSpeed(0); + label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, textfont); + label->SetVisible(true); + return label; + } + + void MainWeatherView::InitView(void) + { + if (container_ == nullptr) + { + return; + } + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); + scrollView1_->Resize(466, 466); + scrollView1_->SetViewId("scrollView1"); + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView1_->SetVerticalScrollState(false); // 设置纵向是否可滚动。 + scrollView1_->SetHorizontalScrollState(false); // 设置横向是否可滚动。 + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (image1_ == nullptr) + { + image1_ = new UIImageView(); + } + image1_->SetPosition(109, 124); + image1_->Resize(100, 100); + image1_->SetViewId("image1"); + image1_->SetSrc(WeatherImag.c_str()); + scrollView1_->Add(image1_); + image1_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + label1_ = InitLabel(185, 52, Time.c_str(), "label1", 40, 47); + scrollView1_->Add(label1_); + /* -------------------------------------------------------------------------- */ + label2_ = InitLabel(249, 126, Temperature.c_str(), "label2", 100, 125); + scrollView1_->Add(label2_); + /* -------------------------------------------------------------------------- */ + label3_ = InitLabel(111, 264, WeatherDescription.c_str(), "label3", 35, 41); + scrollView1_->Add(label3_); + /* -------------------------------------------------------------------------- */ + label4_ = InitLabel(155, 330, WeatherArea.c_str(), "label4", 26, 30); + label4_->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + scrollView1_->Add(label4_); + /* -------------------------------------------------------------------------- */ + label5_ = InitLabel(158, 368, MaxandMinTemperature.c_str(), "label5", 20, 23); + label5_->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + scrollView1_->Add(label5_); + /* -------------------------------------------------------------------------- */ + // Add ImageAnimatorView to App + if (imageAnimator1_ == nullptr) + { + imageAnimator1_ = new UIImageAnimatorView(); + } + imageAnimator1_->SetPosition(213, 400); + imageAnimator1_->Resize(40, 40); + imageAnimator1_->SetViewId("imageAnimator1"); + imageAnimator1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + + // Set additional property + imageAnimator1_->SetImageAnimatorSrc(g_imageAnimator1Info, 2, 200); + imageAnimator1_->SetTimeOfPause(200); + imageAnimator1_->SetRepeatTimes(1); + imageAnimator1_->SetReverse(true); + imageAnimator1_->Start(); + + // Add to scrollView1 + scrollView1_->Add(imageAnimator1_); + imageAnimator1_->SetVisible(true); + } + + void MainWeatherView::DeInitView() + { + + if (label1_ != nullptr) + { + delete label1_; + label1_ = nullptr; + } + if (label2_ != nullptr) + { + delete label2_; + label2_ = nullptr; + } + if (image1_ != nullptr) + { + delete image1_; + image1_ = nullptr; + } + if (label3_ != nullptr) + { + delete label3_; + label3_ = nullptr; + } + if (label4_ != nullptr) + { + delete label4_; + label4_ = nullptr; + } + if (label5_ != nullptr) + { + delete label5_; + label5_ = nullptr; + } + if (imageAnimator1_ != nullptr) + { + imageAnimator1_->Stop(); // 视图退出后动画停止 + delete imageAnimator1_; + imageAnimator1_ = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + + void MainWeatherView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void MainWeatherView::OnStart() + { + View::OnStart(); + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->Resize(466, 466); + container_->SetTouchable(true); + container_->SetDraggable(true); + UIView::OnDragListener *draglistener = static_cast(MainWeatherPresenter::GetInstance()); + container_->SetOnDragListener(draglistener); + } + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void MainWeatherView::OnSetUpView() + { + View::OnSetUpView(); + Draw(); + } + + void MainWeatherView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void MainWeatherView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherReportPresenter.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherReportPresenter.cpp new file mode 100644 index 000000000..22ef28cdb --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherReportPresenter.cpp @@ -0,0 +1,78 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" + +#include "weather/include/WeatherReportPresenter.h" + +namespace OHOS +{ + + // 当前Presenter属性实例化的内存指针 + static WeatherReportPresenter *g_pWeatherReportPresenter = nullptr; + + WeatherReportPresenter::WeatherReportPresenter() + { + + g_pWeatherReportPresenter = this; + } + + WeatherReportPresenter::~WeatherReportPresenter() + { + + g_pWeatherReportPresenter = nullptr; + } + + WeatherReportPresenter *WeatherReportPresenter::GetInstance() + { + + return g_pWeatherReportPresenter; + } + + void WeatherReportPresenter::OnStart() + { + + Presenter::OnStart(); + } + + void WeatherReportPresenter::OnPause(void) + { + + Presenter::OnPause(); + } + + void WeatherReportPresenter::OnResume(void) + { + + Presenter::OnResume(); + } + + void WeatherReportPresenter::OnStop(void) + { + + Presenter::OnStop(); + } + + bool WeatherReportPresenter::OnDrag(UIView &view, const DragEvent &event) + { + + if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM && + (event.GetDeltaY() > 20) && (event.GetDeltaY() > (2 * MATH_ABS(event.GetDeltaX())))) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_WEATHER); // 气象报告界面从上往下滑进入主天气界面 + return true; + } + if (event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_FUTURE_WEATHER); // 气象报告界面从下往上进入未来天气界面 + return true; + } + return false; + } + + bool WeatherReportPresenter::OnClick(UIView &view, const ClickEvent &event) + { + + // 根据控件id查找是哪个控件触发了点击回调 + // if (strcmp(view.GetViewId(), 控件ID) == 0) + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherReportView.cpp b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherReportView.cpp new file mode 100644 index 000000000..d3a048afe --- /dev/null +++ b/code/sdk/application/wearable/nativeapp/nativeui/weather/src/WeatherReportView.cpp @@ -0,0 +1,426 @@ +#include "weather/include/WeatherReportView.h" +#include "weather/include/WeatherReportPresenter.h" +#include "UiConfig.h" + +namespace OHOS +{ + + const char *IMAGEANIMATOR3 = "/user/res/weather/WEATHER_WINDSPEED.bin"; + const char *IMAGEANIMATOR2 = "/user/res/weather/WEATHER_HUMIDITY.bin"; + const char *IMAGEANIMATOR1 = "/user/res/weather/WEATHER_UVI.bin"; + static ImageAnimatorInfo g_imageAnimator3Info[2] = { + {IMAGEANIMATOR3, {341, 167}, 60, 60, IMG_SRC_FILE_PATH}, + {"", {341, 167}, 60, 60, IMG_SRC_FILE_PATH}, + }; + static ImageAnimatorInfo g_imageAnimator2Info[2] = { + {IMAGEANIMATOR2, {207, 167}, 60, 60, IMG_SRC_FILE_PATH}, + {"", {207, 167}, 60, 60, IMG_SRC_FILE_PATH}, + }; + + static ImageAnimatorInfo g_imageAnimator1Info[2] = { + {IMAGEANIMATOR1, {73, 167}, 60, 60, IMG_SRC_FILE_PATH}, + {"", {73, 167}, 60, 60, IMG_SRC_FILE_PATH}, + }; + static ImageAnimatorInfo g_imageAnimatorInfo[2] = { + {PNG_ANIMATOR1_IMAGE, {213, 400}, 40, 40, IMG_SRC_FILE_PATH}, + {PNG_ANIMATOR2_IMAGE, {213, 400}, 40, 40, IMG_SRC_FILE_PATH}, + }; + static WeatherReportView *g_pWeatherReportView{nullptr}; + + WeatherReportView::WeatherReportView() + { + + g_pWeatherReportView = this; + } + + WeatherReportView::~WeatherReportView() + { + if (viewInitStatus == true) + { + DeInitView(); + } + g_pWeatherReportView = nullptr; + } + + WeatherReportView *WeatherReportView::GetInstance() + { + + return g_pWeatherReportView; + } + + void WeatherReportView::InitView() + { + if (container_ == nullptr) + { + container_ = new UIViewGroup(); + container_->SetPosition(0, 0, 466, 466); + container_->SetStyle(STYLE_BACKGROUND_OPA, 0); + container_->SetTouchable(true); + container_->SetDraggable(true); + UIView::OnDragListener *draglistener = static_cast(WeatherReportPresenter::GetInstance()); + container_->SetOnDragListener(draglistener); + } + + // Add ScrollView to App + if (scrollView1_ == nullptr) + { + scrollView1_ = new UIScrollView(); + } + scrollView1_->SetPosition(0, 0); // widget's left position and top position + scrollView1_->Resize(466, 466); // widget's width and height + scrollView1_->SetViewId("scrollView1"); // Set style + scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + + // Set additional property + + // Add to rootView + container_->Add(scrollView1_); + scrollView1_->SetVisible(true); + + // Add Label to App + if (label5_ == nullptr) + { + label5_ = new UILabel(); + } + label5_->SetPosition(173, 52); // widget's left position and top position + label5_->Resize(120, 35); // widget's width and height + label5_->SetViewId("label5"); // Set style + label5_->SetStyle(STYLE_TEXT_FONT, 30); + label5_->SetStyle(STYLE_LINE_HEIGHT, 35); + + // Set additional property + label5_->SetText("气象报告"); + label5_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label5_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label5_->SetRollSpeed(0); + label5_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + + // Add to scrollView1 + scrollView1_->Add(label5_); + label5_->SetVisible(true); + + // Add ImageAnimatorView to App + if (imageAnimator3_ == nullptr) + { + imageAnimator3_ = new UIImageAnimatorView(); + } + imageAnimator3_->SetPosition(341, 167); // widget's left position and top position + imageAnimator3_->Resize(60, 60); // widget's width and height + imageAnimator3_->SetViewId("imageAnimator3"); // Set style + + // Set additional property + imageAnimator3_->SetImageAnimatorSrc(g_imageAnimator3Info, 2, 200); + imageAnimator3_->SetTimeOfPause(500); + imageAnimator3_->SetRepeatTimes(1); + imageAnimator3_->SetReverse(true); + imageAnimator3_->Start(); + + // Add to scrollView1 + scrollView1_->Add(imageAnimator3_); + imageAnimator3_->SetVisible(true); + + // Add ImageAnimatorView to App + if (imageAnimator2_ == nullptr) + { + imageAnimator2_ = new UIImageAnimatorView(); + } + imageAnimator2_->SetPosition(207, 167); // widget's left position and top position + imageAnimator2_->Resize(60, 60); // widget's width and height + imageAnimator2_->SetViewId("imageAnimator2"); // Set style + + // Set additional property + imageAnimator2_->SetImageAnimatorSrc(g_imageAnimator2Info, 2, 200); + imageAnimator2_->SetTimeOfPause(500); + imageAnimator2_->SetRepeatTimes(1); + imageAnimator2_->SetReverse(true); + imageAnimator2_->Start(); + + // Add to scrollView1 + scrollView1_->Add(imageAnimator2_); + imageAnimator2_->SetVisible(true); + + // Add ImageAnimatorView to App + if (imageAnimator1_ == nullptr) + { + imageAnimator1_ = new UIImageAnimatorView(); + } + imageAnimator1_->SetPosition(73, 167); // widget's left position and top position + imageAnimator1_->Resize(60, 60); // widget's width and height + imageAnimator1_->SetViewId("imageAnimator1"); // Set style + + // Set additional property + imageAnimator1_->SetImageAnimatorSrc(g_imageAnimator1Info, 2, 200); + imageAnimator1_->SetTimeOfPause(500); + imageAnimator1_->SetRepeatTimes(1); + imageAnimator1_->SetReverse(true); + imageAnimator1_->Start(); + + // Add to scrollView1 + scrollView1_->Add(imageAnimator1_); + imageAnimator1_->SetVisible(true); + + // Add Label to App + if (label6_ == nullptr) + { + label6_ = new UILabel(); + } + label6_->SetPosition(93, 240); // widget's left position and top position + label6_->Resize(20, 50); // widget's width and height + label6_->SetViewId("label6"); // Set style + label6_->SetStyle(STYLE_TEXT_FONT, 40); + label6_->SetStyle(STYLE_LINE_HEIGHT, 50); + + // Set additional property + label6_->SetText("7"); + label6_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label6_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label6_->SetRollSpeed(0); + label6_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + + // Add to scrollView1 + scrollView1_->Add(label6_); + label6_->SetVisible(true); + + // Add Label to App + if (label7_ == nullptr) + { + label7_ = new UILabel(); + } + label7_->SetPosition(210, 240); // widget's left position and top position + label7_->Resize(200, 60); // widget's width and height + label7_->SetViewId("label7"); // Set style + label7_->SetStyle(STYLE_TEXT_FONT, 40); + label7_->SetStyle(STYLE_LINE_HEIGHT, 50); + + // Set additional property + label7_->SetText("1-2"); + label7_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label7_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label7_->SetRollSpeed(0); + label7_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + + // Add to scrollView1 + scrollView1_->Add(label7_); + label7_->SetVisible(true); + + // Add Label to App + if (label8_ == nullptr) + { + label8_ = new UILabel(); + } + label8_->SetPosition(337, 240); // widget's left position and top position + label8_->Resize(200, 60); // widget's width and height + label8_->SetViewId("label8"); // Set style + label8_->SetStyle(STYLE_TEXT_FONT, 40); + label8_->SetStyle(STYLE_LINE_HEIGHT, 50); + + // Set additional property + label8_->SetText("75%"); + label8_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label8_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label8_->SetRollSpeed(0); + label8_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + + // Add to scrollView1 + scrollView1_->Add(label8_); + label8_->SetVisible(true); + + // Add Label to App + if (label9_ == nullptr) + { + label9_ = new UILabel(); + } + label9_->SetPosition(63, 293); // widget's left position and top position + label9_->Resize(200, 60); // widget's width and height + label9_->SetViewId("label9"); // Set style + label9_->SetStyle(STYLE_TEXT_FONT, 26); + label9_->SetStyle(STYLE_LINE_HEIGHT, 30); + + // Set additional property + label9_->SetText("紫外线"); + label9_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label9_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label9_->SetRollSpeed(0); + label9_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + + // Add to scrollView1 + scrollView1_->Add(label9_); + label9_->SetVisible(true); + + // Add Label to App + if (label10_ == nullptr) + { + label10_ = new UILabel(); + } + label10_->SetPosition(212, 293); // widget's left position and top position + label10_->Resize(290, 60); // widget's width and height + label10_->SetViewId("label10"); // Set style + label10_->SetStyle(STYLE_TEXT_FONT, 26); + label10_->SetStyle(STYLE_LINE_HEIGHT, 30); + + // Set additional property + label10_->SetText("风速"); + label10_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label10_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label10_->SetRollSpeed(0); + label10_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + + // Add to scrollView1 + scrollView1_->Add(label10_); + label10_->SetVisible(true); + + // Add Label to App + if (label11_ == nullptr) + { + label11_ = new UILabel(); + } + label11_->SetPosition(345, 293); // widget's left position and top position + label11_->Resize(200, 60); // widget's width and height + label11_->SetViewId("label11"); // Set style + label11_->SetStyle(STYLE_TEXT_FONT, 26); + label11_->SetStyle(STYLE_LINE_HEIGHT, 30); + + // Set additional property + label11_->SetText("湿度"); + label11_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + label11_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + label11_->SetRollSpeed(0); + label11_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26); + + // Add to scrollView1 + scrollView1_->Add(label11_); + label11_->SetVisible(true); + /* -------------------------------------------------------------------------- */ + // Add ImageAnimatorView to App + if (imageAnimator == nullptr) + { + imageAnimator = new UIImageAnimatorView(); + } + imageAnimator->SetPosition(213, 400); + imageAnimator->Resize(40, 40); + imageAnimator->SetViewId("imageAnimator1"); + imageAnimator->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + + // Set additional property + imageAnimator->SetImageAnimatorSrc(g_imageAnimatorInfo, 2, 200); + imageAnimator->SetTimeOfPause(200); + imageAnimator->SetRepeatTimes(1); + imageAnimator->SetReverse(true); + imageAnimator->Start(); + + // Add to scrollView1 + scrollView1_->Add(imageAnimator); + imageAnimator->SetVisible(true); + } + + void WeatherReportView::DeInitView() + { + if (label5_ != nullptr) + { + delete label5_; + label5_ = nullptr; + } + if (imageAnimator3_ != nullptr) + { + imageAnimator3_->Stop(); + delete imageAnimator3_; + imageAnimator3_ = nullptr; + } + if (imageAnimator2_ != nullptr) + { + imageAnimator2_->Stop(); + delete imageAnimator2_; + imageAnimator2_ = nullptr; + } + if (imageAnimator1_ != nullptr) + { + imageAnimator1_->Stop(); + delete imageAnimator1_; + imageAnimator1_ = nullptr; + } + if (imageAnimator != nullptr) + { + imageAnimator->Stop(); + delete imageAnimator; + imageAnimator = nullptr; + } + if (label6_ != nullptr) + { + delete label6_; + label6_ = nullptr; + } + if (label7_ != nullptr) + { + delete label7_; + label7_ = nullptr; + } + if (label8_ != nullptr) + { + delete label8_; + label8_ = nullptr; + } + if (label9_ != nullptr) + { + delete label9_; + label9_ = nullptr; + } + if (label10_ != nullptr) + { + delete label10_; + label10_ = nullptr; + } + if (label11_ != nullptr) + { + delete label11_; + label11_ = nullptr; + } + if (scrollView1_ != nullptr) + { + delete scrollView1_; + scrollView1_ = nullptr; + } + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } + } + + void WeatherReportView::PreLoad(void) + { + if (!viewInitStatus) + { + InitView(); + viewInitStatus = true; + } + } + void WeatherReportView::OnStart() + { + View::OnStart(); + PreLoad(); + RootView::GetInstance()->Add(container_); + } + + void WeatherReportView::OnSetUpView() + { + + View::OnSetUpView(); + Draw(); + } + + void WeatherReportView::OnTearDownView() + { + + View::OnTearDownView(); + return; + } + + void WeatherReportView::OnStop() + { + + View::OnStop(); + RootView::GetInstance()->RemoveAll(); + return; + } +} \ No newline at end of file