"files.associations": {
"pinctrl_porting.h": "c",
"complex": "cpp",
- "*.inc": "cpp"
+ "*.inc": "cpp",
+ "thread": "cpp",
+ "chrono": "cpp",
+ "iostream": "cpp"
}
}
\ No newline at end of file
#����
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dial/src/DialView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/dial/src/DialPresenter.cpp
+
+ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heartrate/src/HeartRemindView.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/heartrate/src/HeartRemindPresenter.cpp
#ָ����
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassControlView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/compass/src/CompassCalibrationView.cpp
VIEW_UISAMPLE, // 实例
VIEW_GETPIC, // 手势拍照
VIEW_TAKEPIC, // 拍照
+
VIEW_BLOOD, // 血氧
VIEW_BLOODSHOW, // 血氧说明
VIEW_BLOODCHECK, // 血氧检查
VIEW_BLOODERROR, // 血氧监测错误
VIEW_BLOODNOTE, // 血氧过低提醒
+
VIEW_DIAL, // 表盘
VIEW_DIALSETUP, // 表盘安装
VIEW_DIALSUCCES, // 表盘安装成功
+
VIEW_SAVEELE, // 省电模式
VIEW_SAVEBAT, // 省电模式界面
+
VIEW_COMPASS, // 指南针
VIEW_COMPASS_PLACE_MAKER, // 指南针:放置标记点
VIEW_COMPASS_MAKER_POINT, // 指南针:标记点介绍
VIEW_COMPASS_END_BACK_TRACKING, // 指南针:结束路径回溯
VIEW_COMPASS_END_BACK_TRACKING_EARLY, // 指南针:提前结束路径回溯
VIEW_SPORT, // 活动
- VIEW_HEARTRATE, // 心率
+
+ VIEW_HEARTRATEREMIND, // 心率提醒
+
VIEW_TRAINING, // 训练
VIEW_TRAINING_RECORD, // 训练记录
VIEW_BLOODPRESSURE, // 昨日睡眠时间
void InitBloodErrorSlice(void);
void InitBloodNoteSlice(void);
void InitDialSlice(void);
+ void InitHeartRemindSlice(void);
void InitPhoneSlice(void);
void InitPhoneCallSlice(void);
void InitPhoneDirSlice(void);
#include "blood/include/BloodNotePresenter.h"
#include "dial/include/DialPresenter.h"
#include "dial/include/DialView.h"
+#include "heartrate/include/HeartRemindPresenter.h"
+#include "heartrate/include/HeartRemindView.h"
#include "displaybrightness/include/DisplayBrightnessPresenter.h"
#include "displaybrightness/include/DisplayBrightnessView.h"
#include "bluetoothofsetting/include/BlueToothOfSettingPresenter.h"
{VIEW_BLOODERROR, &NativeLauncher::InitBloodErrorSlice},
{VIEW_BLOODNOTE, &NativeLauncher::InitBloodNoteSlice},
{VIEW_DIAL, &NativeLauncher::InitDialSlice}, //表盘
+ {VIEW_HEARTRATEREMIND, &NativeLauncher::InitHeartRemindSlice},
+
{VIEW_DISPLAY_BRIGHTNESS,&NativeLauncher::InitUIDisplayBrightnessSlice}, //显示与亮度的实例化地址
{VIEW_CONNECT_BLUETOOTH,&NativeLauncher::InitBlueToothSettingSlice}, //蓝牙设置的实例化地址
{VIEW_BRIGHTNESS_CONTROL,&NativeLauncher::InitBrightnessControlSlice}, //调节亮度的实例化地址
NativeAbility::GetInstance().AddSliceProxy(VIEW_DIAL, dialview);
}
+void NativeLauncher::InitHeartRemindSlice(void)
+{
+ SliceProxy *heartremindview = new AbilitySliceProxy<HeartRemindView, HeartRemindPresenter>;
+ NativeAbility::GetInstance().AddSliceProxy(VIEW_HEARTRATEREMIND, heartremindview);
+}
+
//DisplayBrightness的实例化
void NativeLauncher::InitUIDisplayBrightnessSlice(void)
{
{VIEW_SPORT, PNG_APPLIST_SPORT_IMAGE, PNG_APPLIST_SPORT_IMAGE, "活动", nullptr},
{VIEW_GETPIC, PNG_APPLIST_GETPIC_IMAGE, PNG_APPLIST_GETPIC_IMAGE, "拍照", nullptr},
{VIEW_BLOOD, PNG_APPLIST_BLOOD_IMAGE, PNG_APPLIST_BLOOD_IMAGE, "血氧监测", nullptr},
- {VIEW_SPORT, PNG_APPLIST_HEARTRATE_IMAGE, PNG_APPLIST_HEARTRATE_IMAGE, "心率", nullptr},
+ {VIEW_HEARTRATEREMIND, PNG_APPLIST_HEARTRATE_IMAGE, PNG_APPLIST_HEARTRATE_IMAGE, "心率", nullptr},
{VIEW_TRAINING, PNG_APPLIST_TRAINING_IMAGE, PNG_APPLIST_TRAINING_IMAGE, "训练", nullptr},
{VIEW_TRAINING_RECORD, PNG_APPLIST_TRAINING_RECORD_IMAGE, PNG_APPLIST_TRAINING_RECORD_IMAGE, "训练记录", nullptr},
{VIEW_BLOODPRESSURE, PNG_APPLIST_BLOODPRESSURE_IMAGE, PNG_APPLIST_BLOODPRESSURE_IMAGE, "睡眠", nullptr},
void RefreshRestHeartRate(uint16_t value); // 刷新静息心率
void HeartbeatImageAnimatorStart(void); // 心形动画启动
void HeartbeatImageAnimatorStop(void); // 心形动画停止
+ void GetHeartRate(void);//获取心率结果
void InitRefreshInterface(void);
private:
UILabel *restRate{nullptr};
UILabel *restRateText1{nullptr};
UILabel *restRateText2{nullptr};
+ UIButton* button_ = nullptr;
uint16_t maxRate;
uint16_t minRate;
--- /dev/null
+#ifndef _HeartRemind_PRESENTER_H
+#define _HeartRemind_PRESENTER_H
+
+#include "Presenter.h"
+#include "HeartRemindView.h"
+
+namespace OHOS
+{
+ class HeartRemindView;
+
+ class HeartRemindPresenter : public Presenter<HeartRemindView>,
+ public UIView::OnClickListener,
+ public UIView::OnDragListener
+ {
+ public:
+ HeartRemindPresenter();
+ virtual ~HeartRemindPresenter();
+
+ void OnStart() override;
+ void OnPause() override;
+ void OnResume() override;
+ void OnStop() override;
+
+ static HeartRemindPresenter *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
--- /dev/null
+#ifndef _HeartRemind_VIEW_H
+#define _HeartRemind_VIEW_H
+
+#include "BaseView.h"
+#include "View.h"
+#include <ui_scroll_view.h>
+#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 "wearable_log.h"
+#include "ohos_types.h"
+#include "components/ui_card_page.h"
+
+#include "HeartRemindPresenter.h"
+namespace OHOS
+{
+#define NOTEBUTTON "Button1" // 退出按键
+
+ class HeartRemindPresenter;
+ class HeartRemindView : public View<HeartRemindPresenter>
+ {
+
+ public:
+ HeartRemindView();
+ virtual ~HeartRemindView();
+ static HeartRemindView *GetInstance(void);
+
+ void OnStart() override;
+ void OnSetUpView() override;
+ void OnTearDownView() override;
+ void OnStop() override;
+ void Init();
+ void DeInit();
+
+ UIView *GetView();
+
+ private:
+ int16 heartrate = 170;
+ UIView::OnDragListener *draglistener{nullptr};
+ HeartRemindView(HeartRemindView &&) = delete;
+ HeartRemindView &operator=(HeartRemindView &&) = delete;
+
+ UIViewGroup *container_ = nullptr;
+ UILabel *label1_ = nullptr;
+ UIImageView *image1_ = nullptr;
+ UILabel *label2_ = nullptr;
+ UILabel *label3_ = nullptr;
+ UILabel *label4_ = nullptr;
+ UIButton *button1_ = nullptr;
+ };
+} // namespace OHOS
+#endif // HeartRemind_PRESENTER_H
HeartRateView::GetInstance()->RefreshHeartRatePerSec(perSec);
HeartRateView::GetInstance()->RefreshHeartRateMax(maxRate);
HeartRateView::GetInstance()->RefreshHeartRateMin(minRate);
+ HeartRateView::GetInstance()->GetHeartRate();//获取心率结果
}
}
}
#include "ScreenModels.h"
#include "ui_resource_image.h"
#include "common/image_cache_manager.h"
-
+#include <string>
+#include <ratio>
+#include <type_traits>
+#include <limits>
+#include <ctime>
+#include <iostream>
+#include <chrono>
+#include <thread>
+#include "MainViewSample.h"
+#include "/heartrate/include/HeartRemindPresenter.h"
namespace OHOS {
static HeartRateView *g_pHeartRateView = nullptr;
imageViewBottom->SetWidth(BOTTOM_IMAGE_WIDTH);
imageViewBottom->SetHeight(BOTTOM_IMAGE_HEIGHT);
Add(imageViewBottom);
+
+ // Add Button to App
+ if (button_ == nullptr) {
+ button_ = new UIButton();
+ }
+ button_->SetPosition(0, 0); // widget's left position and top position
+ button_->Resize(466, 466); // widget's width and height
+ button_->SetViewId("Remind");// Set style
+ button_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ button_->SetStyle(STYLE_BACKGROUND_OPA, 0x00);
+
+ // Set additional property
+ button_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+
+ // Add the CallBack about events
+ UIView::OnClickListener* button3Click = static_cast<UIView::OnClickListener*>(HeartRemindPresenter::GetInstance());
+ button_->SetOnClickListener(button3Click);
+ // Add to rootView
+ Add(button_);
+ button_->SetVisible(true);
}
void HeartRateView::UpdataTopAndBottomRate(void)
UpdataTopAndBottomRate();
HeartbeatImageAnimatorStop();
InitRefreshInterface();
+
return true;
}
}
}
}
+void HeartRateView::GetHeartRate(void)
+{
+ // 模拟心率监测,等待20秒
+ std::this_thread::sleep_for(std::chrono::seconds(20));
+ NativeAbility::GetInstance().ChangeSlice(VIEW_HEARTRATEREMIND);
+}
} // namespace OHOS
--- /dev/null
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+
+#include <iostream>
+#include <chrono>
+#include <thread>
+#include "/heartrate/include/HeartRemindPresenter.h"
+#include "HeartRateView.h"
+
+namespace OHOS
+{
+
+ // 当前Presenter属性实例化的内存指针
+ static HeartRemindPresenter *g_pHeartRemindPresenter = nullptr;
+
+ HeartRemindPresenter::HeartRemindPresenter()
+ {
+
+ g_pHeartRemindPresenter = this;
+ }
+
+ HeartRemindPresenter::~HeartRemindPresenter()
+ {
+
+ g_pHeartRemindPresenter = nullptr;
+ }
+
+ HeartRemindPresenter *HeartRemindPresenter::GetInstance()
+ {
+
+ return g_pHeartRemindPresenter;
+ }
+
+ void HeartRemindPresenter::OnStart()
+ {
+
+ Presenter<HeartRemindView>::OnStart();
+ }
+
+ void HeartRemindPresenter::OnPause(void)
+ {
+
+ Presenter<HeartRemindView>::OnPause();
+ }
+
+ void HeartRemindPresenter::OnResume(void)
+ {
+
+ Presenter<HeartRemindView>::OnResume();
+ }
+
+ void HeartRemindPresenter::OnStop(void)
+ {
+
+ Presenter<HeartRemindView>::OnStop();
+ }
+
+ bool HeartRemindPresenter::OnDrag(UIView &view, const DragEvent &event)
+ {
+
+ // if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT)
+ // {
+ // printf("draglistene is ok!\n");
+ // NativeAbility::GetInstance().ChangeSlice(VIEW_PHONE);
+ // }
+ UNUSED(view);
+ return true;
+ }
+
+ bool HeartRemindPresenter::OnClick(UIView &view, const ClickEvent &event)
+ {
+ // 根据控件id查找是哪个控件触发了点击回调
+ if (strcmp(view.GetViewId(), NOTEBUTTON) == 0)
+ {
+ NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST);
+ }
+ if (strcmp(view.GetViewId(), "Remind") == 0)
+ {
+ // 模拟心率监测,等待20秒
+ //std::this_thread::sleep_for(std::chrono::seconds(20));
+ NativeAbility::GetInstance().ChangeSlice(VIEW_HEARTRATEREMIND);
+ }
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+/*正常的心率范围:60~100*/
+
+#include "/heartrate/include/HeartRemindView.h"
+
+#include "common/image_cache_manager.h"
+#include "UiConfig.h"
+#include "ui_resource_image.h"
+#include <ui_scroll_view.h>
+#include "components/ui_button.h"
+namespace OHOS
+{
+ static HeartRemindView *g_pHeartRemindView{nullptr};
+
+ HeartRemindView::HeartRemindView()
+ {
+
+ g_pHeartRemindView = this;
+ }
+
+ HeartRemindView::~HeartRemindView()
+ {
+ DeInit();
+ g_pHeartRemindView = nullptr;
+ }
+
+ HeartRemindView *HeartRemindView::GetInstance()
+ {
+
+ return g_pHeartRemindView;
+ }
+ void HeartRemindView::Init()
+ {
+ if (container_ == nullptr)
+ {
+ container_ = new UIViewGroup();
+ container_->SetPosition(0, 0, 466, 466);
+ container_->SetStyle(STYLE_BACKGROUND_OPA, 0);
+ }
+
+ // Add Label to App
+ if (label1_ == nullptr)
+ {
+ label1_ = new UILabel();
+ }
+ label1_->SetPosition(173, 52); // widget's left position and top position
+ label1_->Resize(200, 60); // widget's width and height
+ label1_->SetViewId("label1"); // Set style
+ label1_->SetStyle(STYLE_TEXT_FONT, 30);
+
+ // 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 rootView
+ container_->Add(label1_);
+ label1_->SetVisible(true);
+
+ // Add ImageView to App
+ if (image1_ == nullptr)
+ {
+ image1_ = new UIImageView();
+ }
+ image1_->SetPosition(193, 121); // widget's left position and top position
+ image1_->Resize(100, 100); // widget's width and height
+ image1_->SetViewId("image1"); // Set style
+
+ // Set additional property
+#ifdef _WIN32
+ char *image1imagesPath = "c:/Users/caiking/project/image_converter_tool/output/Blood/error.bin";
+#else
+ const char *image1imagesPath = PNG_BLOOD_ERROR_IMAGE;
+#endif
+ image1_->SetSrc(image1imagesPath);
+
+ // Add to rootView
+ container_->Add(image1_);
+ image1_->SetVisible(true);
+
+ // Add Label to App
+ if (label2_ == nullptr)
+ {
+ label2_ = new UILabel();
+ }
+ label2_->SetPosition(50, 235); // widget's left position and top position
+ label2_->Resize(200, 60); // widget's width and height
+ label2_->SetViewId("label2"); // Set style
+ label2_->SetStyle(STYLE_TEXT_FONT, 30);
+
+ // Set additional property
+ if (heartrate > 100)
+ {
+ label2_->SetText("当前心率值高于 "); // 显示当前心率值高于
+
+ }
+ else if (heartrate < 40)
+ {
+ 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);
+
+ // Add to rootView
+ container_->Add(label2_);
+ label2_->SetVisible(true);
+
+ // Add Label to App
+ if (label3_ == nullptr)
+ {
+ label3_ = new UILabel();
+ }
+ label3_->SetPosition(260, 235); // widget's left position and top position
+ label3_->Resize(200, 60); // widget's width and height
+ label3_->SetViewId("label3"); // Set style
+ label3_->SetStyle(STYLE_TEXT_FONT, 30);
+
+ // Set additional property
+ label3_->SetText((std::to_string(heartrate) + "次/分钟").c_str()); // 显示心率值
+ label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+ label3_->SetTextColor(Color::GetColorFromRGBA(0xff, 0x8a, 0x36, 0xff));
+ label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ label3_->SetRollSpeed(0);
+ label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+ // Add to rootView
+ container_->Add(label3_);
+ label3_->SetVisible(true);
+
+ // Add Label to App
+ if (label4_ == nullptr)
+ {
+ label4_ = new UILabel();
+ }
+ label4_->SetPosition(128, 277); // widget's left position and top position
+ label4_->Resize(200, 60); // widget's width and height
+ label4_->SetViewId("label4"); // Set style
+ label4_->SetStyle(STYLE_TEXT_FONT, 30);
+
+ // Set additional property
+ label4_->SetText("请注意身体健康");
+ label4_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT);
+ label4_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ label4_->SetRollSpeed(0);
+ label4_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+
+ // Add to rootView
+ container_->Add(label4_);
+ label4_->SetVisible(true);
+
+ // Add Button to App
+ if (button1_ == nullptr)
+ {
+ button1_ = new UIButton();
+ }
+ button1_->SetPosition(0, 366); // widget's left position and top position
+ button1_->Resize(466, 100); // widget's width and height
+ button1_->SetViewId("Button1"); // Set style
+
+ // Set additional property
+#ifdef _WIN32
+ char *button1defaultImgSrc = "c:/Users/caiking/project/image_converter_tool/output/Blood/boutton.bin";
+#else
+ const char *button1defaultImgSrc = PNG_BLOOD_NOTE_IMAGE;
+#endif
+ char *button1triggeredImgSrc = nullptr;
+ button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc);
+ button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+ // Add the CallBack about events
+ UIView::OnClickListener *button1Click = static_cast<UIView::OnClickListener *>(HeartRemindPresenter::GetInstance());
+ button1_->SetOnClickListener(button1Click);
+ // Add to rootView
+ container_->Add(button1_);
+ button1_->SetVisible(true);
+ }
+
+ void HeartRemindView::DeInit()
+ {
+ if (container_ != nullptr)
+ {
+ container_->RemoveAll();
+ delete container_;
+ container_ = nullptr;
+ }
+ if (label1_ != nullptr)
+ {
+ delete label1_;
+ label1_ = nullptr;
+ }
+ if (image1_ != nullptr)
+ {
+ delete image1_;
+ image1_ = nullptr;
+ }
+ if (label2_ != nullptr)
+ {
+ delete label2_;
+ label2_ = nullptr;
+ }
+ if (label3_ != nullptr)
+ {
+ delete label3_;
+ label3_ = nullptr;
+ }
+ if (label4_ != nullptr)
+ {
+ delete label4_;
+ label4_ = nullptr;
+ }
+ if (button1_ != nullptr)
+ {
+ delete button1_;
+ button1_ = nullptr;
+ }
+ }
+
+ UIView *HeartRemindView::GetView()
+ {
+ Init();
+ return container_;
+ }
+ void HeartRemindView::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<UIView::OnDragListener *>(HeartRemindPresenter::GetInstance());
+ if (draglistener == nullptr)
+ {
+ return;
+ }
+ container_->SetOnDragListener(draglistener);
+
+ container_->SetTouchable(true);
+ container_->SetDraggable(true);
+
+ GetView();
+ RootView::GetInstance()->Add(container_);
+ }
+
+ void HeartRemindView::OnSetUpView()
+ {
+
+ View<HeartRemindPresenter>::OnSetUpView();
+ Draw();
+ }
+
+ void HeartRemindView::OnTearDownView()
+ {
+
+ View<HeartRemindPresenter>::OnTearDownView();
+ return;
+ }
+
+ void HeartRemindView::OnStop()
+ {
+ View<HeartRemindPresenter>::OnStop();
+ RootView::GetInstance()->RemoveAll();
+ return;
+ }
+}