增加手表二维码slice 165/1 165/head 166/target/1
authorluozheng <1732036298@qq.com>
Mon, 13 May 2024 10:19:03 +0000 (18:19 +0800)
committerluozheng <1732036298@qq.com>
Mon, 13 May 2024 10:19:03 +0000 (18:19 +0800)
code/sdk/application/wearable/fd230app/CMakeLists.txt
code/sdk/application/wearable/fd230app/nativelauncher/include/AppViewIDs.h
code/sdk/application/wearable/fd230app/nativelauncher/include/NativeLauncher.h
code/sdk/application/wearable/fd230app/nativelauncher/src/NativeLauncher.cpp
code/sdk/application/wearable/fd230app/nativeui/system/src/SystemPresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/watchQRcode/include/WatchQRCodePresenter.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/watchQRcode/include/WatchQRCodeView.h [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp [new file with mode: 0644]
code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodeView.cpp [new file with mode: 0644]

index bdf9bf9..0703faa 100644 (file)
@@ -362,10 +362,15 @@ set(SOURCES
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/Systemupgrade.cpp    
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/system/src/SystemFactoryResetView.cpp
 
+    #系统更新
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/systemupdate/src/SystemUpdateModel.cpp    
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/systemupdate/src/SystemUpdateView.cpp    
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/systemupdate/src/SystemUpdatePresenter.cpp
 
+    #手表二维码
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp
+    ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/watchQRcode/src/WatchQRCodeView.cpp
+
     #声音与震动
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationPresenter.cpp 
     ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/soundandvibration/src/SoundAndVibrationView.cpp
index 1e61324..4904b54 100644 (file)
@@ -62,6 +62,7 @@ typedef enum : uint16_t
     VIEW_NETWORKANDCALL,            // 网络与通话
     VIEW_MOTION_RECOGNITION,        // 运动识别
     VIEW_SYSTEM_UPDATE,             // 系统更新
+    VIEW_WATCH_QR_CODE,             //手表二维码
     /* ----------------------------------- 录音 ----------------------------------- */
     VIEW_RECORD,
     /* ---------------------------------- 界面 ---------------------------------- */
index d709912..eb201cf 100644 (file)
@@ -58,6 +58,7 @@ namespace OHOS
         void InitNetworkAndCallSlice(void);
         void InitMotionRecognitionSlice(void);
         void InitSystemUpdateSlice(void);
+        void InitWatchQRCodeSlice(void);
         /* --------------------------------界面------------------------------------ */
         void InitRotateSlice(void);
         void InitBloodSlice(void);
index 1c9bb68..a89559e 100644 (file)
 
 #include "systemupdate/include/SystemUpdatePresenter.h"
 #include "systemupdate/include/SystemUpdateView.h"
+
+#include "watchQRcode/include/WatchQRCodePresenter.h"
+#include "watchQRcode/include/WatchQRCodeView.h"
 /* -------------------------------------------------------------------------- */
 #include "traing/include/TraingView.h"
 #include "traing/include/TraingPresenter.h"
@@ -267,6 +270,7 @@ namespace OHOS
         {VIEW_NETWORKANDCALL, &NativeLauncher::InitNetworkAndCallSlice},                     // 网络与通话
         {VIEW_MOTION_RECOGNITION, &NativeLauncher::InitMotionRecognitionSlice},              // 网络与通话
         {VIEW_SYSTEM_UPDATE, &NativeLauncher::InitSystemUpdateSlice},                        // 系统更新界面
+        {VIEW_WATCH_QR_CODE, &NativeLauncher::InitWatchQRCodeSlice},                         // 手表二维码界面
 
         // {VIEW_SECONDARY_FUNCTION, &NativeLauncher::InitSecondaryFunction},
         // {VIEW_FAST_TRAINING, &NativeLauncher::InitFastTrainingSlice},
@@ -1160,6 +1164,18 @@ namespace OHOS
         }
         NativeAbility::GetInstance().AddSliceProxy(VIEW_SYSTEM_UPDATE, systemupdate);
     }
