解决#832手表与APP蓝牙断连,手表端点击找手机,界面不会弹出蓝牙断连提示bug
authorluozheng <1732036298@qq.com>
Mon, 30 Sep 2024 03:46:08 +0000 (11:46 +0800)
committerluozheng <1732036298@qq.com>
Mon, 30 Sep 2024 03:46:08 +0000 (11:46 +0800)
查找手机界面会根据手机蓝牙是否有无连接显示不同界面

code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h
code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp

index af97544..0418fd1 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 15:21:17
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-10 16:23:41
+ * @LastEditTime: 2024-09-30 11:10:19
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h
  */
 #ifndef FINDPHONE_MODEL_H
@@ -16,6 +16,7 @@ namespace OHOS
         static FindPhoneModel &GetInstance();
         void SetBlueToothConnectedState(bool state);
         bool GetBlueToothConnectedState();
+        void start_or_stop_find_phone(int val);
     private:
         FindPhoneModel() {}
         ~FindPhoneModel() {}
index 940f76b..7a0f7f8 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-08-31 09:52:34
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-31 16:38:04
+ * @LastEditTime: 2024-09-30 11:15:01
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h
  * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
  */
@@ -51,7 +51,6 @@ namespace OHOS
         UIImageView *FindPhoneImageView{nullptr};
         const ImageInfo **FindPhonePathsArray{nullptr};
         ImageAnimatorInfo FindPhoneImageInfo[FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];
-        bool viewInitStatus{false};
     };
 } // namespace OHOS
 #endif
\ No newline at end of file
index b2cbdee..eb54d64 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 15:21:30
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-05-10 17:00:42
+ * @LastEditTime: 2024-09-30 11:11:00
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp
  */
 
@@ -10,6 +10,7 @@
 #include "bletest.h"
 #include <custom_runtime.h>
 #include "wearable_log.h"
+#include "bleEvent.h"
 
 namespace OHOS
 {
@@ -28,12 +29,22 @@ namespace OHOS
     /*获取与手机蓝牙是否已连接*/
     bool FindPhoneModel::GetBlueToothConnectedState()
     {
-        //return ble_is_ready() && ble_is_connect_ready();
+        // return ble_is_ready() && ble_is_connect_ready();
         uint8_t ret = uapi_dev_runtime_get_ble_connect_stat();
         WEARABLE_LOGI(WEARABLE_LOG_MODULE_APP, "ble phone connect stat = %d", ret);
         if (ret == 1)
-                return true;
-        else    
-                return false;
+            return true;
+        else
+            return false;
+    }
+
+    // 开始或停止查找手机
+    void FindPhoneModel::start_or_stop_find_phone(int val)
+    {
+        // 发送指令停止震动
+        if (FindPhoneModel::GetInstance().GetBlueToothConnectedState())
+        {
+            senfindphoneSend(val);
+        }
     }
 }
\ No newline at end of file
index 941ba0d..635b86a 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 10:47:40
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-31 16:43:28
+ * @LastEditTime: 2024-09-30 11:13:11
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhonePresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -60,6 +60,7 @@ namespace OHOS
     void FindPhonePresenter::OnStop(void)
     {
         Presenter<FindPhoneView>::OnStop();
+        FindPhoneModel::GetInstance().start_or_stop_find_phone(FINDPHONE_STOP); // 发送指令停止震动
     }
 
     bool FindPhonePresenter::OnClick(UIView &view, const ClickEvent &event)
@@ -68,11 +69,6 @@ namespace OHOS
         UNUSED(event);
         if (strcmp(view.GetViewId(), FINDPHONE_LABELBUTTON) == 0)
         {
-            // 发送指令停止震动
-            if (FindPhoneModel::GetInstance().GetBlueToothConnectedState())
-            {
-                senfindphoneSend(FINDPHONE_STOP);
-            }
             NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
         }
         return true;
@@ -96,11 +92,6 @@ namespace OHOS
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && FindPhonePresenter::X_DRAG_FLAG)
         {
             NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
-            // 发送指令停止震动
-            if (FindPhoneModel::GetInstance().GetBlueToothConnectedState())
-            {
-                senfindphoneSend(FINDPHONE_STOP);
-            }
             FindPhonePresenter::X_DRAG_FLAG = false;
         }
         return true;
