From 070b61d6b8e202f6b3bb5717951dccd755183a52 Mon Sep 17 00:00:00 2001 From: luozheng <1732036298@qq.com> Date: Thu, 21 Mar 2024 11:16:14 +0800 Subject: [PATCH] =?utf8?q?1.=E9=87=8D=E5=90=AF=E7=95=8C=E9=9D=A2=E4=BC=98?= =?utf8?q?=E5=8C=96=202.=E8=A7=A3=E5=86=B3=E6=8C=89=E9=94=AE=E7=9B=91?= =?utf8?q?=E5=90=AC=E5=A4=9A=E6=AC=A1=E8=A7=A6=E5=8F=91=E9=97=AE=E9=A2=98?= =?utf8?q?=203.custom=5Futils=E5=A2=9E=E5=8A=A0uapi=5FsetScreenDuration=20?= =?utf8?q?=E8=AE=BE=E7=BD=AE=E6=9F=90=E4=B8=AASlice=E4=BA=AE=E5=B1=8F?= =?utf8?q?=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../rebootdevice/include/RebootPresenter.h | 53 ++++++++++------- .../rebootdevice/src/RebootPresenter.cpp | 57 ++++++++++++------- .../nativeui/rebootdevice/src/RebootView.cpp | 47 ++++++++------- .../drivers/peripheral/utils/custom_utils.c | 12 +++- .../drivers/peripheral/utils/custom_utils.h | 4 +- 5 files changed, 105 insertions(+), 68 deletions(-) diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootPresenter.h index 990884f67..5dc40d364 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootPresenter.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-01-29 15:37:44 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-03-20 20:25:14 + * @LastEditTime: 2024-03-21 09:48:06 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/RebootPresenter.h * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE */ @@ -20,14 +20,17 @@ #include "NativeAbility.h" #include "BaseView.h" #include "components/ui_image_animator.h" -namespace OHOS { -enum RebootPresenterNum : uint8_t { +#include "KeyInputListener.h" +namespace OHOS +{ + enum RebootPresenterNum : uint8_t + { REBOOTVIEW = 0, REBOOTDEVICEVIEW, SHUTDOWNDEVICEVIEW, - SHUTDOWNANIMATORVIEW, //关机动画视图 + SHUTDOWNANIMATORVIEW, // 关机动画视图 REBOOT_MAX, -}; + }; #define REBOOT_BUTTON "rebootButton" #define SHUTDOWN_BUTTON "shutdownButton" @@ -38,22 +41,28 @@ enum RebootPresenterNum : uint8_t { #define REBOOTDEVICE_VIEW "rebootDeviceView" #define SHUTDOWNDEVICE_VIEW "shutdownDeviceView" -class RebootView; -class RebootPresenter : public Presenter, - public UIView::OnClickListener,public UIImageAnimatorView::AnimatorStopListener, - public UIView::OnDragListener { -public: - RebootPresenter(); - ~RebootPresenter(); - static RebootPresenter *GetInstance(); - void OnStart() override; - void OnPause() override; - void OnResume() override; - void OnStop() override; - bool OnClick(UIView& view, const ClickEvent& event) override; - bool OnDrag(UIView& view, const DragEvent& event) override; - virtual void OnAnimatorStop(UIView &view) override; -private: -}; + class RebootView; + class RebootPresenter : public Presenter, + public UIView::OnClickListener, + public UIImageAnimatorView::AnimatorStopListener, + public RootView::OnKeyActListener, + public UIView::OnDragListener + { + public: + RebootPresenter(); + ~RebootPresenter(); + static RebootPresenter *GetInstance(); + void OnStart() override; + void OnPause() override; + void OnResume() override; + void OnStop() override; + bool OnClick(UIView &view, const ClickEvent &event) override; + bool OnDrag(UIView &view, const DragEvent &event) override; + virtual void OnAnimatorStop(UIView &view) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 + + private: + bool isShutDownOperation{false}; // 是否是关机操作 + }; } // namespace OHOS #endif diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp index 004af7144..3a502e290 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-02-21 19:06:02 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-03-20 20:30:01 + * @LastEditTime: 2024-03-21 11:15:29 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp */ #include "rebootdevice/include/RebootPresenter.h" @@ -12,6 +12,7 @@ #include "wearable_log.h" #include "custom_utils.h" #include "components/ui_image_animator.h" +#include "common/key_code.h" namespace OHOS { static RebootPresenter *g_pRebootPresenter = nullptr; @@ -38,6 +39,7 @@ namespace OHOS { Presenter::OnStart(); WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootPresenter::On Start "); + uapi_setScreenDuration(10 * 1000); } void RebootPresenter::OnPause(void) {} @@ -62,7 +64,9 @@ namespace OHOS { // 重启 WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "REBOOTDEVICE_BUTTON OnClick"); - uapi_reboot_device(); + RebootView::GetInstance()->ChangeView(REBOOTDEVICEVIEW, SHUTDOWNANIMATORVIEW); + ShutDownAnimatorView::GetInstance()->GeShutDownImageAnimatorView()->Start(); + isShutDownOperation = false; } else if (strcmp(view.GetViewId(), SHUTDOWNDEVICE_BUTTON) == 0) { @@ -71,6 +75,7 @@ namespace OHOS // GetPMSDefaultInterface()->ShutDownDevice(NULL, NULL); RebootView::GetInstance()->ChangeView(SHUTDOWNDEVICEVIEW, SHUTDOWNANIMATORVIEW); ShutDownAnimatorView::GetInstance()->GeShutDownImageAnimatorView()->Start(); + isShutDownOperation = true; } return true; } @@ -82,31 +87,16 @@ namespace OHOS { if (strcmp(view.GetViewId(), REBOOT_VIEW) == 0) { - NativeAbility::GetInstance().ChangeSlice(VIEW_MAIN); + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); } else if (strcmp(view.GetViewId(), REBOOTDEVICE_VIEW) == 0) { - if (RebootModel::GetInstance()->GetExitsView() == 0) - { - RebootView::GetInstance()->ChangeView(REBOOTDEVICEVIEW, REBOOTVIEW); - } - else - { - NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); - RebootModel::GetInstance()->SetExitsView(false); - } + RebootView::GetInstance()->ChangeView(REBOOTDEVICEVIEW, REBOOTVIEW); } else if (strcmp(view.GetViewId(), SHUTDOWNDEVICE_VIEW) == 0) { - if (RebootModel::GetInstance()->GetExitsView() == 0) - { - RebootView::GetInstance()->ChangeView(SHUTDOWNDEVICEVIEW, REBOOTVIEW); - } - else - { - NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); - RebootModel::GetInstance()->SetExitsView(false); - } + RebootView::GetInstance()->ChangeView(SHUTDOWNDEVICEVIEW, REBOOTVIEW); } } return true; @@ -114,7 +104,30 @@ namespace OHOS void RebootPresenter::OnAnimatorStop(UIView &view) { + UNUSED(view); WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "RebootPresenter::OnAnimatorStop"); - uapi_poweroff_device(); + if (isShutDownOperation == true) + { + uapi_poweroff_device(); // 关机 + } + else + { + uapi_reboot_device(); // 重启 + } + } + + bool RebootPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; } } diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootView.cpp b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootView.cpp index 9db397c39..88f3ed29a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootView.cpp @@ -62,20 +62,21 @@ namespace OHOS WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootView::~OnStart"); View::OnStart(); BaseView::RootView(Color::Black().full); - if (RebootModel::GetInstance()->GetSelectView() == REBOOT) - { - ChangeView(REBOOT_MAX, REBOOTVIEW); - } - else if (RebootModel::GetInstance()->GetSelectView() == REBOOTDEVICE) - { - ChangeView(REBOOT_MAX, REBOOTDEVICEVIEW); - RebootModel::GetInstance()->SetSelectViewId(REBOOT); - } - else if (RebootModel::GetInstance()->GetSelectView() == SHUTDOWNDEVICE) - { - ChangeView(REBOOT_MAX, SHUTDOWNDEVICEVIEW); - RebootModel::GetInstance()->SetSelectViewId(REBOOT); - } + // if (RebootModel::GetInstance()->GetSelectView() == REBOOT) + // { + // ChangeView(REBOOT_MAX, REBOOTVIEW); + // } + // else if (RebootModel::GetInstance()->GetSelectView() == REBOOTDEVICE) + // { + // ChangeView(REBOOT_MAX, REBOOTDEVICEVIEW); + // RebootModel::GetInstance()->SetSelectViewId(REBOOT); + // } + // else if (RebootModel::GetInstance()->GetSelectView() == SHUTDOWNDEVICE) + // { + // ChangeView(REBOOT_MAX, SHUTDOWNDEVICEVIEW); + // RebootModel::GetInstance()->SetSelectViewId(REBOOT); + // } + ChangeView(REBOOT_MAX, REBOOTVIEW); RootView::GetInstance()->Invalidate(); return; } @@ -84,6 +85,8 @@ namespace OHOS { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "RebootView::~OnSetUpView"); View::OnSetUpView(); + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::RebootPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); Draw(); } @@ -242,15 +245,17 @@ namespace OHOS bool RebootView::ChangeRebootView(int16_t hideView, int16_t thisView) { UNUSED(hideView); - // init view - UIViewGroup *group = InitShowUpView(); - if (group == nullptr) + if (container[thisView] == nullptr) { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); - return false; + UIViewGroup *group = InitShowUpView(); + if (group == nullptr) + { + WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "group nullptr fail"); + return false; + } + container[thisView] = group; + RootView::GetInstance()->Add(container[thisView]); } - container[thisView] = group; - RootView::GetInstance()->Add(container[thisView]); return true; } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index a1b526191..39663c7dc 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -348,7 +348,8 @@ errcode_t uapi_get_yyyymmddhhmmss_Date(char *date) } /// @brief 控制屏幕是否常亮 -/// @param turnOnFlag 1:常亮屏幕 0:取消常亮 +/// @param turnOnFlag 1:常亮屏幕 +/// @param turnOnFlag 0:取消常亮 void ScreenAlwaysOnCtr(uint8_t turnOnFlag) { const power_display_svr_api_t *display_api = power_display_svr_get_api(); @@ -368,7 +369,14 @@ void ScreenAlwaysOnCtr(uint8_t turnOnFlag) } } - +/* + * @brief 设置某个Slice亮屏时间,超过时间后屏幕息屏,单位ms +*/ +void uapi_setScreenDuration(int32_t time) +{ + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + display_api->set_screen_auto_off_timeout(time); +} #include "bts_le_gap.h" diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.h b/code/sdk/drivers/peripheral/utils/custom_utils.h index 2a9ac9b7d..89163fbdb 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -42,7 +42,9 @@ errcode_t uapi_get_yyyymmddhhmmss_Date(char *date); char *uapi_get_local_yyyymmdd_date(void); -void ScreenAlwaysOnCtr(uint8_t turnOnFlag); +void ScreenAlwaysOnCtr(uint8_t turnOnFlag); + +void uapi_setScreenDuration(int32_t time); errcode_t uapi_get_btaddr(uint8_t *buf_btaddr, uint32_t *len_btaddr); errcode_t uapi_get_btname(uint8_t *buf_btname, uint32_t *len_btname); -- 2.17.1