1.解决语言界面黑屏问题
authorluozheng <1732036298@qq.com>
Wed, 21 May 2025 07:20:44 +0000 (15:20 +0800)
committerluozheng <1732036298@qq.com>
Wed, 21 May 2025 07:20:44 +0000 (15:20 +0800)
2.合并二维码界面

code/sdk/application/wearable/fd230/nativeapp/nativeui/languagecode/include/LanguageSwitchPresenter.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/languagecode/include/LanguageSwitchView.h
code/sdk/application/wearable/fd230/nativeapp/nativeui/languagecode/src/LanguageSwitchListAdapter.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/languagecode/src/LanguageSwitchListitemView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/languagecode/src/LanguageSwitchModel.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/languagecode/src/LanguageSwitchPresenter.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/languagecode/src/LanguageSwitchView.cpp
code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/include/WatchQRCodePresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/include/WatchQRCodeView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/src/WatchQRCodeView.cpp [new file with mode: 0644]

index 3be924b..423a66e 100644 (file)
@@ -29,9 +29,6 @@ namespace OHOS
         virtual ~LanguageSwitchPresenter();
 
         void OnStart() override;
-        void OnPause() override;
-        void OnResume() override;
-        void OnStop() override;
 
         static LanguageSwitchPresenter *GetInstance();
         void SetLabelExt(UILabelExt *label);
index d27b2da..d39cc2f 100644 (file)
@@ -28,6 +28,7 @@ namespace OHOS
 
         void OnStart() override;
         void AddLanguageItemToList(const Language &item);
+        void RefreshLanguageList(void);
         UIList *GetLanguageList(void);
         void InithintView();
         void show_hint_group(std::string code,bool data);
index e4cd974..3581dae 100644 (file)
@@ -98,14 +98,14 @@ namespace OHOS
             if (strcmp(LanguageSwitchModel::GetInstance().GetCurLanguageCode(), view_languageid) == 0)
             {
 // 设置选中
-#ifdef FD230_650
+#ifdef FD230
                 item->GetUILabelButtonExt()->SetImageSrc(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_ON_IMAGE);
 #endif
             }
             else
             {
 // 设置未选中
-#ifdef FD230_650
+#ifdef FD230
                 item->GetUILabelButtonExt()->SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE);
 #endif
             }
index 638fb6e..bac660c 100644 (file)
@@ -61,7 +61,7 @@ namespace OHOS
         m_LabelButtonExt.SetLabelPosition(47, 0);
         m_LabelButtonExt.SetImagePosition(290, 30);
         m_LabelButtonExt.SetTouchable(true);
-        #ifdef FD230_650
+        #ifdef FD230
         m_LabelButtonExt.SetImageSrc(PNG_CHECKBOX_OFF_IMAGE, PNG_CHECKBOX_OFF_IMAGE);
         #endif
 
index 1211ca6..5ce6171 100644 (file)
@@ -49,7 +49,7 @@ namespace OHOS
             {
                 set_hint_code(id);
                 set_hint_flag(true);
-#ifdef FD230_650
+#ifdef FD230
                 NativeAbility::GetInstance().EnterSlice(VIEW_LANGUAGE_SWITCH);
 #endif
             }
index 7f28611..25f2a38 100644 (file)
@@ -48,30 +48,17 @@ namespace OHOS
 
     void LanguageSwitchPresenter::OnStart()
     {
-        Presenter<LanguageSwitchView>::OnStart();
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LanguageSwitchPresenter::OnStart");
         if (view_ == nullptr)
         {
             return;
         }
         for (uint8_t i = 0; i < 2; i++)
         {
+            printf("LanguageSwitchPresenter::OnStart: %d\n", i);
             view_->AddLanguageItemToList(languages[i]);
         }
-    }
-
-    void LanguageSwitchPresenter::OnResume(void)
-    {
-        Presenter<LanguageSwitchView>::OnResume();
-    }
-
-    void LanguageSwitchPresenter::OnPause(void)
-    {
-        Presenter<LanguageSwitchView>::OnPause();
-    }
-
-    void LanguageSwitchPresenter::OnStop(void)
-    {
-        Presenter<LanguageSwitchView>::OnStop();
+        view_->RefreshLanguageList();
     }
 
     bool LanguageSwitchPresenter::OnDrag(UIView &view, const DragEvent &event)
