mcu_hi3321_watch/tjd/ui/app/production/TjdUiAppProductView.h
2025-05-26 20:15:20 +08:00

439 lines
12 KiB
C++

#ifndef TJD_UI_APP_PRODUCT_VIEW_H
#define TJD_UI_APP_PRODUCT_VIEW_H
#include "TjdUiAppProductPresenter.h"
#include "TjdUiMultiLanguageExt.h"
#include "View.h"
#include "components/ui_canvas_ext.h"
#include "components/ui_checkbox.h"
#include "components/ui_image_view.h"
#include "components/ui_label.h"
#include "components/ui_label_button.h"
#include "components/ui_scroll_view.h"
#include "components/ui_view_group.h"
#include <cmath>
#include <list>
#include <unordered_set>
#include <vector>
#define PRODUCTION_TP_BTN_NUM 16
namespace TJD {
enum class GnssMsgType
{
GGA,
RMC,
GSV,
VTG,
ZDA,
MAX
};
class ProductViewBase : public OHOS::UIScrollView
{
public:
ProductViewBase() { SetHorizontalScrollState(false); }
virtual ~ProductViewBase() {}
virtual void ShowView() { SetVisible(true); };
virtual void HideView() { SetVisible(false); };
};
class ProductSelectListView : public ProductViewBase
{
public:
ProductSelectListView();
~ProductSelectListView() { RemoveAll(); }
private:
OHOS::UILabel title_;
OHOS::UILabelButton normalButton_;
OHOS::UILabelButton agingButton_;
OHOS::UILabelButton touchButton_;
OHOS::UILabelButton gpsButton_;
OHOS::UIImageView retButton_;
};
class ProductLcdTestView : public ProductViewBase
{
public:
ProductLcdTestView();
~ProductLcdTestView() { RemoveAll(); }
void SetLcdFullColor(uint32_t color);
};
class ProductTpTestView : public ProductViewBase
{
public:
ProductTpTestView();
~ProductTpTestView() { RemoveAll(); }
bool IsTpBtnSelectedAll(void);
void ClearTpBtnMap(void);
private:
class TpTestCheckBox : public OHOS::UIView
{
public:
TpTestCheckBox() : selectedColor_(0xff70B603), unselectedColor_(0)
{
touchable_ = true;
SetStyle(OHOS::STYLE_BACKGROUND_OPA, OHOS::OPA_OPAQUE);
}
virtual ~TpTestCheckBox() {}
void SetColor(uint32_t selectedColor, uint32_t unselectedColor)
{
selectedColor_ = selectedColor;
unselectedColor_ = unselectedColor;
InvalidateColor();
Invalidate();
}
void SetState(bool state)
{
state_ = state;
InvalidateColor();
}
bool GetState() { return state_; }
void ReverseState()
{
state_ = !state_;
InvalidateColor();
}
bool OnClickEvent(const OHOS::ClickEvent &event) override
{
if (!state_) {
state_ = true;
InvalidateColor();
Invalidate();
}
return OHOS::UIView::OnClickEvent(event);
}
private:
void InvalidateColor(void)
{
if (state_) {
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, selectedColor_);
} else {
SetStyle(OHOS::STYLE_BACKGROUND_COLOR, unselectedColor_);
}
}
bool state_{false};
uint32_t selectedColor_{0};
uint32_t unselectedColor_{0};
};
TpTestCheckBox tpTestButton_[PRODUCTION_TP_BTN_NUM];
};
struct PointHash
{
std::size_t operator()(const std::pair<int, int> &p) const
{
return std::hash<int>()(p.first) ^ std::hash<int>()(p.second);
}
};
class ProductTpSlideTestView : public ProductViewBase
{
public:
ProductTpSlideTestView();
~ProductTpSlideTestView() { RemoveAll(); }
bool IsTpTestOk(void);
void ClearTpTest(void);
void DragPos(OHOS::Point pos);
private:
bool IsPointInLine(OHOS::Point start, OHOS::Point end, OHOS::Point point, int width);
OHOS::UICanvasExt canvas_;
std::unordered_set<std::pair<int, int>, PointHash> draggedPoints_;
const int lineWidth_ = 45;
const int originalArea_ = 2 * (lineWidth_ * 466); // 两条线的近似面积
const double threshold_ = 0.8; // 80%的阈值
};
class ProductHeartRateTestView : public ProductViewBase
{
public:
ProductHeartRateTestView();
~ProductHeartRateTestView() { RemoveAll(); }
void SetValue(int value);
private:
OHOS::UILabel title_;
OHOS::UILabel value_;
OHOS::UILabel unit_;
OHOS::UIImageView nextButton_;
};
class ProductGSensorTestView : public ProductViewBase
{
public:
ProductGSensorTestView();
~ProductGSensorTestView() { RemoveAll(); }
void SetValue(int step, int16_t x, int16_t y, int16_t z);
private:
OHOS::UILabel title_;
OHOS::UILabel stepDesc_;
OHOS::UILabel stepValue_;
OHOS::UILabel value_;
OHOS::UIImageView nextButton_;
};
class ProductSpeakerTestView : public ProductViewBase
{
public:
ProductSpeakerTestView();
~ProductSpeakerTestView() { RemoveAll(); }
private:
OHOS::UILabel title_;
OHOS::UIImageView nextButton_;
OHOS::UILabelButton onceButton_;
OHOS::UILabelButton repeatButton_;
};
class ProductMotorTestView : public ProductViewBase
{
public:
ProductMotorTestView();
~ProductMotorTestView() { RemoveAll(); }
private:
OHOS::UILabel title_;
OHOS::UIImageView nextButton_;
OHOS::UILabelButton onceButton_;
OHOS::UILabelButton repeatButton_;
};
class ProductMicTestView : public ProductViewBase
{
public:
ProductMicTestView();
~ProductMicTestView() { RemoveAll(); }
private:
OHOS::UILabel title_;
OHOS::UIImageView nextButton_;
OHOS::UILabel desc_;
};
class ProductButtonTestView : public ProductViewBase
{
public:
ProductButtonTestView();
~ProductButtonTestView() { RemoveAll(); }
void SetRespButtonState(OHOS::UIButton::ButtonState state);
private:
OHOS::UILabel title_;
OHOS::UIImageView nextButton_;
OHOS::UILabelButton respButton_;
};
class ProductAgingTestChooseView : public ProductViewBase
{
public:
ProductAgingTestChooseView();
~ProductAgingTestChooseView() { RemoveAll(); }
void SetRecord(AngingTestResult &result);
bool IsLcdSelected(void) { return lcdCheckBox_.IsSelected(); }
bool IsHeartRateSelected(void) { return heartRateCheckBox_.IsSelected(); }
bool IsMotorSelected(void) { return motorCheckBox_.IsSelected(); }
bool IsSpeakerSelected(void) { return speakerCheckBox_.IsSelected(); }
private:
class AgingTestCheckBox : public OHOS::UIViewGroup
{
public:
AgingTestCheckBox()
{
touchable_ = true;
Resize(106, 32);
}
virtual ~AgingTestCheckBox() { RemoveAll(); }
void InitView(const char *desc);
void SetState(bool state)
{
checkBox_.SetState(state ? OHOS::UICheckBox::UICheckBoxState::SELECTED
: OHOS::UICheckBox::UICheckBoxState::UNSELECTED);
}
bool OnClickEvent(const OHOS::ClickEvent &event) override
{
checkBox_.OnClickEvent(event);
Invalidate();
return OHOS::UIView::OnClickEvent(event);
}
bool IsSelected(void) { return checkBox_.GetState() == OHOS::UICheckBox::UICheckBoxState::SELECTED; }
private:
OHOS::UICheckBox checkBox_;
OHOS::UILabel desc_;
};
OHOS::UILabel title_;
AgingTestCheckBox lcdCheckBox_;
AgingTestCheckBox heartRateCheckBox_;
AgingTestCheckBox motorCheckBox_;
AgingTestCheckBox speakerCheckBox_;
OHOS::UILabel lastTestTitle_;
OHOS::UILabel time_;
OHOS::UILabel power_;
OHOS::UILabel func_;
OHOS::UIImageView retButton_;
OHOS::UIImageView nextButton_;
};
class ProductAgingTestView : public ProductViewBase
{
public:
ProductAgingTestView();
~ProductAgingTestView() { RemoveAll(); }
void SetTime(uint32_t time);
void SetPower(int power);
void SetState(AngingTestItem &item);
void SetColor(uint32_t color);
void Reset(void);
private:
OHOS::UILabel power_;
OHOS::UILabel heartRateState_;
OHOS::UILabel motorState_;
OHOS::UILabel speakerState_;
OHOS::UILabel time_;
};
class ProductTpReportTestView : public ProductViewBase
{
public:
ProductTpReportTestView();
~ProductTpReportTestView() { RemoveAll(); }
void DragPos(OHOS::Point pos);
private:
OHOS::UICanvasExt canvas_;
OHOS::UILabel pointLabel_;
const int16_t lineLen = 200;
};
class TjdChartPlot : public OHOS::UIScrollView
{
public:
TjdChartPlot() {}
virtual ~TjdChartPlot();
void DrawPlot()
{
for (auto gsv : *gsvData) {
AddColumn(gsv.first, gsv.second);
}
}
void SetData(std::unordered_map<std::string, int> *data) { gsvData = data; };
void RefrashPlot();
private:
struct PlotUiView
{
OHOS::UIView *column_;
OHOS::UILabel *number_;
OHOS::UILabel *value_;
OHOS::UILabel *type_;
};
int16_t CalculateViewHeight(int value)
{
const int16_t height = GetHeight() * 3 / 5;
float percent = value / MaxValue_;
return (int16_t)(percent * height) * 4 / 5;
}
int16_t CalculateViewY(int viewHeight)
{
const int16_t height = GetHeight() * 4 / 6;
return height - viewHeight;
}
int GetStarNumber(const std::string &str)
{
std::string numberStr;
for (char ch : str) {
if (std::isdigit(ch)) {
numberStr += ch;
}
}
return numberStr.empty() ? 0 : std::stoi(numberStr);
}
std::string GetGnssType(const std::string &str)
{
if (str.length() < 2) {
return "";
}
return str.substr(0, 2);
}
void AddColumn(std::string number, int showValue);
float MaxValue_{50.0};
std::unordered_map<std::string, int> *gsvData;
std::unordered_map<std::string, PlotUiView> uiDataMap_;
int16_t currentPos_{0};
int16_t weight_{24};
int16_t interval_{5};
};
class ProductGPSTestView : public ProductViewBase
{
public:
ProductGPSTestView();
virtual ~ProductGPSTestView();
void SetData(std::unordered_map<std::string, int> *data) { plot.SetData(data); };
void RefrashPlot() { plot.RefrashPlot(); }
void SetState(const char *text);
void SetUsableStar(int value);
void SetVisibleStar(int value);
private:
TjdChartPlot plot;
OHOS::UILabel title;
OHOS::UILabel visibleStarDesc;
OHOS::UILabel visibleStarValue;
OHOS::UILabel usableStarDesc;
OHOS::UILabel usableStarValue;
OHOS::UILabel state;
OHOS::UIView line_;
};
class TjdUiAppProductPresenter;
class TjdUiAppProductView : public OHOS::View<TjdUiAppProductPresenter>
{
public:
TjdUiAppProductView();
~TjdUiAppProductView();
static TjdUiAppProductView *GetInstance(void);
void OnStart() override;
void OnStop() override;
void ShowView(ProductViewIndex showIndex);
static ProductViewIndex currentViewIndex_;
void SetLcdFullColor(uint32_t color);
void SetAgingTestColor(uint32_t color);
bool IsTpBtnSelectedAll();
void ClearTpBtnMap();
void DragTpSlidePos(OHOS::Point pos);
bool IsTpDragAllArea();
void SetHeartRateValue(int value);
void SetGSensorValue(int step, int16_t x, int16_t y, int16_t z);
void SetRespButtonState(OHOS::UIButton::ButtonState state);
AngingTestItem GetAgingTestItem(void);
void AngingSetStatus(AngingTestItem &item);
void AngingSetValue(int power, uint32_t time);
void AngingReset(void);
void AngingChooseSetRecord(AngingTestResult &result);
void RefrashGpsPlot();
void SetStarNumber(int usable, int visible);
void SetGpsState(const char *text);
private:
void InitTargetView(ProductViewIndex index);
OHOS::UIScrollView *mainView_{nullptr};
ProductViewBase *viewManager_[PRODUCT_UNKNOWN]{nullptr};
};
} // namespace TJD
#endif