VIEW_REBOOTANDSHUTDOWN, //(关机或重启界面)
VIEW_RECORD, // 录音
VIEW_MUSIC_PLAYER, // 音乐播放器
+ VIEW_STRESS_TEST, // 压力测试
/* --------------------------------------------------------------------------*/
// 合并不清晰viewid
--- /dev/null
+#ifndef STRESS_TEST_MAIN_VIEW_H
+#define STRESS_TEST_MAIN_VIEW_H
+
+#include "View.h"
+#include "stress/include/stressTestPresenter.h"
+#include "components/ui_view_group.h"
+#include "stress/include/stressTestStandbyView.h"
+namespace OHOS
+{
+ typedef enum
+ {
+ STRESSTESTIDLEVIEW = 0, // 压力测试待机视图
+ STRESSTESTVIEW, // 压力测试视图
+ STRESSTESTRESULTVIEW, // 压力测试结果视图
+ STRESSTESTFAILVIEW, // 压力测试失败视图
+ MAX_STRESSTESTMAINVIEW,
+ } StressTestMainViewId;
+
+ class StressTestPresenter;
+ class StressTestMainView : public View<StressTestPresenter>
+ {
+ public:
+ StressTestMainView();
+ ~StressTestMainView();
+ static StressTestMainView *GetInstance(void);
+
+ bool ClickFunc(int16_t interface);
+ bool CheckViewParam(int16_t hideView, int16_t showView);
+ void ChangeView(int16_t hideView, int16_t showView);
+ bool ChangeStressTestIdleView(int16_t thisView);
+ bool ChangeStressTestView(int16_t thisView);
+ bool ChangeStressTestResultView(int16_t thisView);
+ bool ChangeStressTestFailView(int16_t thisView);
+ void OnStart() override;
+ private:
+ StressTestStandbyView *standbyView{nullptr};
+ // StressTestView stressTestView{nullptr};
+ // StressTestResultView stressTestResultView{nullptr};
+ // StressTestFailView stressTestFailView{nullptr};
+
+ private:
+ void ClearAll(void);
+
+ UIViewGroup *group[MAX_STRESSTESTMAINVIEW]{nullptr};
+ };
+}
+#endif
\ No newline at end of file
--- /dev/null
+#ifndef STRESS_TEST_MODEL_H
+#define STRESS_TEST_MODEL_H
+
+#include <inttypes.h>
+namespace OHOS
+{
+ class StressTestModel
+ {
+ public:
+ static StressTestModel &GetInstance(void);
+ uint8_t GetCurrentView(void);
+ void SetCurrentView(uint8_t view);
+ private:
+ StressTestModel();
+ ~StressTestModel();
+ StressTestModel(const StressTestModel &) = delete;
+ StressTestModel &operator=(const StressTestModel &) = delete;
+ uint8_t currentView{0};
+ };
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+#ifndef STRESS_TEST_PRESENTER_H
+#define STRESS_TEST_PRESENTER_H
+
+#include "Presenter.h"
+#include "stress/include/stressTestMainView.h"
+#include "key/include/KeyInputListener.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+ class StressTestMainView;
+ class StressTestPresenter : public Presenter<StressTestMainView>,
+ public UIView::OnClickListener,
+ public UIView::OnDragListener,
+ public RootView::OnKeyActListener
+ {
+ public:
+ StressTestPresenter();
+ virtual ~StressTestPresenter();
+ static StressTestPresenter *GetInstance();
+
+ void OnStart() override;
+
+ private:
+ bool OnClick(UIView &view, const ClickEvent &event) override;
+ bool OnDrag(UIView &view, const DragEvent &event) override;
+ bool OnDragEnd(UIView &view, const DragEvent &event) override;
+ bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+
+ bool X_DRAG_FLAG{false};
+ };
+}
+
+#endif
\ No newline at end of file
--- /dev/null
+#ifndef STRESS_TEST_STANDBY_VIEW_H
+#define STRESS_TEST_STANDBY_VIEW_H
+
+#include "components/ui_view_group.h"
+#include "components/ui_label_ext.h"
+#include "components/ui_image_view.h"
+#include "components/ui_label_button_ext.h"
+namespace OHOS
+{
+ static constexpr const char *STRESSTESTSTANDBYVIEW_ID = "STRESSTESTSTANDBYVIEW_ID";
+ static constexpr const char *START_TEST_BUTTON_ID = "START_TEST_BUTTON_ID";
+ class StressTestStandbyView
+ {
+ public:
+ StressTestStandbyView();
+ ~StressTestStandbyView();
+
+ void ClearAll(void);
+ UIViewGroup * CreateStressTestStandbyView(void);
+ private:
+ UIViewGroup *group{nullptr};
+ UILabelExt *titleLabel{nullptr};
+ UILabelExt *descriptionLabel{nullptr};
+ UIImageView *imageView{nullptr};
+ UILabelButtonExt *startTestButton{nullptr};
+ };
+}
+#endif
\ No newline at end of file
--- /dev/null
+#include "stress/include/stressTestMainView.h"
+#include "stress/include/stressTestPresenter.h"
+#include "stress/include/stressTestModel.h"
+
+
+namespace OHOS
+{
+
+ static StressTestMainView *g_pStressTestMainView{nullptr};
+ StressTestMainView::StressTestMainView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView::StressTestMainView");
+ g_pStressTestMainView = this;
+ // 初始化视图容器指针,避免首次进入读取未初始化内存
+ for (int i = 0; i < MAX_STRESSTESTMAINVIEW; i++)
+ {
+ group[i] = nullptr;
+ }
+ }
+
+ StressTestMainView::~StressTestMainView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView::~StressTestMainView");
+ ClearAll();
+ g_pStressTestMainView = nullptr;
+ }
+
+ StressTestMainView *StressTestMainView::GetInstance()
+ {
+ return g_pStressTestMainView;
+ }
+
+ void StressTestMainView::ClearAll(void)
+ {
+ if (standbyView != nullptr)
+ {
+ delete standbyView;
+ standbyView = nullptr;
+ }
+ for (int i = 0; i < MAX_STRESSTESTMAINVIEW; i++)
+ {
+ if (group[i] != nullptr)
+ {
+ group[i] = nullptr;
+ }
+ }
+ }
+
+ void StressTestMainView::OnStart()
+ {
+ ChangeView(MAX_STRESSTESTMAINVIEW, STRESSTESTIDLEVIEW);
+ }
+
+ bool StressTestMainView::ChangeStressTestIdleView(int16_t thisView)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView::ChangeStressTestIdleView %d", thisView);
+ if (group[thisView] == nullptr)
+ {
+ standbyView = new StressTestStandbyView();
+ if (standbyView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView:: new standbyView fail", thisView);
+ return false;
+ }
+ group[thisView] = standbyView->CreateStressTestStandbyView();
+ AddViewToRootContainer(group[thisView]);
+ }
+ return true;
+ }
+
+ bool StressTestMainView::ChangeStressTestView(int16_t thisView)
+ {
+ return true;
+ }
+
+ bool StressTestMainView::ChangeStressTestResultView(int16_t thisView)
+ {
+ return true;
+ }
+
+ bool StressTestMainView::ChangeStressTestFailView(int16_t thisView)
+ {
+ return true;
+ }
+
+ struct StressTestMainViewMapper
+ {
+ const int16_t viewId;
+ bool (StressTestMainView::*func)(int16_t thisView);
+ };
+
+ static const StressTestMainViewMapper ViewMapper[] = {
+ {STRESSTESTIDLEVIEW, &StressTestMainView::ChangeStressTestIdleView},
+ {STRESSTESTVIEW, &StressTestMainView::ChangeStressTestView},
+ {STRESSTESTRESULTVIEW, &StressTestMainView::ChangeStressTestResultView},
+ {STRESSTESTFAILVIEW, &StressTestMainView::ChangeStressTestFailView},
+ };
+
+ bool StressTestMainView::ClickFunc(int16_t interface)
+ {
+ int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]);
+ for (int i = 0; i < funcSize; i++)
+ {
+ if (interface == ViewMapper[i].viewId)
+ {
+ bool jug = (this->*(ViewMapper[i].func))(interface);
+ if (jug == false)
+ {
+ return false;
+ }
+ return true;
+ }
+ }
+ return false;
+ }
+
+ bool StressTestMainView::CheckViewParam(int16_t hideView, int16_t showView)
+ {
+ if (showView < 0 || showView >= MAX_STRESSTESTMAINVIEW)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView::CheckViewParam showView err.");
+ return false;
+ }
+
+ if (hideView < 0 || hideView > MAX_STRESSTESTMAINVIEW)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView::CheckViewParam hideView err.");
+ return false;
+ }
+
+ return true;
+ }
+
+ void StressTestMainView::ChangeView(int16_t hideView, int16_t showView)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView::ChangeView %d, %d", hideView, showView);
+ if (!CheckViewParam(hideView, showView))
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestMainView::CheckViewParam failed.");
+ return;
+ }
+ if (hideView != MAX_STRESSTESTMAINVIEW)
+ {
+ if (group[hideView] == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group[%d] is nullptr", hideView);
+ return;
+ }
+ group[hideView]->SetVisible(false);
+ }
+ ClickFunc(showView);
+ if (group[showView] != nullptr)
+ {
+ group[showView]->SetVisible(true);
+ }
+ else
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group[%d] is nullptr", showView);
+ }
+ Draw();
+ StressTestModel::GetInstance().SetCurrentView(showView);
+ }
+}
\ No newline at end of file
--- /dev/null
+#include "stress/include/stressTestModel.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+ StressTestModel::StressTestModel() {}
+ StressTestModel::~StressTestModel() {}
+ StressTestModel &StressTestModel::GetInstance()
+ {
+ static StressTestModel instance;
+ return instance;
+ }
+
+ uint8_t StressTestModel::GetCurrentView(void)
+ {
+ return currentView;
+ }
+
+ void StressTestModel::SetCurrentView(uint8_t view)
+ {
+ currentView = view;
+ }
+}
--- /dev/null
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "common/key_code.h"
+#include <custom_utils.h>
+#include "UiConfig.h"
+#include "stress/include/stressTestPresenter.h"
+#include "stress/include/stressTestMainView.h"
+#include "ui_resource_string.h"
+#include "NativeRegisterManager.h"
+
+namespace OHOS
+{
+
+ REGIST_MENU_PRO(VIEW_STRESS_TEST, StressTestMainView, StressTestPresenter,
+ PNG_APPLIST_MUSIC_IMAGE_BIG, PNG_APPLIST_MUSIC_IMAGE,PNG_APPLIST_MUSIC_IMAGE, "stress", STR_MUSIC);
+
+
+ // 当前Presenter属性实例化的内存指针
+ static StressTestPresenter *g_pStressTestPresenter = nullptr;
+ StressTestPresenter::StressTestPresenter()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestPresenter::StressTestPresenter");
+ g_pStressTestPresenter = this;
+ }
+
+ StressTestPresenter::~StressTestPresenter()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestPresenter::~StressTestPresenter");
+ g_pStressTestPresenter = nullptr;
+ }
+
+ StressTestPresenter *StressTestPresenter::GetInstance()
+ {
+ return g_pStressTestPresenter;
+ }
+
+ // 启动时执行的逻辑
+ void StressTestPresenter::OnStart()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StressTestPresenter::OnStart");
+ }
+
+
+ bool StressTestPresenter::OnClick(UIView &view, const ClickEvent &event)
+ {
+ UNUSED(event);
+ if (view.GetViewId() == START_TEST_BUTTON_ID)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestPresenter::OnClick start test");
+ }
+ return true;
+ }
+
+ bool StressTestPresenter::OnDrag(UIView &view, const DragEvent &event)
+ {
+ UNUSED(view);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StressTestPresenter::OnDrag");
+ if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+ {
+ StressTestPresenter::X_DRAG_FLAG = true;
+ }
+ return true;
+ }
+
+ bool StressTestPresenter::OnDragEnd(UIView &view, const DragEvent &event)
+ {
+ UNUSED(view);
+ if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && StressTestPresenter::X_DRAG_FLAG)
+ {
+ if (view.GetViewId() == STRESSTESTSTANDBYVIEW_ID)
+ {
+ NativeAbility::GetInstance().Back();
+ StressTestPresenter::X_DRAG_FLAG = false;
+ }
+ }
+ return true;
+ }
+
+ bool StressTestPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件
+ {
+ UNUSED(view);
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "StressTestPresenter::OnKeyAct");
+ uint16_t keyID = event.GetKeyId();
+ uint16_t keyState = event.GetState();
+ // 如果是power键,且是亮屏状态,按键释放就返回上一级
+ if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
+ {
+ NativeAbility::GetInstance().Back();
+ }
+ return true;
+ }
+}
\ No newline at end of file
--- /dev/null
+#include "stress/include/stressTestStandbyView.h"
+#include "stress/include/stressTestPresenter.h"
+
+namespace OHOS
+{
+ StressTestStandbyView::StressTestStandbyView()
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestStandbyView::StressTestStandbyView");
+ }
+
+ StressTestStandbyView::~StressTestStandbyView()
+ {
+ ClearAll();
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestStandbyView::~StressTestStandbyView");
+ }
+
+ void StressTestStandbyView::ClearAll(void)
+ {
+ if (group != nullptr)
+ {
+ group->RemoveAll();
+ delete group;
+ group = nullptr;
+ }
+ if (titleLabel != nullptr)
+ {
+ delete titleLabel;
+ titleLabel = nullptr;
+ }
+ if (descriptionLabel != nullptr)
+ {
+ delete descriptionLabel;
+ descriptionLabel = nullptr;
+ }
+ if (imageView != nullptr)
+ {
+ delete imageView;
+ imageView = nullptr;
+ }
+ if (startTestButton != nullptr)
+ {
+ delete startTestButton;
+ startTestButton = nullptr;
+ }
+ }
+
+ UIViewGroup * StressTestStandbyView::CreateStressTestStandbyView(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "StressTestStandbyView::CreateStressTestStandbyView");
+ if (group == nullptr)
+ {
+ group = new UIViewGroup();
+ if (group == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group new fail!!");
+ return nullptr;
+ }
+ group->SetPosition(0, 0, HORIZONTAL_RESOLUTION, VERTICAL_RESOLUTION);
+ group->SetViewId(STRESSTESTSTANDBYVIEW_ID);
+ group->SetTouchable(true);
+ group->SetDraggable(true);
+ group->SetOnDragListener((UIView::OnDragListener *)OHOS::StressTestPresenter::GetInstance());
+ }
+ if (titleLabel == nullptr)
+ {
+ titleLabel = new UILabelExt();
+ if (titleLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "titleLabel new fail!!");
+ return nullptr;
+ }
+ titleLabel->SetPosition(83, 50,300,35);
+ titleLabel->SetText("压力");
+ titleLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ titleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ titleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ titleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ titleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ titleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ group->Add(titleLabel);
+ }
+ if (imageView == nullptr)
+ {
+ imageView = new UIImageView();
+ if (imageView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "imageView new fail!!");
+ return nullptr;
+ }
+ imageView->SetPosition(158, 103,160,140);
+ imageView->SetSrc("/user/res/stress/STRESS_TEST_STANDBY.bin");
+ group->Add(imageView);
+ }
+ if (descriptionLabel == nullptr)
+ {
+ descriptionLabel = new UILabelExt();
+ if (descriptionLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "descriptionLabel new fail!!");
+ return nullptr;
+ }
+ descriptionLabel->SetPosition(53, 261,360,35);
+ descriptionLabel->SetText("状态正常 35ms");
+ descriptionLabel->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ descriptionLabel->SetTextColor(Color::GetColorFromRGBA(0x0f, 0xaf, 0xff, 0xff));
+ descriptionLabel->SetStyle(STYLE_TEXT_FONT, 30);
+ descriptionLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+ descriptionLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+ descriptionLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ descriptionLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ group->Add(descriptionLabel);
+ }
+ if (startTestButton == nullptr)
+ {
+ startTestButton = new UILabelButtonExt();
+ if (startTestButton == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startTestButton new fail!!");
+ return nullptr;
+ }
+ startTestButton->SetPosition(93, 330,280,90);
+ startTestButton->SetText("检测");
+ startTestButton->SetAlign(TEXT_ALIGNMENT_CENTER);
+ startTestButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+ startTestButton->SetViewId(START_TEST_BUTTON_ID);
+ startTestButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff0d62ff);
+ startTestButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED);
+ startTestButton->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
+ startTestButton->SetOnClickListener((UIView::OnClickListener *)OHOS::StressTestPresenter::GetInstance());
+ group->Add(startTestButton);
+ }
+ return group;
+ }
+}
\ No newline at end of file