遥控拍照:修复遥控拍照退出异常
authorCaisking <3449750381@qq.com>
Fri, 1 Nov 2024 06:49:38 +0000 (14:49 +0800)
committerCaisking <3449750381@qq.com>
Fri, 1 Nov 2024 06:49:38 +0000 (14:49 +0800)
code/sdk/application/wearable/fd230app/nativeui/takephotos/include/TakephotosModel.h
code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp

index 7af14d4..c89e73b 100644 (file)
  * @Date: 2024-07-06 16:27:31
  * @LastEditors: Caisking 3449750381@qq.com
  * @LastEditTime: 2024-07-15 20:30:24
- * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp
+ * @FilePath:
+ * /FD230/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp
  */
 /***
  * @Date: 2024-05-09 17:46:58
  * @LastEditors: Caisking 3449750381@qq.com
  * @LastEditTime: 2024-05-09 18:05:27
- * @FilePath: /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp
+ * @FilePath:
+ * /XTS_FD230/FD230/code/sdk/application/wearable/fd230app/nativeui/takephotos/src/TakephotosModel.cpp
  */
 
+#include "takephotos/include/TakephotosModel.h"
+#include "AppViewIDs.h"
+#include "NativeAbility.h"
+#include "bleEvent.h"
 #include "broadcast_feature.h"
 #include "broadcast_service.h"
+#include "custom_utils.h"
 #include "samgr_lite.h"
+#include "takephotos/include/TakephotosView.h"
+#include "thread_adapter.h"
 #include "vibrator_service.h"
-#include "custom_utils.h"
+#include "wearable_log.h"
 #include <cmsis_os2.h>
 #include <service/graphic_service.h>
-#include "thread_adapter.h"
-#include "wearable_log.h"
-#include "takephotos/include/TakephotosView.h"
-#include "takephotos/include/TakephotosModel.h"
-#include "NativeAbility.h"
-#include "AppViewIDs.h"
-#include "bleEvent.h"
 
 #ifdef __cplusplus
-extern "C"
-{
+extern "C" {
 #endif
-    static void Notify(void *args, const Topic topic, Request *request);
+static void Notify(void *args, const Topic topic, Request *request);
 
-    using namespace OHOS;
+using namespace OHOS;
 
-    Subscriber TakephotosSubscirber = {
-        .identity = NULL,
-        .args = NULL,
-        .Notify = Notify,
-    };
-    void TakephotosSubscribeTopic(Topic topic)
-    {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "stepsubscribeTopic, topic=%u", topic);
-        BroadcastApi *broadcastApi = NULL;
-        IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME);
-        if (api == NULL)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stepsubscribeTopic, GetFeatureApi failed");
-            return;
-        }
-        int result = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);
-        if (result != 0 || broadcastApi == NULL)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stepsubscribeTopic, QueryInterface failed");
-            return;
-        }
-        broadcastApi->SubscribeTopic((IUnknown *)broadcastApi, topic, &TakephotosSubscirber);
-        broadcastApi->Release((IUnknown *)broadcastApi);
-    }
+Subscriber TakephotosSubscirber = {
+    .identity = NULL,
+    .args = NULL,
+    .Notify = Notify,
+};
+void TakephotosSubscribeTopic(Topic topic) {
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "stepsubscribeTopic, topic=%u", topic);
+  BroadcastApi *broadcastApi = NULL;
+  IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME,
+                                                     BROADCAST_FEATURE_NAME);
+  if (api == NULL) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                  "stepsubscribeTopic, GetFeatureApi failed");
+    return;
+  }
+  int result =
+      api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);
+  if (result != 0 || broadcastApi == NULL) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                  "stepsubscribeTopic, QueryInterface failed");
+    return;
+  }
+  broadcastApi->SubscribeTopic((IUnknown *)broadcastApi, topic,
+                               &TakephotosSubscirber);
+  broadcastApi->Release((IUnknown *)broadcastApi);
+}
 
-    void TakephotosUnsubscribeTopic(Topic topic)
-    {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TakephotosUnsubscribeTopic, topic=%u", topic);
-        BroadcastApi *broadcastApi = NULL;
-        IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME, BROADCAST_FEATURE_NAME);
-        if (api == NULL)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TakephotosUnsubscribeTopic, GetFeatureApi failed");
-            return;
-        }
-        int result = api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);
-        if (result != 0 || broadcastApi == NULL)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TakephotosUnsubscribeTopic, QueryInterface failed");
-            return;
-        }
-        broadcastApi->UnsubscribeTopic((IUnknown *)broadcastApi, topic, &TakephotosSubscirber);
-        broadcastApi->Release((IUnknown *)broadcastApi);
-    }
+void TakephotosUnsubscribeTopic(Topic topic) {
+  WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "TakephotosUnsubscribeTopic, topic=%u",
+                topic);
+  BroadcastApi *broadcastApi = NULL;
+  IUnknown *api = SAMGR_GetInstance()->GetFeatureApi(BROADCAST_SERVICE_NAME,
+                                                     BROADCAST_FEATURE_NAME);
+  if (api == NULL) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                  "TakephotosUnsubscribeTopic, GetFeatureApi failed");
+    return;
+  }
+  int result =
+      api->QueryInterface(api, DEFAULT_VERSION, (void **)&broadcastApi);
+  if (result != 0 || broadcastApi == NULL) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP,
+                  "TakephotosUnsubscribeTopic, QueryInterface failed");
+    return;
+  }
+  broadcastApi->UnsubscribeTopic((IUnknown *)broadcastApi, topic,
+                                 &TakephotosSubscirber);
+  broadcastApi->Release((IUnknown *)broadcastApi);
+}
 
