535 lines
17 KiB
C++
535 lines
17 KiB
C++
#ifndef TJDUI_APP_SPORT_VIEW_H
|
|
#define TJDUI_APP_SPORT_VIEW_H
|
|
|
|
#include "TjdUiAppSportAdapter.h"
|
|
#include "TjdUiAppSportModel.h"
|
|
#include "TjdUiAppSportPresenter.h"
|
|
#include "TjdUiImageIds.h"
|
|
#include "TjdUiMemManage.h"
|
|
#include "View.h"
|
|
#include "components/root_view.h"
|
|
#include "components/tjd_ui_transform_list_group.h"
|
|
#include "components/ui_checkbox.h"
|
|
#include "components/ui_circle_progress.h"
|
|
#include "components/ui_label_ext.h"
|
|
#include "components/ui_scroll_view_nested.h"
|
|
#include "components/ui_cross_view.h"
|
|
#include "components/ui_card_page.h"
|
|
#include "graphic_timer.h"
|
|
#include "hal_tick.h"
|
|
#include "rtc_api.h"
|
|
#include "sql_bt.h"
|
|
#include "string"
|
|
#include "ui_canvas.h"
|
|
#include "ui_view_group.h"
|
|
#include "vector"
|
|
#include <components/svg_data.h>
|
|
#include <iostream>
|
|
#include <list>
|
|
#include <sstream>
|
|
#include <ui_canvas_ext.h>
|
|
|
|
namespace TJD {
|
|
|
|
#define MAX_SPORT_TYPE 58
|
|
|
|
struct Time
|
|
{
|
|
uint8_t hours;
|
|
uint8_t minutes;
|
|
uint8_t seconds;
|
|
};
|
|
|
|
class SportUIScrollView : public OHOS::UIScrollViewNested
|
|
{
|
|
public:
|
|
SportUIScrollView() {}
|
|
~SportUIScrollView() {}
|
|
bool OnDragStartEvent(const OHOS::DragEvent &event) override;
|
|
bool OnDragEvent(const OHOS::DragEvent &event) override;
|
|
bool OnDragEndEvent(const OHOS::DragEvent &event) override;
|
|
|
|
private:
|
|
bool isOnStart_{false};
|
|
};
|
|
|
|
class SportViewBase : public OHOS::UIScrollView
|
|
{
|
|
public:
|
|
SportViewBase() {}
|
|
virtual ~SportViewBase() {}
|
|
virtual void ShowView() { SetVisible(true); };
|
|
virtual void HideView() { SetVisible(false); };
|
|
};
|
|
|
|
#pragma region 主界面TjdUiAppSportView
|
|
class TjdUiAppSportView : public OHOS::View<TjdUiAppSportPresenter>, public OHOS::UIViewGroup
|
|
{
|
|
public:
|
|
TjdUiAppSportView();
|
|
~TjdUiAppSportView();
|
|
static TjdUiAppSportView *GetInstance(void);
|
|
void OnStart() override;
|
|
void OnStop() override;
|
|
void SportDataInit(void);
|
|
void InitSportList(SportInfo *sportInfo);
|
|
void InitEditSportView(SportInfo *sportInfo);
|
|
void ChooseSportItem(SportTypeIndex iconIndex);
|
|
void ShowTargetView(SportViewManager showIndex);
|
|
void ShowTargetView(SportViewManager showIndex, uint8_t touchIndex);
|
|
void ShowTargetView(SportViewManager showIndex, SportTypeIndex iconIndex);
|
|
void InitTargetView(SportViewManager index, SportTypeIndex iconIndex, uint8_t touchIndex);
|
|
std::list<SportCaseInfo> *GetSportItemList() { return sportItemList_; }
|
|
std::list<EditItemInfo> *GetEditItemList() { return editItemList_; }
|
|
SportViewBase *GetCurrentView() { return viewManager_[currentViewIndex_]; }
|
|
Time GetCurrentTime(const char *timeStr);
|
|
static SportViewManager currentViewIndex_;
|
|
static SportViewManager lastViewIndex_;
|
|
static SportTypeIndex currentIconIndex_;
|
|
void SetGPState(bool state) { GPS_StateSuccess = state; }
|
|
bool GetGPState() { return GPS_StateSuccess; }
|
|
|
|
SportUIScrollView *mainView_{nullptr};
|
|
SportViewBase *viewManager_[VIEW_MANAGER_MAX]{nullptr}; // 模拟器调试
|
|
private:
|
|
bool GPS_StateSuccess{false}; //记录gps的状态是否定位成功
|
|
std::list<SportCaseInfo> *sportItemList_ = nullptr;
|
|
OHOS::ImageInfo *imgItemInfo[SPORT_MAX_INDEX]{nullptr};
|
|
|
|
std::list<EditItemInfo> *editItemList_ = nullptr;
|
|
OHOS::ImageInfo *editItemInfo[SPORT_MAX_INDEX]{nullptr};
|
|
};
|
|
#pragma endregion
|
|
|
|
#pragma region 运动结束、运动进行中点击事件监听器SportViewOnClickedListener
|
|
class SportViewOnClickedListener : public OHOS::UIView::OnClickListener
|
|
{
|
|
public:
|
|
SportViewOnClickedListener() {}
|
|
virtual ~SportViewOnClickedListener() {}
|
|
virtual bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event);
|
|
|
|
private:
|
|
};
|
|
#pragma endregion
|
|
|
|
#pragma region 运动列表SportList
|
|
class SportList : public SportViewBase
|
|
{
|
|
public:
|
|
explicit SportList();
|
|
~SportList();
|
|
void ShowView();
|
|
static SportList *GetInstance();
|
|
OHOS::UIList *sportList_{nullptr};
|
|
void SetListTitleVisible(bool visible);
|
|
OHOS::UITransformList *customSportList_{nullptr};
|
|
// bool OnDragEvent(const DragEvent& event) ;
|
|
OHOS::UILabelExt *listlTitle_{nullptr};
|
|
friend class SportListScrollListener;
|
|
TjdUITransformListGroup * GetSportListView() { return sportListView_; }
|
|
TjdUITransformListGroup *sportListView_{nullptr};
|
|
TjdUITransformListGroupAdapter<SportCaseInfo, SportCaseItemView, std::list<SportCaseInfo>> *sportAdapterPtr_{
|
|
nullptr};
|
|
|
|
private:
|
|
OHOS::UILabelExt lbEdit_;
|
|
OHOS::UILabel editLabel_;
|
|
OHOS::UITransformGroup editBackground_;
|
|
OHOS::UIView listBackground_;
|
|
|
|
OHOS::UIImageView imgBackground_;
|
|
};
|
|
|
|
#pragma region 321倒计时CountDownView
|
|
|
|
enum class countStage
|
|
{
|
|
STAGE_GRADUAL_CIRCLE = 0,
|
|
STAGE_COUNTING_DOWN,
|
|
STAGE_FADE_OUT,
|
|
STAGE_NONE
|
|
};
|
|
|
|
class CountdownAnimatorCallback : public OHOS::AnimatorCallback
|
|
{
|
|
public:
|
|
explicit CountdownAnimatorCallback(OHOS::UICanvasExt *canvas) : canvas_(canvas) {}
|
|
~CountdownAnimatorCallback() override {}
|
|
void Callback(OHOS::UIView *view) override;
|
|
void NotifyStart();
|
|
void SetInfo(OHOS::UILabel *label, int counts);
|
|
|
|
private:
|
|
void CountingDown();
|
|
void UpdatePath(int16_t start, int16_t end, bool needDrawCircle);
|
|
void UpdateLable(uint32_t curTime);
|
|
void CircleFadeOut();
|
|
void GradualCircle();
|
|
OHOS::UICanvasExt *canvas_ = nullptr;
|
|
OHOS::UILabel *label_ = nullptr;
|
|
bool updateText_ = false;
|
|
bool firstArc_ = false;
|
|
countStage stage_ = countStage::STAGE_NONE;
|
|
int16_t endAngle_ = 0;
|
|
int16_t easeDegree_ = 0;
|
|
uint16_t idleTime_ = 0;
|
|
int16_t counts_ = 0;
|
|
uint32_t lastTime_ = 0;
|
|
uint32_t degreePerSecond_ = 0;
|
|
uint32_t surplusDegree = 0;
|
|
};
|
|
|
|
class CountDownView : public SportViewBase
|
|
{
|
|
public:
|
|
explicit CountDownView();
|
|
~CountDownView();
|
|
void ShowView();
|
|
void HideView();
|
|
static CountDownView *GetInstance();
|
|
void CountDownViewRefresh(SportTypeIndex index);
|
|
OHOS::Animator *GetCountdownAnimator() { return countdownAnimator_; }
|
|
|
|
private:
|
|
OHOS::UILabel listlTitle_;
|
|
OHOS::UILabel label_;
|
|
OHOS::UIImageView imgSport_;
|
|
OHOS::UICanvasExt *canvas_ = nullptr;
|
|
OHOS::Animator *countdownAnimator_ = nullptr;
|
|
CountdownAnimatorCallback *callBack_ = nullptr;
|
|
};
|
|
|
|
#pragma endregion
|
|
|
|
#pragma region GPS定位界面GPSView
|
|
// class GPSOnkeyActListener : public OHOS::RootView::OnKeyActListener
|
|
// {
|
|
// public:
|
|
// GPSOnkeyActListener(){};
|
|
// ~GPSOnkeyActListener() {};
|
|
// private:
|
|
// bool OnKeyAct(OHOS::UIView& view, const OHOS::KeyEvent& event);
|
|
// };
|
|
class GPSIconOnClickListener : public OHOS::UIView::OnClickListener
|
|
{
|
|
public:
|
|
GPSIconOnClickListener() {}
|
|
virtual ~GPSIconOnClickListener() {}
|
|
virtual bool OnClick(OHOS::UIView &view, const OHOS::ClickEvent &event);
|
|
|
|
private:
|
|
};
|
|
|
|
class Signal : public OHOS::UIViewGroup
|
|
{
|
|
public:
|
|
Signal();
|
|
~Signal() { RemoveAll(); }
|
|
void RefreshSignal(int signal);
|
|
|
|
private:
|
|
OHOS::UIView signalLow_;
|
|
OHOS::UIView signalMiddle_;
|
|
OHOS::UIView signalHigh_;
|
|
};
|
|
|
|
class GPSView : public SportViewBase
|
|
{
|
|
public:
|
|
explicit GPSView(SportTypeIndex iconIndex);
|
|
~GPSView();
|
|
static GPSView *GetInstance();
|
|
void GPSViewRefresh(SportTypeIndex index);
|
|
void GPSViewDataRefresh(void);
|
|
void GPSPossitionSuccessRefresh();
|
|
void ShowView();
|
|
void HideView();
|
|
|
|
private:
|
|
Signal signal_;
|
|
OHOS::UILabel GPSTitle_;
|
|
OHOS::UILabelExt GPSTip_;
|
|
OHOS::UILabelExt GPSTip1_;
|
|
OHOS::UILabel hrValue_;
|
|
OHOS::UIImageView hrIcon_;
|
|
// OHOS::UIImageView signal_;
|
|
OHOS::UIImageView SportIcon_;
|
|
OHOS::UIImageView imgBat_;
|
|
OHOS::UILabel batValue_;
|
|
GPSIconOnClickListener GPSIconOnClickListener_;
|
|
// GPSOnkeyActListener GPSOnkeyActListener_;
|
|
};
|
|
|
|
#pragma endregion
|
|
|
|
#pragma region 运动进行中SportingView
|
|
class ImgEndOnTouchListener : public OHOS::UIView::OnTouchListener
|
|
{
|
|
public:
|
|
ImgEndOnTouchListener();
|
|
virtual ~ImgEndOnTouchListener();
|
|
virtual bool OnPress(OHOS::UIView &view, const OHOS::PressEvent &event);
|
|
virtual bool OnRelease(OHOS::UIView &view, const OHOS::ReleaseEvent &event);
|
|
virtual bool OnCancel(OHOS::UIView &view, const OHOS::CancelEvent &event);
|
|
|
|
private:
|
|
OHOS::ImageInfo *pressImgSrc_ = nullptr;
|
|
OHOS::ImageInfo *releaseImgSrc_ = nullptr;
|
|
};
|
|
|
|
enum SportType
|
|
{
|
|
SPORT_TYPE_1, // 有数据:心率、距离、时间、步数、热量的运动类别显示此页面
|
|
SPORT_TYPE_2, // 有数据:心率、距离、时间、热量的运动类别显示此页面
|
|
SPORT_TYPE_3, // 有数据:心率、时间、热量的运动类别显示此页面
|
|
SPORT_TYPE_MAX
|
|
};
|
|
|
|
class StopAnimatorCallback : public OHOS::AnimatorCallback
|
|
{
|
|
public:
|
|
StopAnimatorCallback(OHOS::UICanvasExt *canvas) : animator_(nullptr), canvas_(canvas)
|
|
{
|
|
paint_.SetStyle(OHOS::Paint::PaintStyle::STROKE_STYLE);
|
|
paint_.SetStrokeWidth(10);
|
|
paint_.SetAntialiased(true);
|
|
paint_.SetCapType(OHOS::CapType::CAP_ROUND);
|
|
};
|
|
void SetAnimator(OHOS::Animator *animator) { animator_ = animator; }
|
|
virtual void Callback(OHOS::UIView *view) override;
|
|
virtual void OnStop(OHOS::UIView &view) override;
|
|
|
|
private:
|
|
OHOS::Animator *animator_;
|
|
OHOS::UICanvasExt *canvas_;
|
|
OHOS::PaintExt paint_;
|
|
};
|
|
|
|
// class GPSViewListener : public OHOS::UISwipeView::OnSwipeListener
|
|
// {
|
|
// GPSViewListener() {}
|
|
// ~GPSViewListener() {}
|
|
// virtual bool OnSwipe(OHOS::UISwipeView &swipeView, int16_t direction) override;
|
|
// }
|
|
|
|
class SportingView : public SportViewBase
|
|
{
|
|
public:
|
|
SportingView();
|
|
~SportingView();
|
|
static SportingView *GetInstance();
|
|
void ShowView();
|
|
void HideView();
|
|
void SportingViewRefresh();
|
|
void SportingViewDateRefresh(SportingData_t curSportingData);
|
|
OHOS::UIViewGroup *InitsportingDataRecordView(OHOS::UIViewGroup **sportingDataRecordView_, SportTypeIndex index);
|
|
OHOS::UIViewGroup *InitSportingPauseOrContinueView(OHOS::UIViewGroup **sportingPauseOrContinueView_);
|
|
OHOS::UIViewGroup *InitSportingGPSView(OHOS::UIViewGroup **sportingGPSView_);
|
|
const char *GetSportingRtcLabelText() { return sportingRtcLabel_.GetText(); };
|
|
void SetSportingRtcLabelText(Time currentTime);
|
|
void SetSportingRtcLabelText(const char *text) { sportingRtcLabel_.SetText(text); };
|
|
void ResetSwipeView()
|
|
{
|
|
swipeMainView_->SetCurrentPage(1);
|
|
};
|
|
OHOS::UICircleProgress *GetLongPressCircleProgress() { return &LongPressCircleProgress_; };
|
|
void SetPauseOrContinueCheckBoxState(bool state)
|
|
{
|
|
pauseOrContinueCheckBox_.SetState((OHOS::UICheckBox::UICheckBoxState)state);
|
|
};
|
|
void SetSwipeViewDraggable(bool draggable)
|
|
{
|
|
// swipeView_->SetDraggable(draggable);
|
|
};
|
|
void GPSCanvasAutoCenter();
|
|
void ShowGPSTrackView(bool exit);
|
|
void HideGPSTrackView();
|
|
OHOS::UICanvas GetGPSCanvas(void) {return gpsCanvas_;};
|
|
std::vector<Coordinate> &GetTrajectory() { return trajectory; }
|
|
void UpdateGPSTrack(OHOS::UICanvas* canvas,std::vector<Coordinate> &trajectory);
|
|
static int lastTime;
|
|
static SportType sportType; // 记录当前运动类别
|
|
uint32_t GetStep();
|
|
friend class EndOfSportDataView;
|
|
friend class TjdUiAppSportModel;
|
|
friend class ImgEndOnTouchListener;
|
|
std::vector<Coordinate> trajectory;
|
|
private:
|
|
// OHOS::GraphicTimer *timerOutRemindTimer_ = nullptr;
|
|
// OHOS::GraphicTimer *forceTimerOutRemindTimer_ = nullptr;
|
|
// OHOS::GraphicTimer *autoEndSportTimer_ = nullptr;
|
|
StopAnimatorCallback *stopAnimatorCallback_ = nullptr;
|
|
OHOS::UICanvasExt canvas_;
|
|
OHOS::Animator *animator_ = nullptr;
|
|
// dataView
|
|
OHOS::UILabel sportingRtcLabel_;
|
|
OHOS::UILabelExt sportingTimeLabel_;
|
|
OHOS::UIImageView imgSportIcon_;
|
|
OHOS::UIImageView imgHr01;
|
|
OHOS::UIImageView imgHr02;
|
|
OHOS::UIImageView imgHr03;
|
|
OHOS::UIImageView imgHr04;
|
|
OHOS::UIImageView imgHr05;
|
|
OHOS::UIImageView imgHrIcon_;
|
|
OHOS::UIImageView imgCaloriesIcon_;
|
|
OHOS::UIImageView imgPoint_;
|
|
OHOS::UILabel stepLabel_;
|
|
OHOS::UILabel distanceLabel_;
|
|
OHOS::UILabel caloriesLabel_;
|
|
OHOS::UILabel heartRateLabel_;
|
|
OHOS::UILabelExt stepUnitLabel_;
|
|
OHOS::UILabelExt distanceUnitLabel_;
|
|
OHOS::UILabelExt caloriesUnitLabel_;
|
|
OHOS::UILabelExt heartRateUnitLabel_;
|
|
OHOS::UIView sportingPage;
|
|
OHOS::UIView lastPage;
|
|
OHOS::UIView firstInterval;
|
|
OHOS::UIView secondInterval;
|
|
const OHOS::Vector2<float> VIEW_CENTER = {233, 233};
|
|
|
|
// pauseOrContinueView
|
|
OHOS::UIImageView imgEnd_;
|
|
OHOS::UICheckBox pauseOrContinueCheckBox_;
|
|
OHOS::UICircleProgress LongPressCircleProgress_;
|
|
OHOS::UIView PauseOrContinuePage;
|
|
OHOS::UIView prePage;
|
|
ImgEndOnTouchListener *imgEndOnTouchListener_{nullptr};
|
|
SportViewOnClickedListener *sportViewOnClickedListener_{nullptr};
|
|
|
|
// mainView
|
|
OHOS::UISwipeView *swipeMainView_{nullptr};
|
|
OHOS::UISwipeView *swipeGPSView_{nullptr};
|
|
// OHOS::UISwipeView::OnSwipeListener *onSwipeListener_{nullptr};
|
|
UIView::OnDragListener *OnDragListener_{nullptr};
|
|
UIView::OnClickListener *onClickListener_{nullptr};
|
|
OHOS::UIViewGroup *sportingDataRecordView_{nullptr};
|
|
OHOS::UIViewGroup *sportingPauseOrContinueView_{nullptr};
|
|
OHOS::UIViewGroup *sportingGPSView_{nullptr};
|
|
OHOS::UIViewGroup *containerView_{nullptr};
|
|
//gpsTrack
|
|
OHOS::GraphicTimer *gpsTrackTimer_ = nullptr; // 运动进行中计时器
|
|
OHOS::Animator *trackAnimator_ = nullptr;
|
|
OHOS::UICanvas gpsCanvas_;
|
|
OHOS::UIImageView imgShrink_;
|
|
OHOS::UIImageView imgEnlarge_;
|
|
OHOS::UIImageView imgDestination_;
|
|
OHOS::UIImageView imgState_;
|
|
OHOS::UILabelExt lbState_;
|
|
SportViewOnClickedListener GPSTrackListener_;
|
|
|
|
double distance;
|
|
uint32_t calories;
|
|
uint32_t step;
|
|
int hours;
|
|
int minutes;
|
|
int seconds;
|
|
};
|
|
#pragma endregion
|
|
|
|
#pragma region 运动结束无数据界面EndOfSportNoDataView
|
|
class EndOfSportNoDataView : public SportViewBase
|
|
{
|
|
public:
|
|
EndOfSportNoDataView();
|
|
~EndOfSportNoDataView();
|
|
// static EndOfSportNoDataView *GetInstance();
|
|
void ShowView();
|
|
private:
|
|
OHOS::UILabelExt remindLabel_;
|
|
OHOS::UILabelExt remindLabelTip_;
|
|
OHOS::UIImageView imgConfirm_;
|
|
SportViewOnClickedListener noDataViewOnClickedListener_;
|
|
};
|
|
#pragma endregion
|
|
|
|
#pragma region 运动结束数据界面EndOfSportDataView
|
|
class EndOfSportDataView : public SportViewBase
|
|
{
|
|
public:
|
|
EndOfSportDataView();
|
|
~EndOfSportDataView();
|
|
static EndOfSportDataView *GetInstance();
|
|
void InitView(void);
|
|
void DrawSportTrack(std::vector<Coordinate> trajectory);
|
|
OHOS::Point latLonToScreen(const Coordinate &coordinate, double minLat, double maxLat, double minLon, double maxLon,
|
|
int screenWidth, int screenHeight);
|
|
void EndOfSportDataViewRefresh(std::string fileName);
|
|
void ShowView();
|
|
// void HideView()
|
|
void ChangeSportType(SportType type);
|
|
OHOS::UIScrollView GPSMap_;
|
|
OHOS::UIScrollView DataView_;
|
|
friend class TjdUiAppSportModel;
|
|
|
|
private:
|
|
uint16_t TEMP_HEIGHT = 0;
|
|
OHOS::UICanvas canvas_;
|
|
OHOS::UILabelExt dataViewTitlie_;
|
|
OHOS::UIImageView SportIcon_;
|
|
OHOS::UIImageView sportTimeIcon_;
|
|
OHOS::UIImageView heartRateIcon_;
|
|
OHOS::UIImageView calorieIcon_;
|
|
OHOS::UIImageView sportDistanceIcon_;
|
|
OHOS::UIImageView speedIcon_;
|
|
OHOS::UIImageView stepIcon_;
|
|
OHOS::UIImageView stepFrequencyIcon_;
|
|
OHOS::UILabelExt sportTimeLabel_;
|
|
OHOS::UILabel curSportTime_;
|
|
OHOS::UILabelExt averageHeartRateLabel_;
|
|
OHOS::UILabel curAverageHeartRate_;
|
|
OHOS::UILabel curAverageHeartRateUnitLabel_;
|
|
OHOS::UILabelExt calorieLabel_;
|
|
OHOS::UILabel curCalorie_;
|
|
OHOS::UILabel curCalorieUnitLabel_;
|
|
OHOS::UILabelExt sportDistanceLabel_;
|
|
OHOS::UILabel curSportDistance_;
|
|
OHOS::UILabel curSportDistanceUnitLabel_;
|
|
OHOS::UILabelExt speed_;
|
|
OHOS::UILabel curSpeed_;
|
|
OHOS::UILabel curSpeedUnitLabel_;
|
|
OHOS::UILabelExt curStepLabel_;
|
|
OHOS::UILabel curStep_;
|
|
OHOS::UILabel curStepUnitLabel_;
|
|
OHOS::UILabelExt stepFrequencyLabel_;
|
|
OHOS::UILabel curStepFrequency_;
|
|
OHOS::UILabel curStepFrequencyUnitLabel_;
|
|
OHOS::UIImageView imgConfirm_;
|
|
SportViewOnClickedListener dataViewOnClickedListener_;
|
|
};
|
|
#pragma endregion
|
|
|
|
#pragma region 运动编辑
|
|
class EditSportView : public SportViewBase
|
|
{
|
|
public:
|
|
EditSportView();
|
|
~EditSportView();
|
|
static EditSportView *GetInstance(void);
|
|
void ShowView();
|
|
void HideView();
|
|
// void InitEditSportView();
|
|
friend class EditListScrollListener;
|
|
|
|
TjdUITransformListGroup *editListView_{nullptr};
|
|
TjdUITransformListGroupAdapter<EditItemInfo, EditCaseItemView, std::list<EditItemInfo>> *editListAdapterPtr_{
|
|
nullptr};
|
|
|
|
private:
|
|
OHOS::UILabelExt editTitle_;
|
|
OHOS::UITransformList *editList_{nullptr};
|
|
};
|
|
|
|
#pragma endregion
|
|
|
|
#pragma region == = 运动数据初始化 == ==
|
|
// clang-format off
|
|
|
|
#pragma endregion
|
|
|
|
bool GetIfReturnToDial(OHOS::ImageInfo **imgInfo);
|
|
} // namespace TJD
|
|
|
|
|
|
|
|
#endif |