解决刚刚进入关机动画按power键会取消关机或重启操作
authorluozheng <1732036298@qq.com>
Tue, 30 Jul 2024 02:31:08 +0000 (10:31 +0800)
committerluozheng <1732036298@qq.com>
Tue, 30 Jul 2024 02:31:08 +0000 (10:31 +0800)
code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/RebootAndShutdownPresenter.h
code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/src/RebootAndShutdownPresenter.cpp

index b623075..9b3df54 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-07-18 14:26:31
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-20 11:15:27
+ * @LastEditTime: 2024-07-30 10:25:25
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/rebootandshutdown/include/RebootAndShutdownPresenter.h
  */
 
@@ -35,6 +35,9 @@ namespace OHOS
         void OnPause() override;
         void OnStop() override;
 
+    private:
+        void handleSlider(UISlider *slider, bool isShutdown);
+
     private:
         bool OnClick(UIView &view, const ClickEvent &event) override;
         bool OnDrag(UIView &view, const DragEvent &event) override;
@@ -47,6 +50,7 @@ namespace OHOS
         RebootAndShutdownModel *model;
         bool X_DRAG_FLAG{false};
         bool isShutDownOperation{false};
+        bool isShutDownImageAnimatorStart{false};
     };
 }
 
index 02cbd14..8bbf6e0 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:11:17
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-27 13:03:52
+ * @LastEditTime: 2024-07-30 10:23:45
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/RebootAndShutdownPresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -88,7 +88,7 @@ namespace OHOS
         {
             RebootAndShutdownView::GetInstance()->ChangeView(FACTORYRESET, REBOOTANDSHUTDOWN);
         }
-        else if (strcmp(view.GetViewId(), SHUTDOWN_SLIDER_VIEWID) == 0) 
+        else if (strcmp(view.GetViewId(), SHUTDOWN_SLIDER_VIEWID) == 0)
         {
             auto shutdownSlider = view_->GetShutdownSlider();
             if (shutdownSlider != nullptr)
@@ -96,7 +96,7 @@ namespace OHOS
                 shutdownSlider->SetValue(SLIDER_VALUE_MIN);
             }
         }
-        else if (strcmp(view.GetViewId(), REBOOT_SLIDER_VIEWID) == 0) 
+        else if (strcmp(view.GetViewId(), REBOOT_SLIDER_VIEWID) == 0)
         {
             auto rebootSlider = view_->GetRebootSlider();
             if (rebootSlider != nullptr)
@@ -173,40 +173,35 @@ namespace OHOS
         auto shutdownSlider = view_->GetShutdownSlider();
         auto rebootSlider = view_->GetRebootSlider();
 
-        if (shutdownSlider->GetValue() < SLIDER_VALUE_MAX)
-        {
-            shutdownSlider->SetValue(SLIDER_VALUE_MIN);
-        }
-        else
-        {
-            shutdownSlider->SetValue(SLIDER_VALUE_MAX);
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "关机!!");
-
-            RebootAndShutdownView::GetInstance()->ChangeView(REBOOTANDSHUTDOWN, SHUTDOWNANIMATOR);
-
-            start_shutdown_or_reboot();
-            shutdown_reboot_prejobs();
-
-            ShutDownImageAnimatorView::GetInstance()->GeShutDownImageAnimatorView()->Start();
+        handleSlider(shutdownSlider, true);
+        handleSlider(rebootSlider, false);
+    }
 
-            isShutDownOperation = true;
+    void RebootAndShutdownPresenter::handleSlider(UISlider *slider, bool isShutdown)
+    {
+        if (!slider)
+        {
+            return;
         }
 
-        if (rebootSlider->GetValue() < SLIDER_VALUE_MAX)
+        if (slider->GetValue() < SLIDER_VALUE_MAX)
         {
-            rebootSlider->SetValue(SLIDER_VALUE_MIN);
+            slider->SetValue(SLIDER_VALUE_MIN);
         }
         else
         {
-            rebootSlider->SetValue(SLIDER_VALUE_MAX);
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "重启!!");
-            RebootAndShutdownView::GetInstance()->ChangeView(REBOOTANDSHUTDOWN, SHUTDOWNANIMATOR);
+            slider->SetValue(SLIDER_VALUE_MAX);
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%s!!", isShutdown ? "关机" : "重启");
+            view_->ChangeView(REBOOTANDSHUTDOWN, SHUTDOWNANIMATOR);
             start_shutdown_or_reboot();
             shutdown_reboot_prejobs();
 
-            ShutDownImageAnimatorView::GetInstance()->GeShutDownImageAnimatorView()->Start();
-
-            isShutDownOperation = false;
+            if (ShutDownImageAnimatorView::GetInstance() != nullptr && ShutDownImageAnimatorView::GetInstance()->GeShutDownImageAnimatorView() != nullptr)
+            {
+                ShutDownImageAnimatorView::GetInstance()->GeShutDownImageAnimatorView()->Start();
+                isShutDownImageAnimatorStart = true;
+            }
+            isShutDownOperation = isShutdown;
         }
     }
 
@@ -219,7 +214,10 @@ namespace OHOS
         // 如果是power键,且是亮屏状态,按键释放就返回上一级
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 0 && uapi_get_screen_state() == 0)
         {
-            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+            if (!isShutDownImageAnimatorStart)
+            {
+                NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+            }
         }
         return true;
     }