@@ -115,11 +106,6 @@ namespace OHOS
         // 如果是power键,且是亮屏状态,按键释放就返回上一级
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
         {
-            // 发送指令停止震动
-            if (FindPhoneModel::GetInstance().GetBlueToothConnectedState())
-            {
-                senfindphoneSend(FINDPHONE_STOP);
-            }
             NativeAbility::GetInstance().Back(TransitionType::TRANSITION_BACK_TO_HEXAGONS);
         }
         return true;
index 758763a..706259f 100644 (file)
@@ -8,7 +8,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 10:47:46
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-31 18:27:22
+ * @LastEditTime: 2024-09-30 11:31:16
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp
  */
 #include "findphone/include/FindPhoneView.h"
@@ -45,54 +45,47 @@ namespace OHOS
 
     void FindPhoneView::ClearAll()
     {
-        if (viewInitStatus == true)
+        if (container_ != nullptr)
         {
-            // UIViewGroup *tmpGroup = dynamic_cast<UIViewGroup *>(container_);
-            // UIViewGroup::RemoveAndDeleteAllRecursively(tmpGroup);
-            // FreeImageInfoArray(FindPhonePathsArray, FIND_PONE_IMAGE_SRC, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+            container_->RemoveAll();
+            delete container_;
+            container_ = nullptr;
+        }
+
+        if (FindPhoneGroupView != nullptr)
+        {
+            FindPhoneGroupView->RemoveAll();
 
-            if (container_ != nullptr)
+            if (FindPhoneTitleLabel != nullptr)
             {
-                container_->RemoveAll();
-                delete container_;
-                container_ = nullptr;
+                delete FindPhoneTitleLabel;
+                FindPhoneTitleLabel = nullptr;
             }
-            if (FindPhoneGroupView != nullptr)
+            if (FindPhoneImageView != nullptr)
             {
-                FindPhoneGroupView->RemoveAll();
-
-                if (FindPhoneTitleLabel != nullptr)
-                {
-                    delete FindPhoneTitleLabel;
-                    FindPhoneTitleLabel = nullptr;
-                }
-                if (FindPhoneImageView != nullptr)
-                {
-                    delete FindPhoneImageView;
-                    FindPhoneImageView = nullptr;
-                }
-                if (FindPhoneImageAnimator != nullptr)
-                {
-                    FindPhoneImageAnimator->Stop();
-                    delete FindPhoneImageAnimator;
-                    FindPhoneImageAnimator = nullptr;
-                    // FreeImagePathsArray(FindPhonePathsArray, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
-                    FreeImageInfoArray(FindPhonePathsArray, FIND_PONE_IMAGE_SRC, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
-                }
-                if (FindPhoneLabel != nullptr)
-                {
-                    delete FindPhoneLabel;
-                    FindPhoneLabel = nullptr;
-                }
-                if (FindPhoneLabelButton != nullptr)
-                {
-                    delete FindPhoneLabelButton;
-                    FindPhoneLabelButton = nullptr;
-                }
-                delete FindPhoneGroupView;
-                FindPhoneGroupView = nullptr;
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::ClearAll over!!");
+                delete FindPhoneImageView;
+                FindPhoneImageView = nullptr;
+            }
+            if (FindPhoneImageAnimator != nullptr)
+            {
+                FindPhoneImageAnimator->Stop();
+                delete FindPhoneImageAnimator;
+                FindPhoneImageAnimator = nullptr;
+                FreeImageInfoArray(FindPhonePathsArray, FIND_PONE_IMAGE_SRC, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+            }
+            if (FindPhoneLabel != nullptr)
+            {
+                delete FindPhoneLabel;
+                FindPhoneLabel = nullptr;
             }
+            if (FindPhoneLabelButton != nullptr)
+            {
+                delete FindPhoneLabelButton;
+                FindPhoneLabelButton = nullptr;
+            }
+            delete FindPhoneGroupView;
+            FindPhoneGroupView = nullptr;
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::ClearAll over!!");
         }
     }
 
@@ -121,12 +114,11 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
                 return;
             }
-            FindPhoneTitleLabel->SetPosition(133, 51, 200, 40);
+            FindPhoneTitleLabel->SetPosition(83, 50, 300, 35);
             FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
             FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-            // FindPhoneTitleLabel->SetText("查找手机");
-            FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE);
-            FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+            FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE);//查找手机
+            FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
             FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
             FindPhoneTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
             /* ----------------------- FindPhoneImageView ---------------------- */
