1262,手表不自动息屏,落腕息屏也不生效,进入支付宝扫码页面再退出恢复正常,出现一次bug 1567/1 1567/head
authorluozheng <1732036298@qq.com>
Wed, 25 Dec 2024 06:26:31 +0000 (14:26 +0800)
committerluozheng <1732036298@qq.com>
Wed, 25 Dec 2024 06:26:31 +0000 (14:26 +0800)
code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h
code/sdk/application/wearable/fd230app/nativeui/main/src/MainPresenterSample.cpp

index 33e8420..646ff5c 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-01 15:10:34
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-11-25 21:24:31
+ * @LastEditTime: 2024-12-25 11:33:45
  * @FilePath:
  * /FD230/code/sdk/application/wearable/fd230app/nativeui/main/include/MainPresenterSample.h
  */
@@ -115,12 +115,14 @@ private:
   void ProcessDataNotify(void);
   void SetCircleProgress(void);
   void SetCompassRotate(void);
+  void OpenCompassSensor(void);
+  void CloseCompassSensor(void);
   KeyInputListener *keyActListener_{nullptr};
   uint8_t state_ = UICheckBox::UICheckBoxState::MAX_STATUS_NUM;
   int64_t playerCurrentTime_{0};
   int64_t playerMusicDuration_{0};
   int64_t playerProgressValue_{0};
-  bool isCompassSensorOpened_{false};
+  bool isCompassSensorOpened_{false}; //指南针传感器是否已经打开
   CardId previousCardId{WATCH_FACE};
 
   int isPullDownPageView{false};//是否已经是在下拉界面
index b4d7f44..3871b97 100644 (file)
@@ -11,7 +11,7 @@
 #include "PlayersModel.h"
 #include "PlayersPresenter.h"
 #include "CompassPresenter.h"
-#include "CompassModel.h"
+#include "compass/include/CompassModel.h"
 #include "CompassCalibrationView.h"
 #include "drag_event.h"
 #include "graphic_service.h"
@@ -121,10 +121,6 @@ namespace OHOS
     }
     void MainPresenterSample::OnStop(void)
     {
-        if (isCompassSensorOpened_)
-        {
-            CompassModel::GetInstance()->CloseCompassSensor();
-        }
         Presenter<MainViewSample>::OnStop();
         RootView::GetInstance()->ClearOnKeyActListener();
         if (keyActListener_ != nullptr)
@@ -133,6 +129,7 @@ namespace OHOS
             keyActListener_ = nullptr;
         }
         PullUpDown_StopTimer();
+        CloseCompassSensor(); //切换Slice时要关闭指南针传感器
     }
 
     bool MainPresenterSample::OnClick(UIView &view, const ClickEvent &event)
@@ -311,21 +308,6 @@ namespace OHOS
 
         CardId cardId = view_->GetHorCurrentCard();
         SetTaskPeroid(cardId);
-        if (cardId == COMPASS)
-        {
-            if (!isCompassSensorOpened_)
-            {
-                CompassModel::GetInstance()->OpenCompassSensor();
-                isCompassSensorOpened_ = true;
-                ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //滑动到指南针页面时开启屏幕常亮
-            }
-        }
-        else if (isCompassSensorOpened_)
-        {
-            CompassModel::GetInstance()->CloseCompassSensor();
-            isCompassSensorOpened_ = false;
-            ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //滑动到指南针页面时取消屏幕常亮
-        }
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "OnSwipe OnSwipe");
         return;
     }
@@ -401,6 +383,29 @@ namespace OHOS
             DetermineToRotate();
         }
     }
+
+    // 滑动到指南针卡片开启指南针传感器
+    void MainPresenterSample::OpenCompassSensor(void)
+    {
+        if (!isCompassSensorOpened_)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "OpenCompassSensor");
+            isCompassSensorOpened_ = true;
+            CompassModel::GetInstance()->OpenCompassSensor();
+            ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); //滑动到指南针页面时开启屏幕常亮
+        }
+    }
+    // 关闭指南针传感器
+    void MainPresenterSample::CloseCompassSensor(void)
+    {
+        if(isCompassSensorOpened_)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "CloseCompassSensor");
+            isCompassSensorOpened_ = false;
+            CompassModel::GetInstance()->CloseCompassSensor();
+            ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); //滑动到指南针页面时取消屏幕常亮
+        }
+    }
     /* --------------------------------- 主界面卡片功能 -------------------------------- */
     void MainPresenterSample::Notify(void)
     {
@@ -413,6 +418,11 @@ namespace OHOS
             HeartModel::GetInstance()->Heart_Stop();
             HeartModel::GetInstance()->Heart_Control(HeartState::End,HeartCheck::CARDCHECK); //主动检测心率
         }
+        // 从指南针卡片跳转到其他卡片时切换到关闭长亮屏
+        if (previousCardId == COMPASS && currentCardId != COMPASS)
+        {
+            CloseCompassSensor();
+        }
 
         // 从睡眠卡片跳转到其他卡片时切换到睡眠卡片主界面
         if (previousCardId == SLEEP && currentCardId != SLEEP)
@@ -442,6 +452,7 @@ namespace OHOS
             break;
 
         case COMPASS:
+            OpenCompassSensor();
             SetCompassRotate();
             break;