-    static void Notify(void *args, const Topic topic, Request *request)
-    {
-        UNUSED(args);
-        UNUSED(topic);
-        if (request == NULL)
-        {
-            return;
-        }
-        // 进入拍照界面
-        if (request->msgId == TOPIC_EVENT_ENTER_CMAERA)
-        {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " 遥控拍照 \r\n");
-            uapi_set_screen_on_api(); // 亮屏
-            TakephotosModel::GetInstance()->SetPopStaust(PopupPhoto::TakePopup);
-            //获取当前界面Id
-            int16_t curviewid =  OHOS::NativeAbility::GetInstance().GetCurSliceId();
-            //已经处于遥控拍照界面
-            if (curviewid == VIEW_TAKEPHOTOS) {
-                NativeAbility::GetInstance().ChangeSlice(VIEW_TAKEPHOTOS);
-            }
-            else {
-                NativeAbility::GetInstance().EnterSlice(VIEW_TAKEPHOTOS);
-            }
-        }
-        // 退出拍照
-        if (request->msgId == TOPIC_EVENT_CANCEL_CMAERA)
-        {
-            NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
-            cameraSend(3);
-            TakephotosModel::GetInstance()->SetPopStaust(PopupPhoto::CreamPopup);
-        }
+static void Notify(void *args, const Topic topic, Request *request) {
+  UNUSED(args);
+  UNUSED(topic);
+  if (request == NULL) {
+    return;
+  }
+  // 进入拍照界面
+  if (request->msgId == TOPIC_EVENT_ENTER_CMAERA) {
+    WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " 遥控拍照 \r\n");
+    uapi_set_screen_on_api(); // 亮屏
+    TakephotosModel::GetInstance()->SetPopStaust(PopupPhoto::TakePopup);
+    //获取当前界面Id
+    int16_t curviewid = OHOS::NativeAbility::GetInstance().GetCurSliceId();
+    //已经处于遥控拍照界面
+    if (curviewid == VIEW_TAKEPHOTOS) {
+      NativeAbility::GetInstance().ChangeSlice(VIEW_TAKEPHOTOS);
+    } else {
+      NativeAbility::GetInstance().EnterSlice(VIEW_TAKEPHOTOS);
     }
+  }
+  // 退出拍照
+  if (request->msgId == TOPIC_EVENT_CANCEL_CMAERA) {
+    //获取当前界面Id
+    int16_t curviewid = OHOS::NativeAbility::GetInstance().GetCurSliceId();
+    //已经处于遥控拍照界面
+    if (curviewid == VIEW_TAKEPHOTOS) {
+      NativeAbility::GetInstance().Back(
+          TransitionType::TRANSITION_BACK_TO_HEXAGONS);
+      cameraSend(3);
+      TakephotosModel::GetInstance()->SetPopStaust(PopupPhoto::CreamPopup);
+    }
+  }
+}
 #ifdef __cplusplus
 }
 #endif
 
-namespace OHOS
-{
-    TakephotosModel ::TakephotosModel()
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TakephotosModel::TakephotosModel()");
-        // sportdata->Initialize(); // 初始化结构体
-    }
-    TakephotosModel ::~TakephotosModel()
-    {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TakephotosModel::~TakephotosModel()");
-        TakephotosUnsubscribeTopic(TOPIC_EVENT_ENTER_CMAERA); // 取消订阅
-        TakephotosUnsubscribeTopic(TOPIC_EVENT_CANCEL_CMAERA);
-    }
-    TakephotosModel *TakephotosModel::GetInstance(void)
-    {
-        static TakephotosModel instance;
-        return &instance;
-    }
+namespace OHOS {
+TakephotosModel ::TakephotosModel() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TakephotosModel::TakephotosModel()");
+  // sportdata->Initialize(); // 初始化结构体
+}
+TakephotosModel ::~TakephotosModel() {
+  WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "TakephotosModel::~TakephotosModel()");
+  TakephotosUnsubscribeTopic(TOPIC_EVENT_ENTER_CMAERA); // 取消订阅
+  TakephotosUnsubscribeTopic(TOPIC_EVENT_CANCEL_CMAERA);
+}
+TakephotosModel *TakephotosModel::GetInstance(void) {
+  static TakephotosModel instance;
+  return &instance;
+}
 
-    void TakephotosModel ::Init()
-    {
-        TakephotosSubscribeTopic(TOPIC_EVENT_ENTER_CMAERA); // 进行消息订阅
-        TakephotosSubscribeTopic(TOPIC_EVENT_CANCEL_CMAERA);
-    }
+void TakephotosModel ::Init() {
+  TakephotosSubscribeTopic(TOPIC_EVENT_ENTER_CMAERA); // 进行消息订阅
+  TakephotosSubscribeTopic(TOPIC_EVENT_CANCEL_CMAERA);
+}
 
-    // 设置弹窗状态
-    void TakephotosModel ::SetPopStaust(PopupPhoto status)
-    {
-        popupStatus = status;
-    }
+// 设置弹窗状态
+void TakephotosModel ::SetPopStaust(PopupPhoto status) { popupStatus = status; }
 
-    // 获取弹窗状态
-    PopupPhoto TakephotosModel ::GetPopStaust()
-    {
-        return popupStatus;
-    }
-}
\ No newline at end of file
+// 获取弹窗状态
+PopupPhoto TakephotosModel ::GetPopStaust() { return popupStatus; }
+} // namespace OHOS
\ No newline at end of file