1.设置视图中的Slice添加按键监听
authorluozheng <1732036298@qq.com>
Thu, 21 Mar 2024 08:23:08 +0000 (16:23 +0800)
committerluozheng <1732036298@qq.com>
Thu, 21 Mar 2024 08:23:08 +0000 (16:23 +0800)
2.custom_utils添加获取屏幕状态函数

22 files changed:
code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/classicbluetooth/src/ClassicBlueToothView.cpp
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/include/DisplayBrightnessPresenter.h
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessPresent.cpp
code/sdk/application/wearable/fd230app/nativeui/displaybrightness/src/DisplayBrightnessView.cpp
code/sdk/application/wearable/fd230app/nativeui/rebootdevice/include/ShutDownAnimatorView.h
code/sdk/application/wearable/fd230app/nativeui/rebootdevice/src/RebootPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionPresenter.h
code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/src/SecondaryFunctionView.cpp
code/sdk/application/wearable/fd230app/nativeui/settings/src/SettingPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SystemVolumePresenter.h
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationView.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SystemVolumeView.cpp
code/sdk/application/wearable/fd230app/nativeui/system/include/SystemPresenter.h
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemView.cpp
code/sdk/drivers/peripheral/utils/custom_utils.c
code/sdk/drivers/peripheral/utils/custom_utils.h

index 908b12f..8ff7b93 100644 (file)
@@ -143,8 +143,9 @@ namespace OHOS
     {\r
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ClassicBlueToothPresenter::OnKeyAct");\r
         uint16 keyID = event.GetKeyId();\r
-        // 如果是power键就返回上一级\r
-        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))\r
+        uint16 keyState = event.GetState();\r
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
         {\r
             uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();\r
             if (preSlice == VIEW_SETTING || VIEW_BLUETOOTH_EARPHONE)\r
index 2f44479..f025ed6 100644 (file)
@@ -299,9 +299,8 @@ namespace OHOS
         ClassicBlueToothViewInit();\r
 \r
         // 增加按键监听\r
-        //RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::ClassicBlueToothPresenter::GetInstance();\r
-        //RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
-        RootView::GetInstance()->SetIntercept(true);\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::ClassicBlueToothPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
     }\r
 \r
     void ClassicBlueToothView::OnSetUpView()\r
index 858b97e..74abb5b 100644 (file)
@@ -83,6 +83,7 @@ namespace OHOS
     class DisplayBrightnessPresenter : public Presenter<DisplayBrightnessView>,\r
                                        public UIView::OnClickListener,\r
                                        public UIView::OnDragListener,\r
+                                       public RootView::OnKeyActListener,\r
                                        public UICheckBox::OnChangeListener\r
     {\r
     public:\r
@@ -105,6 +106,7 @@ namespace OHOS
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
         bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
         bool OnChange(UICheckBox::UICheckBoxState state) override;\r
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
     };\r
 } // namespace OHOS\r
 \r
index 35a82a6..72ea7cf 100644 (file)
@@ -6,6 +6,8 @@
 #include "cat1_ctl.h"\r
 #include "displaybrightness/include/DisplayBrightnessModel.h"\r
 #include "power_display_service.h"\r
+#include "common/key_code.h"\r
+#include <custom_utils.h>\r
 namespace OHOS\r
 {\r
     // 当前Presenter属性实例化的内存指针\r
@@ -59,7 +61,7 @@ namespace OHOS
         if (value >= BRIGHTNESS_MIN && value <= BRIGHTNESS_MAX)\r
         {\r
             p_BrightnessControlView->SetScreenBrightnessValue(value);\r
-            DisplayBrightnessModel::GetInstance()->KeepScreenBrightnessValues(0xff);// 将Model层保存的状态清除\r
+            DisplayBrightnessModel::GetInstance()->KeepScreenBrightnessValues(0xff); // 将Model层保存的状态清除\r
         }\r
     }\r
 \r
@@ -85,7 +87,7 @@ namespace OHOS
         {\r
             p_ScreenDurationView->SetRadioButtonSelectStatus(ScreenDurationRadioButton3);\r
         }\r
-        DisplayBrightnessModel::GetInstance()->KeepScreenDurationRadioButtonSlectStatus(ScreenDurationRadioButton1);// 将Model层保存的状态清除\r
+        DisplayBrightnessModel::GetInstance()->KeepScreenDurationRadioButtonSlectStatus(ScreenDurationRadioButton1); // 将Model层保存的状态清除\r
     }\r
 \r
     void DisplayBrightnessPresenter::OnStart()\r
@@ -209,6 +211,21 @@ namespace OHOS
         return true;\r
     }\r
 \r