@@ -91,9 +78,7 @@ namespace OHOS
         UNUSED(view);
         if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && LanguageSwitchPresenter::X_DRAG_FLAG)
         {
-#ifdef FD230_650
             NativeAbility::GetInstance().Back();
-#endif
             LanguageSwitchPresenter::X_DRAG_FLAG = false;
         }
         return true;
@@ -119,7 +104,7 @@ namespace OHOS
                 int32_t Hint_ID = LanguageSwitchView::GetInstance()->get_hint_id();
 
                 g_planguage->ChangeLanguage(Hint_ID);
-#ifdef FD230_650
+#ifdef FD230
                 CustomEventPublish(TOPIC_EVENT_DEVICE_BIND, power_buf, 2);
 #endif
             }
@@ -129,7 +114,7 @@ namespace OHOS
 
                 g_planguage->ChangeLanguage(Hint_ID);
 
-#ifdef FD230_650
+#ifdef FD230
                 CustomEventPublish(TOPIC_EVENT_DEVICE_BIND, power_buf, 2);
 #endif
             }
@@ -168,7 +153,7 @@ namespace OHOS
         {
             if (ConfigModel::GetInstance()->GetisFirstTimeStart() == true)
             {
-#ifdef FD230_650
+#ifdef FD230
                 NativeAbility::GetInstance().EnterSlice(VIEW_WATCH_QR_CODE);
 #endif
             }
@@ -200,7 +185,7 @@ namespace OHOS
                 m_labelext->SetTextId(STR_LANGUAGE_SELECTION);
                 m_labelext->ForceResetText(); // 强制刷新
 
-#ifdef FD230_650
+#ifdef FD230
                 p_UILabelButtonExt->SetImageSrc(PNG_CHECKBOX_ON_IMAGE, PNG_CHECKBOX_ON_IMAGE);
 #endif
                 p_UILabelButtonExt->Invalidate();
@@ -221,7 +206,7 @@ namespace OHOS
         // 如果是power键,且是亮屏状态,按键释放就返回上一级
         if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
         {
-#ifdef FD230_650
+#ifdef FD230
             NativeAbility::GetInstance().Back();
 #endif
 #ifdef SUPPORT_BLE_SERVICE
index 9021405..166ebbb 100644 (file)
@@ -4,7 +4,7 @@
 #include "UiConfig.h"
 namespace OHOS
 {
-    
+
     static constexpr int16_t TITLE_LABEL_X = 83;
     static constexpr int16_t TITLE_LABEL_Y = 50;
     static constexpr int16_t TITLE_LABEL_W = 300;
@@ -47,6 +47,12 @@ namespace OHOS
         p_LanguageSwitchListAdapter->AddListItem(item);
     }
 
+    void LanguageSwitchView::RefreshLanguageList(void)
+    {
+        LanguageList->SetAdapter(p_LanguageSwitchListAdapter);
+        LanguageList->RefreshList();
+    }
+
     UIList *LanguageSwitchView::GetLanguageList(void)
     {
         return LanguageList;
@@ -115,6 +121,8 @@ namespace OHOS
         LanguageSwitchScrollView->SetHorizontalScrollState(false);
         LanguageSwitchScrollView->SetTouchable(true);
         LanguageSwitchScrollView->SetDraggable(true);
+        LanguageSwitchScrollView->SetOnDragListener(presenter_);
+        AddViewToRootContainer(LanguageSwitchScrollView);
 
         return true;
     }
@@ -177,6 +185,7 @@ namespace OHOS
             LanguageList->SetReboundSize(0);
             LanguageList->SetScrollBlankSize(0);
         }
+        LanguageSwitchScrollView->Add(LanguageList);
         return true;
     }
 
