From 9be4b2e9ff69e25f3f7e132c8346b357fa6ec9a9 Mon Sep 17 00:00:00 2001 From: xue <2144439972@qq.com> Date: Mon, 30 Jun 2025 10:03:36 +0800 Subject: [PATCH] =?utf8?q?=E5=A2=9E=E5=8A=A0=E6=81=AF=E5=B1=8F=E6=98=BE?= =?utf8?q?=E7=A4=BAslice?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../wearable/fd230/nativeapp/CMakeLists.txt | 1 + .../nativelauncher/include/AppViewIDs.h | 1 + .../set_aod/include/SetAodDialPresenter.h | 38 ++++ .../nativeui/set_aod/include/SetAodDialView.h | 34 ++++ .../set_aod/src/SetAodDialPresenter.cpp | 119 ++++++++++++ .../nativeui/set_aod/src/SetAodDialView.cpp | 182 ++++++++++++++++++ .../set_dial_style/src/SetDialStyleView.cpp | 16 +- .../nativeui/settings/src/SettingModel.cpp | 1 + 8 files changed, 378 insertions(+), 14 deletions(-) create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialPresenter.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialView.h create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp create mode 100644 code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialView.cpp diff --git a/code/sdk/application/wearable/fd230/nativeapp/CMakeLists.txt b/code/sdk/application/wearable/fd230/nativeapp/CMakeLists.txt index 4c110e326..caf3b330d 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/CMakeLists.txt +++ b/code/sdk/application/wearable/fd230/nativeapp/CMakeLists.txt @@ -37,6 +37,7 @@ set(PRIVATE_HEADER ${NativeApp}/nativeui/add_card/include ${NativeApp}/nativeui/set_dial/include ${NativeApp}/nativeui/set_dial_style/include + ${NativeApp}/nativeui/set_aod/include ${NativeApp}/nativeui/key/include ${NativeApp}/nativeui/player/include ${NativeApp}/nativeui/applist/include diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h index 96c027d17..113ef87da 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h +++ b/code/sdk/application/wearable/fd230/nativeapp/nativelauncher/include/AppViewIDs.h @@ -55,6 +55,7 @@ typedef enum : uint16_t VIEW_BRIGHTNESSLEVEL, // 亮度调节 VIEW_NETWORKANDCALL, // 网络与通话 VIEW_MOTION_RECOGNITION, // 运动识别 + VIEW_SET_AODDIAL, // 息屏显示 VIEW_SYSTEM_UPDATE, // 系统更新 VIEW_WATCH_QR_CODE, // 手表二维码 VIEW_RESPIRATORY_TRAINING, // 呼吸训练 diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialPresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialPresenter.h new file mode 100644 index 000000000..4192e0e0e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialPresenter.h @@ -0,0 +1,38 @@ +#ifndef SET_DIAL_AOD_PRESENTER_H +#define SET_DIAL_AOD_PRESENTER_H + +#include "Presenter.h" +#include "View.h" +#include "components/ui_toggle_button.h" + +namespace OHOS +{ + class SetAodDialView; + class SetAodDialPresenter : public Presenter, + public UIView::OnClickListener, + public RootView::OnKeyActListener, + public UICheckBox::OnChangeListener, + public UIView::OnDragListener + { + public: + SetAodDialPresenter(); + virtual ~SetAodDialPresenter(); + + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + + static SetAodDialPresenter *GetInstance(); + + 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 OnChange(UICheckBox::UICheckBoxState state); + bool X_DRAG_FLAG { false }; + }; +} + +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialView.h new file mode 100644 index 000000000..a65cdc15e --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/include/SetAodDialView.h @@ -0,0 +1,34 @@ +#ifndef SET_DIAL_AOD_VIEW_H +#define SET_DIAL_AOD_VIEW_H + +#include "View.h" + +#include "components/ui_scroll_view.h" +#include "components/ui_label_ext.h" +#include "components/ui_image_view.h" +#include "components/ui_toggle_button.h" +namespace OHOS +{ + class SetAodDialPresenter; + class SetAodDialView : public View + { + + public: + SetAodDialView(); + virtual ~SetAodDialView(); + static SetAodDialView *GetInstance(void); + void OnStart() override; + + private : + void SetAodDialViewInit(void); + void ClearAll(void); + UIScrollView *scrollView = nullptr; + UILabelExt *Title = nullptr; + UIImageView *SetAodDialImage = nullptr; + UILabelExt *SetAodDialLabel = nullptr; + UIToggleButton *SetAodDialToggleButton = nullptr; + UILabelExt *note{nullptr}; + bool viewInitStatus{false}; + }; +} +#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp new file mode 100644 index 000000000..d8466564b --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialPresenter.cpp @@ -0,0 +1,119 @@ +#include "AppViewIDs.h" +#include "NativeAbility.h" +#include "set_aod/include/SetAodDialPresenter.h" +#include "set_aod/include/SetAodDialView.h" +#include "common/key_code.h" +#include +#include "ConfigModel.h" +#include +#include "custom_runtime.h" + +#include "NativeRegisterManager.h" +#include "MainModel.h" + +namespace OHOS +{ + + REGIST_SLICE(VIEW_SET_AODDIAL, SetAodDialView, SetAodDialPresenter); + + // 当前Presenter属性实例化的内存指针 + static SetAodDialPresenter *g_pSetAodDialPresenter = nullptr; + + SetAodDialPresenter::SetAodDialPresenter() + { + g_pSetAodDialPresenter = this; + } + + SetAodDialPresenter::~SetAodDialPresenter() + { + g_pSetAodDialPresenter = nullptr; + } + + SetAodDialPresenter *SetAodDialPresenter::GetInstance() + { + return g_pSetAodDialPresenter; + } + + void SetAodDialPresenter::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::OnStart"); + Presenter::OnStart(); + } + + void SetAodDialPresenter::OnPause(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::OnPause"); + Presenter::OnPause(); + } + + void SetAodDialPresenter::OnResume(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::OnResume"); + Presenter::OnResume(); + } + + void SetAodDialPresenter::OnStop(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::OnStop"); + Presenter::OnStop(); + } + + bool SetAodDialPresenter::OnClick(UIView &view, const ClickEvent &event) + { + UNUSED(view); + UNUSED(event); + return true; + } + bool SetAodDialPresenter::OnChange(UICheckBox::UICheckBoxState state) + { + switch (state) + { + case UICheckBox::SELECTED: + MainModel::GetInstance().EnableAod(true); + break; + case UICheckBox::UNSELECTED: + MainModel::GetInstance().EnableAod(false); + break; + default: + break; + } + return true; + } + + bool SetAodDialPresenter::OnDrag(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialPresenter::OnDrag"); + if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 + { + X_DRAG_FLAG = true; + } + return true; + } + + bool SetAodDialPresenter::OnDragEnd(UIView &view, const DragEvent &event) + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialPresenter::OnDragEnd"); + if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) + { + NativeAbility::GetInstance().Back(); + X_DRAG_FLAG = false; + } + return true; + } + + bool SetAodDialPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialPresenter::OnKeyAct"); + unsigned short keyID = event.GetKeyId(); + unsigned short keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().Back(); + } + return true; + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialView.cpp new file mode 100644 index 000000000..79e665d53 --- /dev/null +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_aod/src/SetAodDialView.cpp @@ -0,0 +1,182 @@ +#include "set_aod/include/SetAodDialPresenter.h" +#include "set_aod/include/SetAodDialView.h" +#include "wearable_log.h" +#include "ConfigModel.h" +#include +#include +#include "MainModel.h" +namespace OHOS +{ + + static SetAodDialView *g_pSetAodDialView{nullptr}; + + SetAodDialView::SetAodDialView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::SetAodDialView"); + g_pSetAodDialView = this; + } + + SetAodDialView::~SetAodDialView() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::~SetAodDialView"); + + g_pSetAodDialView = nullptr; + } + + SetAodDialView *SetAodDialView::GetInstance() + { + return g_pSetAodDialView; + } + + void SetAodDialView::ClearAll(void) + { + if (scrollView != nullptr) + { + scrollView->RemoveAll(); + + if (Title != nullptr) + { + delete Title; + Title = nullptr; + } + + if (SetAodDialImage != nullptr) + { + delete SetAodDialImage; + SetAodDialImage = nullptr; + } + if (SetAodDialLabel != nullptr) + { + delete SetAodDialLabel; + SetAodDialLabel = nullptr; + } + + if (SetAodDialToggleButton != nullptr) + { + delete SetAodDialToggleButton; + SetAodDialToggleButton = nullptr; + } + if (note != nullptr) + { + delete note; + note = nullptr; + } + + scrollView->ClearFocus(); + delete scrollView; + scrollView = nullptr; + } + } + + void SetAodDialView::SetAodDialViewInit(void) + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::SetAodDialViewInit"); + if (scrollView == nullptr) + { + scrollView = new UIScrollView(); + scrollView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight()); + scrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + scrollView->SetScrollBlankSize(50); + scrollView->SetHorizontalScrollState(false); + scrollView->SetReboundSize(35); + scrollView->SetOnDragListener(presenter_); + scrollView->RequestFocus(); + scrollView->SetRotateFactor(1.0); + /* -------------------------------------------------------------------------- */ + Title = new UILabelExt(); + if (Title == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetAodDialView::Title can not be nullptr!"); + return; + } + Title->SetPosition(83, 50, 300, 40); + Title->SetStyle(STYLE_TEXT_FONT, 30); + Title->SetStyle(STYLE_LINE_HEIGHT, 35); + Title->SetText("AOD表盘"); /*AOD表盘*/ + Title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); + Title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); + Title->SetRollSpeed(23); + Title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + Title->SetVisible(true); + /* -------------------------------------------------------------------------- */ + if (SetAodDialImage == nullptr) + { + SetAodDialImage = new UIImageView(); + } + SetAodDialImage->SetPosition(43, 120, 380, 100); + SetAodDialImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); + SetAodDialImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff); + SetAodDialImage->SetStyle(STYLE_BORDER_RADIUS, 100); + /* -------------------------------------------------------------------------- */ + SetAodDialLabel = new UILabelExt(); + if (SetAodDialLabel == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetAodDialView::SetAodDialLabel can not be nullptr!"); + return; + } + SetAodDialLabel->SetPosition(90, 153, 180, 40); + SetAodDialLabel->SetStyle(STYLE_TEXT_FONT, 30); + SetAodDialLabel->SetStyle(STYLE_LINE_HEIGHT, 35); + SetAodDialLabel->SetText("息屏显示"); /*息屏显示*/ + SetAodDialLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE); + SetAodDialLabel->SetRollSpeed(23); + SetAodDialLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); + /* -------------------------------------------------------------------------- */ + SetAodDialToggleButton = new UIToggleButton(); + if (SetAodDialToggleButton == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::SetAodDialToggleButton is nullptr!"); + return; + } + SetAodDialToggleButton->SetPosition(298, 145, 100, 50); + SetAodDialToggleButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); + SetAodDialToggleButton->SetImages(PNG_TOGGLEBUTTON_ON_IMAGE, PNG_TOGGLEBUTTON_OFF_IMAGE); + SetAodDialToggleButton->SetState(MainModel::GetInstance().IsAodEnabled()); + /* ----------------------------- onclickListener ---------------------------- */ + SetAodDialToggleButton->SetOnChangeListener(presenter_); + /* -------------------------------------------------------------------------- */ + if (note == nullptr) + { + note = new UILabelExt(); + if (note == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetAodDialView::note can not be nullptr!"); + return; + } + } + note->SetPosition(63, SetAodDialImage->GetY() + SetAodDialImage->GetHeight() + 20, 340, 80); + note->SetStyle(STYLE_TEXT_FONT, 20); + note->SetStyle(STYLE_LINE_HEIGHT, 40); + note->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); + note->SetText("开启后,手表在在息屏状态下也会显示时间等信息,但同时会增加耗电"); // 开启后,手表在在息屏状态下也会显示时间等信息。 + note->SetLineBreakMode(UILabel::LINE_BREAK_WRAP); + note->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 20); + /* -------------------------------------------------------------------------- */ + + viewInitStatus = true; + /* -------------------------------------------------------------------------- */ + } + } + + void SetAodDialView::OnStart() + { + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetAodDialView::OnStart"); + View::OnStart(); + + if (!viewInitStatus) + { + SetAodDialViewInit(); + } + + // 增加按键监听 + // GetRootContainer()->SetOnKeyActListener(presenter_); + + scrollView->Add(Title); + scrollView->Add(SetAodDialImage); + scrollView->Add(SetAodDialLabel); + scrollView->Add(SetAodDialToggleButton); + scrollView->Add(note); + AddViewToRootContainer(scrollView); + RootView::GetInstance()->SetOnKeyActListener(presenter_); + } +} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp index 7d786aab4..54c08a757 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/set_dial_style/src/SetDialStyleView.cpp @@ -40,22 +40,15 @@ void SetDialStyleView::OnStart() labelCover_.SetText("Coverflow"); AddViewToRootContainer(&labelCover_); - labelRoller_.SetPosition(ROLLER_X, Y2, LABEL_WIDTH, LABEL_HEIGHT); + labelRoller_.SetPosition(ENABLE_X, Y2, LABEL_WIDTH, LABEL_HEIGHT); labelRoller_.SetText("Roller"); AddViewToRootContainer(&labelRoller_); btnCover_.SetPosition(COVER_X, Y1, BTN_WIDTH, BTN_HEIGHT); AddViewToRootContainer(&btnCover_); - btnRoller_.SetPosition(ROLLER_X, Y1, BTN_WIDTH, BTN_HEIGHT); + btnRoller_.SetPosition(ENABLE_X, Y1, BTN_WIDTH, BTN_HEIGHT); AddViewToRootContainer(&btnRoller_); - labelEnableAod_.SetPosition(ENABLE_X, Y2, LABEL_WIDTH, LABEL_HEIGHT); - labelEnableAod_.SetText("打开熄屏显示"); - AddViewToRootContainer(&labelEnableAod_); - btnEnableAod_.SetPosition(ENABLE_X, Y1, BTN_WIDTH, BTN_HEIGHT); - AddViewToRootContainer(&btnEnableAod_); - btnEnableAod_.SetState(MainModel::GetInstance().IsAodEnabled()); - const DialStyle style = SetDialStyleModel::GetInstance().GetStyle(); int len = sizeof(styleTable_) / sizeof(styleTable_[0]); for (int i = 0; i < len; ++i) { @@ -68,7 +61,6 @@ void SetDialStyleView::OnStart() btnCover_.SetOnClickListener(presenter_); btnRoller_.SetOnClickListener(presenter_); - btnEnableAod_.SetOnClickListener(presenter_); } void SetDialStyleView::OnClick(UIView &view) @@ -77,10 +69,6 @@ void SetDialStyleView::OnClick(UIView &view) if (ptr == nullptr) { return; } - if (ptr == &btnEnableAod_) { - MainModel::GetInstance().EnableAod(ptr->GetState()); - return; - } int len = sizeof(styleTable_) / sizeof(styleTable_[0]); for (int i = 0; i < len; ++i) { if (ptr == styleTable_[i].btn) { diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp index 276788979..ccc559b44 100644 --- a/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp +++ b/code/sdk/application/wearable/fd230/nativeapp/nativeui/settings/src/SettingModel.cpp @@ -41,6 +41,7 @@ namespace OHOS settings[index++] = {VIEW_SOUND_VIBRATION, PNG_SETTINGS_SOUND_VIBRATION, STR_SOUND_AND_VIBRATION, true}; settings[index++] = {VIEW_THEME_STYLE, PNG_SETTINGS_DISPLAY_MODE, STR_DISPLAY_MODE, true}; settings[index++] = {VIEW_MOTION_RECOGNITION, PNG_SETTINGS_MOTION_RECOGNITION, STR_MOTION_RECOGNITION, true}; + settings[index++] = {VIEW_SET_AODDIAL, PNG_SETTINGS_MOTION_RECOGNITION, STR_MOTION_RECOGNITION, true}; settings[index++] = {VIEW_DNOTDISTURB, PNG_SETTINGS_DISTURB_IMAGE, STR_DO_NOT_DISTURB, true}; settings[index++] = {VIEW_ADD_CARD, PNG_SETTINGS_CARDSET_IMAGE, STR_CARD_MANAGEMENT, true}; settings[index++] = {VIEW_SET_DIAL_STYLE, PNG_SETTINGS_CHANGEDIAL_IMAGE, STR_DIAL_BROWSING_SPECIAL_EFFECTS, true}; -- 2.17.1