+
+    /*手表二维码*/
+    void NativeLauncher::InitWatchQRCodeSlice(void)
+    {
+        SliceProxy *watchqrcode = new AbilitySliceProxy<WatchQRCodeView, WatchQRCodePresenter>;
+        if (watchqrcode == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "watchqrcode");
+            return;
+        }
+        NativeAbility::GetInstance().AddSliceProxy(VIEW_WATCH_QR_CODE, watchqrcode);
+    }
     /* -------------------------------------------------------------------------- */
     void NativeLauncher::InitSetDesktopSlice(void)
     {
index 344cda8..26cd71e 100644 (file)
@@ -170,7 +170,8 @@ namespace OHOS
         }\r
         else if (strcmp(view.GetViewId(), WATCH_QR_CODE) == 0) // 点击进入手表二维码视图\r
         {\r
-            p_SystemView->ChangeView(SYSTEMVIEW, WATCHQRCODE);\r
+            //p_SystemView->ChangeView(SYSTEMVIEW, WATCHQRCODE);\r
+            NativeAbility::GetInstance().EnterSlice(VIEW_WATCH_QR_CODE);\r
             return true;\r
         }\r
         else if (strcmp(view.GetViewId(), SYSTEM_LANGUAGE) == 0) // 点击进入系统语言界面\r
