AI界面取消notify更新界面,聆听和思考界面隐藏界面时停止动画
authorluozheng <1732036298@qq.com>
Mon, 16 Jun 2025 08:28:58 +0000 (16:28 +0800)
committerluozheng <1732036298@qq.com>
Mon, 16 Jun 2025 08:28:58 +0000 (16:28 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceListeningView.cpp
code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceThinkingView.cpp

index ede8f78..805f00a 100644 (file)
@@ -22,8 +22,8 @@ namespace OHOS
                              public UIView::OnDragListener,
                              public RootView::OnKeyActListener,
                              public UIPicker::SelectedListener,
-                             public UIView::OnTouchListener,
-                             public ModelListenerSample
+                             public UIView::OnTouchListener
+                            //  public ModelListenerSample
     {
     public:
         typedef enum : uint8_t
@@ -44,7 +44,7 @@ namespace OHOS
         void OnResume() override;
         void OnPause() override;
         void OnStop() override;
-        void Notify() override;
+        // void Notify() override;
         void calculateChatContentItemViewHeight(std::string text, bool flag);
 
         bool JumpToReturnResultTextView(void);
index d681965..8c35c3b 100644 (file)
@@ -71,6 +71,7 @@ namespace OHOS
         static AivoiceListeningView *GetInstance(void);
         UIScrollView *CreateAivoiceListeningView(void);
         UILabelExt *GetShowtimeoutLabel(void);
+        void StartOrStopAivoiceListeningImageAnimatorView(bool val);
 
     private:
         void ClearAll(void);
index d5b7c34..9f4bbd9 100644 (file)
@@ -64,6 +64,7 @@ namespace OHOS
         ~AivoiceThinkingView();
         static AivoiceThinkingView *GetInstance(void);
         UIScrollView *CreateAivoiceThinkingView(void);
+        void StartOrStopAiVoiceThinkingImageAnimatorView(bool val);
 
     private:
         void ClearAll(void);
index d68303f..9ffb8cb 100644 (file)
@@ -550,7 +550,7 @@ namespace OHOS
         {
             if (view_ != nullptr)
             {
-                start_ai4g_tts_play_timer();//开启一个定时器,用于播放tts音频
+                start_ai4g_tts_play_timer(); // 开启一个定时器,用于播放tts音频
                 if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())
                 {
                     if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串
@@ -638,12 +638,12 @@ namespace OHOS
 #if IS_SUPPORT_REALTIME_RECORD_SEND_AI
             int type = GetCurUsingAiModelType();
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "type = %d", type);
-            if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT)
+            if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT)
             {
                 streamingRecordAndSend_AI(type); // 实时发送录音数据
             }
-            else if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
-            {   
+            else if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G)
+            {
                 startAudioCaptureTask();
             }
 #else
@@ -679,7 +679,7 @@ namespace OHOS
             uapi_stop_asr();
             stop_AudioCaptureProcess_AI();
         }
-        else if(GetSelect4gorbt() == AI_SELECT_BT)
+        else if (GetSelect4gorbt() == AI_SELECT_BT)
         {
             int32_t argc = 1;
             uint8_t *argv = (uint8_t *)"stop";
@@ -885,7 +885,7 @@ namespace OHOS
         {
             // 60s后息屏停止定时
             AiVoiceModel::GetInstance().ai_stop_screen60s_timer();
-            if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT)
+            if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT)
             {
                 ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消常亮屏
             }
@@ -1242,12 +1242,10 @@ namespace OHOS
             // 移除所有换行符(包括 '\n' 和 '\r')
             str.erase(
                 std::remove(str.begin(), str.end(), '\n'),
-                str.end()
-            );
+                str.end());
             str.erase(
                 std::remove(str.begin(), str.end(), '\r'),
-                str.end()
-            );
+                str.end());
             uapi_start_tts_single_txt((char *)str.c_str());
         }
     }
index f7572ea..33f1135 100644 (file)
@@ -94,7 +94,7 @@ namespace OHOS
         ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON);
         // 开启一个60s取消长亮屏timer
         model->ai_start_screen60s_timer();
