添加查找手机界面
authorluozheng <1732036298@qq.com>
Wed, 27 Mar 2024 11:48:33 +0000 (19:48 +0800)
committerluozheng <1732036298@qq.com>
Wed, 27 Mar 2024 11:48:33 +0000 (19:48 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneView.h
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp

index 4a9bf32..f3de236 100644 (file)
@@ -259,6 +259,7 @@ set(SOURCES
     #查找手机
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/findphone/src/FindPhonePresenter.cpp
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/findphone/src/FindPhoneView.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/findphone/src/FindPhoneModel.cpp
 
     #天气
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/weather/src/MainWeatherPresenter.cpp
diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h b/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h
new file mode 100644 (file)
index 0000000..7e303fb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-27 15:21:17
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-03-27 19:41:24
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/include/FindPhoneModel.h
+ */
+#ifndef FINDPHONE_MODEL_H
+#define FINDPHONE_MODEL_H
+
+namespace OHOS
+{
+    class FindPhoneModel
+    {
+    public:
+        static FindPhoneModel &GetInstance();
+        void SetBlueToothConnectedState(bool state);
+        bool GetBlueToothConnectedState();
+    private:
+        FindPhoneModel() {}
+        ~FindPhoneModel() {}
+        FindPhoneModel(const FindPhoneModel &) = delete;
+        const FindPhoneModel &operator=(const FindPhoneModel &) = delete;
+
+        bool isBlueToothConnected{false}; // 蓝牙是否连接
+    };
+}
+#endif
\ No newline at end of file
index 71415b4..6340d3c 100644 (file)
@@ -7,6 +7,7 @@
 #include "components/ui_label_ext.h"
 #include "components/ui_image_animator.h"
 #include "components/ui_label_button_ext.h"
+#include "components/ui_image_view.h"
 namespace OHOS
 {
     static constexpr int FINDPHONE_IMAGE_ANIMATOR_VIEW_X = 173;
@@ -30,7 +31,8 @@ namespace OHOS
         void OnStop() override;
 
     private:
-        void FindPhoneViewInit(void);
+        void FindPhoneViewInit_BlueToothConnected(void);
+        void FindPhoneViewInit_BlueToothDisConnected(void);
         void ClearAll();
         const char **CreateImagePathsArray(const char *basePath, const char *fileExtension, int numImages);
         void FreeImagePathsArray(const char **imagePaths, const int numImages);
@@ -39,6 +41,7 @@ namespace OHOS
         UILabelExt *FindPhoneLabel = nullptr;
         UIImageAnimatorView *FindPhoneImageAnimator = nullptr;
         UILabelButtonExt *FindPhoneLabelButton = nullptr;
+        UIImageView *FindPhoneImageView{nullptr};
         const char **FindPhonePathsArray{nullptr};
         ImageAnimatorInfo FindPhoneImageInfo[FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];
         bool viewInitStatus{false};
diff --git a/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp b/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp
new file mode 100644 (file)
index 0000000..66cffb2
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-27 15:21:30
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-03-27 19:41:35
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneModel.cpp
+ */
+
+#include "findphone/include/FindPhoneModel.h"
+
+namespace OHOS
+{
+    FindPhoneModel &FindPhoneModel::GetInstance()
+    {
+        static FindPhoneModel instance;
+        return instance;
+    }
+
+    /*设置蓝牙是否已连接*/
+    void FindPhoneModel::SetBlueToothConnectedState(bool state)
+    {
+        isBlueToothConnected = state;
+    }
+
+    /*获取蓝牙是否已连接*/
+    bool FindPhoneModel::GetBlueToothConnectedState()
+    {
+        return isBlueToothConnected;
+    }
+}
\ No newline at end of file
index 8806696..5278431 100644 (file)
@@ -2,13 +2,13 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-03-27 10:47:46
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-03-27 14:34:02
+ * @LastEditTime: 2024-03-27 19:39:53
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/findphone/src/FindPhoneView.cpp
  */
 #include "findphone/include/FindPhoneView.h"
 #include "findphone/include/FindPhonePresenter.h"
 #include "wearable_log.h"
-
+#include "findphone/include/FindPhoneModel.h"
 namespace OHOS
 {
 
@@ -36,24 +36,45 @@ namespace OHOS
     {
         if (viewInitStatus == true)
         {
-            FindPhoneGroupView->RemoveAll();
+            if (FindPhoneGroupView != nullptr)
+            {
+                FindPhoneGroupView->RemoveAll();
 
-            delete FindPhoneTitleLabel;
-            FindPhoneTitleLabel = nullptr;
+                if (FindPhoneTitleLabel == nullptr)
+                {
+                    delete FindPhoneTitleLabel;
+                    FindPhoneTitleLabel = nullptr;
+                }
 
-            FindPhoneImageAnimator->Stop();
-            delete FindPhoneImageAnimator;
-            FindPhoneImageAnimator = nullptr;
-            FreeImagePathsArray(FindPhonePathsArray, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+                if (FindPhoneImageView != nullptr)
+                {
+                    delete FindPhoneImageView;
+                    FindPhoneImageView = nullptr;
+                }
 
-            delete FindPhoneLabel;
-            FindPhoneLabel = nullptr;
+                if (FindPhoneImageAnimator != nullptr)
+                {
+                    FindPhoneImageAnimator->Stop();
+                    delete FindPhoneImageAnimator;
+                    FindPhoneImageAnimator = nullptr;
+                    FreeImagePathsArray(FindPhonePathsArray, FINDPHONE_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+                }
 
-            delete FindPhoneLabelButton;
-            FindPhoneLabelButton = nullptr;
+                if (FindPhoneLabel != nullptr)
+                {
+                    delete FindPhoneLabel;
+                    FindPhoneLabel = nullptr;
+                }
 
-            delete FindPhoneGroupView;
-            FindPhoneGroupView = nullptr;
+                if (FindPhoneLabelButton != nullptr)
+                {
+                    delete FindPhoneLabelButton;
+                    FindPhoneLabelButton = nullptr;
+                }
+
+                delete FindPhoneGroupView;
+                FindPhoneGroupView = nullptr;
+            }
         }
     }
 
@@ -84,16 +105,17 @@ namespace OHOS
         }
     }
 
-    void FindPhoneView::FindPhoneViewInit(void)
+    /*蓝牙如果是未连接状态*/
+    void FindPhoneView::FindPhoneViewInit_BlueToothDisConnected(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit");
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit_BlueToothConnected");
         if (FindPhoneGroupView == nullptr)
         {
             /* --------------------------- FindPhoneGroupView --------------------------- */
             FindPhoneGroupView = new UIViewGroup();
             if (FindPhoneGroupView == nullptr)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit] FindPhoneGroupView new fail!!");
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneGroupView new fail!!");
                 return;
             }
             FindPhoneGroupView->SetPosition(0, 0, 466, 466);
@@ -102,7 +124,87 @@ namespace OHOS
             FindPhoneTitleLabel = new UILabelExt();
             if (FindPhoneTitleLabel == nullptr)
             {
-                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit] FindPhoneTitleLabel new fail!!");
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
+                return;
+            }
+            FindPhoneTitleLabel->SetPosition(133, 51, 200, 40);
+            FindPhoneTitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+            FindPhoneTitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+            FindPhoneTitleLabel->SetText("查找手机");
+            FindPhoneTitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+            FindPhoneTitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+            FindPhoneTitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+            /* ----------------------- FindPhoneImageView ---------------------- */
+            FindPhoneImageView = new UIImageView();
+            if (FindPhoneImageView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
+                return;
+            }
+            FindPhoneImageView->SetPosition(193, 140, 80, 80);
+            const char *imagesPath = "/user/res/FastTrainingAttentionVector.bin";
+            FindPhoneImageView->SetSrc(imagesPath);
+            /* ----------------------------- FindPhoneLabel ----------------------------- */
+            FindPhoneLabel = new UILabelExt();
+            if (FindPhoneLabel == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabel new fail");
+                return;
+            }
+            FindPhoneLabel->SetPosition(33, 270, 400, 40);
+            FindPhoneLabel->SetStyle(STYLE_TEXT_FONT, 30);
+            FindPhoneLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+            FindPhoneLabel->SetText("蓝牙未连接");
+            FindPhoneLabel->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
+            FindPhoneLabel->SetTextColor(Color::GetColorFromRGBA(0x4f, 0xc3, 0x4c, 0xff));
+            FindPhoneLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+            FindPhoneLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+            /* -------------------------- FindPhoneLabelButton -------------------------- */
+            FindPhoneLabelButton = new UILabelButtonExt();
+            if (FindPhoneLabelButton == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[CreateDeviceUnBindingView] FindPhoneLabelButton new fail");
+                return;
+            }
+            FindPhoneLabelButton->SetPosition(0, 366, 466, 100);
+            FindPhoneLabelButton->SetViewId(FINDPHONE_LABELBUTTON);
+            const char *ImgSrc = "/user/res/466x100button.bin";
+            FindPhoneLabelButton->SetImageSrc(ImgSrc, ImgSrc);
+            FindPhoneLabelButton->SetText("关闭");
+            FindPhoneLabelButton->SetTextColor(Color::GetColorFromRGBA(0xff, 0x5a, 0x36, 0xff));
+            FindPhoneLabelButton->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+            FindPhoneLabelButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+            UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(FindPhonePresenter::GetInstance());
+            FindPhoneLabelButton->SetOnClickListener(clickListener);
+            /* ----------------------------------- Add ---------------------------------- */
+            FindPhoneGroupView->Add(FindPhoneTitleLabel);
+            FindPhoneGroupView->Add(FindPhoneImageView);
+            FindPhoneGroupView->Add(FindPhoneLabel);
+            FindPhoneGroupView->Add(FindPhoneLabelButton);
+        }
+        viewInitStatus = true;
+    }
+
+    /*蓝牙如果是已连接状态将初始化这个视图*/
+    void FindPhoneView::FindPhoneViewInit_BlueToothConnected(void)
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "FindPhoneView::FindPhoneViewInit_BlueToothConnected");
+        if (FindPhoneGroupView == nullptr)
+        {
+            /* --------------------------- FindPhoneGroupView --------------------------- */
+            FindPhoneGroupView = new UIViewGroup();
+            if (FindPhoneGroupView == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneGroupView new fail!!");
+                return;
+            }
+            FindPhoneGroupView->SetPosition(0, 0, 466, 466);
+            FindPhoneGroupView->SetStyle(STYLE_BACKGROUND_OPA, 0);
+            /* --------------------------- FindPhoneTitleLabel -------------------------- */
+            FindPhoneTitleLabel = new UILabelExt();
+            if (FindPhoneTitleLabel == nullptr)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "[FindPhoneViewInit_BlueToothConnected] FindPhoneTitleLabel new fail!!");
                 return;
             }
             FindPhoneTitleLabel->SetPosition(133, 51, 200, 40);
@@ -182,8 +284,15 @@ namespace OHOS
     void FindPhoneView::OnStart()
     {
         View<FindPhonePresenter>::OnStart();
-        FindPhoneViewInit();
 
+        if (FindPhoneModel::GetInstance().GetBlueToothConnectedState() == true) // 判断蓝牙是否是连接状态
+        {
+            FindPhoneViewInit_BlueToothConnected();
+        }
+        else
+        {
+            FindPhoneViewInit_BlueToothDisConnected();
+        }
         // 增加按键监听
         RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::FindPhonePresenter::GetInstance();
         RootView::GetInstance()->SetOnKeyActListener(keyactListener);