diff --git a/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/include/WatchQRCodePresenter.h b/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/include/WatchQRCodePresenter.h
new file mode 100644 (file)
index 0000000..38b7796
--- /dev/null
@@ -0,0 +1,37 @@
+#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();
+
+        virtual void OnStart() override;
+        virtual void OnResume() override;
+        virtual void OnStop() 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/fd230app/nativeui/watchQRcode/include/WatchQRCodeView.h b/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/include/WatchQRCodeView.h
new file mode 100644 (file)
index 0000000..d2001cb
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef WATCH_QR_CODE_VIEW_H
+#define WATCH_QR_CODE_VIEW_H
+
+#include "View.h"
+#include "BaseView.h"
+#include "components/ui_qrcode.h"
+#include "components/ui_label_ext.h"
+namespace OHOS
+{
+    class WatchQRCodePresenter;
+    class WatchQRCodeView : public View<WatchQRCodePresenter>
+    {
+    public:
+        WatchQRCodeView();
+        virtual ~WatchQRCodeView();
+        static WatchQRCodeView *GetInstance();
+
+    public:
+        virtual void OnStart() override;
+        virtual void OnSetUpView() override;
+        virtual void OnTearDownView() override;
+        virtual void OnStop() override;
+
+    private:
+        void WatchQRCodeViewInit();
+        bool WatchQRCodeInitViewGroup(void);
+        bool WatchQRCodeInitQrcodeImage(void);
+        bool WatchQRCodeInitLabel(void);
+        void ClearAll();
+        UIViewGroup *WatchQRCodeGroupView{nullptr};
+        UIQrcode *Watch_QR_Code_View{nullptr}; // 手表二维码
+        UILabel *DeviceNameLabel{nullptr};
+    };
+
+}
+#endif
\ No newline at end of file
diff --git a/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp b/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodePresenter.cpp
new file mode 100644 (file)
index 0000000..51b31e9
--- /dev/null
@@ -0,0 +1,99 @@
+#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>
+
+namespace OHOS
+{
+    // 当前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()
+    {
+        Presenter<WatchQRCodeView>::OnStart();
+    }
+
+    void WatchQRCodePresenter::OnResume(void)
+    {
+        Presenter<WatchQRCodeView>::OnResume();
+    }
+
+    void WatchQRCodePresenter::OnStop(void)
+    {
+        Presenter<WatchQRCodeView>::OnStop();
+        return;
+    }
+
+    bool WatchQRCodePresenter::OnClick(UIView &view, const ClickEvent &event)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "WatchQRCodePresenter::OnDrag");
+        UNUSED(view);
+        UNUSED(event);
+
+        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 == 0 && uapi_get_screen_state() == 0)
+        {
+            NativeAbility::GetInstance().Back();
+        }
+        return true;
+    }
+
+    std::string WatchQRCodePresenter::WatchQRCodeGetQRCodeStr()
+    {
+        std::string str = "https://www.kumi.top/p-i-kumi.html?c=5&p=5&m=ea:33:29:55:9b:fc";
+        return str;
+    }
+}
diff --git a/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodeView.cpp b/code/sdk/application/wearable/fd230app/nativeui/watchQRcode/src/WatchQRCodeView.cpp
new file mode 100644 (file)
index 0000000..1fd9495
--- /dev/null
@@ -0,0 +1,167 @@
+#include "watchQRcode/include/WatchQRCodePresenter.h"
+#include "watchQRcode/include/WatchQRCodeView.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+
+    static WatchQRCodeView *g_pWatchQRCodePresenter = nullptr;
+
+    WatchQRCodeView::WatchQRCodeView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeView");
+        g_pWatchQRCodePresenter = this;
+    }
+
+    WatchQRCodeView::~WatchQRCodeView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::~WatchQRCodeView");
+        ClearAll();
+        g_pWatchQRCodePresenter = nullptr;
+    }
+
+    WatchQRCodeView *WatchQRCodeView::GetInstance()
+    {
+        return g_pWatchQRCodePresenter;
+    }
+
+    void WatchQRCodeView::ClearAll()
+    {
+        if (WatchQRCodeGroupView != nullptr)
+        {
+            WatchQRCodeGroupView->RemoveAll();
+
+            delete Watch_QR_Code_View;
+            Watch_QR_Code_View = nullptr;
+
+            delete DeviceNameLabel;
+            DeviceNameLabel = nullptr;
+
+            delete WatchQRCodeGroupView;
+            WatchQRCodeGroupView = nullptr;
+        }
+    }
+
+    bool WatchQRCodeView::WatchQRCodeInitViewGroup(void)
+    {
+        WEARABLE_LOGE(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->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+        WatchQRCodeGroupView->SetTouchable(true);
+        WatchQRCodeGroupView->SetDraggable(true);
+        UIView::OnDragListener *dragListener = static_cast<UIView::OnDragListener *>(WatchQRCodePresenter::GetInstance());
+        if (dragListener == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::dragListener new fail!");
+            return false;
+        }
+        WatchQRCodeGroupView->SetOnDragListener(dragListener);
+        return true;
+    }
+
+    bool WatchQRCodeView::WatchQRCodeInitQrcodeImage(void)
+    {
+        WEARABLE_LOGE(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, 110, 280, 280);
+        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_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeInitLabel");
+        DeviceNameLabel = new UILabel();
+        if (DeviceNameLabel == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::DeviceNameLabel new label fail");
+            return false;
+        }
+        DeviceNameLabel->SetText("KUMI_XXXX");
+        DeviceNameLabel->SetPosition(83, 412, 300, 35);
+        DeviceNameLabel->SetStyle(STYLE_TEXT_FONT, 30);
+        DeviceNameLabel->SetStyle(STYLE_LINE_HEIGHT, 35);
+        DeviceNameLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30);
+        DeviceNameLabel->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
+        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_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::OnStart");
+        View<WatchQRCodePresenter>::OnStart();
+        WatchQRCodeViewInit();
+        /* --------------------------------- 添加按键监听 --------------------------------- */
+        RootView::OnKeyActListener *keyactListener = (RootView::OnKeyActListener *)OHOS::WatchQRCodePresenter::GetInstance();
+        RootView::GetInstance()->SetOnKeyActListener(keyactListener);
+        /* -------------------------------------------------------------------------- */
+        return;
+    }
+
+    void WatchQRCodeView::OnSetUpView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::OnSetUpView");
+        View<WatchQRCodePresenter>::OnSetUpView();
+        if (WatchQRCodeGroupView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::WatchQRCodeGroupView is nullptr!");
+            return;
+        }
+        RootView::GetInstance()->Add(WatchQRCodeGroupView);
+        return;
+    }
+
+    void WatchQRCodeView::OnTearDownView()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::OnTearDownView");
+        View<WatchQRCodePresenter>::OnTearDownView();
+        return;
+    }
+
+    void WatchQRCodeView::OnStop()
+    {
+        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "WatchQRCodeView::OnStop");
+        View<WatchQRCodePresenter>::OnStop();
+
+        RootView::GetInstance()->RemoveAll();
+        RootView::GetInstance()->ClearOnKeyActListener();
+        return;
+    }
+
+}