From: Caisking <3449750381@qq.com> Date: Sat, 10 Aug 2024 06:22:18 +0000 (+0800) Subject: 优化省电模式进入UI;并且适配按键回退 X-Git-Tag: release_V1.2.70_20241020_135402~679^2~12 X-Git-Url: http://git.snicker.com.cn/css/static/gitweb.css?a=commitdiff_plain;h=90b0aab208ac6333991421473eeafa31875480db;p=mirrors%2FFD230.git 优化省电模式进入UI;并且适配按键回退 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h index 2a3894e48..56a6e0610 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h @@ -1,35 +1,43 @@ +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 15:01:58 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveElePresenter.h + */ #ifndef _SAVEELE_PRESENTER_H #define _SAVEELE_PRESENTER_H - #include "Presenter.h" #include "SaveEleView.h" - + namespace OHOS { + static constexpr const char *SAVEBUTTONOK = "buttonok"; + static constexpr const char *SAVEBUTTONNO = "buttonno"; + class SaveEleView; - class SaveElePresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener + public UIView::OnClickListener, + public UIView::OnDragListener, + public RootView::OnKeyActListener { public: SaveElePresenter(); virtual ~SaveElePresenter(); - - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - - static SaveElePresenter *GetInstance(); - + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SaveElePresenter *GetInstance(); + private: - //因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; + // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 }; -} //namespace OHOS - - -#endif //SLEEPDETAIL_PRESENTER_H \ No newline at end of file +} // namespace OHOS + +#endif // SLEEPDETAIL_PRESENTER_H \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleView.h b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleView.h index 3464edced..b4602f97c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/include/SaveEleView.h @@ -3,12 +3,13 @@ #include "BaseView.h" #include "View.h" -#include + #include "components/ui_view_group.h" #include "components/ui_label.h" #include "components/ui_label_ext.h" #include "components/ui_image_view.h" #include "components/ui_button.h" +#include "components/ui_scroll_view.h" #include "SaveElePresenter.h" namespace OHOS @@ -26,32 +27,23 @@ namespace OHOS void OnSetUpView() override; void OnTearDownView() override; void OnStop() override; - void Init(); + void InitView(); void DeInit(); - UIView *GetView(); private: UIView::OnDragListener *draglistener{nullptr}; - // void InitImage(void); - // void InitLable(void); - - // 以下控件属性通过new实例化后,add到对应root属性上; - // SaveEleView(constSaveEleView &) = delete; - // SaveEleView &operator=(constSaveEleView &) = delete; SaveEleView(SaveEleView &&) = delete; SaveEleView &operator=(SaveEleView &&) = delete; - UIViewGroup *container_ = nullptr; - UIScrollView *scrollView1_ = nullptr; - UILabel *label1_ = nullptr; - UILabel *label3_ = nullptr; - UILabel *label4_ = nullptr; - UIButton *button1_ = nullptr; - UIButton *button2_ = nullptr; - UIImageView *image2_ = nullptr; - UIImageView *image1_ = nullptr; - UILabel *label2_ = nullptr; + UILabelExt *labeltitle = nullptr; + UILabelExt *labelnote = nullptr; + UILabelExt *labelkown = nullptr; + UIButton *buttonok = nullptr; + UIButton *buttonno = nullptr; + UIImageView *iamgeicon = nullptr; + + UIScrollView *container_{nullptr}; }; } // namespace OHOS #endif // SaveEle_PRESENTER_H diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp index 350f3eb08..963e645a0 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp @@ -1,7 +1,16 @@ +/*** + * @Date: 2024-05-30 15:59:37 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 15:14:49 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveElePresenter.cpp + */ #include "AppViewIDs.h" #include "components/ui_label_ext.h" -#include"ui_resource_string.h" +#include "ui_resource_string.h" #include "NativeAbility.h" +#include "KeyInputListener.h" +#include "custom_utils.h" +#include "common/key_code.h" #include "saveele/include/SaveElePresenter.h" @@ -56,27 +65,35 @@ namespace OHOS bool SaveElePresenter::OnDrag(UIView &view, const DragEvent &event) { - // if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) - // { - // NativeAbility::GetInstance().ChangeSlice(VIEW_APPLIST); - // } + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && + (event.GetDeltaX() > 20) && (event.GetDeltaX() > (2 * MATH_ABS(event.GetDeltaY())))) + { + NativeAbility::GetInstance().Back(); + } UNUSED(view); return true; } bool SaveElePresenter::OnClick(UIView &view, const ClickEvent &event) { - // 根据控件id查找是哪个控件触发了点击回调 - // if (strcmp(view.GetViewId(), 控件ID) == 0) - if (strcmp(view.GetViewId(), "button1") == 0) + if (strcmp(view.GetViewId(), SAVEBUTTONNO) == 0) + { + NativeAbility::GetInstance().Back(); + } + if (strcmp(view.GetViewId(), SAVEBUTTONOK) == 0) { - // NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); - uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); - NativeAbility::GetInstance().ChangeSlice(preSlice); + NativeAbility::GetInstance().EnterSlice(VIEW_SAVEBAT); } - if (strcmp(view.GetViewId(), "button2") == 0) + return true; + } + bool SaveElePresenter::OnKeyAct(UIView &view, const KeyEvent &event) + { + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_SAVEBAT); + NativeAbility::GetInstance().Back(); } return true; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp index 967f2d8c5..14bbc29b7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp @@ -1,26 +1,41 @@ - +/*** + * @Date: 2024-04-15 10:55:58 + * @LastEditors: Caisking 3449750381@qq.com + * @LastEditTime: 2024-08-09 14:41:32 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/saveele/src/SaveEleView.cpp + */ #include "saveele/include/SaveEleView.h" +#include "saveele/include/SaveElePresenter.h" #include "common/image_cache_manager.h" #include "UiConfig.h" #include "ui_resource_image.h" #include #include "components/ui_button.h" +#include "uicomponents/UIComponents.h" +#include "ui_resource_string.h" +#include "components/ui_scroll_view.h" + namespace OHOS { static SaveEleView *g_pSaveEleView{nullptr}; + static const uint32_t BACK_GROUND_COLOR = 0xfff6f6f6; + + static constexpr char *iconImgPath = "/user/res/Save_Ele/SaveEle.bin"; + static constexpr char *butnoImgPath = "/user/res/Save_Ele/Save_Error.bin"; + static constexpr char *butokImgPath = "/user/res/Save_Ele/Save_Right.bin"; SaveEleView::SaveEleView() { - g_pSaveEleView = this; } SaveEleView::~SaveEleView() { - DeInit(); + UIViewGroup *tmpGroup = dynamic_cast(container_); + UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup); g_pSaveEleView = nullptr; } @@ -29,306 +44,75 @@ namespace OHOS return g_pSaveEleView; } - void SaveEleView::Init() + void SaveEleView::InitView() { if (container_ == nullptr) { - container_ = new UIViewGroup(); + container_ = new UIScrollView(); container_->SetPosition(0, 0, 466, 466); container_->SetStyle(STYLE_BACKGROUND_OPA, 0); } - // Add ScrollView to App - if (scrollView1_ == nullptr) - { - scrollView1_ = new UIScrollView(); - } - scrollView1_->SetPosition(0, 0); // widget's left position and top position - scrollView1_->Resize(466, 466); // widget's width and height - scrollView1_->SetViewId("scrollView1"); // Set style - scrollView1_->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - - // Set additional property - scrollView1_->SetDirection(1); - - // Add the CallBack about events - UIView::OnDragListener *scrollView1Drag = static_cast(SaveElePresenter::GetInstance()); - scrollView1_->SetOnDragListener(scrollView1Drag); - // Add to rootView - container_->Add(scrollView1_); - scrollView1_->SetVisible(true); - - // Add Label to App - if (label1_ == nullptr) - { - label1_ = new UILabel(); - } - label1_->SetPosition(173, 52); // widget's left position and top position - label1_->Resize(120, 35); // widget's width and height - label1_->SetViewId("label1"); // Set style - label1_->SetStyle(STYLE_TEXT_FONT, 30); - label1_->SetStyle(STYLE_LINE_SPACE, 0); - label1_->SetStyle(STYLE_LETTER_SPACE, 1); - label1_->SetStyle(STYLE_LINE_HEIGHT, 35); - - // 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 scrollView1 - scrollView1_->Add(label1_); - label1_->SetVisible(true); - - // Add Label to App - if (label3_ == nullptr) - { - label3_ = new UILabel(); - } - label3_->SetPosition(33, 440); // 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); - label3_->SetStyle(STYLE_LINE_HEIGHT, 35); + /*初始化label*/ + InitLabelExt(labeltitle, 83, 50, 300, 35, "labletitle", STR_POWER_SAVE_MODE, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(labelnote, 53, 217, 360, 200, "labletitle", STR_SAVENOTE, DEFAULT_VECTOR_FONT_FILENAME, 30); + InitLabelExt(labelkown, 53, 385, 360, 100, "labelrecord", STR_SAVEBACK, DEFAULT_VECTOR_FONT_FILENAME, 30); + labelkown->SetTextColor(Color::Orange()); - // Set additional property - label3_->SetText("长按屏幕3秒以上或充电可退\n出省电模式"); - label3_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label3_->SetTextColor(Color::GetColorFromRGBA(0xff, 0xc3, 0x00, 0xff)); - label3_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label3_->SetRollSpeed(0); - label3_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /*初始化图片*/ + InitImageView(iamgeicon, 188, 121, 80, 90, "saveicon", iconImgPath); - // Add to scrollView1 - scrollView1_->Add(label3_); - label3_->SetVisible(true); + /*初始化按键*/ + InitButton(buttonno, 110, 501, 100, 100, SAVEBUTTONNO); + buttonno->SetImageSrc(butnoImgPath, butnoImgPath); + buttonno->SetOnClickListener(presenter_); - // Add Label to App - if (label4_ == nullptr) - { - label4_ = new UILabel(); - } - label4_->SetPosition(173, 547); // widget's left position and top position - label4_->Resize(400, 395); // widget's width and height - label4_->SetViewId("label4"); // Set style - label4_->SetStyle(STYLE_TEXT_FONT, 30); - label4_->SetStyle(STYLE_LINE_HEIGHT, 35); - - // Set additional property - label4_->SetText("是否开启"); - label4_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label4_->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); - label4_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label4_->SetRollSpeed(0); - label4_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to scrollView1 - scrollView1_->Add(label4_); - label4_->SetVisible(true); - - // Add Button to App - if (button1_ == nullptr) - { - button1_ = new UIButton(); - } - button1_->SetPosition(110, 636); // widget's left position and top position - button1_->Resize(100, 100); // widget's width and height - button1_->SetViewId("button1"); // Set style - button1_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - button1_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - - char *button1defaultImgSrc = "/user/res/Save_Ele/Save_Error.bin"; - char *button1triggeredImgSrc = nullptr; - button1_->SetImageSrc(button1defaultImgSrc, button1triggeredImgSrc); - button1_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xffff1919, UIButton::PRESSED); - button1_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - - // Add the CallBack about events - UIView::OnClickListener *button1Click = static_cast(SaveElePresenter::GetInstance()); - button1_->SetOnClickListener(button1Click); - // Add to scrollView1 - scrollView1_->Add(button1_); - button1_->SetVisible(true); - - // Add Button to App - if (button2_ == nullptr) - { - button2_ = new UIButton(); - } - button2_->SetPosition(255, 636); // widget's left position and top position - button2_->Resize(100, 100); // widget's width and height - button2_->SetViewId("button2"); // Set style - button2_->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - button2_->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - - char *button2defaultImgSrc = "/user/res/Save_Ele/Save_Right.bin"; - char *button2triggeredImgSrc = nullptr; - button2_->SetImageSrc(button2defaultImgSrc, button2triggeredImgSrc); - button2_->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff19ff5e, UIButton::PRESSED); - button2_->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED); - - // Add the CallBack about events - UIView::OnClickListener *button2Click = static_cast(SaveElePresenter::GetInstance()); - button2_->SetOnClickListener(button2Click); - // Add to scrollView1 - scrollView1_->Add(button2_); - button2_->SetVisible(true); - - // Add ImageView to App - if (image2_ == nullptr) - { - image2_ = new UIImageView(); - } - image2_->SetPosition(183, 775); // widget's left position and top position - image2_->Resize(100, 100); // widget's width and height - image2_->SetViewId("image2"); // Set style - - // Set additional property - - // Add to scrollView1 - scrollView1_->Add(image2_); - image2_->SetVisible(true); - - // Add ImageView to App - if (image1_ == nullptr) - { - image1_ = new UIImageView(); - } - image1_->SetPosition(188, 121); // widget's left position and top position - image1_->Resize(90, 90); // widget's width and height - image1_->SetViewId("image1"); // Set style - - // Set additional property - char *image1imagesPath = "/user/res/Save_Ele/SaveEle.bin"; - image1_->SetSrc(image1imagesPath); - - // Add to scrollView1 - scrollView1_->Add(image1_); - image1_->SetVisible(true); - - // Add Label to App - if (label2_ == nullptr) - { - label2_ = new UILabel(); - } - label2_->SetPosition(33, 217); // widget's left position and top position - label2_->Resize(400, 395); // widget's width and height - label2_->SetViewId("label2"); // Set style - label2_->SetStyle(STYLE_TEXT_FONT, 30); - label2_->SetStyle(STYLE_LINE_HEIGHT, 35); + InitButton(buttonok, 255, 501, 100, 100, SAVEBUTTONOK); + buttonok->SetImageSrc(butokImgPath, butokImgPath); + buttonok->SetOnClickListener(presenter_); - // Set additional property - label2_->SetText("开启省电模式会关闭非必要的\n蓝牙连接(通话/耳机蓝牙),以\n及传感器监测(心率监测及血\n氧监测等会停止)等功能\n 仅保留时间日期可查看"); - label2_->SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - label2_->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); - label2_->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label2_->SetRollSpeed(0); - label2_->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - - // Add to scrollView1 - scrollView1_->Add(label2_); - label2_->SetVisible(true); - } - - void SaveEleView::DeInit() - { - scrollView1_->RemoveAll(); - container_->RemoveAll(); - if (label1_ != nullptr) - { - delete label1_; - label1_ = nullptr; - } - if (label3_ != nullptr) - { - delete label3_; - label3_ = nullptr; - } - if (label4_ != nullptr) - { - delete label4_; - label4_ = nullptr; - } - if (button1_ != nullptr) - { - delete button1_; - button1_ = nullptr; - } - if (button2_ != nullptr) - { - delete button2_; - button2_ = nullptr; - } - if (image2_ != nullptr) - { - delete image2_; - image2_ = nullptr; - } - if (image1_ != nullptr) - { - delete image1_; - image1_ = nullptr; - } - if (label2_ != nullptr) - { - delete label2_; - label2_ = nullptr; - } - if (scrollView1_ != nullptr) - { - delete scrollView1_; - scrollView1_ = nullptr; - } - if (container_ != nullptr) - { - delete container_; - container_ = nullptr; - } + container_->Add(labeltitle); + container_->Add(labelnote); + container_->Add(labelkown); + container_->Add(iamgeicon); + container_->Add(buttonno); + container_->Add(buttonok); } - UIView *SaveEleView::GetView() - { - Init(); - return container_; - } void SaveEleView::OnStart() { + + View::OnStart(); + container_ = new UIScrollView(); if (container_ == nullptr) { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "container_ new fail"); return; } - container_->SetPosition(0, 0); - container_->SetWidth(Screen::GetInstance().GetWidth()); - container_->SetHeight(Screen::GetInstance().GetHeight() * 2); - - // 创建 draglistener 实例并设置为拖动监听器 - UIView::OnDragListener *draglistener = static_cast(SaveElePresenter::GetInstance()); - if (draglistener == nullptr) - { - return; - } - container_->SetOnDragListener(draglistener); + container_->SetScrollBlankSize(35); + container_->SetReboundSize(50); + container_->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + container_->SetOnDragListener(presenter_); container_->SetTouchable(true); container_->SetDraggable(true); + container_->SetStyle(STYLE_BACKGROUND_COLOR, BACK_GROUND_COLOR); + container_->SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - GetView(); - RootView::GetInstance()->Add(container_); + InitView(); + SetContainerView(container_); + RootView::GetInstance()->SetOnKeyActListener(presenter_); } void SaveEleView::OnSetUpView() { - View::OnSetUpView(); Draw(); } void SaveEleView::OnTearDownView() { - View::OnTearDownView(); return; } @@ -336,6 +120,12 @@ namespace OHOS void SaveEleView::OnStop() { View::OnStop(); + if (container_ != nullptr) + { + container_->RemoveAll(); + delete container_; + container_ = nullptr; + } RootView::GetInstance()->RemoveAll(); return; }