-        add_4GAI_vote();//4g投票
+        add_4GAI_vote(); // 4g投票
 
         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH_AI);
     }
@@ -130,7 +130,7 @@ namespace OHOS
         model->stop_ai_isready_timer();
         model->stop_ai4g_connect_timer();
         model->stop_ai4g_tts_play_timer();
-        remove_4GAI_vote();//移除4g投票
+        remove_4GAI_vote(); // 移除4g投票
 
         uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW);
     }
@@ -139,16 +139,24 @@ namespace OHOS
     bool AiVoicePresenter::JumpToReturnResultTextView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView");
-        if (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr &&
-            view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())
+        if (model->GetSelect4gorbt() == AI_SELECT_4G)
         {
             preHeight = 0;
             ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_RETURN_RESULT_TEXT_VIEWID);
         }
-        else
+        else if (model->GetSelect4gorbt() == AI_SELECT_BT)
         {
-            WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView fail");
-            return false;
+            if (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr &&
+                view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())
+            {
+                preHeight = 0;
+                ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID);
+            }
+            else
+            {
+                WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView fail");
+                return false;
+            }
         }
         return true;
     }
@@ -290,7 +298,10 @@ namespace OHOS
         switch (hideView)
         {
         case AIVOICE_STARTCHAT_VIEWID:
-            model->QuerySelectedAiModelIsConnect(); /*查询用户选择的AI模型是否已经连接*/
+            if (model->GetAI_4G_state() == true || model->GetAI_BT_state() == true)
+            {
+                model->QuerySelectedAiModelIsConnect(); /*查询用户选择的AI模型是否已经连接*/
+            }
             if (showView == AIVOICE_LISTENING_VIEWID)
             {
                 model->StartListenAndRecordingUserQuestion();
@@ -393,7 +404,7 @@ namespace OHOS
                 {
                     uapi_start_asr();
                     usleep(50000);
-                    ChangeViewAndLogicOperator(AIVOICE_RETURN_RESULT_TEXT_VIEWID,AIVOICE_AIMODE_CONNECTING);
+                    ChangeViewAndLogicOperator(AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_AIMODE_CONNECTING);
                     return true;
                 }
                 else if (model->GetSelect4gorbt() == AI_SELECT_BT)
@@ -496,6 +507,7 @@ namespace OHOS
             }
             else
             {
+                model->QuerySelectedAiModelIsConnect();                                          /*查询用户选择的AI模型是否已经连接*/
                 ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING
             }
             return true;
@@ -503,6 +515,7 @@ namespace OHOS
         else if (viewId == AIVOICE_SELECT_VIEW_BUTTONBT_VIEW_ID) // 如果点击的是蓝牙连接方式
         {
             model->SetSelect4gorbt(AI_SELECT_BT);
+            model->QuerySelectedAiModelIsConnect(); /*查询用户选择的AI模型是否已经连接*/
             ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_AIMODE_CONNECTING);
         }
 
@@ -653,23 +666,33 @@ namespace OHOS
         {
             preHeight = label.GetTextHeight();
             isScroll = true;
-        }
-        return;
-    }
-
-    // 监听高度是否变化
-    void AiVoicePresenter::Notify()
-    {
-        if ((view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) != nullptr) &&
-            (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()))
-        {
-            if (isScroll)
+            if ((view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) != nullptr) &&
+                (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()))
             {
-                // 监听,让List实现滚动
-                AivoiceReturnResultTextView::GetInstance()->GetChatContentList()->ScrollBy(-120);
-                isScroll = false;
+                if (isScroll)
+                {
+                    // 监听,让List实现滚动
+                    AivoiceReturnResultTextView::GetInstance()->GetChatContentList()->ScrollBy(-120);
+                    isScroll = false;
+                }
             }
         }
         return;
     }
+
+    // 监听高度是否变化
+    // void AiVoicePresenter::Notify()
+    // {
+    //     if ((view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) != nullptr) &&
+    //         (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()))
+    //     {
+    //         if (isScroll)
+    //         {
+    //             // 监听,让List实现滚动
+    //             AivoiceReturnResultTextView::GetInstance()->GetChatContentList()->ScrollBy(-120);
+    //             isScroll = false;
+    //         }
+    //     }
+    //     return;
+    // }
 }
