From b4e7a7d9b8d65fae2ab6843238a93c8511bf4103 Mon Sep 17 00:00:00 2001 From: Caisking <3449750381@qq.com> Date: Sat, 17 Aug 2024 18:30:26 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=AE=E6=94=B9=E7=9C=81=E7=94=B5=E6=A8=A1?= =?utf8?q?=E5=BC=8F=E8=A1=A8=E7=9B=98UI?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../saveele/include/SaveBatPresenter.h | 11 +- .../nativeui/saveele/include/SaveBatView.h | 23 ++-- .../nativeui/saveele/include/SaveEleModel.h | 58 ++++++---- .../nativeui/saveele/src/SaveBatPresenter.cpp | 36 ++++-- .../nativeui/saveele/src/SaveBatView.cpp | 105 +++++++++++++++++- .../nativeui/saveele/src/SaveEleModel.cpp | 14 ++- 6 files changed, 202 insertions(+), 45 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h index aa35ea550..79cba458e 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-17 16:00:26 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatPresenter.h + */ #ifndef _SAVEBAT_PRESENTER_H #define _SAVEBAT_PRESENTER_H @@ -14,7 +20,8 @@ namespace OHOS public UIView::OnClickListener, public UIView::OnDragListener, public UIView::OnLongPressListener, - public ModelListenerSample + public ModelListenerSample, + public UIView::OnTouchListener { public: SaveBatPresenter(); @@ -34,6 +41,8 @@ namespace OHOS bool OnClick(UIView &view, const ClickEvent &event) override; bool OnDrag(UIView &view, const DragEvent &event) override; bool OnLongPress(UIView &view, const LongPressEvent &event); + bool OnPress(UIView &view, const PressEvent &event); + bool OnRelease(UIView &view, const ReleaseEvent &event); }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h index 5f563e6ab..1b6be41d9 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveBatView.h @@ -18,6 +18,8 @@ #include "components/ui_button.h" #include "components/ui_digital_clock.h" #include "components/ui_box_progress.h" +#include "components/ui_circle_progress.h" + #include "SaveBatPresenter.h" #include @@ -42,25 +44,32 @@ namespace OHOS UIView *GetView(); void RefreshView(); + void InitBatteryView(); void InitTimeView(); void InitButtonView(); + void InitShowBackView(); + + void UpdateView(); private: UIView::OnDragListener *draglistener{nullptr}; SaveBatView(SaveBatView &&) = delete; SaveBatView &operator=(SaveBatView &&) = delete; - - UILabel *timelabel = nullptr; // 时间 - UILabel *datelabel = nullptr; // 日期标签 - UILabel *weeklabel = nullptr; // 星期标签 - + /*省电界面*/ + UILabel *timelabel = nullptr; // 时间 + UILabel *datelabel = nullptr; // 日期标签 + UILabel *weeklabel = nullptr; // 星期标签 UILabel *batterylabel = nullptr; // 电量标签 UIBoxProgress *batteryprogress{nullptr}; // 电池进度条 UIImageView *batteryiamge = nullptr; // 电池框图标 - - UIButton *button_exit = nullptr; // 退出按键 + UIButton *button_exit = nullptr; // 退出按键 + /*退出界面*/ + UILabel *curren_timelabel{nullptr}; + UILabel *countlabel{nullptr}; + UIImageView *wathchiamge = nullptr; + UICircleProgress *backprogress{nullptr}; }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleModel.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleModel.h index 1d056ce5d..044c0734a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleModel.h +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleModel.h @@ -1,24 +1,36 @@ +#ifndef SAVE_ELE_MODEL_H +#define SAVE_ELE_MODEL_H -#ifndef SaveEle_MODEL_H -#define SaveEle_MODEL_H - -namespace OHOS -{ - class SaveEleModel - { - public: - static SaveEleModel *GetInstance(void); - int GetChargeStuaut(); - void SetChargeStuaut(int chargestuaut); - - private: - SaveEleModel() = default; - ~SaveEleModel() {} - SaveEleModel(const SaveEleModel &) = delete; - SaveEleModel &operator=(const SaveEleModel &) = delete; - - int ChargeStuaut = 0; // 充电状态 - }; -} - -#endif \ No newline at end of file +namespace OHOS +{ + class SaveEleModel + { + public: + // 获取单例实例 + static SaveEleModel *GetInstance(); + + // 获取充电状态 + int GetChargeStatus(); + + // 设置充电状态 + void SetChargeStatus(int chargeStatus); + + // 获取视图状态 + bool GetViewState() const { return viewState; } + + // 设置视图状态 + void SetViewState(bool state) { viewState = state; } + + private: + SaveEleModel() = default; // 默认构造函数 + ~SaveEleModel() {} // 默认析构函数 + + SaveEleModel(const SaveEleModel &) = delete; // 禁止拷贝构造 + SaveEleModel &operator=(const SaveEleModel &) = delete; // 禁止赋值操作 + + int chargeStatus = 0; // 充电状态 + bool viewState{false}; // 视图状态 + }; +} + +#endif // SAVE_ELE_MODEL_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp index c6bdb4609..349b5690d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp @@ -1,17 +1,19 @@ -/*** +/*** * @Date: 2024-04-15 10:55:58 * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-08-17 11:49:58 + * @LastEditTime: 2024-08-17 15:08:53 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatPresenter.cpp */ #include "AppViewIDs.h" #include "components/ui_label_ext.h" -#include"ui_resource_string.h" +#include "ui_resource_string.h" #include "NativeAbility.h" #include "saveele/include/SaveBatPresenter.h" #include "saveele/include/SaveEleModel.h" + +#include "string.h" namespace OHOS { @@ -56,7 +58,7 @@ namespace OHOS void SaveBatPresenter::OnStop(void) { - + SaveEleModel::GetInstance()->SetViewState(false); Presenter::OnStop(); } @@ -69,12 +71,17 @@ namespace OHOS bool SaveBatPresenter::OnClick(UIView &view, const ClickEvent &event) { - + if (strcmp(view.GetViewId(), "button_exit") == 0) + { + /*点击*/ + bool state = SaveEleModel::GetInstance()->GetViewState(); + SaveEleModel::GetInstance()->SetViewState(!state); + SaveBatView::GetInstance()->UpdateView(); + } return true; } bool SaveBatPresenter::OnLongPress(UIView &view, const LongPressEvent &event) { - // 1.长按三秒button1 // 2.退出 button1NativeAbility::GetInstance().ChangeSlice(VIEW_SAVEELE); // 3.返回 true 以消耗点击事件 if (strcmp(view.GetViewId(), "button_exit") == 0) @@ -83,9 +90,24 @@ namespace OHOS } return true; } + bool SaveBatPresenter::OnPress(UIView &view, const PressEvent &event) + { + + return true; + } + bool SaveBatPresenter::OnRelease(UIView &view, const ReleaseEvent &event) + { + if (strcmp(view.GetViewId(), "button_exit") == 0) + { + /*释放*/ + SaveEleModel::GetInstance()->SetViewState(false); + SaveBatView::GetInstance()->UpdateView(); + } + return true; + } void SaveBatPresenter::ExitView(void) { - if (SaveEleModel::GetInstance()->GetChargeStuaut()) + if (SaveEleModel::GetInstance()->GetChargeStatus()) { NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); } diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp index bf4bb482a..e0a4b44e4 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveBatView.cpp @@ -1,6 +1,7 @@ #include "saveele/include/SaveBatView.h" +#include "saveele/include/SaveEleModel.h" #include "common/image_cache_manager.h" #include "UiConfig.h" @@ -24,6 +25,8 @@ std::string Cnweekday[] = {"周天", "周一", "周二", "周三", "周四", " static constexpr const char *WHITE_BATTERY = "/user/res/Battery/Battery-E.bin"; static constexpr const char *SAVE_BUTTON = "/user/res/Save_Ele/finger.bin"; +static constexpr const char *BACK_BUTTON = "/user/res/Save_Ele/finger2.bin"; +static constexpr const char *SAVE_WATHCH = "/user/res/Save_Ele/wathch.bin"; namespace OHOS { @@ -76,7 +79,7 @@ namespace OHOS // 构建日期和时间字符串 std::string dateStr = (month < 10 ? "0" : "") + std::to_string(month) + "-" + - (day < 10 ? "0" : "") + std::to_string(day)+" "+weekStr; + (day < 10 ? "0" : "") + std::to_string(day) + " " + weekStr; std::string stringtime = (hour < 10 ? "0" : "") + std::to_string(hour) + ":" + @@ -195,9 +198,105 @@ namespace OHOS button_exit->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff000000, UIButton::PRESSED); button_exit->SetOnLongPressListener(presenter_); + // button_exit->SetOnClickListener(presenter_); container_->Add(button_exit); } + void SaveBatView::InitShowBackView() + { + // 时间 + if (curren_timelabel == nullptr) + { + curren_timelabel = new UILabel(); + } + curren_timelabel->SetPosition(181, 52); + curren_timelabel->Resize(200, 60); + curren_timelabel->SetViewId("label4"); + curren_timelabel->SetStyle(STYLE_TEXT_FONT, 40); + curren_timelabel->SetText("12:10"); + curren_timelabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + curren_timelabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + curren_timelabel->SetRollSpeed(0); + curren_timelabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + container_->Add(curren_timelabel); + curren_timelabel->SetVisible(false); + + // 圆形进度条 + if (backprogress == nullptr) + { + backprogress = new UICircleProgress(); + } + backprogress->SetPosition(143, 143); + backprogress->Resize(183, 186); + backprogress->SetViewId("circleProgress1"); + backprogress->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + backprogress->SetBackgroundStyle(STYLE_BACKGROUND_COLOR, 0xff000000); + backprogress->SetBackgroundStyle(STYLE_LINE_WIDTH, 20); + backprogress->SetForegroundStyle(STYLE_BACKGROUND_COLOR, 0xff2195F6); + backprogress->SetForegroundStyle(STYLE_BORDER_COLOR, 0xff000000); + backprogress->SetForegroundStyle(STYLE_LINE_COLOR, 0xff18ef05); + backprogress->SetForegroundStyle(STYLE_LINE_WIDTH, 20); + backprogress->SetCenterPosition(92, 93); + backprogress->SetRadius(90); + backprogress->SetEndAngle(359); + backprogress->SetValue(30); + container_->Add(backprogress); + backprogress->SetVisible(false); + + // 手表image + if (wathchiamge == nullptr) + { + wathchiamge = new UIImageView(); + } + wathchiamge->SetPosition(188, 182); + wathchiamge->Resize(100, 100); + wathchiamge->SetViewId("image1"); + wathchiamge->SetSrc(SAVE_WATHCH); + container_->Add(wathchiamge); + wathchiamge->SetVisible(false); + + // 倒计时 + if (countlabel == nullptr) + { + countlabel = new UILabel(); + } + countlabel->SetPosition(221, 212); + countlabel->Resize(200, 60); + countlabel->SetViewId("label3"); + countlabel->SetStyle(STYLE_TEXT_FONT, 40); + countlabel->SetText("3"); + countlabel->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); + countlabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + countlabel->SetRollSpeed(0); + countlabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 40); + container_->Add(countlabel); + countlabel->SetVisible(false); + } + // 更新当前界面状态 + void SaveBatView ::UpdateView() + { + bool state = SaveEleModel::GetInstance()->GetViewState(); + + /*原界面*/ + timelabel->SetVisible(!state); + datelabel->SetVisible(!state); + weeklabel->SetVisible(!state); + batterylabel->SetVisible(!state); + batteryprogress->SetVisible(!state); + batteryiamge->SetVisible(!state); + + /*退出界面*/ + curren_timelabel->SetVisible(state); + countlabel->SetVisible(state); + wathchiamge->SetVisible(state); + backprogress->SetVisible(state); + /* + if (state) + button_exit->SetImageSrc(BACK_BUTTON, BACK_BUTTON); + else + button_exit->SetImageSrc(SAVE_BUTTON, SAVE_BUTTON); + */ + } void SaveBatView::OnStart() { container_ = new UIViewGroup(); @@ -205,6 +304,7 @@ namespace OHOS { return; } + container_->SetPosition(0, 0); container_->SetWidth(Screen::GetInstance().GetWidth()); container_->SetHeight(Screen::GetInstance().GetHeight()); @@ -214,20 +314,19 @@ namespace OHOS InitBatteryView(); InitTimeView(); InitButtonView(); + // InitShowBackView(); RootView::GetInstance()->Add(container_); } void SaveBatView::OnSetUpView() { - View::OnSetUpView(); Draw(); } void SaveBatView::OnTearDownView() { - View::OnTearDownView(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleModel.cpp index 8f7d9f698..072adcfcd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleModel.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleModel.cpp @@ -1,3 +1,9 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-17 16:15:17 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleModel.cpp + */ #include "saveele/include/SaveEleModel.h" namespace OHOS @@ -8,12 +14,12 @@ namespace OHOS static SaveEleModel instance; return &instance; } - int SaveEleModel::GetChargeStuaut() + int SaveEleModel::GetChargeStatus() { - return ChargeStuaut; + return chargeStatus; } - void SaveEleModel::SetChargeStuaut(int chargestuaut) + void SaveEleModel::SetChargeStatus(int chargeStatus) { - ChargeStuaut = chargestuaut; + chargeStatus = chargeStatus; } } \ No newline at end of file -- 2.17.1