Ai语音添加滚动编码器切换Ai模型
authorluozheng <1732036298@qq.com>
Mon, 29 Jul 2024 02:39:47 +0000 (10:39 +0800)
committerluozheng <1732036298@qq.com>
Mon, 29 Jul 2024 02:39:47 +0000 (10:39 +0800)
code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.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

index ad1c5d1..117a71b 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-07-27 17:05:56
+ * @LastEditTime: 2024-07-29 10:32:57
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h
  */
 #ifndef AI_VOICE_PRESENTER_H
@@ -11,6 +11,7 @@
 #include "Presenter.h"
 #include "View.h"
 #include "ui_resource_string.h"
+#include "components/ui_time_picker.h"
 namespace OHOS
 {
     class AiVoiceView;
@@ -19,6 +20,7 @@ namespace OHOS
                              public UIView::OnClickListener,
                              public UIView::OnDragListener,
                              public RootView::OnKeyActListener,
+                             public UIPicker::SelectedListener,
                              public UIView::OnTouchListener
     {
     public:
@@ -48,6 +50,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);
 
         AiVoiceModel *model;
         bool X_DRAG_FLAG{false};
index cc98be9..10c2344 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:14:50
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-27 18:35:32
+ * @LastEditTime: 2024-07-29 09:50:45
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
  */
 #include "aivoice/include/AiVoiceModel.h"
@@ -616,14 +616,32 @@ namespace OHOS
     }
 
     /*获取已选择的ai模型的textid*/
-    int AiVoiceModel::GetAiModelTextId(void)
+    int AiVoiceModel::GetAiModelTextId()
     {
-        std::map<int, int> selectAiModelToTextId = {
-            {AiVoicePresenter::AIMODES_WENXINYIYAN, STR_AIMODES_WENXINYIYAN},
-            {AiVoicePresenter::AIMODES_KIMI, STR_AIMODES_KIMI},
-            {AiVoicePresenter::AIMODES_DOUBAO, STR_AIMODELS_DOUBAO},
-            {AiVoicePresenter::AIMODES_CHATGPT, STR_AIMODES_CHATGPT},
-        };
+        int language = ConfigModel::GetInstance()->GetLanguage();
+        int textId;
+
+        std::map<int, int> selectAiModelToTextId;
+        if (language == 0)
+        {
+            selectAiModelToTextId = {
+                {0, STR_AIMODES_WENXINYIYAN},
+                {1, STR_AIMODES_KIMI},
+                {2, STR_AIMODELS_DOUBAO},
+                {3, STR_AIMODES_CHATGPT},
+            };
+            textId = STR_AIMODES_WENXINYIYAN;
+        }
+        else
+        {
+            selectAiModelToTextId = {
+                {0, STR_AIMODES_CHATGPT},
+                {1, STR_AIMODES_WENXINYIYAN},
+                {2, STR_AIMODES_KIMI},
+                {3, STR_AIMODELS_DOUBAO},
+            };
+            textId = STR_AIMODES_CHATGPT;
+        }
 
         // 根据视图ID设置文本ID
         auto it = selectAiModelToTextId.find(GetSelectAiModel());
@@ -631,9 +649,8 @@ namespace OHOS
         {
             return it->second;
         }
-        else 
-        {
-            return STR_AIMODES_WENXINYIYAN;
-        }
+
+        return textId;
     }
+
 }
index 61c7a71..584f12f 100644 (file)
@@ -2,7 +2,7 @@
  * @Author: luozheng 1732036298@qq.com
  * @Date: 2024-06-20 15:11:17
  * @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-27 18:21:46
+ * @LastEditTime: 2024-07-29 10:32:54
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
  */
 #include "AppViewIDs.h"
@@ -281,7 +281,7 @@ namespace OHOS
             int index = model->GetSelectAiModel() + 1;
             if (index >= AIMODES_MAX_NUM)
             {
-                index = AIMODES_WENXINYIYAN;
+                index = 0;
             }
             WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiModelsPresenter::index = %d", index);
             model->SetSelectAiModel(index);
@@ -409,4 +409,11 @@ namespace OHOS
         }
         return true;
     }
+
+    void AiVoicePresenter::OnPickerStoped(UIPicker &picker)
+    {
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnPickerStoped,%d", picker.GetSelected());
+        model->SetSelectAiModel(picker.GetSelected());
+        view_->ChangeAiModelAndUpdateComponentsStatus();
+    }
 }
\ No newline at end of file
index 377c6e3..b031636 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-07-27 18:22:15
+ * @LastEditTime: 2024-07-29 10:38:14
  * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
  */
 #include "aivoice/include/AiVoicePresenter.h"
@@ -347,6 +347,9 @@ namespace OHOS
             aiModelPicker->SetStyle(STYLE_BORDER_RADIUS, 150);
             aiModelPicker->SetItemHeight(40);
             aiModelPicker->SetLoopState(true);
+            aiModelPicker->SetRotateFactor(1.0);
+            aiModelPicker->RequestFocus();
+            aiModelPicker->RegisterSelectedListener(presenter_);
             aiModelPicker->SetTextColor(Color::GetColorFromRGBA(0x00, 0x00, 0x00, 0xff), Color::GetColorFromRGBA(0xff, 0x00, 0x00, 0xff));
             const char *uiPicker1Data[] = {"0", "1", "2", "3"};
             aiModelPicker->SetValues(uiPicker1Data, 4);
@@ -649,7 +652,7 @@ namespace OHOS
 
     void AiVoiceView::ChangeAiModelAndUpdateComponentsStatus(void)
     {
-        WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiModelAndUpdateComponentsStatus");
+        WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiModelAndUpdateComponentsStatus");
         int textId = AiVoiceModel::GetInstance().GetAiModelTextId();
         if (title)
         {