+    bool DisplayBrightnessPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
+    {\r
+        UNUSED(view);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DisplayBrightnessPresenter::OnKeyAct");\r
+        unsigned short keyID = event.GetKeyId();\r
+        unsigned short keyState = event.GetState();\r
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+        {\r
+            uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();\r
+            NativeAbility::GetInstance().ChangeSlice(preSlice);\r
+        }\r
+        return true;\r
+    }\r
+\r
     bool ScreenDurationRadiobuttonOnChangeListener::OnChange(UICheckBox::UICheckBoxState state)\r
     {\r
         DisplayBrightnessView *p_DisplayBrightnessView = DisplayBrightnessView::GetInstance();\r
@@ -373,4 +390,5 @@ namespace OHOS
         UNUSED(view);\r
         return true;\r
     }\r
+\r
 }
\ No newline at end of file
index 4b24a89..617122e 100644 (file)
@@ -522,6 +522,8 @@ namespace OHOS
         {\r
             DisplayAndBrightnessViewInit();\r
         }\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::DisplayBrightnessPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
     }\r
 \r
     void DisplayBrightnessView::OnSetUpView()\r
@@ -557,6 +559,7 @@ namespace OHOS
     {\r
 \r
         View<DisplayBrightnessPresenter>::OnStop();\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index a410018..b6ce033 100644 (file)
@@ -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:
index 3a502e2..69534af 100644 (file)
@@ -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<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0)
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
         {
             uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
             NativeAbility::GetInstance().ChangeSlice(preSlice);
index 39b8142..70b198b 100644 (file)
@@ -1,8 +1,17 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-02-27 18:06:27\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-03-21 14:32:11\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/secondaryfunction/include/SecondaryFunctionPresenter.h\r
+ */\r
 #ifndef SECONDARY_FUNCTION_PRESENTER_H\r
 #define SECONDARY_FUNCTION_PRESENTER_H\r
 \r
 #include "Presenter.h"\r
 #include "SecondaryFunctionView.h"\r
+#include "KeyInputListener.h"\r
+\r
 namespace OHOS\r
 {\r
 \r
@@ -35,6 +44,7 @@ namespace OHOS
     class SecondaryFunctionView;\r
     class SecondaryFunctionPresenter : public Presenter<SecondaryFunctionView>,\r
                                        public UIView::OnClickListener,\r
+                                       public RootView::OnKeyActListener,\r
                                        public UIView::OnDragListener\r
     {\r
     public:\r
@@ -48,11 +58,13 @@ namespace OHOS
 \r
         static SecondaryFunctionPresenter *GetInstance();\r
         void SetHeartRateOrBloodOxygenQuickAccessRadioButtonSelectState(int state);\r
+\r
     private:\r
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
         bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
     };\r
 } // namespace OHOS\r
 #endif
\ No newline at end of file
index 7375fb3..1f104dd 100644 (file)
@@ -3,6 +3,9 @@
 #include "NativeAbility.h"\r
 #include "secondaryfunction/include/SecondaryFunctionPresenter.h"\r
 #include "secondaryfunction/include/SecondaryFunctionModel.h"\r
+#include "components/ui_image_animator.h"\r
+#include "common/key_code.h"\r
+#include "custom_utils.h"\r
 namespace OHOS\r
 {\r
 \r
@@ -110,6 +113,20 @@ namespace OHOS
         return false;\r
     }\r
 \r
+    bool SecondaryFunctionPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
+    {\r
+        UNUSED(view);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct");\r
+        uint16 keyID = event.GetKeyId();\r
+        uint16 keyState = event.GetState();\r
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+        {\r
+            NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING);\r
+        }\r
+        return true;\r
+    }\r
+\r
     bool SecondaryFunctionPresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
         UNUSED(event);\r
index e76738b..e8ff535 100644 (file)
@@ -330,6 +330,9 @@ namespace OHOS
     {\r
         View<SecondaryFunctionPresenter>::OnStart();\r
         SecondaryFunctionViewInit();\r
+\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SecondaryFunctionPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
     }\r
 \r
     void SecondaryFunctionView::OnSetUpView()\r
