* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-08 09:36:01
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-25 14:53:47
+ * @LastEditTime: 2024-07-27 18:22:22
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/AiVoiceView.h
*/
#ifndef AI_VOICE_VIEW_H
#include "components/ui_button.h"
#include "components/ui_scroll_view.h"
#include "components/ui_image_view.h"
+#include "components/ui_picker.h"
#include "aivoice/include/AiVoiceBluetoothFailedStartView.h"
#include "aivoice/include/AivoiceMobileDataFailedStartView.h"
#include "aivoice/include/AivoiceConnectTimeoutView.h"
#include "aivoice/include/AivoiceListeningView.h"
#include "aivoice/include/AivoiceThinkingView.h"
#include "aivoice/include/AivoiceReturnResultTextView.h"
+#include "iostream"
+#include "string"
+#include "map"
namespace OHOS
{
- static constexpr const char *START_CHAT_BUTTON_VIEW_ID = "StartChatButton"; // 开始对话
+ static constexpr const char *AIMODEL_WENXINYIYAN_PATH = "/user/res/AIVoice/aimodels/aimodels_wenxinyiyan.bin"; /*文心一言*/
+ static constexpr const char *AIMODEL_CHATGPT_ON_PATH = "/user/res/AIVoice/aimodels/aimodels_chatgpt.bin"; /*ChatGPT*/
+ static constexpr const char *AIMODEL_KIMI_PATH = "/user/res/AIVoice/aimodels/aimodels_kimi.bin"; /*KIMI*/
+ static constexpr const char *AIMODEL_DOUBAO_PATH = "/user/res/AIVoice/aimodels/aimodels_doubao.bin"; /*豆包*/
+
+ static constexpr const char *AIVOICE_START_CHAT_BUTTON_VIEW_ID = "aivoice_start_chat_button_view_id"; // 开始对话
+ static constexpr const char *AIVOICE_CHAT_BUTTON_VIEW_ID = "aivoice_chat_button_view_id"; // 对话
+ static constexpr const char *AIVOICE_APIKEYS_BUTTON_VIEW_ID = "aivoice_apikeys_button_view_id"; // API Keys
+ static constexpr const char *AIVOICE_PICKER_VIEW_ID = "aivoice_picker_view_id";
+ static constexpr const char *AIVOICE_IMGAE_VIEW_ID = "aivoice_imgae_view_id";
typedef enum
{
MAX_AIVOICE_VIEWID,
} AIVOICEVIEWID;
+ static std::map<int, const char *> TextIdToImagePath = {
+ {STR_AIMODES_WENXINYIYAN, AIMODEL_WENXINYIYAN_PATH},
+ {STR_AIMODES_KIMI, AIMODEL_KIMI_PATH},
+ {STR_AIMODELS_DOUBAO, AIMODEL_DOUBAO_PATH},
+ {STR_AIMODES_CHATGPT, AIMODEL_CHATGPT_ON_PATH},
+ };
+
class AiVoicePresenter;
class AiVoiceView : public View<AiVoicePresenter>
{
int16_t y;
int16_t w;
int16_t h;
+ const char *src;
};
struct ButtonConfig
bool ChangeAiVoicThinkingView(int16_t thisView);
bool ChangeAiVoicReturnResultTextView(int16_t thisView);
+ void SetAiVoiceViewAllComponentsVisibilityStatus();
+ void ChangeAiModelAndUpdateComponentsStatus(void);
+
void OnStart() override;
void OnSetUpView() override;
void OnTearDownView() override;
bool CreateAiVoiceViewLabel(void);
bool CreateAiVoiceViewImageView(void);
bool CreateAiVoiceViewButton(void);
+ bool CreateAiVoiceViewPicker(void);
bool CreateAiVoiceScrollView(void);
void CreateAiVoiceView(void);
void ClearAll(void);
- UILabelExt *title{nullptr};
- UILabelExt *startChatLabel{nullptr};
- UIButton *startChatButton{nullptr};
- UIImageView *startChatImage{nullptr};
+ void SetComponentVisibility(UIView *component, bool isVisible);
+ UILabelExt *title{nullptr}; /*标题*/
+ UILabelExt *startChatLabel{nullptr}; /*开始对话标签*/
+ UIButton *startChatButton{nullptr}; /*开始对话按钮*/
+ UILabelExt *chatLabel{nullptr}; /*对话标签*/
+ UIButton *chatButton{nullptr}; /*对话按钮*/
+ UIImageView *aiModelImage{nullptr}; /*ai模型图片*/
+ UILabelExt *apiKeysLabel{nullptr}; /*API Keys标签*/
+ UIButton *apiKeysButton{nullptr}; /*API Keys按钮*/
+ UIPicker *aiModelPicker{nullptr}; /*ai模型选择器*/
UIScrollView *AiVoiceScrollView[MAX_AIVOICE_VIEWID]{nullptr};
-
bool viewInitStatus{false};
};
}
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-05-07 11:25:58
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-12 16:05:22
+ * @LastEditTime: 2024-07-27 18:22:15
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
*/
#include "aivoice/include/AiVoicePresenter.h"
#include "aivoice/include/AiVoiceView.h"
+#include "aivoice/include/AiVoiceModel.h"
#include "wearable_log.h"
#include "ui_resource_string.h"
-#include "aimodels/include/AiModelsModel.h"
+#include "ConfigModel.h"
namespace OHOS
{
delete title;
title = nullptr;
- delete startChatImage;
- startChatImage = nullptr;
+ delete aiModelImage;
+ aiModelImage = nullptr;
delete startChatButton;
startChatButton = nullptr;
delete startChatLabel;
startChatLabel = nullptr;
+ delete chatButton;
+ chatButton = nullptr;
+
+ delete chatLabel;
+ chatLabel = nullptr;
+
+ delete apiKeysLabel;
+ apiKeysLabel = nullptr;
+
+ delete apiKeysButton;
+ apiKeysButton = nullptr;
+
+ delete aiModelPicker;
+ aiModelPicker = nullptr;
+
delete AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID];
AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID] = nullptr;
}
return nullptr;
}
Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h);
+ Image->SetSrc(imageconfig.src);
return Image;
}
.height = 35,
.fontSize = 30,
.lineHeigh = 35,
- .textId = AiModelsModel::GetInstance().GetAiModelTextId(),
+ .textId = AiVoiceModel::GetInstance().GetAiModelTextId(),
.lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
};
title = AiVoiceViewLabelInit(labelConfig);
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title new fail!");
return false;
}
-
+ /* ----------------------------- startChatLabel ----------------------------- */
labelConfig = {
.left = 133,
- .top = 368,
+ .top = 348,
.width = 200,
.height = 35,
.fontSize = 30,
.lineHeigh = 35,
- .textId = STR_START_CHAT,
+ .textId = STR_START_CHAT, /*开始对话*/
.lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
};
startChatLabel = AiVoiceViewLabelInit(labelConfig);
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startChatLabel new fail!");
return false;
}
+ startChatLabel->SetVisible(false);
+ /* -------------------------------- ChatLabel ------------------------------- */
+ labelConfig = {
+ .left = 93,
+ .top = 350,
+ .width = 100,
+ .height = 30,
+ .fontSize = 26,
+ .lineHeigh = 30,
+ .textId = STR_CHAT, /*对话*/
+ .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
+ };
+ chatLabel = AiVoiceViewLabelInit(labelConfig);
+ if (chatLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chatLabel new fail!");
+ return false;
+ }
+ chatLabel->SetVisible(false);
+ /* ------------------------------ apiKeysLabel ------------------------------ */
+ labelConfig = {
+ .left = 273,
+ .top = 350,
+ .width = 100,
+ .height = 30,
+ .fontSize = 26,
+ .lineHeigh = 30,
+ .textId = STR_API_KEYS, /*API Keys标签*/
+ .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION,
+ };
+ apiKeysLabel = AiVoiceViewLabelInit(labelConfig);
+ if (apiKeysLabel == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "apiKeysLabel new fail!");
+ return false;
+ }
+ apiKeysLabel->SetVisible(false);
return true;
}
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewImageView");
ImageConfig imagecinfig = {
- .x = 207,
- .y = 182,
- .w = 52,
- .h = 52,
+ .x = 173,
+ .y = 143,
+ .w = 120,
+ .h = 120,
+ .src = "",
};
- startChatImage = AiVoiceViewImageView(imagecinfig);
- if (startChatImage == nullptr)
+
+ // 根据视图ID设置文本ID
+ auto it = TextIdToImagePath.find(AiVoiceModel::GetInstance().GetAiModelTextId());
+ if (it != TextIdToImagePath.end())
+ {
+ imagecinfig.src = it->second;
+ }
+
+ aiModelImage = AiVoiceViewImageView(imagecinfig);
+ if (aiModelImage == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::startChatImage is nullptr!!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::aiModelImage is nullptr!!");
return false;
}
- startChatImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
- startChatImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
- startChatImage->SetStyle(STYLE_BORDER_RADIUS, 100);
+ aiModelImage->SetTouchable(true);
+ aiModelImage->SetViewId(AIVOICE_IMGAE_VIEW_ID);
+ aiModelImage->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+ aiModelImage->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ aiModelImage->SetStyle(STYLE_BORDER_RADIUS, 100);
+ aiModelImage->SetOnClickListener(presenter_);
return true;
}
bool AiVoiceView::CreateAiVoiceViewButton(void)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewButton");
+ /* ----------------------------- startChatButton ---------------------------- */
ButtonConfig buttonconfig = {
.x = 93,
- .y = 340,
+ .y = 320,
.w = 280,
.h = 90,
- .ViewId = START_CHAT_BUTTON_VIEW_ID,
+ .ViewId = AIVOICE_START_CHAT_BUTTON_VIEW_ID,
};
startChatButton = AiVoiceViewButtonInit(buttonconfig);
if (startChatButton == nullptr)
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "startChatButton new fail!");
return false;
}
+ startChatButton->SetVisible(false);
+ /* ------------------------------- chatButton ------------------------------- */
+ buttonconfig = {
+ .x = 58,
+ .y = 320,
+ .w = 170,
+ .h = 90,
+ .ViewId = AIVOICE_CHAT_BUTTON_VIEW_ID,
+ };
+ chatButton = AiVoiceViewButtonInit(buttonconfig);
+ if (chatButton == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chatButton new fail!");
+ return false;
+ }
+ chatButton->SetVisible(false);
+ /* ------------------------------ apiKeysButton ----------------------------- */
+ buttonconfig = {
+ .x = 238,
+ .y = 320,
+ .w = 170,
+ .h = 90,
+ .ViewId = AIVOICE_APIKEYS_BUTTON_VIEW_ID,
+ };
+ apiKeysButton = AiVoiceViewButtonInit(buttonconfig);
+ if (apiKeysButton == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "apiKeysButton new fail!");
+ return false;
+ }
+ apiKeysButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919);
+ apiKeysButton->SetVisible(false);
+
+ return true;
+ }
+
+ bool AiVoiceView::CreateAiVoiceViewPicker(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewPicker");
+ if (aiModelPicker == nullptr)
+ {
+ aiModelPicker = new UIPicker();
+ if (aiModelPicker == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "aiModelPicker new fail!");
+ return false;
+ }
+ aiModelPicker->SetPosition(203, 203, 60, 60);
+ aiModelPicker->SetViewId(AIVOICE_PICKER_VIEW_ID);
+ aiModelPicker->SetStyle(STYLE_BACKGROUND_COLOR, 0xffffffff);
+ aiModelPicker->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ aiModelPicker->SetStyle(STYLE_BORDER_RADIUS, 150);
+ aiModelPicker->SetItemHeight(40);
+ aiModelPicker->SetLoopState(true);
+ 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);
+ }
return true;
}
void AiVoiceView::CreateAiVoiceView(void)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView");
- if (!CreateAiVoiceScrollView() || !CreateAiVoiceViewLabel() ||
- !CreateAiVoiceViewImageView() || !CreateAiVoiceViewButton())
+ if (!CreateAiVoiceScrollView() || !CreateAiVoiceViewImageView() || !CreateAiVoiceViewPicker() ||
+ !CreateAiVoiceViewLabel() || !CreateAiVoiceViewButton())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView fail!");
return;
}
AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(title);
- AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(startChatImage);
+ AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(aiModelPicker);
+ AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(aiModelImage);
AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(startChatButton);
AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(startChatLabel);
+ AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(chatButton);
+ AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(chatLabel);
+ AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(apiKeysButton);
+ AiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID]->Add(apiKeysLabel);
}
void AiVoiceView::OnStart()
viewInitStatus = true;
}
+ SetAiVoiceViewAllComponentsVisibilityStatus();
+
RootView::GetInstance()->SetOnKeyActListener(presenter_);
return;
}
return nullptr;
}
}
+
+ void AiVoiceView::SetAiVoiceViewAllComponentsVisibilityStatus(void)
+ {
+ bool isAiModeChatGpt = (AiVoiceModel::GetInstance().GetAiModelTextId() == STR_AIMODES_CHATGPT);
+
+ SetComponentVisibility(chatButton, isAiModeChatGpt);
+ SetComponentVisibility(chatLabel, isAiModeChatGpt);
+ SetComponentVisibility(apiKeysButton, isAiModeChatGpt);
+ SetComponentVisibility(apiKeysLabel, isAiModeChatGpt);
+
+ SetComponentVisibility(startChatLabel, !isAiModeChatGpt);
+ SetComponentVisibility(startChatButton, !isAiModeChatGpt);
+ }
+
+ void AiVoiceView::SetComponentVisibility(UIView *component, bool isVisible)
+ {
+ if (component)
+ {
+ component->SetVisible(isVisible);
+ }
+ }
+
+ void AiVoiceView::ChangeAiModelAndUpdateComponentsStatus(void)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiModelAndUpdateComponentsStatus");
+ int textId = AiVoiceModel::GetInstance().GetAiModelTextId();
+ if (title)
+ {
+ title->SetTextId(textId);
+ title->ForceResetText();
+ }
+ if (aiModelImage)
+ {
+ auto it = TextIdToImagePath.find(textId);
+ if (it != TextIdToImagePath.end())
+ {
+ aiModelImage->SetSrc(it->second);
+ aiModelImage->Invalidate();
+ }
+ }
+
+ SetAiVoiceViewAllComponentsVisibilityStatus();
+ }
+
}
\ No newline at end of file