@@ -145,12 +137,11 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail");
                 return;
             }
-            FindPhoneLabel->SetPosition(33, 270, 400, 40);
+            FindPhoneLabel->SetPosition(53, 270, 360, 35);
             FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30);
             FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-            // FindPhoneLabel->SetText("蓝牙未连接");
-            FindPhoneLabel->SetTextId(STR_BLUETOOTH_DISCONNECTED);
-            FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+            FindPhoneLabel->SetTextId(STR_BLUETOOTH_DISCONNECTED);//蓝牙未连接
+            FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
             FindPhoneLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff));
             FindPhoneLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
             FindPhoneLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
@@ -164,8 +155,7 @@ namespace OHOS
             FindPhoneLabelButton->SetPosition(0, 366, 466, 100);
             FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON);
             FindPhoneLabelButton->SetImageSrc(PNG_BUTTON_466x100_IMAGE, PNG_BUTTON_466x100_IMAGE);
-            // FindPhoneLabelButton->SetText("关闭");
-            FindPhoneLabelButton->SetTextId(STR_CLOSE);
+            FindPhoneLabelButton->SetTextId(STR_CLOSE);//关闭
             FindPhoneLabelButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff));
             FindPhoneLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
             FindPhoneLabelButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
@@ -177,7 +167,6 @@ namespace OHOS
             FindPhoneGroupView->Add(FindPhoneLabelButton);
             container_->Add(FindPhoneGroupView);
         }
-        viewInitStatus = true;
     }
 
     /*蓝牙如果是已连接状态将初始化这个视图*/
@@ -205,12 +194,11 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
                 return;
             }
-            FindPhoneTitleLabel->SetPosition(133, 51, 200, 40);
+            FindPhoneTitleLabel->SetPosition(83, 50, 300, 35);
             FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
             FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-            // FindPhoneTitleLabel->SetText("查找手机");
-            FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE);
-            FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+            FindPhoneTitleLabel->SetTextId(STR_FIND_PHONE);//查找手机
+            FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
             FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
             FindPhoneTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
             /* ----------------------- FindPhoneImageAnimator ---------------------- */
@@ -247,12 +235,11 @@ namespace OHOS
                 WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail");
                 return;
             }
-            FindPhoneLabel->SetPosition(33, 270, 400, 40);
+            FindPhoneLabel->SetPosition(53, 270, 360, 35);
             FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30);
             FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
-            // FindPhoneLabel->SetText("手机正在响铃/震动");
-            FindPhoneLabel->SetTextId(STR_PHONE_RINGING_VIBRATING);
-            FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+            FindPhoneLabel->SetTextId(STR_PHONE_RINGING_VIBRATING);//手机正在响铃/震动
+            FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
             FindPhoneLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff));
             FindPhoneLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
             FindPhoneLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
@@ -279,21 +266,11 @@ namespace OHOS
             FindPhoneGroupView->Add(FindPhoneLabelButton);
             container_->Add(FindPhoneGroupView);
         }
-        viewInitStatus = true;
     }
 
     void FindPhoneView::OnStart()
     {
         View<FindPhonePresenter>::OnStart();
-        // if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() == true) // 判断蓝牙是否是连接状态
-        // {
-        //     FindPhoneViewInit_BlueToothConnected();
-        //     senfindphoneSend(FINDPHONE_START);
-        // }
-        // else
-        // {
-        //     FindPhoneViewInit_BlueToothDisConnected();
-        // }
         SetContainerView(new UIViewGroup());
         if (GetContainer() == nullptr)
         {
@@ -304,12 +281,16 @@ namespace OHOS
         container_->SetTouchable(true);
         container_->SetDraggable(true);
 
-        if (!viewInitStatus)
+        if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() == true) // 判断蓝牙是否是连接状态
         {
             FindPhoneViewInit_BlueToothConnected();
-            senfindphoneSend(FINDPHONE_START);
-            viewInitStatus = true;
+            FindPhoneModel::GetInstance().start_or_stop_find_phone(FINDPHONE_START);
         }
+        else
+        {
+            FindPhoneViewInit_BlueToothDisConnected();
+        }
+
         RootView::GetInstance()->SetOnKeyActListener(presenter_);
     }