AI语音界面优化修改
authorluozheng <1732036298@qq.com>
Sat, 3 Aug 2024 09:37:27 +0000 (17:37 +0800)
committerluozheng <1732036298@qq.com>
Sat, 3 Aug 2024 09:37:27 +0000 (17:37 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp
code/sdk/application/wearable/nativeabilityfwk/include/Ability.h

index 2f1187b..ec7cdbe 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-08-03 11:09:56
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-03 11:32:24
+ * @LastEditTime: 2024-08-03 16:55:59
  * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceConnectingView.h
  */
 
 #include "components/ui_button.h"
 #include "components/ui_scroll_view.h"
 #include "components/ui_label_ext.h"
+#include "components/ui_image_animator.h"
 namespace OHOS
 {
     static constexpr const char *AIVOICECONNECTINGVIEW_CANCEL_BUTTON_VIEW_ID = "AivoiceConnectingcancelButton"; // 正在连接中界面取消按钮
+    static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 20;                            // 图片帧数
 
     class AiVoiceConnectingView
     {
@@ -38,22 +40,41 @@ namespace OHOS
             const char *viewId;
         };
 
+        struct ImageAnimatorConfig
+        {
+            int16_t x;
+            int16_t y;
+            int16_t width;
+            int16_t height;
+            ImageAnimatorInfo *imageInfoArray;
+            const char *const *pathsArray;
+            uint8_t numFrames;
+            int delay;
+        };
+
         AiVoiceConnectingView();
         ~AiVoiceConnectingView();
         static AiVoiceConnectingView *GetInstance(void);
         UIScrollView *CreateAiVoiceConnectingView(void);
 
     private:
+        const char **CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension = "bin");
+        void FreeImagePathsArray(const char **imagePaths, const int numImages);
+        UIImageAnimatorView *connectingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig);
         UILabelExt *AiVoiceConnectingViewLabelInit(LabelConfig &labelconfig);
         UIButton *AiVoiceConnectingViewButtonInit(ButtonConfig &buttonconfig);
         bool CreateAiVoiceConnectingViewLabel(void);
         bool CreateAiVoiceConnectingViewButton(void);
+        bool CreateAivoiceConnectingImageAnimator(void);
         bool CreateAiVoiceConnectingScrollView(void);
         void ClearAll(void);
         UIScrollView *scrollView{nullptr};
         UILabelExt *title{nullptr};
         UILabelExt *cancelLabel{nullptr};
         UIButton *cancelButton{nullptr};
+        UIImageAnimatorView *connectingAnimatorView{nullptr};
+        ImageAnimatorInfo connectingImageInfo[AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES];
+        const char **connectingPathsArray{nullptr};
     };
 }
 
index abc91fa..4438950 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 14:44:22
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-03 14:27:50
+ * @LastEditTime: 2024-08-03 17:28:03
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
  */
 #ifndef AI_VOICE_PRESENTER_H
@@ -51,7 +51,7 @@ namespace OHOS
         bool OnDrag(UIView &view, const DragEvent &event) override;
         bool OnDragEnd(UIView &view, const DragEvent &event) override;
         bool OnKeyAct(UIView &view, const KeyEvent &event) override; // 增加按键事件
-        void OnPickerStoped(UIPicker& picker);
+        void OnPickerStoped(UIPicker& picker) override;
 
         AiVoiceModel *model;
         bool X_DRAG_FLAG{false};
index d194567..927d350 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-08 09:36:01
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-03 11:37:00
+ * @LastEditTime: 2024-08-03 16:40:55
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/AiVoiceView.h
  */
 #ifndef AI_VOICE_VIEW_H
@@ -108,6 +108,7 @@ namespace OHOS
         UIScrollView *GetAiVoiceScrollView(int16_t index);
         bool ClickFunc(int16_t interface);
         bool CheckViewParam(int16_t hideView, int16_t showView);