@@ -193,7 +202,7 @@ namespace OHOS
     void LanguageSwitchView::show_hint_group(std::string code, bool data)
     {
         group->SetVisible(data);
-       RootView::GetInstance()->Invalidate();
+        RootView::GetInstance()->Invalidate();
         if (data)
         {
             hint_id_code = code;
@@ -224,15 +233,19 @@ namespace OHOS
     // Take effect after restart
     void LanguageSwitchView::InithintView()
     {
-        group = new UIViewGroup();
         if (group == nullptr)
         {
-            return;
+            group = new UIViewGroup();
+            if (group == nullptr)
+            {
+                return;
+            }
         }
         group->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
         group->SetTouchable(true);
         group->SetDraggable(true);
         group->SetOnDragListener(presenter_);
+        AddViewToRootContainer(group);
 
         if (LanguageSwitchViewhintLabel == nullptr)
         {
@@ -282,7 +295,7 @@ namespace OHOS
         button_ensure->SetImagePosition(15, 15);
         button_ensure->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED);
         button_ensure->SetStyleForState(STYLE_BACKGROUND_OPA, 0x00, UIButton::PRESSED);
-#ifdef FD230_650
+#ifdef FD230
         button_ensure->SetImageSrc(PNG_SYSTEM_CHECK_ON_IMAGE, PNG_SYSTEM_CHECK_ON_IMAGE);
 #endif
         button_ensure->SetViewId("BUTTON_CHECK_OK");
@@ -305,17 +318,10 @@ namespace OHOS
 
     void LanguageSwitchView::OnStart()
     {
-        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::OnStart");
-        View<LanguageSwitchPresenter>::OnStart();
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "LanguageSwitchView::OnStart");
         LanguageSwitchViewInit();
         InithintView();
-
-        AddViewToRootContainer(LanguageSwitchScrollView);
-        LanguageList->SetAdapter(p_LanguageSwitchListAdapter);
-        LanguageSwitchScrollView->Add(LanguageList);
-        AddViewToRootContainer(group);
         RootView::GetInstance()->SetOnKeyActListener(presenter_);
-
         return;
     }
 }
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/include/WatchQRCodePresenter.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/include/WatchQRCodePresenter.h
new file mode 100644 (file)
index 0000000..059cbca
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef WATCH_QR_CODE_PRESENTER_H
+#define WATCH_QR_CODE_PRESENTER_H
+
+#include "Presenter.h"
+#include "View.h"
+#include "components/ui_view.h"
+#include "string"
+namespace OHOS
+{
+
+    class WatchQRCodeView;
+    class WatchQRCodeModel;
+    class WatchQRCodePresenter : public Presenter<WatchQRCodeView>,
+                                 public UIView::OnClickListener,
+                                 public RootView::OnKeyActListener,
+                                 public UIView::OnDragListener
+    {
+    public:
+        WatchQRCodePresenter();
+        virtual ~WatchQRCodePresenter();
+        static WatchQRCodePresenter *GetInstance();
+        std::string WatchQRCodeGetQRCodeStr();
+
+        void OnStart() override;
+
+        bool OnClick(UIView &view, const ClickEvent &event) override;
+        bool OnDrag(UIView &view, const DragEvent &event) override;
+        bool OnDragEnd(UIView &view, const DragEvent &event) override;
+        bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
+
+        bool X_DRAG_FLAG{false};
+    };
+
+}
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/include/WatchQRCodeView.h b/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/include/WatchQRCodeView.h
new file mode 100644 (file)
index 0000000..da9ad81
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-06-12 11:44:04
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-09-30 15:48:53
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/include/WatchQRCodeView.h
+ */
+#ifndef WATCH_QR_CODE_VIEW_H
+#define WATCH_QR_CODE_VIEW_H
+
+#include "View.h"
+#include "components/ui_qrcode.h"
+#include "components/ui_label_ext.h"
+
+namespace OHOS
+{
+    static constexpr const char *WATCHQRCODEVIEWID = "WatchQRCodeView";
+    class WatchQRCodePresenter;
+    class WatchQRCodeView : public View<WatchQRCodePresenter>
+    {
+    public:
+        WatchQRCodeView();
+        virtual ~WatchQRCodeView();
+        static WatchQRCodeView *GetInstance();
+
+    public:
+        void OnStart() override;
+        /* -------------------------------------------------------------------------- */
+        static uint8_t refresh_time;
+        std::string get_voltage_and_version_string(void);
+        void update_label(void);
+        void start_refresh_timer(uint32_t interval = 2000);
+        void stop_refresh_timer(void);
+        /* -------------------------------------------------------------------------- */
+
+    private:
+        void WatchQRCodeViewInit();
+        bool WatchQRCodeInitViewGroup(void);
+        bool WatchQRCodeInitQrcodeImage(void);
+        bool WatchQRCodeInitLabel(void);
+        void ClearAll();
+        UIViewGroup *WatchQRCodeGroupView{nullptr};
+        UIQrcode *Watch_QR_Code_View{nullptr}; // 手表二维码
+        UILabelExt *TitleLabel{nullptr};       /*标题*/
+        UILabel *DeviceNameLabel{nullptr};     /*蓝牙设备名称*/
+    };
+
+}
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp
new file mode 100644 (file)
index 0000000..d01ced5
--- /dev/null
@@ -0,0 +1,159 @@
+#include "watchQRcode/include/WatchQRCodePresenter.h"
+#include "watchQRcode/include/WatchQRCodeView.h"
+#include "NativeAbility.h"
+#include "wearable_log.h"
+#include "common/key_code.h"
+#include <custom_utils.h>
+#include <ohos_types.h>
+#include "UiConfig.h"
+#include <graphic_math.h>
+#ifdef SUPPORT_BLE_SERVICE
+#include "bleService.h"
+#endif
+#include "broadcast_feature.h"
+#include "AppViewIDs.h"
+#include "NativeRegisterManager.h"
+
+namespace OHOS
+{
+
+    REGIST_SLICE(VIEW_WATCH_QR_CODE, WatchQRCodeView, WatchQRCodePresenter);
+
+    // 当前Presenter属性实例化的内存指针
+    static WatchQRCodePresenter *g_WatchQRCodePresenter = nullptr;
+    WatchQRCodePresenter::WatchQRCodePresenter()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodePresenter::WatchQRCodePresenter");
+        g_WatchQRCodePresenter = this;
+    }
+
+    WatchQRCodePresenter::~WatchQRCodePresenter()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodePresenter::~WatchQRCodePresenter");
+        g_WatchQRCodePresenter = nullptr;
+    }
+
+    WatchQRCodePresenter *WatchQRCodePresenter::GetInstance()
+    {
+        return g_WatchQRCodePresenter;
+    }
+
+    void WatchQRCodePresenter::OnStart(){}
+
+    static uint32_t time = 0;
+    static uint32_t OnClick_num = 0;
+    bool WatchQRCodePresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodePresenter::OnDrag");
+        UNUSED(event);
+        std::string viewId = view.GetViewId();
+        if (viewId == WATCHQRCODEVIEWID)
+        {
+            if (view_)
+            {
+                view_->start_refresh_timer();
+            }
+            if (time == 0)
+            {
+                time = event.GetTimeStamp();
+                OnClick_num = 1;
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "222  %d", time);
+            }
+            else
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "111   %d", event.GetTimeStamp());
+                if (event.GetTimeStamp() - time < 2000)
+                {
+                    OnClick_num++;
+                    if (OnClick_num > 5)
+                    {
+                        // CustomEventPublish(TOPIC_EVENT_DEBUGOUTPUT, NULL, 0);
+                        NativeAbility::GetInstance().ChangeSlice(VIEW_TEST);
+                    }
+                }
+                else
+                {
+                    time = 0;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    bool WatchQRCodePresenter::OnDrag(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodePresenter::OnDrag");
+        UNUSED(view);
+        if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动
+        {
+            WatchQRCodePresenter::X_DRAG_FLAG = true;
+        }
+        return false;
+    }
+
+    bool WatchQRCodePresenter::OnDragEnd(UIView &view, const DragEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodePresenter::OnDragEnd");
+        UNUSED(view);
+        if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && WatchQRCodePresenter::X_DRAG_FLAG)
+        {
+            NativeAbility::GetInstance().Back();
+            X_DRAG_FLAG = false;
+        }
+        return true;
+    }
+
+    // 增加按键事件
+    bool WatchQRCodePresenter::OnKeyAct(UIView &view, const KeyEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SettingPresenter::OnKeyAct");
+        uint16 keyID = event.GetKeyId();
+        uint16_t keyState = event.GetState();
+        // 如果是power键就返回上一级
+        if (keyID == static_cast<uint16_t>(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+            #ifdef SUPPORT_BLE_SERVICE
+            br_adv_start(20);
+            #endif
+        }
+        return true;
+    }
+
+    // 获取当前手表的Mac地址
+    static std::string GetCurrentWatchMacAddress()
+    {
+        uint8_t btaddr[6] = {0};
+        uint32_t len = 6;
+        char btaddr_str[64] = {0};
+        uint8_t ret = uapi_get_nv_btaddr((uint8_t *)btaddr, &len);
+
+        if (ret == ERRCODE_SUCC)
+        { // 检查获取是否成功
+            int index = 0;
+            for (int i = 5; i >= 0; i--)
+            {
+                sprintf_s(btaddr_str + index, len, "%02x:", btaddr[i]);
+                index += 3;
+            }
+            btaddr_str[index - 1] = '\0';
+            return btaddr_str;
+        }
+        else
+        {
+            return ""; // 如果获取失败,返回空字符串
+        }
+    }
+
+    std::string WatchQRCodePresenter::WatchQRCodeGetQRCodeStr()
+    {
+        /*实例:https://www.kumi.top/p-i-kumi.html?c=5&p=5&m=7a:8c:2d:61:9a:fc*/
+        /*m=后边的值为手表 mac 地址,前面部分为固定格式*/
+        std::string QRCodeStr = "https://www.kumi.top/p-i-kumi.html?c=5&p=5&m=";
+        std::string MacAddress = GetCurrentWatchMacAddress(); // 假设这是获取当前手表 Mac 地址的函数
+        QRCodeStr += MacAddress;
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "QRCodeStr:%s", QRCodeStr.c_str());
+        return QRCodeStr;
+    }
+}
diff --git a/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/src/WatchQRCodeView.cpp b/code/sdk/application/wearable/fd230/nativeapp/nativeui/watchQRcode/src/WatchQRCodeView.cpp
new file mode 100644 (file)
index 0000000..2fffbfd
--- /dev/null
@@ -0,0 +1,319 @@
+#include "watchQRcode/include/WatchQRCodePresenter.h"
+#include "watchQRcode/include/WatchQRCodeView.h"
+#include "wearable_log.h"
+#include "custom_utils.h"
+#include "ui_resource_string.h"
+#include "iostream"
+#include "string"
+#include "graphic_service.h"
+#include <cmsis_os2.h>
+#include <cmsis_os.h>
+
+namespace OHOS
+{
+    static WatchQRCodeView *g_pWatchQRCodePresenter = nullptr;
+
+    WatchQRCodeView::WatchQRCodeView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeView");
+        g_pWatchQRCodePresenter = this;
+    }
+
+    WatchQRCodeView::~WatchQRCodeView()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::~WatchQRCodeView");
+        stop_refresh_timer();
+        ClearAll();
+        g_pWatchQRCodePresenter = nullptr;
+    }
+
+    WatchQRCodeView *WatchQRCodeView::GetInstance()
+    {
+        return g_pWatchQRCodePresenter;
+    }
+
+    void WatchQRCodeView::ClearAll()
+    {
+        if (WatchQRCodeGroupView != nullptr)
+        {
+            WatchQRCodeGroupView->RemoveAll();
+
+            if (TitleLabel != nullptr)
+            {
+                delete TitleLabel;
+                TitleLabel = nullptr;
+            }
+
+            if (Watch_QR_Code_View != nullptr)
+            {
+                delete Watch_QR_Code_View;
+                Watch_QR_Code_View = nullptr;
+            }
+
+            if (DeviceNameLabel != nullptr)
+            {
+                delete DeviceNameLabel;
+                DeviceNameLabel = nullptr;
+            }
+
+            delete WatchQRCodeGroupView;
+            WatchQRCodeGroupView = nullptr;
+        }
+    }
+
+    extern "C"
+    {
+#ifdef SUPPORT_BLE_SERVICE
+#include "build_version.h"
+#include "battery_hal.h"
+        extern uint8_t battery_get_voltage(float *voltage);
+        const char *get_version_string(void);
+#else
+        extern uint8_t battery_get_voltage(float *voltage){ return 0;}
+        const char *get_version_string(void);
+#endif
+    }
+
+    bool WatchQRCodeView::WatchQRCodeInitViewGroup(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeInitViewGroup");
+        WatchQRCodeGroupView = new UIViewGroup();
+        if (WatchQRCodeGroupView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeGroupView new fail!");
+            return false;
+        }
+        WatchQRCodeGroupView->SetPosition(0, 0, Screen::GetInstance().GetWidth(), Screen::GetInstance().GetHeight());
+        WatchQRCodeGroupView->SetViewId(WATCHQRCODEVIEWID);
+        WatchQRCodeGroupView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        WatchQRCodeGroupView->SetTouchable(true);
+        WatchQRCodeGroupView->SetDraggable(true);
+        WatchQRCodeGroupView->SetOnDragListener(presenter_);
+        WatchQRCodeGroupView->SetOnClickListener(presenter_);
+        AddViewToRootContainer(WatchQRCodeGroupView);
+        return true;
+    }
+
+    bool WatchQRCodeView::WatchQRCodeInitQrcodeImage(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeInitQrcodeImage");
+        Watch_QR_Code_View = new UIQrcode();
+        if (Watch_QR_Code_View == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::Watch_QR_Code_View new fail!");
+            return false;
+        }
+        Watch_QR_Code_View->SetPosition(93, 100, 280, 280);
+        Watch_QR_Code_View->SetECCLevel(QrCode::Ecc::LOW); /*QR 码的 ECC(Error Correction Code ,错误纠正码)级别表示二维码的纠错能力或容错率*/
+        Watch_QR_Code_View->SetAutoEnable(false);
+        Watch_QR_Code_View->SetResizeMode(UIImageView::ImageResizeMode::CENTER);
+        std::string str = WatchQRCodePresenter::GetInstance()->WatchQRCodeGetQRCodeStr();
+        Watch_QR_Code_View->SetQrcodeInfo(str.c_str());
+        WatchQRCodeGroupView->Add(Watch_QR_Code_View);
+        return true;
+    }
+
+    bool WatchQRCodeView::WatchQRCodeInitLabel(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeInitLabel");
+        TitleLabel = new UILabelExt();
+        if (TitleLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::TitleLabel new label fail");
+            return false;
+        }
+        TitleLabel->SetPosition(83, 50, 300, 35);
+        TitleLabel->SetStyle(STYLE_TEXT_FONT, 30);
+        TitleLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+        uint8_t ble_name[30] = {0};
+        uint32_t ble_name_len = sizeof(ble_name);
+        errcode_t ret = uapi_get_nv_btname(ble_name, &ble_name_len);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "get btname %s ,ret 0x%X\n", ble_name, ret);
+        TitleLabel->SetText((char *)ble_name);
+        TitleLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
+        TitleLabel->SetRollSpeed(23);
+        TitleLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+        TitleLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        WatchQRCodeGroupView->Add(TitleLabel);
+        /* -------------------------------------------------------------------------- */
+        DeviceNameLabel = new UILabel();
+        if (DeviceNameLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::DeviceNameLabel new label fail");
+            return false;
+        }
+        DeviceNameLabel->SetText(get_voltage_and_version_string().c_str());
+        DeviceNameLabel->SetPosition(83, 390, 300, 35);
+        DeviceNameLabel->SetStyle(STYLE_TEXT_FONT, 30);
+        DeviceNameLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+        DeviceNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30);
+        DeviceNameLabel->SetRollSpeed(23);
+        DeviceNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION);
+        DeviceNameLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
+        DeviceNameLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+        WatchQRCodeGroupView->Add(DeviceNameLabel);
+        return true;
+    }
+
+    void WatchQRCodeView::WatchQRCodeViewInit()
+    {
+        if (!WatchQRCodeInitViewGroup())
+        {
+            return;
+        }
+
+        if (!WatchQRCodeInitQrcodeImage())
+        {
+            return;
+        }
+
+        if (!WatchQRCodeInitLabel())
+        {
+            return;
+        }
+    }
+
+    void WatchQRCodeView::OnStart()
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::OnStart");
+        start_refresh_timer();
+        WatchQRCodeViewInit();
+        RootView::GetInstance()->SetOnKeyActListener(presenter_);
+        /* --------------------------------- 添加按键监听 --------------------------------- */
+        RootView::GetInstance()->SetOnKeyActListener(presenter_);
+        /* -------------------------------------------------------------------------- */
+        return;
+    }
+
+    std::string WatchQRCodeView::get_voltage_and_version_string(void)
+    {
+        // 电量:
+        float voltage = 0.0F;
+        uint8_t value = 0;
+        value = battery_get_voltage(&voltage);
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "battery_get_voltage = %d", value);
+
+        // 版本号:
+        std::string temp = get_version_string();
+        std::string version_string = "V" + temp;
+        std::string str = "bat:" + std::to_string(value) + "%" + " " + version_string;
+        return str;
+    }
+
+    void WatchQRCodeView::update_label(void)
+    {
+        if (DeviceNameLabel)
+        {
+            std::string str = get_voltage_and_version_string();
+            DeviceNameLabel->SetText(str.c_str());
+            DeviceNameLabel->Invalidate();
+        }
+    }
+
+    // 声明定时器变量
+    static osTimerId_t g_timer = nullptr;
+    static uint8_t UPDATETIME_OUT = 30; // 30秒
+    uint8_t WatchQRCodeView::refresh_time = UPDATETIME_OUT;
+    /*定时器到期时的处理*/
+    static void QRCodeView_TimerCallbackProc(int data)
+    {
+        if (uapi_get_screen_state() == 0) // 如果在亮屏状态
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_get_screen_state() == 0");
+            if (WatchQRCodeView::GetInstance())
+            {
+                WatchQRCodeView::GetInstance()->update_label();
+            }
+            if (WatchQRCodeView::refresh_time != UPDATETIME_OUT) // 如果是亮屏后息屏再亮屏(此时息屏时间没超过 UPDATETIME_OUT)则恢复
+            {
+                WatchQRCodeView::refresh_time = UPDATETIME_OUT;
+            }
+        }
+        else
+        {
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "uapi_get_screen_state() == 1");
+            WatchQRCodeView::refresh_time -= 2;
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d", WatchQRCodeView::refresh_time);
+            if (WatchQRCodeView::refresh_time <= 0) // 息屏状态下超时删除定时器
+            {
+                if (WatchQRCodeView::GetInstance())
+                {
+                    GraphicService::GetInstance()->PostGraphicEvent(std::bind(&WatchQRCodeView::stop_refresh_timer, WatchQRCodeView::GetInstance()));
+                }
+            }
+            else
+            {
+                if (WatchQRCodeView::GetInstance())
+                {
+                    WatchQRCodeView::GetInstance()->update_label();
+                }
+            }
+        }
+        return;
+    }
+
+    /*
+     * @brief 回调函数
+     */
+    static void QRCodeView_TimerCallback(int data)
+    {
+        GraphicService::GetInstance()->PostGraphicEvent(std::bind(QRCodeView_TimerCallbackProc, data));
+    }
+
+    /*
+     *  @brief 开启定时器函数
+     *  @param interval 时间间隔,单位ms
+     */
+    void WatchQRCodeView::start_refresh_timer(uint32_t interval)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "start_refresh_timer");
+        /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */
+        if (g_timer != nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " Timer already exists!!");
+            return;
+        }
+        /* --------------------------------- 2.创建定时器 -------------------------------- */
+        g_timer = osTimerNew((osTimerFunc_t)QRCodeView_TimerCallback, osTimerPeriodic, nullptr, nullptr);
+        // 检查定时器创建是否成功
+        if (g_timer == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!");
+            return;
+        }
+        /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */
+        int tick = osMs2Tick(interval);
+        /* --------------------------------- 4.启动定时器 -------------------------------- */
+        osStatus_t ret = osTimerStart(g_timer, tick);
+        /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */
+        if (ret != osOK)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
+            if (g_timer != nullptr)
+            {
+                ret = osTimerDelete(g_timer);
+            }
+            g_timer = nullptr;
+            return;
+        }
+        return;
+    }
+
+    void WatchQRCodeView::stop_refresh_timer(void)
+    {
+        // 检查定时器是否存在
+        if (g_timer != nullptr)
+        {
+            osTimerStop(g_timer);
+            // 删除定时器并置为 nullptr
+            osStatus_t ret = osTimerDelete(g_timer);
+            if (ret != osOK)
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret);
+            }
+            g_timer = nullptr;
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "g_timer stop success");
+            refresh_time = UPDATETIME_OUT;
+        }
+    }
+}