From: luozheng <1732036298@qq.com> Date: Thu, 21 Mar 2024 08:23:08 +0000 (+0800) Subject: 1.设置视图中的Slice添加按键监听 X-Git-Tag: release_V1.2.70_20241020_135402~1250^2~17 X-Git-Url: http://git.snicker.com.cn/Users/apple/Desktop/static/gitweb.css?a=commitdiff_plain;h=4c3cc471f28c73ee577694ce1417c1c01967db98;p=mirrors%2FFD230.git 1.设置视图中的Slice添加按键监听 2.custom_utils添加获取屏幕状态函数 --- diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp index 908b12f75..8ff7b9374 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp @@ -143,8 +143,9 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnKeyAct"); uint16 keyID = event.GetKeyId(); - // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); if (preSlice == VIEW_SETTING || VIEW_BLUETOOTH_EARPHONE) diff --git a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp index 2f44479e9..f025ed6b7 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp @@ -299,9 +299,8 @@ namespace OHOS ClassicBlueToothViewInit(); // 增加按键监听 - //RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::ClassicBlueToothPresenter::GetInstance(); - //RootView::GetInstance()->SetOnKeyActListener(keyactListener); - RootView::GetInstance()->SetIntercept(true); + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::ClassicBlueToothPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void ClassicBlueToothView::OnSetUpView() diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h index 858b97e1a..74abb5b2f 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h @@ -83,6 +83,7 @@ namespace OHOS class DisplayBrightnessPresenter : public Presenter, public UIView::OnClickListener, public UIView::OnDragListener, + public RootView::OnKeyActListener, public UICheckBox::OnChangeListener { public: @@ -105,6 +106,7 @@ namespace OHOS bool OnDrag(UIView &view, const DragEvent &event) override; bool OnDragEnd(UIView &view, const DragEvent &event) override; bool OnChange(UICheckBox::UICheckBoxState state) override; + bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp index 35a82a658..72ea7cf17 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp @@ -6,6 +6,8 @@ #include "cat1_ctl.h" #include "displaybrightness/include/DisplayBrightnessModel.h" #include "power_display_service.h" +#include "common/key_code.h" +#include namespace OHOS { // 当前Presenter属性实例化的内存指针 @@ -59,7 +61,7 @@ namespace OHOS if (value >= BRIGHTNESS_MIN && value <= BRIGHTNESS_MAX) { p_BrightnessControlView->SetScreenBrightnessValue(value); - DisplayBrightnessModel::GetInstance()->KeepScreenBrightnessValues(0xff);// 将Model层保存的状态清除 + DisplayBrightnessModel::GetInstance()->KeepScreenBrightnessValues(0xff); // 将Model层保存的状态清除 } } @@ -85,7 +87,7 @@ namespace OHOS { p_ScreenDurationView->SetRadioButtonSelectStatus(ScreenDurationRadioButton3); } - DisplayBrightnessModel::GetInstance()->KeepScreenDurationRadioButtonSlectStatus(ScreenDurationRadioButton1);// 将Model层保存的状态清除 + DisplayBrightnessModel::GetInstance()->KeepScreenDurationRadioButtonSlectStatus(ScreenDurationRadioButton1); // 将Model层保存的状态清除 } void DisplayBrightnessPresenter::OnStart() @@ -209,6 +211,21 @@ namespace OHOS return true; } + bool DisplayBrightnessPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnKeyAct"); + 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) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; + } + bool ScreenDurationRadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state) { DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance(); @@ -373,4 +390,5 @@ namespace OHOS UNUSED(view); return true; } + } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp index 4b24a896d..617122e74 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp @@ -522,6 +522,8 @@ namespace OHOS { DisplayAndBrightnessViewInit(); } + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::DisplayBrightnessPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void DisplayBrightnessView::OnSetUpView() @@ -557,6 +559,7 @@ namespace OHOS { View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); RootView::GetInstance()->RemoveAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/ShutDownAnimatorView.h b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/ShutDownAnimatorView.h index a41001825..b6ce03324 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/ShutDownAnimatorView.h +++ b/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/ShutDownAnimatorView.h @@ -2,7 +2,7 @@ * @Author: luozheng 1732036298@qq.com * @Date: 2024-03-20 16:37:13 * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-03-20 19:33:40 + * @LastEditTime: 2024-03-21 16:20:28 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/ShutDownAnimatorView.h */ @@ -20,7 +20,7 @@ namespace OHOS static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_H = 100; static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 70; // 图片帧数 static constexpr int16_t SHUTDOWN_IMAGE_ANIMATOR_TIME = 100; // 图片更新间隔 - static constexpr char *ShutDownPaths = "/user/res/RebootAndShutDown/ShutDown/"; + static constexpr char *ShutDownPaths = "/user/res/RebootAndShutDown/ShutDown/"; //关机图片路径 class ShutDownAnimatorView { public: 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 3a502e290..69534af5f 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-21 11:15:29 + * @LastEditTime: 2024-03-21 14:23:19 * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp */ #include "rebootdevice/include/RebootPresenter.h" @@ -122,8 +122,8 @@ namespace OHOS 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) + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); NativeAbility::GetInstance().ChangeSlice(preSlice); diff --git a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionPresenter.h index 39b8142b6..70b198b0c 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionPresenter.h @@ -1,8 +1,17 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-27 18:06:27 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-03-21 14:32:11 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionPresenter.h + */ #ifndef SECONDARY_FUNCTION_PRESENTER_H #define SECONDARY_FUNCTION_PRESENTER_H #include "Presenter.h" #include "SecondaryFunctionView.h" +#include "KeyInputListener.h" + namespace OHOS { @@ -35,6 +44,7 @@ namespace OHOS class SecondaryFunctionView; class SecondaryFunctionPresenter : public Presenter, public UIView::OnClickListener, + public RootView::OnKeyActListener, public UIView::OnDragListener { public: @@ -48,11 +58,13 @@ namespace OHOS static SecondaryFunctionPresenter *GetInstance(); void SetHeartRateOrBloodOxygenQuickAccessRadioButtonSelectState(int state); + private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; 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; // 增加按键事件 }; } // namespace OHOS #endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionPresenter.cpp index 7375fb302..1f104dd13 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionPresenter.cpp @@ -3,6 +3,9 @@ #include "NativeAbility.h" #include "secondaryfunction/include/SecondaryFunctionPresenter.h" #include "secondaryfunction/include/SecondaryFunctionModel.h" +#include "components/ui_image_animator.h" +#include "common/key_code.h" +#include "custom_utils.h" namespace OHOS { @@ -110,6 +113,20 @@ namespace OHOS return false; } + bool SecondaryFunctionPresenter::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 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + } + return true; + } + bool SecondaryFunctionPresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(event); diff --git a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionView.cpp b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionView.cpp index e76738bdb..e8ff53550 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionView.cpp @@ -330,6 +330,9 @@ namespace OHOS { View::OnStart(); SecondaryFunctionViewInit(); + + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SecondaryFunctionPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void SecondaryFunctionView::OnSetUpView() @@ -357,6 +360,7 @@ namespace OHOS { View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); RootView::GetInstance()->RemoveAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp index 27880edf0..c4f465ace 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp @@ -84,8 +84,9 @@ namespace OHOS { WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct"); uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); // 如果是power键就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER)) + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0) { uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); if (preSlice == VIEW_APPLIST) diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h index d8438752b..df3df6e4a 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h @@ -1,8 +1,16 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-19 10:39:08 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-03-21 11:49:25 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h + */ #ifndef SOUND_AND_VIBRATION_PRESENTER_H #define SOUND_AND_VIBRATION_PRESENTER_H #include "Presenter.h" #include "SoundAndVibrationView.h" +#include "KeyInputListener.h" namespace OHOS { @@ -25,6 +33,7 @@ namespace OHOS class SoundAndVibrationView; class SoundAndVibrationPresenter : public Presenter, public UIView::OnClickListener, + public RootView::OnKeyActListener, public UIView::OnDragListener { public: @@ -39,11 +48,14 @@ namespace OHOS static SoundAndVibrationPresenter *GetInstance(); void VibrationReminderToggleButtonStateSetting(bool value); void SilentModeToggleButtonStateSetting(bool value); + private: // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承; 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; // 增加按键事件 + private: UIView *view_{nullptr}; }; diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h index 85810c04e..42e23dd98 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h @@ -4,14 +4,14 @@ #include "Presenter.h" #include "SystemVolumeView.h" #include "wearable_log.h" - +#include "KeyInputListener.h" namespace OHOS { typedef enum : uint8_t { VOLUMEREDUCE = 0, // 声音降低 VOLUMEADD = 1, // 声音增加 - OTHER = 2, // 其他 + OTHER = 2, // 其他 } VolumeStatusChange; /* @@ -39,6 +39,7 @@ namespace OHOS class SystemVolumeView; class SystemVolumePresenter : public Presenter, public UIView::OnClickListener, + public RootView::OnKeyActListener, public UIView::OnDragListener { public: @@ -56,6 +57,7 @@ namespace OHOS // 因为继承了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 diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp index 684e274fd..f50de29c3 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp @@ -1,9 +1,20 @@ +/* + * @Author: luozheng 1732036298@qq.com + * @Date: 2024-02-19 10:39:11 + * @LastEditors: luozheng 1732036298@qq.com + * @LastEditTime: 2024-03-21 14:23:38 + * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp + */ + #include "AppViewIDs.h" #include "NativeAbility.h" #include "graphic_math.h" #include "string.h" #include "soundandvibration/include/SoundAndVibrationPresenter.h" #include "soundandvibration/include/SoundAndVibrationModel.h" +#include "common/key_code.h" +#include "custom_utils.h" + namespace OHOS { @@ -93,6 +104,8 @@ namespace OHOS bool SoundAndVibrationPresenter::OnDragEnd(UIView &view, const DragEvent &event) { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnDragEnd"); if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT) { NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); @@ -100,6 +113,20 @@ namespace OHOS return true; } + bool SoundAndVibrationPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING); + } + return true; + } + bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event) { diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp index bbbd6c549..404fe0838 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp @@ -536,6 +536,8 @@ namespace OHOS { View::OnStart(); InitView(); + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SoundAndVibrationPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void SoundAndVibrationView::OnSetUpView() @@ -576,6 +578,7 @@ namespace OHOS { View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); RootView::GetInstance()->RemoveAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp index cd2beb8f6..719e50383 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp @@ -3,8 +3,10 @@ #include "graphic_math.h" #include "string.h" #include "soundandvibration/include/SystemVolumePresenter.h" - #include +#include "common/key_code.h" +#include "custom_utils.h" + // 系统音量 namespace OHOS { @@ -67,6 +69,21 @@ namespace OHOS return true; } + bool SystemVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + return true; + } + bool SystemVolumePresenter::OnClick(UIView &view, const ClickEvent &event) { UNUSED(view); diff --git a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp index 2e9f089ac..47e7cc963 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp @@ -80,6 +80,8 @@ namespace OHOS { View::OnStart(); SystemVolumeViewInit(); + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SystemVolumePresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void SystemVolumeView::OnSetUpView() @@ -98,6 +100,7 @@ namespace OHOS void SystemVolumeView::OnStop() { View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); RootView::GetInstance()->RemoveAll(); return; } diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h index c456417d6..f588801cd 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h +++ b/code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h @@ -6,6 +6,8 @@ #include "SystemView.h" #include "system/include/SystemModel.h" #include "components/ui_radio_button.h" +#include "KeyInputListener.h" + namespace OHOS { typedef enum @@ -55,6 +57,7 @@ namespace OHOS class SystemView; class SystemPresenter : public Presenter, public UIView::OnClickListener, + public RootView::OnKeyActListener, public UIView::OnDragListener { public: @@ -73,9 +76,11 @@ namespace OHOS 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; // 增加按键事件 private: SystemModel *systemModel; + bool isSystemUpgradeState{false};//是否处于升级状态 }; } // namespace OHOS diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp index 1921ea40c..beb1bc73d 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp @@ -7,6 +7,8 @@ #include "font/ui_font.h" #include "language/LanguageInit.h" #include "../../../../../../drivers/peripheral/utils/custom_utils.h" +#include "common/key_code.h" +#include "custom_utils.h" namespace OHOS { @@ -222,4 +224,21 @@ namespace OHOS #endif return true; } + + bool SystemPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 + { + if(!isSystemUpgradeState){ //如果处于系统升级状态power键返回功能无效 + UNUSED(view); + WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnKeyAct"); + uint16 keyID = event.GetKeyId(); + uint16 keyState = event.GetState(); + // 如果是power键,且是亮屏状态,按键释放就返回上一级 + if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0) + { + uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId(); + NativeAbility::GetInstance().ChangeSlice(preSlice); + } + } + return true; + } } \ No newline at end of file diff --git a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp index a725a0180..f8fdfa3e6 100644 --- a/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp +++ b/code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp @@ -475,6 +475,9 @@ namespace OHOS View::OnStart(); //InitIView(); initView_ext(43,120,380,100,120,"/user/res/SETTING_NEXT.bin"); + + RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SystemPresenter::GetInstance(); + RootView::GetInstance()->SetOnKeyActListener(keyactListener); } void SystemView::OnSetUpView() @@ -514,6 +517,7 @@ namespace OHOS { View::OnStop(); + RootView::GetInstance()->ClearOnKeyActListener(); RootView::GetInstance()->RemoveAll(); return; } diff --git a/code/sdk/drivers/peripheral/utils/custom_utils.c b/code/sdk/drivers/peripheral/utils/custom_utils.c index 39663c7dc..378a12b0a 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.c +++ b/code/sdk/drivers/peripheral/utils/custom_utils.c @@ -378,6 +378,15 @@ void uapi_setScreenDuration(int32_t time) display_api->set_screen_auto_off_timeout(time); } +/* + * @brief 获取屏幕状态 +*/ +int32_t uapi_get_screen_state(void) +{ + const power_display_svr_api_t *display_api = power_display_svr_get_api(); + return display_api->get_screen_state(); +} + #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 89163fbdb..29d8709ee 100644 --- a/code/sdk/drivers/peripheral/utils/custom_utils.h +++ b/code/sdk/drivers/peripheral/utils/custom_utils.h @@ -46,6 +46,8 @@ void ScreenAlwaysOnCtr(uint8_t turnOnFlag); void uapi_setScreenDuration(int32_t time); +int32_t uapi_get_screen_state(void); + 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);