+        void DestroyTempView(int16_t hideView);
         void ChangeView(int16_t hideView, int16_t showView);
         bool ChangeAiVoiceStartChatView(int16_t thisView);
         bool ChangeAiVoiceBluetoothFailedStartView(int16_t thisView);
index 1523f1c..790abdc 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-08-03 11:10:08
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-03 15:19:28
+ * @LastEditTime: 2024-08-03 17:27:27
  * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp
  */
 #include "aivoice/include/AiVoiceConnectingView.h"
 
 namespace OHOS
 {
+    static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_X = 183;
+    static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_Y = 153;
+    static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_W = 100;
+    static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_H = 120;
+    static constexpr int16_t AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY = 200; // 图片更新间隔
+    static constexpr const char *AIVoiceListeningImagePaths = "/user/res/connect/";
+
     static AiVoiceConnectingView *g_pAiVoiceConnecting{nullptr};
     AiVoiceConnectingView::AiVoiceConnectingView()
     {
@@ -36,6 +43,13 @@ namespace OHOS
                 delete title;
                 title = nullptr;
             }
+            if (connectingAnimatorView)
+            {
+                connectingAnimatorView->Stop();
+                delete connectingAnimatorView;
+                connectingAnimatorView = nullptr;
+                FreeImagePathsArray(connectingPathsArray, AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+            }
             if (cancelLabel)
             {
                 delete cancelLabel;
@@ -91,6 +105,63 @@ namespace OHOS
         return button;
     }
 
+    const char **AiVoiceConnectingView::CreateImagePathsArray(const char *basePath, const int numImages, const char *fileExtension)
+    {
+        const char **imagePaths = new const char *[numImages];
+        if (imagePaths == nullptr)
+        {
+            return nullptr;
+        }
+
+        char buffer[256];
+        for (int i = 0; i < numImages; i++)
+        {
+            snprintf(buffer, sizeof(buffer), "%s%d.%s", basePath, i + 1, fileExtension);
+            imagePaths[i] = strdup(buffer);
+            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, " imagePaths[%d] = %s", i, imagePaths[i]);
+        }
+        return imagePaths;
+    }
+
+    void AiVoiceConnectingView::FreeImagePathsArray(const char **imagePaths, const int numImages)
+    {
+        for (int i = 0; i < numImages; i++)
+        {
+            delete imagePaths[i];
+            imagePaths[i] = nullptr;
+        }
+    }
+
+    UIImageAnimatorView *AiVoiceConnectingView::connectingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig)
+    {
+        UIImageAnimatorView *animatorView = new UIImageAnimatorView();
+        if (animatorView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceListeningImageAnimatorView::AiVoiceListeningImageAnimatorView new fail");
+            return nullptr;
+        }
+
+        for (uint8_t i = 0; i < imageanimatorconfig.numFrames; i++)
+        {
+            // imageanimatorconfig.imageInfoArray[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(imageanimatorconfig.pathsArray[i]);
+            imageanimatorconfig.imageInfoArray[i].imagePath = (imageanimatorconfig.pathsArray[i]);
+            imageanimatorconfig.imageInfoArray[i].imageType = IMG_SRC_FILE_PATH;
+            imageanimatorconfig.imageInfoArray[i].pos.x = imageanimatorconfig.x;
+            imageanimatorconfig.imageInfoArray[i].pos.y = imageanimatorconfig.y;
+            imageanimatorconfig.imageInfoArray[i].width = imageanimatorconfig.width;
+            imageanimatorconfig.imageInfoArray[i].height = imageanimatorconfig.height;
+        }
+
+        animatorView->SetPosition(imageanimatorconfig.x, imageanimatorconfig.y, imageanimatorconfig.width, imageanimatorconfig.height);
+        animatorView->SetImageAnimatorSrc(imageanimatorconfig.imageInfoArray, imageanimatorconfig.numFrames, imageanimatorconfig.delay);
+        animatorView->SetRepeat(true);
+        animatorView->SetAutoEnable(false);
+        animatorView->SetResizeMode(UIImageAnimatorView::FILL);
+        animatorView->Start();
+
+        return animatorView;
+    }
+
     bool AiVoiceConnectingView::CreateAiVoiceConnectingViewLabel(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewLabel");
@@ -159,6 +230,36 @@ namespace OHOS
         return true;
     }
 