\ No newline at end of file
index 2359ad5..f7aa2a0 100644 (file)
@@ -636,6 +636,7 @@ namespace OHOS
         }
         if (p_AivoiceListeningView)
         {
+            p_AivoiceListeningView->StartOrStopAivoiceListeningImageAnimatorView(true);
             p_AivoiceListeningView->GetShowtimeoutLabel()->SetText("10");
             p_AivoiceListeningView->GetShowtimeoutLabel()->Invalidate();
         }
@@ -665,6 +666,10 @@ namespace OHOS
             AiVoiceScrollView[thisView] = scrollview;
             container_->Add(AiVoiceScrollView[thisView]);
         }
+        if (p_AivoiceThinkingView)
+        {
+            p_AivoiceThinkingView->StartOrStopAiVoiceThinkingImageAnimatorView(true);
+        }
         return true;
     }
 
@@ -901,6 +906,8 @@ namespace OHOS
     static const int16 AiVoiceDestroyMapper[] = {
         AIVOICE_AIMODE_CONNECTING,
         AIVOICE_4GSERVICECON_VIEW,
+        // AIVOICE_LISTENING_VIEWID,
+        // AIVOICE_THINKING_VIEWID,
     };
 
     void AiVoiceView::DestroyTempView(int16_t hideView)
@@ -934,6 +941,22 @@ namespace OHOS
                 p_Aivoice4gServiceConView = nullptr;
             }
             break;
+        case AIVOICE_LISTENING_VIEWID:
+            if (p_AivoiceListeningView)
+            {
+                // delete p_AivoiceListeningView;
+                // p_AivoiceListeningView = nullptr;
+                p_AivoiceListeningView->StartOrStopAivoiceListeningImageAnimatorView(false);
+            }
+            break;
+        case AIVOICE_THINKING_VIEWID:
+            if (p_AivoiceThinkingView)
+            {
+                // delete p_AivoiceThinkingView;
+                // p_AivoiceThinkingView = nullptr;
+                p_AivoiceThinkingView->StartOrStopAiVoiceThinkingImageAnimatorView(false);
+            }
+            break;
         default:
             break;
         }
index 050d452..f1d1b34 100644 (file)
@@ -141,7 +141,7 @@ namespace OHOS
         animatorView->SetSizeFixed(true);
         // animatorView->SetAutoEnable(false);
         // animatorView->SetResizeMode(UIImageAnimatorView::FILL);
-        animatorView->Start();
+        // animatorView->Start();
 
         return animatorView;
     }
@@ -279,6 +279,17 @@ namespace OHOS
         return true;
     }
 
+    void AivoiceListeningView::StartOrStopAivoiceListeningImageAnimatorView(bool val)
+    {
+        if (AiVoiceListeningImageAnimatorView)
+        {
+            if (val)
+                AiVoiceListeningImageAnimatorView->Start();
+            else
+                AiVoiceListeningImageAnimatorView->Stop();
+        }
+    }
+
     UIScrollView *AivoiceListeningView::CreateAivoiceListeningView(void)
     {
         WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningView");
index 6e7db53..f77f124 100644 (file)
@@ -136,7 +136,7 @@ namespace OHOS
         animatorView->SetSizeFixed(true);
         // animatorView->SetAutoEnable(false);
         // animatorView->SetResizeMode(UIImageAnimatorView::FILL);
-        animatorView->Start();
+        // animatorView->Start();
 
         return animatorView;
     }
@@ -262,6 +262,17 @@ namespace OHOS
         return true;
     }
 
+    void AivoiceThinkingView::StartOrStopAiVoiceThinkingImageAnimatorView(bool val)
+    {
+        if (AiVoiceThinkingImageAnimatorView != nullptr)
+        {
+            if (val)
+                AiVoiceThinkingImageAnimatorView->Start();
+            else
+                AiVoiceThinkingImageAnimatorView->Stop();
+        }
+    }
+
     UIScrollView *AivoiceThinkingView::CreateAivoiceThinkingView(void)
     {
         WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingView");