${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceListeningView.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceThinkingView.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceChatContentListAdapter.cpp
${CMAKE_CURRENT_SOURCE_DIR}/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp
#声音与震动
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:14:43
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-26 17:39:41
+ * @LastEditTime: 2024-07-01 17:55:21
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
*/
#ifndef AI_VOICE_MODEL_H
#include "string"
#include "iostream"
#include "string"
+#include "aivoice/include/AivoiceChatContentListItemView.h"
namespace OHOS
{
+ static const uint16_t CHATCONTENT_ITEM_COUNT = 2;
class AiVoiceModel
{
public:
bool GetMobileDataIsOpen(void);
bool GetAiVoiceConnectStatus(void);
+ void InitchatContentItems(void);
+
std::string GetUserQuestionStr(void);
void SetUserQuestionStr(std::string str);
std::string userQuestionStr; // 存储用户提出的问题
std::string aiAnswerStr; // 存储ai回答的问题
+ int16_t chatNum{0}; // 对话数量
+ int16_t chatListHeight{0};
+ ChatContentItem chatTtems[CHATCONTENT_ITEM_COUNT] = {0, nullptr, false};
};
}
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-28 14:26:55
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-01 18:03:29
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/include/AivoiceChatContentListAdapter.h
+ */
+#ifndef AIVOICE_CHAT_CONTENT_LIST_ADAPTER_H
+#define AIVOICE_CHAT_CONTENT_LIST_ADAPTER_H
+
+#include "components/abstract_adapter.h"
+#include "components/ui_label_button_ext.h"
+#include "components/ui_list.h"
+#include "language/LanguageInit.h"
+#include "UiConfig.h"
+#include <list>
+#include "aivoice/include/AivoiceChatContentListItemView.h"
+#include "iostream"
+
+namespace OHOS
+{
+
+ class AivoiceChatContentListAdapter : public AbstractAdapter
+ {
+ public:
+ AivoiceChatContentListAdapter();
+ ~AivoiceChatContentListAdapter();
+
+ void SetData(std::list<ChatContentItem> &data);
+ void ClearData(void);
+ virtual uint16_t GetCount(void) override;
+ virtual UIView *GetView(UIView *inView, int16_t index) override;
+ void AddListItem(const ChatContentItem &item);
+ void SetItemClickListener(UIView::OnClickListener *itemclicklistener);
+ void calculateChatContentItemViewHeight(std::string text, bool flag);
+
+ private:
+ std::list<ChatContentItem> listData;
+ UIView::OnClickListener *itemClickListener{nullptr};
+ int16_t itemViewHeight{0};
+ bool aiAnswerFalg{false};
+ };
+
+}
+
+#endif
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-06-29 17:26:19
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-01 14:46:08
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceChatContentListItemView.h
+ */
+
+#ifndef AIVOICE_CHAT_CONTENT_LIST_ITEM_VIEW_H
+#define AIVOICE_CHAT_CONTENT_LIST_ITEM_VIEW_H
+
+#include "components/ui_view_group.h"
+#include "components/ui_label_ext.h"
+#include "View.h"
+#include "iostream"
+
+namespace OHOS
+{
+ typedef struct
+ {
+ int index;
+ std::string text;
+ bool isAiAnswer;
+ } ChatContentItem;
+
+ class AivoiceChatContentListItemView : public UIViewGroup
+ {
+ public:
+ AivoiceChatContentListItemView(int16_t viewHeight, bool isAiAnswerFalg);
+ ~AivoiceChatContentListItemView();
+ void SetItemInfo(const ChatContentItem itemInfo);
+ void SetUpChild();
+
+ private:
+ UILabelExt chatContentLabel;
+ int16_t m_viewHeight{250};
+ bool m_isAiAnswerFalg{false};
+ };
+}
+
+#endif
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-22 16:46:26
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-25 17:40:57
+ * @LastEditTime: 2024-07-01 14:22:24
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h
*/
#include "components/ui_label_ext.h"
#include "components/ui_button.h"
#include "components/ui_image_view.h"
-
+#include "aivoice/include/AivoiceChatContentListAdapter.h"
+#include "aivoice/include/AivoiceChatContentListItemView.h"
namespace OHOS
{
static constexpr const char *AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID = "AivoiceReturnResultTextReturnButton"; // 返回对话内容界面的返回按钮
~AivoiceReturnResultTextView();
static AivoiceReturnResultTextView *GetInstance(void);
UIScrollView *CreateAivoiceReturnResultTextView(void);
+ void AddChatContentToList(const ChatContentItem &item);
+ AivoiceChatContentListAdapter* GetAivoiceChatContentListAdapter(void);
+ UIList* GetChatContentList(void);
private:
void ClearAll(void);
UIButton *AivoiceReturnResultTextButtonInit(ButtonConfig &buttonconfig);
UIImageView *AivoiceReturnResultTextImageInit(ImageConfig &imageconfig);
bool CreateAivoiceReturnResultTextLabel(void);
- bool CreateAivoiceReturnResultTextUserQuestionLabel(void);
- bool CreateAivoiceReturnResultTextAIAnswerLabel(void);
- bool CreateAivoiceReturnResultTextLImage(void);
+ bool CreateAivoiceReturnResultTextList(void);
bool CreateAivoiceReturnResultTextButton(void);
bool CreateAivoiceReturnResultTextScrollView(void);
UIScrollView *scrollView{nullptr};
UILabelExt *title{nullptr};
- UILabelExt *question{nullptr}; // 提出的问题
- UIScrollView *questionScrollView{nullptr};
- UIImageView *recGreenImage{nullptr};
-
- UILabelExt *answer{nullptr}; // AI回答的答案
- UIScrollView *answerScrollView{nullptr};
- UIImageView *recBlackImage{nullptr};
-
UIButton *returnButton{nullptr};
UIButton *continueChatButton{nullptr};
UILabelExt *continueChat{nullptr};
+
+ AivoiceChatContentListAdapter *chatContentListAdapter{nullptr};
+ UIList *chatContentList{nullptr};
};
}
#endif
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-22 16:46:26
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-24 16:18:51
+ * @LastEditTime: 2024-07-01 17:20:11
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h
*/
static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_H = 160;
static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 29; // 图片帧数
static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_DELAY = 200; // 图片更新间隔
- static constexpr char *AIVoiceThinkingImagePaths = "/user/res/AIVoice/AIVoiceThinking/Ai_Thinking_";
+ static constexpr const char *AIVoiceThinkingImagePaths = "/user/res/AIVoice/AIVoiceThinking/Ai_Thinking_";
class AivoiceThinkingView
{
public:
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:14:50
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-26 17:39:53
+ * @LastEditTime: 2024-07-01 20:07:37
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
*/
#include "aivoice/include/AiVoiceModel.h"
#include "aivoice/include/AiVoicePresenter.h"
#include "aivoice/include/AiVoiceView.h"
+#include "aivoice/include/AivoiceReturnResultTextView.h"
#include "wearable_log.h"
#include <stdio.h>
#include <stdlib.h>
return true;
}
+ void AiVoiceModel::InitchatContentItems(void)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::InitchatContentItems");
+ AivoiceReturnResultTextView *p_AivoiceReturnResultTextView = AivoiceReturnResultTextView::GetInstance();
+ if (p_AivoiceReturnResultTextView == nullptr)
+ {
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::GetInstance fail!! ");
+ return;
+ }
+ int index = 0;
+ chatTtems[index++] = {0, GetUserQuestionStr(), false};
+ chatTtems[index++] = {1, GetAiAnswerStrStr(), true};
+ chatNum = index / 2;
+ for (uint8_t i = 0; i < index; i++)
+ {
+ p_AivoiceReturnResultTextView->AddChatContentToList(chatTtems[i]);
+ }
+ }
+
// 获取蓝牙是否打开
bool AiVoiceModel::GetBluetoothIsOpen(void)
{
std::string AiVoiceModel::GetUserQuestionStr(void)
{
- // userQuestionStr = "写一篇100字文章";
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "userQuestionStr:\n", userQuestionStr.c_str());
+ userQuestionStr = "写一篇100字文章";
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "userQuestionStr:%s\n", userQuestionStr.c_str());
return userQuestionStr;
}
std::string AiVoiceModel::GetAiAnswerStrStr(void)
{
- // aiAnswerStr = "春风化雨,时光荏苒。百年之内,生命如白驹过隙,转瞬即逝。唯有心存善念,用爱化解芥蒂,用智慧建构未来,才是人生的真正意义。让我们携手共进,用每一分时光去关爱他人,用每一滴汗水去创造奇迹,用每一个眼神去传递温暖。让这个世界因我们的存在而变得更加美好。生命短暂,但只要我们怀着虔诚的心,坚韧前行,我们就一定能在有限的时光里留下无限的可能。";
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "aiAnswerStr:\n", aiAnswerStr.c_str());
+ aiAnswerStr = "春风化雨,时光荏苒。百年之内,生命如白驹过隙,转瞬即逝。唯有心存善念,用爱化解芥蒂,用智慧建构未来,才是人生的真正意义。让我们携手共进,用每一分时光去关爱他人,用每一滴汗水去创造奇迹,用每一个眼神去传递温暖。让这个世界因我们的存在而变得更加美好。生命短暂,但只要我们怀着虔诚的心,坚韧前行,我们就一定能在有限的时光里留下无限的可能。";
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "aiAnswerStr:%s\n", aiAnswerStr.c_str());
return aiAnswerStr;
}
if ((view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID) != nullptr) &&
(view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->IsVisible()))
{
- const char *defaultArgs[6] = {"01", "pcm", "16000", "1", "16", AiVoiceModel::GetInstance().GetAIAudioPath().c_str()};
+ std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath();
+ const char *defaultArgs[6] = {"01", "pcm", "16000", "1", "16",audioPath.c_str()};
AudioCaptureSample(6, (const char **)defaultArgs);
}
// 开启定时器
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:11:17
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-26 17:40:11
+ * @LastEditTime: 2024-07-01 19:32:08
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
*/
#include "AppViewIDs.h"
}
else
{
- view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 聆听中->思考中界面
+ // view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 聆听中->思考中界面
+ view_->ChangeView(AIVOICE_LISTENING_VIEWID, AIVOICE_RETURN_RESULT_TEXT_VIEWID); // 聆听中->思考中界面
model->StopListenAndRecordingUserQuestion();
}
return true;
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-03-28 14:27:05
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-01 20:28:31
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/src/AivoiceChatContentListAdapter.cpp
+ */
+#include "aivoice/include/AivoiceChatContentListAdapter.h"
+#include "wearable_log.h"
+#include <UiConfig.h>
+
+namespace OHOS
+{
+
+ AivoiceChatContentListAdapter::AivoiceChatContentListAdapter()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::AivoiceChatContentListAdapter");
+ }
+
+ AivoiceChatContentListAdapter::~AivoiceChatContentListAdapter()
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::~AivoiceChatContentListAdapter");
+ listData.clear();
+ }
+
+ uint16_t AivoiceChatContentListAdapter::GetCount(void)
+ {
+ return listData.size();
+ }
+
+ void AivoiceChatContentListAdapter::SetData(std::list<ChatContentItem> &data)
+ {
+ if (!listData.empty())
+ {
+ listData.clear();
+ }
+ std::list<ChatContentItem>::iterator it;
+ for (it = data.begin(); it != data.end(); it++)
+ {
+ listData.push_back(*it);
+ }
+ }
+
+ void AivoiceChatContentListAdapter::ClearData(void)
+ {
+ if (!listData.empty())
+ {
+ listData.clear();
+ }
+ }
+
+ void AivoiceChatContentListAdapter::calculateChatContentItemViewHeight(std::string text, bool flag)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::calculateChatContentItemViewHeight");
+
+ const char *Text = text.c_str();
+ aiAnswerFalg = flag;
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Text:%s,aiAnswerFalg:%d", Text, aiAnswerFalg);
+
+ UILabel label;
+ label.SetPosition(53, 100);
+ label.Resize(360, 60);
+ label.SetStyle(STYLE_TEXT_FONT, 26);
+ label.SetStyle(STYLE_LINE_HEIGHT, 30);
+ label.SetText(Text);
+ label.SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ label.SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
+ label.SetFont(DEFAULT_VECTOR_FONT_FILENAME, 26);
+
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "label.GetHeight:%d,label.GetTextHeight:%d", label.GetHeight(), label.GetTextHeight());
+ itemViewHeight = label.GetTextHeight();
+ }
+
+ UIView *AivoiceChatContentListAdapter::GetView(UIView *inView, int16_t index)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceChatContentListAdapter::GetView,index %d", index);
+ // 1.先检查列表数据是否为空,若为空则返回空指针
+ if (listData.empty())
+ {
+ return nullptr;
+ }
+ // 2.接着检查索引是否小于0,若小于0则返回空指针
+ if (index < 0)
+ {
+ return nullptr;
+ }
+ // 3.检查是否超出列表数据大小,若超出则返回空指针
+ size_t uindex = index;
+ if (uindex >= listData.size())
+ {
+ return nullptr;
+ }
+ // 4.通过迭代器访问列表中指定索引位置的元素,将其赋值给itemData变量
+ std::list<ChatContentItem>::iterator it = listData.begin();
+ for (int i = 0; i < index; i++)
+ {
+ it++;
+ }
+ ChatContentItem itemData = *it;
+ AivoiceChatContentListItemView *item = nullptr;
+ /* -------------------------------------------------------------------------- */
+ calculateChatContentItemViewHeight(itemData.text, itemData.isAiAnswer);
+ /* -------------------------------------------------------------------------- */
+ // 5.根据传入的inView参数是否已经存在一个视图对象,若为空则创建一个新的LanguageSwitchListItemView对象,否则将inView转换成LanguageSwitchListItemView类型的指针
+ if (inView == nullptr)
+ {
+ item = new AivoiceChatContentListItemView(itemViewHeight, aiAnswerFalg);
+ }
+ else
+ {
+ item = dynamic_cast<AivoiceChatContentListItemView *>(inView);
+ }
+ item->SetItemInfo(itemData);
+ return item;
+ }
+
+ void AivoiceChatContentListAdapter::SetItemClickListener(UIView::OnClickListener *itemclicklistener)
+ {
+ itemClickListener = itemclicklistener;
+ }
+
+ void AivoiceChatContentListAdapter::AddListItem(const ChatContentItem &item)
+ {
+ listData.push_back(item);
+ }
+
+}
\ No newline at end of file
--- /dev/null
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-06-29 17:27:25
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-01 20:23:44
+ * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp
+ */
+
+#include "aivoice/include/AivoiceChatContentListItemView.h"
+#include "wearable_log.h"
+
+namespace OHOS
+{
+ static constexpr int16_t QUESTION_ITEM_VIEW_X = 112 + 53;
+ static constexpr int16_t ANSWER_ITEM_VIEW_X = 53;
+
+ static constexpr int16_t QUESTION_ITEM_VIEW_Y = 0;
+ static constexpr int16_t ANSWER_ITEM_VIEW_Y = 30;
+
+ static constexpr int16_t QUESTION_ITEM_VIEW_W = 280;
+ static constexpr int16_t ANSWER_ITEM_VIEW_W = 360;
+
+ static constexpr int64_t QUESTION_ITEM_VIEW_COLOR = 0xff4fc34c;
+ static constexpr int64_t ANSWER_ITEM_VIEW_COLOR = 0xff191919;
+
+ static constexpr int64_t ITEM_VIEW_RADIUS = 20;
+
+ static constexpr int16_t CHATCONTENTLABEL_TEXT_FONT = 26;
+ static constexpr int16_t CHATCONTENTLABEL_LINE_HEIGHT = 30;
+ static constexpr int16_t CHATCONTENTLABEL_ROLLSPEED = 40;
+ static constexpr int16_t NUM_2 = 2;
+
+ AivoiceChatContentListItemView::AivoiceChatContentListItemView(int16_t viewHeight, bool isAiAnswerFalg)
+ {
+ m_viewHeight = viewHeight;
+ m_isAiAnswerFalg = isAiAnswerFalg;
+ SetPosition(m_isAiAnswerFalg ? ANSWER_ITEM_VIEW_X : QUESTION_ITEM_VIEW_X, m_isAiAnswerFalg ? ANSWER_ITEM_VIEW_Y : QUESTION_ITEM_VIEW_Y);
+ Resize((m_isAiAnswerFalg ? ANSWER_ITEM_VIEW_W : QUESTION_ITEM_VIEW_W), m_viewHeight + 50);
+ SetStyle(STYLE_BACKGROUND_COLOR, m_isAiAnswerFalg ? ANSWER_ITEM_VIEW_COLOR : QUESTION_ITEM_VIEW_COLOR);
+ SetStyle(STYLE_BACKGROUND_OPA, 0xff);
+ SetStyle(STYLE_BORDER_RADIUS, ITEM_VIEW_RADIUS);
+ SetTouchable(true);
+ SetUpChild();
+ Add(&chatContentLabel);
+ }
+
+ AivoiceChatContentListItemView::~AivoiceChatContentListItemView()
+ {
+ Remove(&chatContentLabel);
+ }
+
+ void AivoiceChatContentListItemView::SetItemInfo(const ChatContentItem itemInfo)
+ {
+ chatContentLabel.SetText(itemInfo.text.c_str());
+ }
+
+ void AivoiceChatContentListItemView::SetUpChild()
+ {
+ chatContentLabel.SetPosition(0, 25);
+ chatContentLabel.Resize((GetWidth() - chatContentLabel.GetX() * 2), (GetHeight() - chatContentLabel.GetY() * 2));
+ chatContentLabel.SetStyle(STYLE_TEXT_FONT, CHATCONTENTLABEL_TEXT_FONT);
+ chatContentLabel.SetStyle(STYLE_LINE_HEIGHT, CHATCONTENTLABEL_LINE_HEIGHT);
+ chatContentLabel.SetLineBreakMode(UILabel::LINE_BREAK_WRAP);
+ chatContentLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
+ chatContentLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME, CHATCONTENTLABEL_TEXT_FONT);
+ chatContentLabel.SetTextColor(m_isAiAnswerFalg ? Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff) : Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xcc));
+ }
+}
\ No newline at end of file
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-05-07 11:25:58
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-06-25 17:45:39
+ * @LastEditTime: 2024-07-01 20:28:51
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceReturnResultTextView.cpp
*/
#include "aivoice/include/AiVoicePresenter.h"
{
/* -------------------------------------------------------------------------- */
- static constexpr const int16_t QUESTION_SCROLLVIEW_X = 112;
- static constexpr const int16_t QUESTION_SCROLLVIEW_Y = 120;
- static constexpr const int16_t QUESTION_SCROLLVIEW_W = 280;
- static constexpr const int16_t QUESTION_SCROLLVIEW_H = 80;
- static constexpr const int64_t QUESTION_BACKGROUND_COLOR = 0xff4fc34c;
-
- static constexpr const int16_t QUESTION_LABEL_W = 200;
- static constexpr const int16_t QUESTION_LABEL_H = 30;
- static constexpr const int16_t QUESTION_LABEL_FONTSIZE = 26;
- static constexpr const int16_t QUESTION_LABEL_LINEHEIGHT = 30;
- /* -------------------------------------------------------------------------- */
-
- static constexpr const int16_t ANSWER_SCROLLVIEW_X = 53;
- static constexpr const int16_t ANSWER_SCROLLVIEW_Y = QUESTION_SCROLLVIEW_Y + QUESTION_SCROLLVIEW_H + 30;
- static constexpr const int16_t ANSWER_SCROLLVIEW_W = 360;
- static constexpr const int16_t ANSWER_SCROLLVIEW_H = 250;
- static constexpr const int64_t ANSWER_BACKGROUND_COLOR = 0xff191919;
+ static constexpr const int16_t CHATCONTENT_LIST_X = 53;
+ static constexpr const int16_t CHATCONTENT_LIST_Y = 120;
+ static constexpr const int16_t CHATCONTENT_LIST_W = 360;
+ static constexpr const int16_t CHATCONTENT_LIST_H = 300;
+ static constexpr const int16_t REBOUNDSIZE = 35;
+ static constexpr const int16_t CHATCONTENT_SCROLLBLANKSIZE = 35;
+ static constexpr const int16_t MAX_SCR_DIS = 1000;
+ static constexpr const int16_t SNUM_2 = 2;
- static constexpr const int16_t ANSWER_LABEL_W = 270;
- static constexpr const int16_t ANSWER_LABEL_H = 194;
- static constexpr const int16_t ANSWER_LABEL_FONTSIZE = 26;
- static constexpr const int16_t ANSWER_LABEL_LINEHEIGHT = 30;
-
- /* -------------------------------------------------------------------------- */
- static constexpr const int16_t RECGREEN_IMAGE_X = 342;
- static constexpr const int16_t RECGREEN_IMAGE_Y = QUESTION_SCROLLVIEW_Y;
- static constexpr const int16_t RECGREEN_IMAGE_W = 70;
- static constexpr const int16_t RECGREEN_IMAGE_H = 30;
- static constexpr const char *RECGREEN_IMAGE_PATH = "/user/res/AIVoice/AI_RecGreen.bin";
-
- static constexpr const int16_t RECBLACK_IMAGE_X = 32;
- static constexpr const int16_t RECBLACK_IMAGE_Y = ANSWER_SCROLLVIEW_Y;
- static constexpr const int16_t RECBLACK_IMAGE_W = 70;
- static constexpr const int16_t RECBLACK_IMAGE_H = 30;
- static constexpr const char *RECBLACK_IMAGE_PATH = "/user/res/AIVoice/AI_RecBlack.bin";
/* -------------------------------------------------------------------------- */
static constexpr const int16_t RETURN_BUTTON_X = 73;
- static constexpr const int16_t RETURN_BUTTON_Y = ANSWER_SCROLLVIEW_Y + ANSWER_SCROLLVIEW_H + 20;
+ static constexpr const int16_t RETURN_BUTTON_Y = CHATCONTENT_LIST_Y + CHATCONTENT_LIST_H + 20;
static constexpr const int16_t RETURN_BUTTON_W = 100;
static constexpr const int16_t RETURN_BUTTON_H = 100;
static constexpr const char *RETURN_BUTTON_PATH = "/user/res/AIVoice/AI_Union.bin";
static constexpr const int16_t CONTINUECHAT_BUTTON_X = 183;
- static constexpr const int16_t CONTINUECHAT_BUTTON_Y = ANSWER_SCROLLVIEW_Y + ANSWER_SCROLLVIEW_H + 20;
+ static constexpr const int16_t CONTINUECHAT_BUTTON_Y = CHATCONTENT_LIST_Y + CHATCONTENT_LIST_H + 20;
static constexpr const int16_t CONTINUECHAT_BUTTON_W = 210;
static constexpr const int16_t CONTINUECHAT_BUTTON_H = 100;
/* -------------------------------------------------------------------------- */
title = nullptr;
}
- if (questionScrollView != nullptr)
+ if (chatContentListAdapter != nullptr)
{
- questionScrollView->Remove(question);
- if (question != nullptr)
- {
- delete question;
- question = nullptr;
- }
- delete questionScrollView;
- questionScrollView = nullptr;
+ delete chatContentListAdapter;
+ chatContentListAdapter = nullptr;
}
- if (recGreenImage != nullptr)
+ if (chatContentList != nullptr)
{
- delete recGreenImage;
- recGreenImage = nullptr;
- }
-
- if (answerScrollView != nullptr)
- {
- answerScrollView->Remove(answer);
- if (answer != nullptr)
- {
- delete answer;
- answer = nullptr;
- }
- delete answerScrollView;
- answerScrollView = nullptr;
- }
-
- if (recBlackImage != nullptr)
- {
- delete recBlackImage;
- recBlackImage = nullptr;
+ delete chatContentList;
+ chatContentList = nullptr;
}
if (returnButton != nullptr)
scrollView->SetThrowDrag(true);
scrollView->SetMaxScrollDistance(1000);
scrollView->SetDirection(UIScrollView::VERTICAL);
+ scrollView->SetRotateFactor(2);
+ scrollView->RequestFocus();
return true;
}
- bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextUserQuestionLabel(void)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextUserQuestionLabel");
- if (questionScrollView == nullptr)
- {
- questionScrollView = new UIScrollView();
- if (questionScrollView == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::questionScrollView is nullptr!");
- return false;
- }
- questionScrollView->SetPosition(QUESTION_SCROLLVIEW_X, QUESTION_SCROLLVIEW_Y, QUESTION_SCROLLVIEW_W, QUESTION_SCROLLVIEW_H);
- questionScrollView->SetStyle(STYLE_BACKGROUND_COLOR, QUESTION_BACKGROUND_COLOR);
- questionScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
- questionScrollView->SetStyle(STYLE_BORDER_RADIUS, 20);
- }
- /* -------------------------------------------------------------------------- */
- int16_t QUESTION_LABEL_X = (questionScrollView->GetWidth() - QUESTION_LABEL_W) / ONE_HALF_NUM;
- int16_t QUESTION_LABEL_Y = (questionScrollView->GetHeight() - QUESTION_LABEL_H) / ONE_HALF_NUM;
- if (question == nullptr)
- {
- question = new UILabelExt();
- if (question == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::question is nullptr!");
- return false;
- }
-
- question->SetPosition(QUESTION_LABEL_X, QUESTION_LABEL_Y, QUESTION_LABEL_W, QUESTION_LABEL_H);
- question->SetStyle(STYLE_TEXT_FONT, QUESTION_LABEL_FONTSIZE);
- question->SetStyle(STYLE_LINE_HEIGHT, QUESTION_LABEL_LINEHEIGHT);
- std::string questionStr = AiVoiceModel::GetInstance().GetUserQuestionStr();
- question->SetText(questionStr.c_str());
- question->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xcc));
- question->SetLineBreakMode(UILabel::LINE_BREAK_MARQUEE);
- question->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER);
- question->SetFont(DEFAULT_VECTOR_FONT_FILENAME, QUESTION_LABEL_FONTSIZE);
-
- questionScrollView->Add(question);
- }
- return true;
- }
-
- bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextAIAnswerLabel(void)
- {
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextAIAnswerLabel");
- if (answerScrollView == nullptr)
- {
- answerScrollView = new UIScrollView();
- if (answerScrollView == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::answerScrollView is nullptr!");
- return false;
- }
- answerScrollView->SetPosition(ANSWER_SCROLLVIEW_X, ANSWER_SCROLLVIEW_Y, ANSWER_SCROLLVIEW_W, ANSWER_SCROLLVIEW_H);
- answerScrollView->SetStyle(STYLE_BACKGROUND_COLOR, ANSWER_BACKGROUND_COLOR);
- answerScrollView->SetStyle(STYLE_BACKGROUND_OPA, 0xff);
- answerScrollView->SetStyle(STYLE_BORDER_RADIUS, 20);
- /* -------------------------------------------------------------------------- */
- int16_t ANSWER_LABEL_X = (answerScrollView->GetWidth() - ANSWER_LABEL_W) / ONE_HALF_NUM;
- int16_t ANSWER_LABEL_Y = (answerScrollView->GetHeight() - ANSWER_LABEL_H) / ONE_HALF_NUM;
- if (answer == nullptr)
- {
- answer = new UILabelExt();
- if (answer == nullptr)
- {
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::answer is nullptr!");
- return false;
- }
-
- answer->SetPosition(ANSWER_LABEL_X, ANSWER_LABEL_Y, ANSWER_LABEL_W, ANSWER_LABEL_H);
- answer->SetStyle(STYLE_TEXT_FONT, ANSWER_LABEL_FONTSIZE);
- answer->SetStyle(STYLE_LINE_HEIGHT, ANSWER_LABEL_LINEHEIGHT);
- std::string answerStr = AiVoiceModel::GetInstance().GetAiAnswerStrStr();
- answer->SetText(answerStr.c_str());
- answer->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff));
- answer->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS);
- answer->SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER);
- answer->SetFont(DEFAULT_VECTOR_FONT_FILENAME, QUESTION_LABEL_FONTSIZE);
-
- answerScrollView->Add(answer);
- }
- }
- return true;
- }
-
bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLabel(void)
{
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLabel");
return false;
}
/* -------------------------------------------------------------------------- */
- if (!CreateAivoiceReturnResultTextUserQuestionLabel() || !CreateAivoiceReturnResultTextAIAnswerLabel())
- {
- return false;
- }
- /* -------------------------------------------------------------------------- */
labelconfig = {
.left = CONTINUECHAT_X,
.top = CONTINUECHAT_Y,
return true;
}
- bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLImage(void)
+ bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextList(void)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLImage");
- ImageConfig imageconfig = {
- .x = RECGREEN_IMAGE_X,
- .y = RECGREEN_IMAGE_Y,
- .w = RECGREEN_IMAGE_W,
- .h = RECGREEN_IMAGE_H,
- .src = RECGREEN_IMAGE_PATH,
- };
- recGreenImage = AivoiceReturnResultTextImageInit(imageconfig);
- if (recGreenImage == nullptr)
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextList");
+ chatContentListAdapter = new AivoiceChatContentListAdapter();
+ if (chatContentListAdapter == nullptr)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::chatContentListAdapter is nullptr");
+ return false;
+ }
+ UIView::OnClickListener *clickListener = static_cast<UIView::OnClickListener *>(AiVoicePresenter::GetInstance());
+ if (clickListener == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::recGreenImage is nullptr!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::chatContentListAdapter is nullptr");
return false;
}
+ chatContentListAdapter->SetItemClickListener(clickListener);
+
/* -------------------------------------------------------------------------- */
- imageconfig = {
- .x = RECBLACK_IMAGE_X,
- .y = RECBLACK_IMAGE_Y,
- .w = RECBLACK_IMAGE_W,
- .h = RECBLACK_IMAGE_H,
- .src = RECBLACK_IMAGE_PATH,
- };
- recBlackImage = AivoiceReturnResultTextImageInit(imageconfig);
- if (recBlackImage == nullptr)
+ AiVoiceModel::GetInstance().InitchatContentItems();
+ /* -------------------------------------------------------------------------- */
+
+ chatContentList = new UIList(UIList::VERTICAL);
+ if (chatContentList == nullptr)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::recBlackImage is nullptr!");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SettingView::OnStart::chatContentList is nullptr");
return false;
}
+ chatContentList->SetPosition(CHATCONTENT_LIST_X, CHATCONTENT_LIST_Y, CHATCONTENT_LIST_W, CHATCONTENT_LIST_H);
+ chatContentList->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000);
+ chatContentList->EnableAutoAlign(true);
+ chatContentList->SetTouchable(true);
+ chatContentList->SetDraggable(true);
+ chatContentList->SetThrowDrag(true);
+ chatContentList->SetReboundSize(REBOUNDSIZE);
+ chatContentList->SetMaxScrollDistance(MAX_SCR_DIS);
+ chatContentList->SetIntercept(true);
+ // chatContentList->SetAutoSize(true);
+ chatContentList->SetAdapter(chatContentListAdapter);
return true;
}
if (scrollView == nullptr)
{
if (!CreateAivoiceReturnResultTextScrollView() || !CreateAivoiceReturnResultTextLabel() ||
- !CreateAivoiceReturnResultTextLImage() || !CreateAivoiceReturnResultTextButton())
+ !CreateAivoiceReturnResultTextList() || !CreateAivoiceReturnResultTextButton())
{
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextView fail!!");
return nullptr;
}
/* ----------------------------------- Add ---------------------------------- */
scrollView->Add(title);
- scrollView->Add(questionScrollView);
- scrollView->Add(recGreenImage);
- scrollView->Add(answerScrollView);
- scrollView->Add(recBlackImage);
+ scrollView->Add(chatContentList);
scrollView->Add(returnButton);
scrollView->Add(continueChatButton);
scrollView->Add(continueChat);
}
return scrollView;
}
+
+ /*添加对话内容到List*/
+ void AivoiceReturnResultTextView::AddChatContentToList(const ChatContentItem &item)
+ {
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::AddChatContentToList");
+ // /* -------------------------------------------------------------------------- */
+ // chatContentListAdapter->calculateChatContentItemViewHeight(item.text, item.isAiAnswer);
+ // /* -------------------------------------------------------------------------- */
+ chatContentListAdapter->AddListItem(item);
+ }
+
+ AivoiceChatContentListAdapter *AivoiceReturnResultTextView::GetAivoiceChatContentListAdapter(void)
+ {
+ return chatContentListAdapter;
+ }
+
+ UIList *AivoiceReturnResultTextView::GetChatContentList(void)
+ {
+ return chatContentList;
+ }
}
\ No newline at end of file