+    bool AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator(void)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator");
+        connectingPathsArray = CreateImagePathsArray(AIVoiceListeningImagePaths, AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES);
+        if (connectingPathsArray == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingPathsArray  is nullptr!!");
+            return false;
+        }
+
+        ImageAnimatorConfig imageanimatorconfig = {
+            .x = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_X,
+            .y = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_Y,
+            .width = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_W,
+            .height = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_H,
+            .imageInfoArray = connectingImageInfo,
+            .pathsArray = connectingPathsArray,
+            .numFrames = AIVOICE_CONNECTING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES,
+            .delay = AIVOICE_CONNECTING_IMAGE_ANIMATOR_DELAY,
+        };
+        connectingAnimatorView = connectingImageAnimatorInit(imageanimatorconfig);
+        if (connectingAnimatorView == nullptr)
+        {
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::connectingAnimatorView new fail");
+            return false;
+        }
+
+        return true;
+    }
+
     bool AiVoiceConnectingView::CreateAiVoiceConnectingScrollView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView");
@@ -185,12 +286,13 @@ namespace OHOS
     UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView");
-        if (!CreateAiVoiceConnectingScrollView() || !CreateAiVoiceConnectingViewLabel() || !CreateAiVoiceConnectingViewButton())
+        if (!CreateAiVoiceConnectingScrollView() || !CreateAivoiceConnectingImageAnimator()|| !CreateAiVoiceConnectingViewLabel() || !CreateAiVoiceConnectingViewButton())
         {
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView fail!!");
             return nullptr;
         }
         scrollView->Add(title);
+        scrollView->Add(connectingAnimatorView);
         scrollView->Add(cancelButton);
         scrollView->Add(cancelLabel);
 
index 6cf64de..63a1996 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-05-07 11:25:58
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-08-03 16:24:36
+ * @LastEditTime: 2024-08-03 16:45:06
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -715,6 +715,36 @@ namespace OHOS
         return true;
     }
 
+    static const int16 AiVoiceDestroyMapper[] = {
+        AIVOICE_AIMODE_CONNECTING,
+    };
+
+    void AiVoiceView::DestroyTempView(int16_t hideView)
+    {
+        int viewSize = sizeof(AiVoiceDestroyMapper) / sizeof(AiVoiceDestroyMapper[0]);
+        for (int i = 0; i < viewSize; i++)
+        {
+            if (hideView == AiVoiceDestroyMapper[i])
+            {
+                container_->Remove(AiVoiceScrollView[hideView]);
+                AiVoiceScrollView[hideView] = nullptr;
+                break;
+            }
+        }
+        switch (hideView)
+        {
+        case AIVOICE_AIMODE_CONNECTING:
+            if (p_AiVoiceConnectingView)
+            {
+                delete p_AiVoiceConnectingView;
+                p_AiVoiceConnectingView = nullptr;
+            }
+            break;
+        default:
+            break;
+        }
+    }
+
     void AiVoiceView::ChangeView(int16_t hideView, int16_t showView)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeView");
@@ -727,6 +757,8 @@ namespace OHOS
         ClickFunc(showView);
         AiVoiceScrollView[showView]->SetVisible(true);
         Draw();
+        DestroyTempView(hideView);
+        return;
     }
 
     UIScrollView *AiVoiceView::GetAiVoiceScrollView(int16_t index)
index d176bc2..4a3b4f8 100755 (executable)
@@ -155,7 +155,7 @@ public:
         std::stack<uint16_t> tempStack = backStack_;
         while(!tempStack.empty())
         {
-            WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "%d,", tempStack.top());
+            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "%d,", tempStack.top());
             tempStack.pop();
         }
     }