@@ -357,6 +360,7 @@ namespace OHOS
     {\r
 \r
         View<SecondaryFunctionPresenter>::OnStop();\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index 27880ed..c4f465a 100644 (file)
@@ -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<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER))
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0)
         {
             uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();
             if (preSlice == VIEW_APPLIST)
index d843875..df3df6e 100644 (file)
@@ -1,8 +1,16 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-02-19 10:39:08\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-03-21 11:49:25\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/include/SoundAndVibrationPresenter.h\r
+ */\r
 #ifndef SOUND_AND_VIBRATION_PRESENTER_H\r
 #define SOUND_AND_VIBRATION_PRESENTER_H\r
 \r
 #include "Presenter.h"\r
 #include "SoundAndVibrationView.h"\r
+#include "KeyInputListener.h"\r
 \r
 namespace OHOS\r
 {\r
@@ -25,6 +33,7 @@ namespace OHOS
     class SoundAndVibrationView;\r
     class SoundAndVibrationPresenter : public Presenter<SoundAndVibrationView>,\r
                                        public UIView::OnClickListener,\r
+                                       public RootView::OnKeyActListener,\r
                                        public UIView::OnDragListener\r
     {\r
     public:\r
@@ -39,11 +48,14 @@ namespace OHOS
         static SoundAndVibrationPresenter *GetInstance();\r
         void VibrationReminderToggleButtonStateSetting(bool value);\r
         void SilentModeToggleButtonStateSetting(bool value);\r
+\r
     private:\r
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
         bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
+\r
     private:\r
         UIView *view_{nullptr};\r
     };\r
index 85810c0..42e23dd 100644 (file)
@@ -4,14 +4,14 @@
 #include "Presenter.h"\r
 #include "SystemVolumeView.h"\r
 #include "wearable_log.h"\r
-\r
+#include "KeyInputListener.h"\r
 namespace OHOS\r
 {\r
     typedef enum : uint8_t\r
     {\r
         VOLUMEREDUCE = 0, // 声音降低\r
         VOLUMEADD = 1,    // 声音增加\r
-        OTHER = 2,  // 其他\r
+        OTHER = 2,        // 其他\r
     } VolumeStatusChange;\r
 \r
     /*\r
@@ -39,6 +39,7 @@ namespace OHOS
     class SystemVolumeView;\r
     class SystemVolumePresenter : public Presenter<SystemVolumeView>,\r
                                   public UIView::OnClickListener,\r
+                                  public RootView::OnKeyActListener,\r
                                   public UIView::OnDragListener\r
     {\r
     public:\r
@@ -56,6 +57,7 @@ namespace OHOS
         // 因为继承了OnClickListener,所以有OnClick属性,至于参数,原函数也这样直接继承;\r
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
     };\r
 } // namespace OHOS\r
 \r
index 684e274..f50de29 100644 (file)
@@ -1,9 +1,20 @@
+/*\r
+ * @Author: luozheng 1732036298@qq.com\r
+ * @Date: 2024-02-19 10:39:11\r
+ * @LastEditors: luozheng 1732036298@qq.com\r
+ * @LastEditTime: 2024-03-21 14:23:38\r
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp\r
+ */\r
+\r
 #include "AppViewIDs.h"\r
 #include "NativeAbility.h"\r
 #include "graphic_math.h"\r
 #include "string.h"\r
 #include "soundandvibration/include/SoundAndVibrationPresenter.h"\r
 #include "soundandvibration/include/SoundAndVibrationModel.h"\r
+#include "common/key_code.h"\r
+#include "custom_utils.h"\r
+\r
 namespace OHOS\r
 {\r
 \r
@@ -93,6 +104,8 @@ namespace OHOS
 \r
     bool SoundAndVibrationPresenter::OnDragEnd(UIView &view, const DragEvent &event)\r
     {\r
+        UNUSED(view);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnDragEnd");\r
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT)\r
         {\r
             NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING);\r
@@ -100,6 +113,20 @@ namespace OHOS
         return true;\r
     }\r
 \r
+    bool SoundAndVibrationPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
+    {\r
+        UNUSED(view);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SoundAndVibrationPresenter::OnKeyAct");\r
+        uint16 keyID = event.GetKeyId();\r
+        uint16 keyState = event.GetState();\r
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+        {\r
+            NativeAbility::GetInstance().ChangeSlice(VIEW_SETTING);\r
+        }\r
+        return true;\r
+    }\r
+\r
     bool SoundAndVibrationPresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
 \r
index bbbd6c5..404fe08 100644 (file)
@@ -536,6 +536,8 @@ namespace OHOS
     {\r
         View<SoundAndVibrationPresenter>::OnStart();\r
         InitView();\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SoundAndVibrationPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
     }\r
 \r
     void SoundAndVibrationView::OnSetUpView()\r
@@ -576,6 +578,7 @@ namespace OHOS
     {\r
 \r
         View<SoundAndVibrationPresenter>::OnStop();\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index cd2beb8..719e503 100644 (file)
@@ -3,8 +3,10 @@
 #include "graphic_math.h"\r
 #include "string.h"\r
 #include "soundandvibration/include/SystemVolumePresenter.h"\r
-\r
 #include <audio_manager.h>\r
+#include "common/key_code.h"\r
+#include "custom_utils.h"\r
+\r
 // 系统音量\r
 namespace OHOS\r
 {\r
@@ -67,6 +69,21 @@ namespace OHOS
         return true;\r
     }\r
 \r
+    bool SystemVolumePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
+    {\r
+        UNUSED(view);\r
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumePresenter::OnKeyAct");\r
+        uint16 keyID = event.GetKeyId();\r
+        uint16 keyState = event.GetState();\r
+        // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+        {\r
+            uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();\r
+            NativeAbility::GetInstance().ChangeSlice(preSlice);\r
+        }\r
+        return true;\r
+    }\r
+\r
     bool SystemVolumePresenter::OnClick(UIView &view, const ClickEvent &event)\r
     {\r
         UNUSED(view);\r
index 2e9f089..47e7cc9 100644 (file)
@@ -80,6 +80,8 @@ namespace OHOS
     {\r
         View<SystemVolumePresenter>::OnStart();\r
         SystemVolumeViewInit();\r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SystemVolumePresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
     }\r
 \r
     void SystemVolumeView::OnSetUpView()\r
@@ -98,6 +100,7 @@ namespace OHOS
     void SystemVolumeView::OnStop()\r
     {\r
         View<SystemVolumePresenter>::OnStop();\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index c456417..f588801 100644 (file)
@@ -6,6 +6,8 @@
 #include "SystemView.h"\r
 #include "system/include/SystemModel.h"\r
 #include "components/ui_radio_button.h"\r
+#include "KeyInputListener.h"\r
+\r
 namespace OHOS\r
 {\r
     typedef enum\r
@@ -55,6 +57,7 @@ namespace OHOS
     class SystemView;\r
     class SystemPresenter : public Presenter<SystemView>,\r
                             public UIView::OnClickListener,\r
+                            public RootView::OnKeyActListener,\r
                             public UIView::OnDragListener\r
     {\r
     public:\r
@@ -73,9 +76,11 @@ namespace OHOS
         bool OnClick(UIView &view, const ClickEvent &event) override;\r
         bool OnDrag(UIView &view, const DragEvent &event) override;\r
         bool OnDragEnd(UIView &view, const DragEvent &event) override;\r
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件\r
 \r
     private:\r
         SystemModel *systemModel;\r
+        bool isSystemUpgradeState{false};//是否处于升级状态\r
     };\r
 } // namespace OHOS\r
 \r
index 1921ea4..beb1bc7 100644 (file)
@@ -7,6 +7,8 @@
 #include "font/ui_font.h"\r
 #include "language/LanguageInit.h"\r
 #include "../../../../../../drivers/peripheral/utils/custom_utils.h"\r
+#include "common/key_code.h"\r
+#include "custom_utils.h"\r
 \r
 namespace OHOS\r
 {\r
@@ -222,4 +224,21 @@ namespace OHOS
 #endif\r
         return true;\r
     }\r
+\r
+    bool SystemPresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件\r
+    {\r
+        if(!isSystemUpgradeState){ //如果处于系统升级状态power键返回功能无效\r
+            UNUSED(view);\r
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemPresenter::OnKeyAct");\r
+            uint16 keyID = event.GetKeyId();\r
+            uint16 keyState = event.GetState();\r
+            // 如果是power键,且是亮屏状态,按键释放就返回上一级\r
+            if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)\r
+            {\r
+                uint16_t preSlice = NativeAbility::GetInstance().GetPreSliceId();\r
+                NativeAbility::GetInstance().ChangeSlice(preSlice);\r
+            }\r
+        }\r
+        return true;\r
+    }\r
 }
\ No newline at end of file
index a725a01..f8fdfa3 100644 (file)
@@ -475,6 +475,9 @@ namespace OHOS
         View<SystemPresenter>::OnStart();\r
         //InitIView();\r
         initView_ext(43,120,380,100,120,"/user/res/SETTING_NEXT.bin");\r
+        \r
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::SystemPresenter::GetInstance();\r
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);\r
     }\r
 \r
     void SystemView::OnSetUpView()\r
@@ -514,6 +517,7 @@ namespace OHOS
     {\r
 \r
         View<SystemPresenter>::OnStop();\r
+        RootView::GetInstance()->ClearOnKeyActListener();\r
         RootView::GetInstance()->RemoveAll();\r
         return;\r
     }\r
index 39663c7..378a12b 100644 (file)
@@ -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"
 
 
index 89163fb..29d8709 100644 (file)
@@ -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);