From: luozheng <1732036298@qq.com> Date: Fri, 17 Oct 2025 10:04:02 +0000 (+0800) Subject: fd272删除与ai相关代码 X-Git-Tag: V1.0.9_20251128_194606_LN~211 X-Git-Url: http://git.snicker.com.cn/css/static/script.js?a=commitdiff_plain;h=53aaec9c1ad8a5838330b9f81e163b55b8d83d68;p=mirrors%2FFD230.git fd272删除与ai相关代码 --- diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h deleted file mode 100644 index aedba05fa..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-21 17:07:07 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-31 14:16:00 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceBluetoothFailedStartView.h - */ - -#ifndef AI_VOICE_BLUETOOTH_FAILEDSTART_VIEW_H -#define AI_VOICE_BLUETOOTH_FAILEDSTART_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" -#include "components/ui_image_view.h" - -namespace OHOS -{ - static constexpr const char *ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID = "AppBluetoothAnd4gNetworkEnsureButton";//APP蓝牙与4G网络都连接异常界面的确定按钮 - - class AiVoiceBluetoothFailedStartView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - struct ButtonConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ViewId; - }; - - struct ImageConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - }; - - AiVoiceBluetoothFailedStartView(); - ~AiVoiceBluetoothFailedStartView(); - static AiVoiceBluetoothFailedStartView *GetInstance(void); - UIScrollView *CreateAiVoiceBluetoothFailedStartView(void); - void UpdateTitleTextId(int textId); - - private: - void ClearAll(void); - UILabelExt *AiVoiceBluetoothFailedStartLabelInit(LabelConfig &labelconfig); - UIButton *AiVoiceBluetoothFailedStartButtonInit(ButtonConfig &buttonconfig); - UIImageView *AiVoiceBluetoothFailedStartImageInit(ImageConfig &imageconfig); - bool CreateAiVoiceBluetoothFailedStartLabel(void); - bool CreateAiVoiceBluetoothFailedStartButton(void); - bool CreateAiVoiceBluetoothFailedStartImage(void); - bool CreateAiVoiceBluetoothFailedStartScrollView(void); - UIScrollView *scrollView{nullptr}; - UILabelExt *title{nullptr}; - UIImageView *attentionImage{nullptr}; - UILabelExt *label[2]{nullptr}; - UILabelExt *ensure{nullptr}; - UIButton *ensureButton{nullptr}; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModel.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModel.h deleted file mode 100644 index 6f619a1ce..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModel.h +++ /dev/null @@ -1,213 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-20 15:14:43 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-19 09:44:14 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h - */ -#ifndef AI_VOICE_MODEL_H -#define AI_VOICE_MODEL_H - -#include "iostream" -#include "string" -#include "iostream" -#include "string" -#include "ChatContentItem.h" -#include "map" -#define AIAUDIO_TYPE_PCM 0 -#define AIAUDIO_TYPE_SBC 1 -#define AIAUDIO_TYPE_MSBC 2 - -#define AI_VOICE_ENABLE 0 - -// 常量定义 -#define MAX_CHAT_CONTENT_COUNT 2 -#define DEFAULT_TIMEOUT_5S 5 //5秒 -#define DEFAULT_TIMEOUT_10S 10 //10秒 -#define DEFAULT_TIMEOUT_30S 30 //30秒 -#define DEFAULT_TIMEOUT_60S 60 //60秒 - -// 设置当前使用的音频类型,0 表示 PCM,1 表示 SBC,2 表示 MSBC -#define CURRENT_AIAUDIO_TYPE AIAUDIO_TYPE_SBC - -#if defined(SUPPORT_CHINA_MOBILE_DMP) || defined(SUPPORT_CHINA_MOBILE_AI_REGULATION) - #define AI_VOICE_FD230 // 九天版本 -#elif defined(BOARD_N9) - #define AI_VOICE_N9 //N9 星辰Ai -#else - #define AI_VOICE_FD230 -#endif - - -namespace OHOS -{ -#define AI_SELECT_DEFAULT -1 -#define AI_SELECT_4G 1 -#define AI_SELECT_BT 0 - - class AiVoiceModel - { - public: - enum aiResponseType :uint8_t { - AI_RECORDING_PARSING_ERROR = 0, //AI录音解析错误 - AI_RECORDING_PARSING_CONTENT, //AI录音解析内容 - AI_RESPONSE_CONTENT, //AI回应内容 - AI_RESPONSE_ERROR,//AI 回应错误 - AI_RESPONSE_END,//AI 回应结束 - AI_BLE_ERROR,//蓝牙数据传入错误 - }; - - static AiVoiceModel &GetInstance(void); // 获取单例实例 - bool ChangeToReturnResultTextView(void); - bool ChangeToAIVoiceListeningView(bool value); - bool ChangeToAIVoiceConnectTimeoutView(); - void FunctionKeyOnClickToChangeAIModel(void); - // 初始化和状态管理 - void StatusResume(void); - - bool IsExistOpenAIAPIKeys(); - void DeleteLocalOpenAIAPIKeys(); - bool GetAPPBluetoothIsConnect(void); - bool GetMobileDataIsOpen(void); - void QuerySelectedAiModelIsConnect(); - void CancelCurAIChat(void); - int GetAIResponseType(void); - std::string GetErrnote(void); - void SetErrnote(std::string str); - void SetCurView(int16_t viewNum); - int GetCurView(void); - - // 聊天内容管理 - bool InitchatContentItems(void); - bool AddUserQuestionToChatItems(); - bool AddAiAnswerToChatItems(); - bool AddChatContentToItemArray(const ChatContentItem &item); - uint8_t GetChatContentListCount(void); - void SetChatContentListCount(uint8_t count); - - // 更新和清空问题及回答 - bool RemoveLastTwoItemsOrClear(); - bool UpdateUserQuestionStr(void); - bool UpdateAiAnswerStr(void); - void ClearQuestionAndAiAnswerStr(void); - - // 获取和设置问题及回答 - std::string GetUserQuestionStr(void); - void SetUserQuestionStr(std::string str); - std::string GetAiAnswerStr(void); - void SetAiAnswerStrStr(std::string str); - void SetAiAnswerStrStr(std::string str,uint8_t type); - uint8_t GetCurUsingAiModelType(void); - uint8_t GetCurUsing4GAiModelType(void); - - //发送AI已经就绪(继续对话时候使用) - void sendAIIsReady(); - - // AI录音路径管理 - std::string GetAIAudioPath(void); - - // 启动和停止录音 - void StartListenAndRecordingUserQuestion(void); - void StopListenAndRecordingUserQuestion(void); - - // 定时器管理 - void AIVoice_StartTimer(uint32_t interval = 1000); - void AIVoice_StopTimer(void); - - void ai_start_screen60s_timer(uint32_t interval = 30*1000); - void ai_stop_screen60s_timer(void); - void reset_ai_screen60s_timer_time(); - bool get_screen60s_timer_is_stop(void); - - void start_listening_timer(uint32_t interval = 1000); - void stop_listening_timer(void); - - void start_ai_isready_timer(uint32_t interval = 1000); - void stop_ai_isready_timer(void); - - void start_ai4g_connect_timer(uint32_t interval = 1000); - void stop_ai4g_connect_timer(void); - - void start_ai4g_tts_play_timer(uint32_t interval = 600); - void stop_ai4g_tts_play_timer(void); - - void start_update_ai_answer_timer(uint32_t interval = 300); - void stop_update_ai_answer_timer(void); - - void start_uapi_stop_tts_timer(uint32_t interval = 2000); - void stop_uapi_stop_tts_timer(void); - - void SetSelectAiModel(int index); - int GetSelectAiModel(void); - int GetAiModelTextId(void); - - bool CreateDirectory(const char* path); - - void SetIsClickable(bool value); - bool GetIsClickable(void); - - void SetIsLimitDisplayed(bool value); - bool GetIsLimitDisplayed(void); - - void SetAI_4G_state(bool state); - bool GetAI_4G_state(void); - void SetAI_BT_state(bool state); - bool GetAI_BT_state(void); - void SetInit_4gai_task(bool state); - bool GetInit_4gai_task(void); - void SetSelect4gorbt(int state); - int GetSelect4gorbt(void); - - void ProcessTextByPunctuation(); - std::string GetAccumulatedText(void); - void sendSegment(const std::string &text, size_t pos); - - bool is_need_to_jump_result_view(void); - - bool getentryTextViewState(void); - - bool get_is_first_receive(); - void set_is_first_receive(bool); - void delete_start_line_break_str(std::string &str); - - private: - AiVoiceModel(); - ~AiVoiceModel(); - AiVoiceModel(const AiVoiceModel &) = delete; - AiVoiceModel &operator=(const AiVoiceModel &) = delete; - -// 私有成员变量 -#if CURRENT_AIAUDIO_TYPE == AIAUDIO_TYPE_PCM - std::string AIAIAudioPath = "/user/userdata/AiRecording/AIAudio.pcm"; // AI录音的文件路径 -#elif CURRENT_AIAUDIO_TYPE == AIAUDIO_TYPE_SBC - std::string AIAIAudioPath = "/user/userdata/AiRecording/AIAudio.sbc"; // AI录音的文件路径 -#elif CURRENT_AIAUDIO_TYPE == AIAUDIO_TYPE_MSBC - std::string AIAIAudioPath = "/user/userdata/AiRecording/AIAudio.msbc"; // AI录音的文件路径 -#endif - std::string userQuestionStr; // 用户提出的问题 - std::string aiAnswerStr; // AI回答的问题 - std::string accumulatedText; // tts播放文本 - uint8_t ChatContentListCount{0}; // 列表数量 - static const uint16_t MaxChatContentListCount = MAX_CHAT_CONTENT_COUNT; // 对话列表最大数量 - ChatContentItem chatTtems[MaxChatContentListCount] = {0, "", false}; // 对话项数组 - bool entryTextViewState{false}; // 进入返回结果界面的标志 - std::map> selectAiModelToTextId; // pair的参数类型<模型的textid,查询模型是否可用id> - bool AiVoiceConnectStatus{false}; //与AI模型的连接状态 - uint8_t AIResponseType; - std::string errnote; //错误信息 - int16_t curView{0}; - bool isClickable{false}; - bool isLimitDisplayed{false};//AI答案是否显示到极限了 - - bool AI_4G_state{false}; //4g网络状态 - bool AI_BT_state{false}; //蓝牙连接状态 - bool init_4gai_task{false}; //4g服务器连接状态 - uint8_t select4gorbt{-1}; //0:4g 1:蓝牙 -1:未连接 - - bool isFirstReceive{true}; //静态变量标记是否是首次接收 - bool hasTtsStartSucceeded{false}; // uapi_start_tts 成功后置位,仅允许发送一次 - }; - -} - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h deleted file mode 100644 index c5ea62451..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceModelC.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef AI_VOICE_MODELC_H -#define AI_VOICE_MODELC_H - -#ifdef __cplusplus -#if __cplusplus -extern "C" -{ -#endif -#endif -#include - - uint8_t getselect4gorbtai(void); - void ble_AI_init(void); - void net4g_AI_init(void); - -#ifdef __cplusplus -#if __cplusplus -} -#endif -#endif -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoicePresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoicePresenter.h deleted file mode 100644 index f8125e03e..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoicePresenter.h +++ /dev/null @@ -1,81 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-20 14:44:22 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-02-18 14:32:12 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoicePresenter.h - */ -#ifndef AI_VOICE_PRESENTER_H -#define AI_VOICE_PRESENTER_H - -#include "key/include/KeyInputListener.h" -#include "Presenter.h" -#include "View.h" -#include "ui_resource_string.h" -#include "components/ui_time_picker.h" -#include "components/ui_slider.h" -#include "ModelListenerSample.h" -namespace OHOS -{ - class AiVoiceView; - class AiVoiceModel; - class AiVoicePresenter : public Presenter, - public UIView::OnClickListener, - public UIView::OnDragListener, - public RootView::OnKeyActListener, - public UIPicker::SelectedListener, - public UIView::OnRotateListener, - public UIView::OnTouchListener - // public ModelListenerSample - { - public: - typedef enum : uint8_t - { - AIMODES_WENXINYIYAN = 0, /*文心一言*/ - AIMODES_KIMI, /*KIMI*/ - AIMODES_DOUBAO, /*豆包*/ - AIMODES_TONGYI_QIANWEN, /*通义千问->DeepSeek*/ - AIMODES_IFLYTEK_SPARK, /*讯飞星火*/ - AIMODES_CHATGPT, /*chatgpt*/ - AIMODES_MAX_NUM, - } aimodels; - AiVoicePresenter(); - virtual ~AiVoicePresenter(); - static AiVoicePresenter *GetInstance(); - - void OnStart() override; - void OnStop() override; - void OnResume() override; - // void Notify() override; - void calculateChatContentItemViewHeight(std::string text, bool flag); - - bool JumpToReturnResultTextView(void); - bool ChangeToAIVoiceListeningView(bool val); - bool ChangeToAIVoiceConnectTimeoutView(); - bool ChangeViewAndLogicOperator(int16_t hideView, int16_t showView); - void FunctionKeyOnClickToChangeAIModel(void); - void DragLeftToRightChangeAIModel(void); - void DragRightToLetfChangeAIModel(void); - void ChangeVolume(UIView &view, const RotateEvent &event); - void JumpThinkingView(void); - - private: - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnPress(UIView& view, const PressEvent& event) override; - bool OnRelease(UIView &view, const ReleaseEvent &event) override; - 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) override; - bool OnRotate(UIView& view, const RotateEvent& event); - bool OnRotateEnd(UIView& view, const RotateEvent& event); - - AiVoiceModel *model; - bool X_DRAG_FLAG{false}; - - int preHeight{0}; - bool isScroll{false}; - }; -} - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceSelectView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceSelectView.h deleted file mode 100644 index a920a21cb..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceSelectView.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef AIVOICESELECTVIEW_H -#define AIVOICESELECTVIEW_H -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" - -namespace OHOS -{ - static constexpr const char *AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID = "aivoice_select_view_button4g_view_id"; // 选择界面4G连接按钮 - static constexpr const char *AIVOICE_SELECT_VIEW_BUTTONBT_VIEW_ID = "aivoice_select_view_buttonbt_view_id"; // 选择界面蓝牙连接按钮 - - class AiVoiceSelectView - { - public: - AiVoiceSelectView(); - ~AiVoiceSelectView(); - static AiVoiceSelectView *GetInstance(void); - UIScrollView *CreateAiVoiceSelectView(void); - - private: - void ClearAll(void); - UILabelExt *title{nullptr}; - UIScrollView *scrollView{nullptr}; - UILabelExt *label4g{nullptr}; - UILabelExt *labelbt{nullptr}; - UIButton *button4g{nullptr}; - UIButton *buttonbt{nullptr}; - }; -} - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceView.h deleted file mode 100644 index 48c5cb6b1..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceView.h +++ /dev/null @@ -1,196 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-08 09:36:01 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-02-18 14:48:55 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/AiVoiceView.h - */ -#ifndef AI_VOICE_VIEW_H -#define AI_VOICE_VIEW_H - - -#include "View.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" -#include "components/ui_scroll_view.h" -#include "components/ui_image_view.h" -#include "components/ui_picker.h" -#include "components/ui_slider.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 "aivoice/include/apikeys/SetApiKeysView.h" -#include "aivoice/include/apikeys/NotSetApiKeysView.h" -#include "aivoice/include/apikeys/ApiKeysDeleteView.h" -#include "aivoice/include/AiVoiceConnectingView.h" -#include "aivoice/include/AiVoiceSelectView.h" -#include "aivoice/include/Aivoice4gServiceConView.h" -#include "aivoice/include/AiVoiceVolumeView.h" -#include "ui_resource_string.h" -#include "iostream" -#include "string" -#include "map" -namespace OHOS -{ - /*图片路径*/ - 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 *AIMODEL_TONGYI_QIANWEN_PATH = "/user/res/AIVoice/aimodels/aimodes_tongyi_qianwen.bin"; /*通义千问*/ - static constexpr const char *AIMODEL_IFLYTEK_SPARK_PATH = "/user/res/AIVoice/aimodels/aimodes_iflytek_spark.bin"; /*讯飞星火*/ - static constexpr const char *AIMODEL_DEEPSEEK_PATH = "/user/res/AIVoice/aimodels/aimodes_deepseek.bin"; /*deepseek*/ - static constexpr const char *AIMODEL_LINGXI_PATH = "/user/res/AIVoice/aimodels/aimodels_lingxi.bin"; /*jiutian*/ - - /*组件ID*/ - 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 - { - AIVOICE_STARTCHAT_VIEWID = 0, // 开始对话界面 - AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, // APP蓝牙与4G网络都连接异常界面 - AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, // 模型连接失败弹窗界面 - AIVOICE_CONNECT_TIMEOUT_VIEWID, // 连接超时界面 - AIVOICE_LISTENING_VIEWID, // 聆听中界面 - AIVOICE_THINKING_VIEWID, // 思考中界面 - AIVOICE_RETURN_RESULT_TEXT_VIEWID, // 返回结果文本界面 - AIVOICE_SETAPIKEYS, // API Keys set界面 - AIVOICE_NOTSETAPIKEYS, // API Keys notset界面 - AIVOICE_APIKEYS_DELETE, // API Keys 删除界面 - AIVOICE_AIMODE_CONNECTING, // AI Mode正在连接视图 - AIVOICE_SELECT_VIEW, // AI选择界面 - AIVOICE_4GSERVICECON_VIEW, // AI4G连接中界面 - AIVOICE_VOLUME_VIEW, // AI音量界面 - MAX_AIVOICE_VIEWID, - } AIVOICEVIEWID; - - static std::map TextIdToImagePath = { - {STR_AIMODES_WENXINYIYAN, AIMODEL_WENXINYIYAN_PATH}, - {STR_AIMODES_KIMI, AIMODEL_KIMI_PATH}, - {STR_AIMODELS_DOUBAO, AIMODEL_DOUBAO_PATH}, - // {STR_TONGYI_QIANWEN, AIMODEL_TONGYI_QIANWEN_PATH}, - {STR_DEEPSEEK, AIMODEL_DEEPSEEK_PATH}, - {STR_IFLYTEK_SPARK, AIMODEL_IFLYTEK_SPARK_PATH}, - {STR_AIMODES_CHATGPT, AIMODEL_CHATGPT_ON_PATH}, - {STR_JIUTIAN, AIMODEL_LINGXI_PATH}, - }; - - class AiVoicePresenter; - class AiVoiceView : public View - { - - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - - struct ImageConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *src; - }; - - struct ButtonConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ViewId; - }; - - AiVoiceView(); - ~AiVoiceView(); - static AiVoiceView *GetInstance(void); - 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); - bool ChangeAiVoiceMobileDataFailedStartView(int16_t thisView); - bool ChangeAiVoicConnectTimeoutView(int16_t thisView); - bool ChangeAiVoicListeningView(int16_t thisView); - bool ChangeAiVoicThinkingView(int16_t thisView); - bool ChangeAiVoicReturnResultTextView(int16_t thisView); - bool ChangeAiVoicSetApiKeysView(int16_t thisView); - bool ChangeAiVoicNotSetApiKeysView(int16_t thisView); - bool ChangeAiVoicApiKeysDeleteView(int16_t thisView); - bool ChangeAiVoicConnectingView(int16_t thisView); - bool ChangeAiVoicSelectView(int16_t thisView); - bool ChangeAiVoic4gServiceConView(int16_t thisView); - bool ChangeAiVoicVolumeView(int16_t thisView); - - void SetAiVoiceViewAllComponentsVisibilityStatus(); - void ChangeAiModelAndUpdateComponentsStatus(void); - - void OnStart() override; - - - private: - AiVoiceBluetoothFailedStartView *p_AiVoiceBluetoothFailedStartView{nullptr}; - AivoiceMobileDataFailedStartView *p_AivoiceMobileDataFailedStartView{nullptr}; - AivoiceConnectTimeoutView *p_AivoiceConnectTimeoutView{nullptr}; - AivoiceListeningView *p_AivoiceListeningView{nullptr}; - AivoiceThinkingView *p_AivoiceThinkingView{nullptr}; - AivoiceReturnResultTextView *p_AivoiceReturnResultTextView{nullptr}; - SetApiKeysView *p_SetApiKeysView{nullptr}; - NotSetApiKeysView *p_NotSetApiKeysView{nullptr}; - ApiKeysDeleteView *p_ApiKeysDeleteView{nullptr}; - AiVoiceConnectingView *p_AiVoiceConnectingView{nullptr}; - AiVoiceSelectView *p_AiVoiceSelectView{nullptr}; - AiVoice4gServiceConView *p_Aivoice4gServiceConView{nullptr}; - AiVoiceVolumeView *p_AiVoiceVolumeView{nullptr}; - - private: - UILabelExt *AiVoiceViewLabelInit(LabelConfig &labelconfig); - UIImageView *AiVoiceViewImageView(ImageConfig &imageconfig); - UIButton *AiVoiceViewButtonInit(ButtonConfig &buttonconfig); - bool CreateAiVoiceViewLabel(void); - bool CreateAiVoiceViewImageView(void); - bool CreateAiVoiceViewButton(void); - bool CreateAiVoiceViewPicker(void); - bool CreateAiVoiceScrollView(void); - bool CreateAiVoiceVoiceView(void); - UIScrollView *CreateAiVoiceView(void); - void ClearAllAiVoiceScrollView(void); - void ClearAll(void); - void SetComponentVisibility(UIView *component, bool isVisible); - UIScrollView *scrollView{nullptr}; - UILabelExt *title{nullptr}; /*标题*/ - UILabelExt *startChatLabel{nullptr}; /*开始对话标签,暂时不用*/ - UIButton *startChatButton{nullptr}; /*开始对话按钮*/ - UILabelExt *chatLabel{nullptr}; /*对话标签,暂时不用*/ - UIButton *chatButton{nullptr}; /*对话按钮*/ - UIImageView *aiModelImage{nullptr}; /*ai模型图片*/ - UIImageView *buttonBgImage{nullptr}; /*按钮背景图片*/ - UIImageView *upImage{nullptr}; /*上拉箭头*/ - UILabelExt *apiKeysLabel{nullptr}; /*API Keys标签,暂时不用*/ - UIButton *apiKeysButton{nullptr}; /*API Keys按钮,,暂时不用*/ - UIPicker *aiModelPicker{nullptr}; /*ai模型选择器*/ - UIScrollView *AiVoiceScrollView[MAX_AIVOICE_VIEWID]{nullptr}; - /* ----------------------------------- 九天 ----------------------------------- */ - UISlider *VolumeProcess{nullptr}; - /* -------------------------------------------------------------------------- */ - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceVolumeView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceVolumeView.h deleted file mode 100644 index b52aa2ab7..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AiVoiceVolumeView.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef AIVOICEVOLUMEVIEW_H -#define AIVOICEVOLUMEVIEW_H - -#include "components/ui_scroll_view.h" -#include "soundandvibration/include/SoundAndVibrationVolumeSettingView.h" -namespace OHOS -{ - class AiVoiceVolumeView - { - public: - AiVoiceVolumeView(); - ~AiVoiceVolumeView(); - static AiVoiceVolumeView *GetInstance(void); - UIScrollView *CreateAiVoiceVolumeView(void); - void SetRequestFocus(); - - private: - void ClearAll(); - UIScrollView *SystemVolumeScrollView{nullptr}; - SoundAndVibrationVolumeSettingView *p_SoundAndVibrationVolumeSettingView{nullptr}; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/Aivoice4gServiceConView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/Aivoice4gServiceConView.h deleted file mode 100644 index 1e451dec9..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/Aivoice4gServiceConView.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef AIVOICE4GSERVICECONVIEW_H -#define AIVOICE4GSERVICECONVIEW_H -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" -#include "components/ui_image_animator.h" - -namespace OHOS -{ - class AiVoice4gServiceConView - { - public: - AiVoice4gServiceConView(); - ~AiVoice4gServiceConView(); - static AiVoice4gServiceConView *GetInstance(void); - UIScrollView *CreateAiVoice4gServiceConView(void); - void StartOrStopAiVoice4gServiceConImageAnimatorView(bool val); - - private: - void ClearAll(void); - UIScrollView *scrollView{nullptr}; - UILabelExt *label{nullptr}; - UIImageAnimatorView *AI4GImageAni{nullptr}; - ImageAnimatorInfo AI4GsearchImageInfo[8]; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceChatContentListAdapter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceChatContentListAdapter.h deleted file mode 100644 index f0fed0504..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceChatContentListAdapter.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-03-28 14:26:55 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-15 20:25:36 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/languagecode/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 "languagecode/LanguageInit.h" -#include "UiConfig.h" -#include -#include "aivoice/include/AivoiceChatContentListItemView.h" -#include "iostream" - -namespace OHOS -{ - - class AivoiceChatContentListAdapter : public AbstractAdapter - { - public: - AivoiceChatContentListAdapter(); - ~AivoiceChatContentListAdapter(); - - void SetData(std::list &data); - void ClearData(void); - std::list &GetChatContentItem(); - 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 listData; - UIView::OnClickListener *itemClickListener{nullptr}; - int itemViewHeight{0}; - bool aiAnswerFlag{false}; - }; - -} - -#endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceChatContentListItemView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceChatContentListItemView.h deleted file mode 100644 index bde48ec66..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceChatContentListItemView.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-29 17:26:19 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-26 15:21:21 - * @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 "components/ui_scroll_view.h" -#include "components/ui_image_view.h" -#include "View.h" -#include "iostream" -#include "ChatContentItem.h" -namespace OHOS -{ - class AivoiceChatContentListItemView : public UIViewGroup - { - public: - AivoiceChatContentListItemView(int viewHeight, bool isAiAnswerFalg); - ~AivoiceChatContentListItemView(); - void SetItemInfo(const ChatContentItem &itemInfo); - void SetUpChild(); - void ResetItemView(int viewHeight, bool isAiAnswerFlag); - - private: - UILabel chatContentLabel; - UILabel mindLabel; - UIImageView chatContentImage; - UIScrollView chatContentScrollView; - int m_viewHeight; - bool m_isAiAnswerFalg{false}; - }; -} - -#endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceConnectTimeoutView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceConnectTimeoutView.h deleted file mode 100644 index 187c2a579..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceConnectTimeoutView.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-22 16:46:26 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-08-31 16:14:01 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceConnectTimeoutView.h - */ - -#ifndef AIVOICE_CONNECT_TIMEOUT_VIEW_H -#define AIVOICE_CONNECT_TIMEOUT_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" -#include "components/ui_image_view.h" - -namespace OHOS -{ - static constexpr const char *AIVOICECONNECTTIMEOUT_ENSURE_BUTTON_VIEW_ID = "AivoiceConnectTimeoutEnsureButton"; // 连接超时界面确定按钮 - - class AivoiceConnectTimeoutView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - struct ButtonConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ViewId; - }; - - struct ImageConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - }; - - AivoiceConnectTimeoutView(); - ~AivoiceConnectTimeoutView(); - static AivoiceConnectTimeoutView *GetInstance(void); - UIScrollView *CreateAivoiceConnectTimeoutView(void); - void UpdateTitleTextId(int textId); - void UpdateNoteText(); - private: - void ClearAll(void); - UILabelExt *AivoiceConnectTimeoutLabelInit(LabelConfig &labelconfig); - UIButton *AivoiceConnectTimeoutButtonInit(ButtonConfig &buttonconfig); - UIImageView *AivoiceConnectTimeoutImageInit(ImageConfig &imageconfig); - bool CreateAivoiceConnectTimeoutLabel(void); - bool CreateAivoiceConnectTimeoutButton(void); - bool CreateAivoiceConnectTimeoutImage(void); - bool CreateAivoiceConnectTimeoutScrollView(void); - UIScrollView *scrollView{nullptr}; - UILabelExt *title{nullptr}; - UIImageView *attentionImage{nullptr}; - UILabelExt *NoteLabel{nullptr}; - UILabelExt *ensure{nullptr}; - UIButton *ensureButton{nullptr}; - }; -} -#endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceListeningView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceListeningView.h deleted file mode 100644 index c620e77a4..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceListeningView.h +++ /dev/null @@ -1,94 +0,0 @@ -/*** - * @Date: 2024-06-26 16:59:51 - * @LastEditors: Caisking 3449750381@qq.com - * @LastEditTime: 2024-08-30 18:57:36 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h - */ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-22 16:46:26 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-25 20:34:17 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceListeningView.h - */ - -#ifndef AIVOICE_LISTENING_VIEW_H -#define AIVOICE_LISTENING_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" -#include "components/ui_image_view.h" -#include "components/ui_image_animator.h" -namespace OHOS -{ - static constexpr const char *FINISH_SPEAKING_BUTTON_VIEW_ID = "FinishSpeakingButton"; // 聆听中界面说话完毕按钮 - - static constexpr int16_t AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_X = 113; - static constexpr int16_t AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_Y = 178; - static constexpr int16_t AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_W = 240; - static constexpr int16_t AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_H = 60; - static constexpr int16_t AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 40; // 图片帧数 - static constexpr int16_t AIVOICE_LISTENING_IMAGE_ANIMATOR_DELAY = 70; // 图片更新间隔 - static constexpr char *AIVoiceListeningImagePaths = "/user/res/AIVoice/AIVoiceListening/"; - class AivoiceListeningView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - struct ButtonConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ViewId; - }; - - struct ImageAnimatorConfig - { - int16_t x; - int16_t y; - int16_t width; - int16_t height; - ImageAnimatorInfo *imageInfoArray; - const ImageInfo **pathsArray; - uint8_t numFrames; - int delay; - }; - - AivoiceListeningView(); - ~AivoiceListeningView(); - static AivoiceListeningView *GetInstance(void); - UIScrollView *CreateAivoiceListeningView(void); - UILabelExt *GetShowtimeoutLabel(void); - void StartOrStopAivoiceListeningImageAnimatorView(bool val); - - private: - void ClearAll(void); - UILabelExt *AivoiceListeningLabelInit(LabelConfig &labelconfig); - UIButton *AivoiceListeningButtonInit(ButtonConfig &buttonconfig); - UIImageAnimatorView *AivoiceListeningImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig); - bool CreateAivoiceListeningLabel(void); - bool CreateAivoiceListeningButton(void); - bool CreateAivoiceListeningImageAnimator(void); - bool CreateAivoiceListeningScrollView(void); - UIScrollView *scrollView{nullptr}; - UILabelExt *title{nullptr}; - UILabelExt *finishSpeak{nullptr}; - UIButton *finishSpeakButton{nullptr}; - UIImageAnimatorView *AiVoiceListeningImageAnimatorView{nullptr}; - ImageAnimatorInfo AiVoiceListeningImageInfo[AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; - UILabelExt *showtimeout{nullptr}; - }; -} -#endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h deleted file mode 100644 index 442903d1b..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-22 15:22:56 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-31 15:08:31 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceMobileDataFailedStartView.h - */ - -#ifndef AIVOICE_MOBILEDATA_FAILEDSTART_VIEW_H -#define AIVOICE_MOBILEDATA_FAILEDSTART_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" -#include "components/ui_image_view.h" - -namespace OHOS -{ - static constexpr const char *AIMODEL_CONNECT_FAILED_ENSURE_BUTTON_VIEW_ID = "AimodelConnectFailedEnsureButton_"; // 模型连接失败弹窗界面的确定按钮 - - class AivoiceMobileDataFailedStartView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - struct ButtonConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ViewId; - }; - - struct ImageConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - }; - - AivoiceMobileDataFailedStartView(); - ~AivoiceMobileDataFailedStartView(); - static AivoiceMobileDataFailedStartView *GetInstance(void); - UIScrollView *CreateAivoiceMobileDataFailedStartView(void); - void UpdateTitleTextId(int textId); - - private: - void ClearAll(void); - UILabelExt *AivoiceMobileDataFailedStartLabelInit(LabelConfig &labelconfig); - UIButton *AivoiceMobileDataFailedStartButtonInit(ButtonConfig &buttonconfig); - UIImageView *AivoiceMobileDataFailedStartImageInit(ImageConfig &imageconfig); - bool CreateAivoiceMobileDataFailedStartLabel(void); - bool CreateAivoiceMobileDataFailedStartButton(void); - bool CreateAivoiceMobileDataFailedStartImage(void); - bool CreateAivoiceMobileDataFailedStartScrollView(void); - UIScrollView *scrollView{nullptr}; - UILabelExt *title{nullptr}; - UIImageView *attentionImage{nullptr}; - UILabelExt *label[2]{nullptr}; - UILabelExt *ensure{nullptr}; - UIButton *ensureButton{nullptr}; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceReturnResultTextView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceReturnResultTextView.h deleted file mode 100644 index f3d8408f6..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceReturnResultTextView.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-22 16:46:26 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-07 09:26:23 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceReturnResultTextView.h - */ - -#ifndef AIVOICE_RETURN_RESULT_TEXT_VIEW_H -#define AIVOICE_RETURN_RESULT_TEXT_VIEW_H - -#include "components/ui_scroll_view.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"; // 返回对话内容界面的返回按钮 - static constexpr const char *AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID = "AivoiceReturnResultTextContinueChatButton"; // 返回对话内容界面的继续对话按钮 - - class AivoiceReturnResultTextView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeight; - uint16_t textId; - uint8_t lineBreakMode; - }; - struct ButtonConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ViewId; - }; - struct ImageConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *src; - }; - - AivoiceReturnResultTextView(); - ~AivoiceReturnResultTextView(); - static AivoiceReturnResultTextView *GetInstance(void); - UIScrollView *CreateAivoiceReturnResultTextView(void); - void AddChatContentToList(const ChatContentItem &item); - AivoiceChatContentListAdapter *GetAivoiceChatContentListAdapter(void); - UIList *GetChatContentList(void); - void UpdateTitleTextId(int textId); - void IsScrollChatContentList(bool isScroll); - void SetRequestFocus(); - - private: - void ClearAll(void); - UILabelExt *AivoiceReturnResultTextLabelInit(LabelConfig &labelconfig); - UIButton *AivoiceReturnResultTextButtonInit(ButtonConfig &buttonconfig); - UIImageView *AivoiceReturnResultTextImageInit(ImageConfig &imageconfig); - bool CreateAivoiceReturnResultTextLabel(void); - bool CreateAivoiceReturnResultTextList(void); - bool CreateAivoiceReturnResultTextButton(void); - bool CreateAivoiceReturnResultTextScrollView(void); - UIScrollView *scrollView{nullptr}; - UILabelExt *title{nullptr}; - - UIButton *returnButton{nullptr}; - - UIButton *continueChatButton{nullptr}; - UILabelExt *continueChat{nullptr}; - - AivoiceChatContentListAdapter *chatContentListAdapter{nullptr}; - UIList *chatContentList{nullptr}; - }; -} -#endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceThinkingView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceThinkingView.h deleted file mode 100644 index 9bfdd7815..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/AivoiceThinkingView.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-22 16:46:26 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-06 18:02:48 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AivoiceThinkingView.h - */ - -#ifndef AIVOICE_THINKING_VIEW_H -#define AIVOICE_THINKING_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" -#include "components/ui_image_view.h" -#include "components/ui_image_animator.h" -namespace OHOS -{ - static constexpr const char *CANCEL_THINKING_BUTTON_VIEW_ID = "CancelThinkingButton"; // 思考中界面取消按钮 - - static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_X = 153; - static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_Y = 136; - static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_W = 160; - static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_H = 160; - static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES = 40; // 图片帧数 - static constexpr int16_t AIVOICE_THINKING_IMAGE_ANIMATOR_DELAY = 70; // 图片更新间隔 - static constexpr const char *AIVoiceThinkingImagePaths = "/user/res/AIVoice/AIVoiceThinking/"; - class AivoiceThinkingView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - struct ButtonConfig - { - int16_t x; - int16_t y; - int16_t w; - int16_t h; - const char *ViewId; - }; - - struct ImageAnimatorConfig - { - int16_t x; - int16_t y; - int16_t width; - int16_t height; - ImageAnimatorInfo *imageInfoArray; - const ImageInfo **pathsArray; - uint8_t numFrames; - int delay; - }; - - AivoiceThinkingView(); - ~AivoiceThinkingView(); - static AivoiceThinkingView *GetInstance(void); - UIScrollView *CreateAivoiceThinkingView(void); - void StartOrStopAiVoiceThinkingImageAnimatorView(bool val); - - private: - void ClearAll(void); - UILabelExt *AivoiceThinkingLabelInit(LabelConfig &labelconfig); - UIButton *AivoiceThinkingButtonInit(ButtonConfig &buttonconfig); - UIImageAnimatorView *AivoiceThinkingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig); - bool CreateAivoiceThinkingLabel(void); - bool CreateAivoiceThinkingButton(void); - bool CreateAivoiceThinkingImageAnimator(void); - bool CreateAivoiceThinkingScrollView(void); - UIScrollView *scrollView{nullptr}; - UILabelExt *title{nullptr}; - UILabelExt *cancelThink{nullptr}; - UIButton *cancelThinkButton{nullptr}; - UIImageAnimatorView *AiVoiceThinkingImageAnimatorView{nullptr}; - ImageAnimatorInfo AiVoiceThinkingImageInfo[AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES]; - }; -} -#endif diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/ChatContentItem.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/ChatContentItem.h deleted file mode 100644 index 9222a2d60..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/ChatContentItem.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-02 09:46:24 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-02 09:48:05 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/ChatContentItem.h - */ -#ifndef CHAT_CONTENT_ITEM_H -#define CHAT_CONTENT_ITEM_H - -#include -#include "string" -namespace OHOS -{ - typedef struct - { - int index; - std::string text; - bool isAiAnswer; - } ChatContentItem; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/ApiKeysDeleteView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/ApiKeysDeleteView.h deleted file mode 100644 index 38aa04b91..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/ApiKeysDeleteView.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:01:34 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 15:10:06 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/apikeys/ApiKeysDeleteView.h - */ - -#ifndef APIKEYS_DELETE_VIEW_H -#define APIKEYS_DELETE_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" - -namespace OHOS -{ - static constexpr const char *APIKEYS_DELETE_BUTTON_VIEWID = "apikeys_delete_button_viewid"; /*删除APIKeys*/ - static constexpr const char *APIKEYS_CANCEL_DELETE_BUTTON_VIEWID = "apikeys_cancel_delete_button_viewid"; /*取消删除APIkeys*/ - static constexpr const char *APIKEYS_DELETE_SCROLLVIEW_VIEWID = "apikeys_delete_scrollview_viewid"; - - class ApiKeysDeleteView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - - ApiKeysDeleteView(); - ~ApiKeysDeleteView(); - UIScrollView *CreateApiKeysDeleteView(void); - - private: - UILabelExt *ApiKeysDeleteViewLabelInit(LabelConfig &labelconfig); - bool CreateApiKeysDeleteViewLabel(void); - void ClearAll(void); - UIScrollView *ApiKeysDeleteScrollView{nullptr}; - UILabelExt *ApiKeysDeleteTitleLabel{nullptr}; - UILabelExt *ApiKeysDeleteNoteLabel{nullptr}; - UIButton *ApiKeysDeleteButton{nullptr}; - UIButton *ApiKeysCancelDeleteButton{nullptr}; - UIView::OnClickListener *clickListener{nullptr}; - UIView::OnDragListener *dragListener{nullptr}; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/ApiKeysPresenter.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/ApiKeysPresenter.h deleted file mode 100644 index e5b7e65bc..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/ApiKeysPresenter.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:14:05 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-29 16:24:29 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/apikeys/ApiKeysPresenter.h - */ - -#ifndef AI_MODELS_PRESENTER_H -#define AI_MODELS_PRESENTER_H - -#include "View.h" -namespace OHOS -{ - class ApiKeysPresenter : public UIView::OnClickListener, - public UIView::OnDragListener - { - public: - ApiKeysPresenter(); - virtual ~ApiKeysPresenter(); - static ApiKeysPresenter *GetInstance(); - - private: - bool OnClick(UIView &view, const ClickEvent &event) override; - bool OnDrag(UIView &view, const DragEvent &event) override; - bool OnDragEnd(UIView &view, const DragEvent &event) override; - - bool X_DRAG_FLAG{false}; - }; -} - -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/NotSetApiKeysView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/NotSetApiKeysView.h deleted file mode 100644 index 3410e4b5c..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/NotSetApiKeysView.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:00:52 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 09:53:04 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/apikeys/NotNotSetApiKeysView.h - */ - -#ifndef NOT_SET_APIKEYS_VIEW_H -#define NOT_SET_APIKEYS_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_button.h" - -namespace OHOS -{ - static constexpr const char *NOTSETAPIKEYS_ENSURE_BUTTON_VIEWID = "notsetapikeys_ensure_button_viewid"; - static constexpr const char *NOTSETAPIKEYS_SCROLLVIEW_VIEWID = "notsetapikeys_scrollview_viewid"; - - class NotSetApiKeysView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - - NotSetApiKeysView(); - ~NotSetApiKeysView(); - UIScrollView *CreateNotSetApiKeysView(void); - - private: - UILabelExt *NotSetApiKeysViewLabelInit(LabelConfig &labelconfig); - bool CreateNotSetApiKeysViewLabel(void); - void ClearAll(void); - UIScrollView *NotSetApiKeysScrollView{nullptr}; - UILabelExt *NotSetApiKeysTitleLabel{nullptr}; - UILabelExt *NotSetApiKeysNoteLabel[3]{nullptr}; - UILabelExt *NotSetApiKeysEnsureLabel{nullptr}; - UIButton *NotSetApiKeysEnsureButton{nullptr}; - UIView::OnClickListener *clickListener{nullptr}; - UIView::OnDragListener *dragListener{nullptr}; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/SetApiKeysView.h b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/SetApiKeysView.h deleted file mode 100644 index 96da534c8..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/include/apikeys/SetApiKeysView.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:00:31 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-29 18:22:38 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/apikeys/SetApiKeysView.h - */ - -#ifndef SET_APIKEYS_VIEW_H -#define SET_APIKEYS_VIEW_H - -#include "components/ui_scroll_view.h" -#include "components/ui_label_ext.h" -#include "components/ui_image_view.h" -#include "components/ui_button.h" - -namespace OHOS -{ - static constexpr const char *SETAPIKEYS_DELETE_BUTTON_VIEWID = "setapikeys_delete_button_viewid"; - static constexpr const char *SETAPIKEYS_SCROLLVIEW_VIEWID = "setapikeys_scrollview_viewid"; - - static constexpr const char *SETAPIKEYS_IMAGE_PATH = "/user/res/AIVoice/apikey.bin"; - class SetApiKeysView - { - public: - struct LabelConfig - { - int16_t left; - int16_t top; - int16_t width; - int16_t height; - int16_t fontSize; - int16_t lineHeigh; - uint16_t textId; - uint8_t lineBreakMode; - }; - - SetApiKeysView(); - ~SetApiKeysView(); - UIScrollView *CreateSetApiKeysView(void); - - private: - UILabelExt *SetApiKeysViewLabelInit(LabelConfig &labelconfig); - bool CreateSetApiKeysViewLabel(void); - void ClearAll(void); - UIScrollView *SetApiKeysScrollView{nullptr}; - UILabelExt *SetApiKeysTitleLabel{nullptr}; - UIImageView *SetApiKeysImage{nullptr}; - UILabelExt *SetApiKeysNoteLabel[2]{nullptr}; - UILabelExt *SetApiKeysDeleteLabel{nullptr}; - UIButton *SetApiKeysDeleteButton{nullptr}; - UIView::OnClickListener *clickListener{nullptr}; - UIView::OnDragListener *dragListener{nullptr}; - }; -} -#endif \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp deleted file mode 100644 index 1094f3238..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceBluetoothFailedStartView.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-05-07 11:25:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-03 15:10:17 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceBluetoothFailedStartView.cpp - */ -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AiVoiceModel.h" -#include "aivoice/include/AiVoiceBluetoothFailedStartView.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -#include -#include "ConfigModel.h" -namespace OHOS -{ - - static AiVoiceBluetoothFailedStartView *g_pAiVoiceBluetoothFailedStartView{nullptr}; - - AiVoiceBluetoothFailedStartView::AiVoiceBluetoothFailedStartView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::AiVoiceBluetoothFailedStartView"); - g_pAiVoiceBluetoothFailedStartView = this; - } - - AiVoiceBluetoothFailedStartView::~AiVoiceBluetoothFailedStartView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::~AiVoiceBluetoothFailedStartView"); - ClearAll(); - g_pAiVoiceBluetoothFailedStartView = nullptr; - } - - AiVoiceBluetoothFailedStartView *AiVoiceBluetoothFailedStartView::GetInstance() - { - return g_pAiVoiceBluetoothFailedStartView; - } - - void AiVoiceBluetoothFailedStartView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::ClearAll"); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - - if (title != nullptr) - { - delete title; - title = nullptr; - } - - if (attentionImage != nullptr) - { - delete attentionImage; - attentionImage = nullptr; - } - - for (int i = 0; i < (sizeof(label) / sizeof(label[0])); i++) - { - if (label[i] != nullptr) - { - delete label[i]; - label[i]; - } - } - - if (ensure != nullptr) - { - delete ensure; - ensure = nullptr; - } - - if (ensureButton != nullptr) - { - delete ensureButton; - ensureButton = nullptr; - } - - delete scrollView; - scrollView = nullptr; - } - } - - UILabelExt *AiVoiceBluetoothFailedStartView::AiVoiceBluetoothFailedStartLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetRollSpeed(23); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - UIButton *AiVoiceBluetoothFailedStartView::AiVoiceBluetoothFailedStartButtonInit(ButtonConfig &buttonconfig) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - - return button; - } - - UIImageView *AiVoiceBluetoothFailedStartView::AiVoiceBluetoothFailedStartImageInit(ImageConfig &imageconfig) - { - UIImageView *Image = new UIImageView(); - if (Image == nullptr) - { - return nullptr; - } - Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); - return Image; - } - - bool AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartScrollView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartScrollView"); - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::scrollView new fail!"); - return false; - } - scrollView->SetPosition(0, 0, 466, 466); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::dragListener new fail!"); - return false; - } - scrollView->SetOnDragListener(dragListener); - return true; - } - - bool AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartLabel"); - LabelConfig labelconfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = AiVoiceModel::GetInstance().GetAiModelTextId(), - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - title = AiVoiceBluetoothFailedStartLabelInit(labelconfig); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::title is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - labelconfig.left = 53; - labelconfig.width = 360; - int textId[] = {STR_BOOT_FAILED, STR_PCY4GC_OR_AS}; /*启动失败,请检查4G或打开APP连接*/ - for (int i = 0; i < sizeof(textId) / sizeof(textId[0]); i++) - { - labelconfig.top = 222 + i * 35; - labelconfig.textId = textId[i]; - label[i] = AiVoiceBluetoothFailedStartLabelInit(labelconfig); - if (label[i] == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::label[%d] is nullptr!", i); - return false; - } - } - /* -------------------------------------------------------------------------- */ - labelconfig = { - .left = 133, - .top = 368, - .width = 200, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_OK, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - ensure = AiVoiceBluetoothFailedStartLabelInit(labelconfig); - if (ensure == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::ensure is nullptr!"); - return false; - } - - return true; - } - - bool AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartButton"); - ButtonConfig buttonconfig = { - .x = 93, - .y = 340, - .w = 280, - .h = 90, - .ViewId = ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID, - }; - ensureButton = AiVoiceBluetoothFailedStartButtonInit(buttonconfig); - if (ensureButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ensureButton new fail!"); - return false; - } - UIView::OnTouchListener *onReleaseListener = static_cast(AiVoicePresenter::GetInstance()); - if (onReleaseListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::draglistener can not be nullptr!"); - return false; - } - ensureButton->SetOnTouchListener(onReleaseListener); - - return true; - } - - bool AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartImage(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartImage"); - ImageConfig imageconfig = { - .x = 193, - .y = 120, - .w = 80, - .h = 80, - }; - attentionImage = AiVoiceBluetoothFailedStartImageInit(imageconfig); - if (attentionImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "attentionImage new fail!"); - return false; - } - attentionImage->SetStyle(STYLE_BORDER_RADIUS, 100); - attentionImage->SetSrc(PNG_ATTENTION_IMAGE); - - return true; - } - - UIScrollView *AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartView"); - if (scrollView == nullptr) - { - if (!CreateAiVoiceBluetoothFailedStartScrollView() || !CreateAiVoiceBluetoothFailedStartLabel() || - !CreateAiVoiceBluetoothFailedStartButton() || !CreateAiVoiceBluetoothFailedStartImage()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceBluetoothFailedStartView::CreateAiVoiceBluetoothFailedStartView fail!!"); - return nullptr; - } - scrollView->Add(title); - scrollView->Add(attentionImage); - scrollView->Add(label[0]); - scrollView->Add(label[1]); - scrollView->Add(ensureButton); - scrollView->Add(ensure); - } - return scrollView; - } - - void AiVoiceBluetoothFailedStartView::UpdateTitleTextId(int textId) - { - if (title) - { - title->SetTextId(textId); - title->ForceResetText(); - } - } - -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceConnectingView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceConnectingView.cpp index 45f140192..86ad721b1 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceConnectingView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceConnectingView.cpp @@ -6,7 +6,6 @@ * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceConnectingView.cpp */ #include "aivoice/include/AiVoiceConnectingView.h" -#include "aivoice/include/AiVoicePresenter.h" #include "wearable_log.h" #include "ui_resource_string.h" #include "common/image_cache_manager.h" @@ -253,36 +252,6 @@ namespace OHOS return true; } - bool AiVoiceConnectingView::CreateAiVoiceConnectingViewButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewButton"); - ButtonConfig buttonconfig = { - .x = 93, - .y = 340, - .w = 280, - .h = 90, - .viewId = AIVOICECONNECTINGVIEW_CANCEL_BUTTON_VIEW_ID, - }; - if (cancelButton == nullptr) - { - cancelButton = AiVoiceConnectingViewButtonInit(buttonconfig); - if (cancelButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cancelButton new fail!"); - return false; - } - } - UIView::OnTouchListener *touchListener = static_cast(AiVoicePresenter::GetInstance()); - if (touchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::touchListener can not be nullptr!"); - return false; - } - cancelButton->SetOnTouchListener(touchListener); - - return true; - } - bool AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator(void) { WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator"); @@ -338,13 +307,7 @@ namespace OHOS return false; } } - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::dragListener new fail!"); - return false; - } - scrollView->SetOnDragListener(dragListener); + scrollView->SetPosition(0, 0, 466, 466); scrollView->SetTouchable(true); scrollView->SetDraggable(true); @@ -371,65 +334,6 @@ namespace OHOS return true; } - UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingView"); -#if 0 - 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); - - return scrollView; -#else - if (!CreateAiVoiceConnectingScrollView()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingScrollView fail!!"); - } - if (!CreateAivoiceConnectingImageAnimator()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAivoiceConnectingImageAnimator fail!!"); - } - if (!CreateAiVoiceConnectingViewLabel()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewLabel fail!!"); - } - if (!CreateAiVoiceConnectingViewButton()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceConnectingView::CreateAiVoiceConnectingViewButton fail!!"); - } - -#endif - if (scrollView == nullptr) - { - return nullptr; - } - else - { - if (title) - { - scrollView->Add(title); - } - if (connectingAnimatorView) - { - scrollView->Add(connectingAnimatorView); - } - if (cancelButton) - { - scrollView->Add(cancelButton); - } - if (cancelLabel) - { - scrollView->Add(cancelLabel); - } - return scrollView; - } - } UIScrollView *AiVoiceConnectingView::CreateAiVoiceConnectingView(uint8_t type) { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp deleted file mode 100644 index cdfc8d787..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceModel.cpp +++ /dev/null @@ -1,2234 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-20 15:14:50 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-19 11:09:58 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp - */ -#include "aivoice/include/AiVoiceModel.h" -#include "aivoice/include/AiVoiceModelC.h" -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AiVoiceView.h" -#include "aivoice/include/AivoiceReturnResultTextView.h" -#include "wearable_log.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include "uiservice/include/ui_service.h" -#include -#ifdef SUPPORT_BLE_SERVICE -#include -#include "bleService.h" -#endif -#include -#include "ConfigModel.h" -#include "settings/include/SettingModel.h" -#include -#include -#include -#include "custom_runtime.h" -#include "voice_call_volte_sample_wrapper.h" -#include -#include "websocket_server_manager.h" -#include "font/ui_font.h" - -namespace OHOS -{ - AiVoiceModel::AiVoiceModel() - { - CreateDirectory("/user/userdata/AiRecording/"); - } - - AiVoiceModel::~AiVoiceModel() {} - - AiVoiceModel &AiVoiceModel::GetInstance() - { - static AiVoiceModel instance; - return instance; - } - - bool AiVoiceModel::CreateDirectory(const char *path) - { - if (access(path, F_OK) == -1) - { // 如果路径不存在 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Directory %s not exist, creating directory\n", path); - if (mkdir(path, 0777) != 0) - { // 尝试创建目录,如果创建失败 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Create directory %s failed\n", path); - return false; - } - } - else - { // 如果路径存在 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Directory %s already exists\n", path); - } - return true; - } - - // 跳转到返回结果界面 - bool AiVoiceModel::ChangeToReturnResultTextView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ChangeToReturnResultTextView"); - AiVoicePresenter *Aipresenter_ = AiVoicePresenter::GetInstance(); - if (Aipresenter_ == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ChangeToReturnResultTextView fail!!"); - return false; - } - Aipresenter_->JumpToReturnResultTextView(); - entryTextViewState = false; - return true; - } - - /*跳转到AI聆听界面界面*/ - bool AiVoiceModel::ChangeToAIVoiceListeningView(bool value) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ChangeToAIVoiceListeningView"); - AiVoicePresenter *Aipresenter_ = AiVoicePresenter::GetInstance(); - if (Aipresenter_ == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ChangeToAIVoiceListeningView fail!!"); - return false; - } - Aipresenter_->ChangeToAIVoiceListeningView(value); - return true; - } - - // 切换到AI回应错误界面 - bool AiVoiceModel::ChangeToAIVoiceConnectTimeoutView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ChangeToAIVoiceConnectTimeoutView"); - AiVoicePresenter *Aipresenter_ = AiVoicePresenter::GetInstance(); - if (Aipresenter_ == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::GetInstance() fail!!"); - return false; - } - Aipresenter_->ChangeToAIVoiceConnectTimeoutView(); - return true; - } - - // 功能键切换模型 - void AiVoiceModel::FunctionKeyOnClickToChangeAIModel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::FunctionKeyOnClickToChangeAIModel"); - AiVoicePresenter *Aipresenter_ = AiVoicePresenter::GetInstance(); - if (Aipresenter_ == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::FunctionKeyOnClickToChangeAIModel fail!!"); - return; - } - Aipresenter_->FunctionKeyOnClickToChangeAIModel(); - return; - } - - /*获取API Keys是否可用*/ - bool AiVoiceModel::IsExistOpenAIAPIKeys() - { - bool flag; - if (ConfigModel::GetInstance()->GetOpenAIAPIKeys() == "-1") - { - flag = false; - } - else - { - flag = true; - } - return flag; - } - - /*删除本地的API Keys*/ - void AiVoiceModel::DeleteLocalOpenAIAPIKeys() - { - ConfigModel::GetInstance()->SetOpenAIAPIKeys("-1"); - } - - // 获取APP蓝牙是否已连接 - bool AiVoiceModel::GetAPPBluetoothIsConnect(void) - { -#ifdef SUPPORT_BLE_SERVICE - return get_ble_connect(); -#else - return false; -#endif - } - - // 获取4G网络是否正常 - bool AiVoiceModel::GetMobileDataIsOpen(void) - { - if (uapi_dev_runtime_get_cat1_networkstat() == 1) - { - return true; - } - return false; - } - - /*查询用户选择的AI模型是否已经连接*/ - void AiVoiceModel::QuerySelectedAiModelIsConnect() - { - auto it = selectAiModelToTextId.find(GetSelectAiModel()); - if (it != selectAiModelToTextId.end()) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "[QuerySelectedAiModelIsConnect] SelectAiModel = %d", it->second.second); - if (GetSelect4gorbt() == AI_SELECT_4G) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G"); - if (GetInit_4gai_task()) - { -#ifdef SUPPORT_AI_SERVICE - uapi_start_AI_asr(); -#endif - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "init_4gai_task fail!!"); - } - } - else if (GetSelect4gorbt() == AI_SELECT_BT) - { -#ifdef SUPPORT_BLE_SERVICE - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "蓝牙:查询Ai是否就绪:%d",it->second.second); - inquire_AI_is_ready(it->second.second); -#endif - } - } - } - - // 获取当前正在使用的AI模型 - uint8_t AiVoiceModel::GetCurUsingAiModelType(void) - { - auto it = selectAiModelToTextId.find(GetSelectAiModel()); - if (it != selectAiModelToTextId.end()) - { - return it->second.second; - } - return 0; - } - - uint8_t AiVoiceModel::GetCurUsing4GAiModelType(void) - { -#if AI_VOICE_ENABLE - int value = GetSelectAiModel(); - std::map> selectAiModelToAiModelType = { - {0, {STR_DEEPSEEK, AI_TYPE_DE}}, - {1, {STR_JIUTIAN, AI_TYPE_JIU}}, - {2, {STR_AIMODELS_DOUBAO, AI_TYPE_DOU}}, - {3, {STR_AIMODES_WENXINYIYAN, AI_TYPE_WEN}}, - {4, {STR_AIMODES_KIMI, AI_TYPE_KIMI}}, - {5, {STR_AIMODES_CHATGPT, AI_TYPE_0}}, - }; - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetCurUsing4GAiModelType = %d", selectAiModelToAiModelType[value].second); - return selectAiModelToAiModelType[value].second; -#endif - return 0; - } - - /*取消当前AI对话*/ - void AiVoiceModel::CancelCurAIChat(void) - { -// cancel_AI_cur_chat(); //线程发送取消当前对话 -#ifdef SUPPORT_BLE_SERVICE - cancel_AI_cur_chat_(); // 直接发送取消当前对话 -#endif - } - - int AiVoiceModel::GetAIResponseType(void) - { - return AIResponseType; - } - - std::string AiVoiceModel::GetErrnote(void) - { - return errnote; - } - - void AiVoiceModel::SetErrnote(std::string str) - { - errnote = str; - } - - /*设置当前哪个子视图是可见的*/ - void AiVoiceModel::SetCurView(int16_t viewNum) - { - curView = viewNum; - } - - /*获取当前哪个子视图是可见的*/ - int AiVoiceModel::GetCurView(void) - { - return curView; - } - - /*列表数量*/ - uint8_t AiVoiceModel::GetChatContentListCount(void) - { - return ChatContentListCount; - } - - void AiVoiceModel::SetChatContentListCount(uint8_t count) - { - ChatContentListCount = count; - } - - /*添加聊天内容项到数组*/ - bool AiVoiceModel::AddChatContentToItemArray(const ChatContentItem &item) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ChatContentListCount = %d", ChatContentListCount); - // 检查 ChatContentListCount 是否超出范围 - if (ChatContentListCount >= MaxChatContentListCount) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ChatContentListCount out of bounds!!"); - return false; - } - - chatTtems[ChatContentListCount] = item; - ChatContentListCount++; - - return true; - } - - /*添加用户问题项*/ - bool AiVoiceModel::AddUserQuestionToChatItems() - { - ChatContentItem UserQuestionStrItem; - UserQuestionStrItem.index = GetChatContentListCount(); - UserQuestionStrItem.text = GetUserQuestionStr(); - UserQuestionStrItem.isAiAnswer = false; - return AddChatContentToItemArray(UserQuestionStrItem); - } - - /*添加AI回答项*/ - bool AiVoiceModel::AddAiAnswerToChatItems() - { - ChatContentItem AiAnswerStrItem; - AiAnswerStrItem.index = GetChatContentListCount(); - AiAnswerStrItem.text = GetAiAnswerStr(); - AiAnswerStrItem.isAiAnswer = true; - return AddChatContentToItemArray(AiAnswerStrItem); - } - - /*初始化历史对话数据*/ - bool 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 false; - } - - // 添加用户问题项到数组 - if (!AddUserQuestionToChatItems()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!"); - return false; - } - - // 添加AI回答项到数组 - if (!AddAiAnswerToChatItems()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddAiAnswerToChatItems fail!!"); - return false; - } - - // 将聊天内容添加到显示列表中 - for (uint8_t i = 0; i < ChatContentListCount; i++) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chatTtems[%d]", i); - p_AivoiceReturnResultTextView->AddChatContentToList(chatTtems[i]); - } - - // 更新显示列表 - auto chatContentListAdapter = p_AivoiceReturnResultTextView->GetAivoiceChatContentListAdapter(); - auto chatContentList = p_AivoiceReturnResultTextView->GetChatContentList(); - if (chatContentListAdapter != nullptr && chatContentList != nullptr) - { - chatContentList->SetAdapter(chatContentListAdapter); - // chatContentList->RefreshList(); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Chat content list or adapter is nullptr!!"); - return false; - } - - return true; - } - - // 函数定义:移除列表的最后两项或清空列表 - bool AiVoiceModel::RemoveLastTwoItemsOrClear() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::RemoveLastTwoItemsOrClear"); - AivoiceReturnResultTextView *p_AivoiceReturnResultTextView = AivoiceReturnResultTextView::GetInstance(); - if (p_AivoiceReturnResultTextView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::GetInstance fail!!"); - return false; - } - // 获取适配器 - AivoiceChatContentListAdapter *adapter = p_AivoiceReturnResultTextView->GetAivoiceChatContentListAdapter(); - if (adapter != nullptr) - { - // 获取列表的大小 - size_t listSize = adapter->GetChatContentItem().size(); - - // 移除最后两项或清空列表 - if (listSize >= 2) - { - auto it = adapter->GetChatContentItem().end(); - std::advance(it, -2); // 移动迭代器到倒数第二项的位置 - adapter->GetChatContentItem().erase(it, adapter->GetChatContentItem().end()); - } - else if (listSize == 1) - { - // 如果列表只有一项,直接清空 - adapter->GetChatContentItem().clear(); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "listSize = %d", listSize); - ChatContentListCount -= (listSize < 2 ? listSize : 2); - } - return true; - } - - /* 更新用户问题字符串 */ - bool AiVoiceModel::UpdateUserQuestionStr() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateUserQuestionStr"); - - if (!RemoveLastTwoItemsOrClear()) - { - return false; - } - - if (!AddUserQuestionToChatItems()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddUserQuestionToChatItems fail!!"); - return false; - } - - // 更新显示列表 - AivoiceReturnResultTextView *p_AivoiceReturnResultTextView = AivoiceReturnResultTextView::GetInstance(); - if (!p_AivoiceReturnResultTextView) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::GetInstance fail!!"); - return false; - } - - AivoiceChatContentListAdapter *adapter = static_cast(p_AivoiceReturnResultTextView->GetAivoiceChatContentListAdapter()); - if (adapter) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetChatContentListCount() - 1 = %d,line =%d", GetChatContentListCount() - 1, __LINE__); - adapter->GetChatContentItem().push_back(chatTtems[GetChatContentListCount() - 1]); - p_AivoiceReturnResultTextView->GetChatContentList()->RefreshList(); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Chat content adapter is nullptr!!"); - return false; - } - - return true; - } - - /*更新Ai答案字符串*/ - bool AiVoiceModel::UpdateAiAnswerStr() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::UpdateAiAnswerStr"); - int index = GetChatContentListCount() - 1; - if (index < 0 || index >= MaxChatContentListCount) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid index: %d", index); - return false; - } - - if (chatTtems[index].isAiAnswer) // 处理ai1的多段回答 - { - ChatContentListCount--; - } - - if (!AddAiAnswerToChatItems()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AddAiAnswerToChatItems fail!!"); - return false; - } - - // 更新显示列表 - AivoiceReturnResultTextView *p_AivoiceReturnResultTextView = AivoiceReturnResultTextView::GetInstance(); - if (!p_AivoiceReturnResultTextView) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::GetInstance fail!!"); - return false; - } - - AivoiceChatContentListAdapter *adapter = static_cast(p_AivoiceReturnResultTextView->GetAivoiceChatContentListAdapter()); - if (adapter != nullptr && !adapter->GetChatContentItem().empty()) - { - // 如果最后一条是 AI 回答,则移除 - if (adapter->GetChatContentItem().back().isAiAnswer) - { - adapter->GetChatContentItem().pop_back(); - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetChatContentListCount() - 1 = %d,line = %d", GetChatContentListCount() - 1, __LINE__); - // 将更新后的 AI 回答内容添加到列表 - adapter->GetChatContentItem().push_back(chatTtems[GetChatContentListCount() - 1]); - if (AiVoicePresenter::GetInstance()) - AiVoicePresenter::GetInstance()->calculateChatContentItemViewHeight(chatTtems[GetChatContentListCount() - 1].text, true); - p_AivoiceReturnResultTextView->GetChatContentList()->RefreshList(); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Chat content adapter is nullptr!!"); - return false; - } - - return true; - } - - void AiVoiceModel::SetIsClickable(bool value) - { - isClickable = value; - } - - bool AiVoiceModel::GetIsClickable(void) - { - return isClickable; - } - - void AiVoiceModel::SetIsLimitDisplayed(bool value) - { - isLimitDisplayed = value; - } - bool AiVoiceModel::GetIsLimitDisplayed(void) - { - return isLimitDisplayed; - } - - /*获取用户问题的字符串*/ - std::string AiVoiceModel::GetUserQuestionStr(void) - { - // userQuestionStr = "写一篇100字文章"; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetUserQuestionStr:%s\n", userQuestionStr.c_str()); - return userQuestionStr; - } - - /*设置用户问题的字符串*/ - void AiVoiceModel::SetUserQuestionStr(std::string str) - { - if (GetSelect4gorbt() == AI_SELECT_4G) - { - if (str.empty()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "传入的问题为空"); - return; - } - userQuestionStr += str; - } - else if (GetSelect4gorbt() == AI_SELECT_BT) - { - if (!entryTextViewState) - { - SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0); - entryTextViewState = true; // 进入返回结果界面的标志 避免重复发消息 - usleep(50000); // 延时等待创建完成,0.05秒 - } - /* -------------------------------------------------------------------------- */ - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "传入的问题:%s", str.c_str()); - userQuestionStr = str; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "拼接的问题:%s", userQuestionStr.c_str()); - /* -------------------------------------------------------------------------- */ - SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0); - } - } - - /*获取Ai回答的字符串*/ - std::string AiVoiceModel::GetAiAnswerStr(void) - { - // aiAnswerStr = "春风化雨,时光荏苒。百年之内,生命如白驹过隙,转瞬即逝。唯有心存善念,用爱化解芥蒂,用智慧建构未来,才是人生的真正意义。让我们携手共进,用每一分时光去关爱他人,用每一滴汗水去创造奇迹,用每一个眼神去传递温暖。让这个世界因我们的存在而变得更加美好。生命短暂,但只要我们怀着虔诚的心,坚韧前行,我们就一定能在有限的时光里留下无限的可能。"; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "GetAiAnswerStr:%s", aiAnswerStr.c_str()); - return aiAnswerStr; - } - - /*设置Ai回答的字符串*/ - void AiVoiceModel::SetAiAnswerStrStr(std::string str) - { - aiAnswerStr += str; - SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0); - } - - // 安全替换 UTF-8 字符串中的字符 - static void safe_replace_utf8(std::string &str, const std::string &from_chars, char replacement) - { - std::string result; - result.reserve(str.length()); // 预分配足够空间 - - const char *p = str.c_str(); - const char *end = p + str.length(); - - while (p < end) - { - unsigned char c = *p; - size_t char_size = 1; - - // 判断 UTF-8 字符的字节数 - if ((c & 0x80) == 0) - { - // 1字节字符 (ASCII) - char_size = 1; - } - else if ((c & 0xE0) == 0xC0) - { - // 2字节字符 - char_size = 2; - } - else if ((c & 0xF0) == 0xE0) - { - // 3字节字符 (常见中文) - char_size = 3; - } - else if ((c & 0xF8) == 0xF0) - { - // 4字节字符 (如 Emoji) - char_size = 4; - } - else - { - // 无效字符,按单字节处理 - char_size = 1; - } - - // 检查字符是否在要替换的集合中 - bool replace = false; - if (char_size == 1) - { - // 单字节字符直接检查 - replace = (from_chars.find(c) != std::string::npos); - } - else - { - // 多字节字符,提取完整字符并检查 - std::string utf8_char(p, char_size); - for (size_t i = 0; i < from_chars.length();) - { - // 提取 from_chars 中的下一个 UTF-8 字符 - unsigned char fc = from_chars[i]; - size_t fc_size = 1; - - if ((fc & 0x80) == 0) - { - fc_size = 1; - } - else if ((fc & 0xE0) == 0xC0) - { - fc_size = 2; - } - else if ((fc & 0xF0) == 0xE0) - { - fc_size = 3; - } - else if ((fc & 0xF8) == 0xF0) - { - fc_size = 4; - } - - if (i + fc_size <= from_chars.length()) - { - std::string fc_str = from_chars.substr(i, fc_size); - if (fc_str == utf8_char) - { - replace = true; - break; - } - } - - i += fc_size; - } - } - - // 添加到结果字符串 - if (replace) - { - result += replacement; - } - else - { - result.append(p, char_size); - } - - p += char_size; - } - - // 替换原字符串 - str.swap(result); - } - - static int fouce_count = 0; // - void AiVoiceModel::ProcessTextByPunctuation() - { - const std::string punctuation = ",。!?;:))“”、\"\""; // 要替换的中文标点 - const char replacement = ','; // 替换为英文逗号 - const size_t MAX_SEGMENT_LENGTH = 120; // 最大分段长度 - const size_t MIN_SEGMENT_LENGTH = 1; // 最小发送长度(可调整) - - if (accumulatedText.empty()) - return; - - // 安全替换中文标点为英文逗号 - std::string processedText = accumulatedText; - safe_replace_utf8(processedText, punctuation, replacement); - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "processedText:%s", processedText.c_str()); - - accumulatedText = processedText; - size_t commaPos = accumulatedText.find_last_of(','); - - // 处理长度限制,若超过最大长度则强制分段 - if (accumulatedText.length() >= MAX_SEGMENT_LENGTH) - { - commaPos = MAX_SEGMENT_LENGTH - 1; - // 查找最大长度内最近的逗号 - size_t lastCommaInRange = accumulatedText.find_last_of(',', commaPos); - if (lastCommaInRange != std::string::npos) - { - commaPos = lastCommaInRange; - } - } - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "commaPos:%d", commaPos); - - if (commaPos != std::string::npos) - { - // 按标点分段发送 - sendSegment(accumulatedText, commaPos); - } - else - { - // 无逗号时的处理逻辑 - if (accumulatedText.length() >= MIN_SEGMENT_LENGTH) - { - // 强制发送完整文本(无论是否有标点) - std::string segment = accumulatedText; - segment.erase( - std::remove(segment.begin(), segment.end(), '\n'), - segment.end()); - segment.erase( - std::remove(segment.begin(), segment.end(), '\r'), - segment.end()); - - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "强制发送文本: %s (长度: %zu)", - segment.c_str(), segment.length()); - bool sendret = false; -#if AI_VOICE_ENABLE - sendret = uapi_start_tts_single_txt((char *)segment.c_str()); -#endif - // 如果为true发送成功,如果发送失败等待下次发送不清空文本 - if (sendret) - { - // 发送后清空累积文本 - accumulatedText.clear(); - fouce_count = 0; - } - else - { - // 发送失败,等待下次发送 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送,fouce_count:%d", fouce_count); - fouce_count++; - if (fouce_count >= 3 && !hasTtsStartSucceeded) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败准备发送:uapi_start_tts有且只发一次"); - bool startOk = false; -#if AI_VOICE_ENABLE - startOk = uapi_start_tts(); -#endif - fouce_count = 0; - if (startOk) - { - hasTtsStartSucceeded = true; - } - } - } - } - else - { - // 文本过短,继续累积 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "累积文本过短(长度: %zu), 继续累积", - accumulatedText.length()); - } - } - } - - // 辅助函数:按标点分段发送 - void AiVoiceModel::sendSegment(const std::string &text, size_t pos) - { - // 提取分段(包含英文逗号) - std::string segment = text.substr(0, pos + 1); - - // 清理文本 - segment.erase( - std::remove(segment.begin(), segment.end(), '\n'), - segment.end()); - segment.erase( - std::remove(segment.begin(), segment.end(), '\r'), - segment.end()); - - // 发送到TTS播放 - bool ret = false; - if (!segment.empty()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "按标点发送分段: %s (长度: %zu)", - segment.c_str(), segment.length()); -#if AI_VOICE_ENABLE - ret = uapi_start_tts_single_txt((char *)segment.c_str()); -#endif - } - - if (ret) - { - // 更新累积文本 - if (pos + 1 < text.length()) - { - accumulatedText = text.substr(pos + 1); - } - else - { - accumulatedText.clear(); - } - fouce_count = 0; - } - else - { - // 发送失败,等待下次发送 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败,等待下次发送,fouce_count:%d", fouce_count); - fouce_count++; - if (fouce_count >= 3 && !hasTtsStartSucceeded) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "发送失败准备发送:uapi_start_tts有且只发一次"); - bool startOk = false; -#if AI_VOICE_ENABLE - startOk = uapi_start_tts(); -#endif - fouce_count = 0; - if (startOk) - { - hasTtsStartSucceeded = true; - } - } - } - } - - std::string AiVoiceModel::GetAccumulatedText(void) - { - return accumulatedText; - } - - void AiVoiceModel::SetAiAnswerStrStr(std::string str, uint8_t type) - { - AIResponseType = type; - errnote = str; - AiVoiceView *view_ = AiVoiceView::GetInstance(); - if (GetSelect4gorbt() == AI_SELECT_4G) // 4G - { - if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串 - { - delete_start_line_break_str(str); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "传入的str:%s", str.c_str()); - aiAnswerStr += str; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str()); - /* -------------------------------------------------------------------------- */ - // 累积接收到的文本 - // accumulatedText += str;//tts播放的代码去除掉 - /* -------------------------------------------------------------------------- */ - } - if (view_ != nullptr) - { - if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()) - { - // start_ai4g_tts_play_timer(); // 开启一个定时器,用于播放tts音频 - start_update_ai_answer_timer(); - } - } - } - else if (GetSelect4gorbt() == AI_SELECT_BT) // 蓝牙 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIResponseType = %d,errnote = %s\n", AIResponseType, errnote.c_str()); - // 如果是:AI录音解析错误或AI 回应错误 ,或者重传多次录音数据->跳转AI回应错误界面 - if (AIResponseType == AiVoiceModel::AI_RECORDING_PARSING_ERROR || AIResponseType == AiVoiceModel::AI_RESPONSE_ERROR || AIResponseType == AiVoiceModel::AI_BLE_ERROR) - { - SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)errnote.c_str(), errnote.length()); - return; - } - else if (AiVoiceModel::AI_RESPONSE_END) // 如果是AI 回应结束 - { - if (errnote.empty()) // 如果没有回应数据 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::GetErrnote is empty!!"); - AiVoiceModel::GetInstance().SetErrnote("响应内容为空"); - std::string str = AiVoiceModel::GetInstance().GetErrnote(); - SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length()); - return; - } - } - if (view_ != nullptr) - { - if (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible()) - { - if (!OHOS::AiVoiceModel::GetInstance().GetIsLimitDisplayed()) // 如果ai答案没有显示到极限了,就更新ai答案字符串 - { - aiAnswerStr += str; - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "接受字的符串:%s", aiAnswerStr.c_str()); - SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0); - } - } - } - } - } - - /*清空上次用户问题和Ai回答字符串*/ - void AiVoiceModel::ClearQuestionAndAiAnswerStr(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "清空上次用户问题和Ai回答字符串"); - userQuestionStr = ""; - aiAnswerStr = ""; - accumulatedText = ""; - set_is_first_receive(true); - } - - /*获取AI音频路径*/ - std::string AiVoiceModel::GetAIAudioPath(void) - { - return AIAIAudioPath; - } - -#ifdef __cplusplus - extern "C" - { -#endif - int32_t AudioCaptureSample(int32_t argc, const char *argv[]); - int32_t streamingRecordAndSend_AI(int type); -#define IS_SUPPORT_REALTIME_RECORD_SEND_AI 1 // 是否支持实时发送录音数据 -#ifdef __cplusplus - }; -#endif - - // 开始聆听并录取用户问题 - void AiVoiceModel::StartListenAndRecordingUserQuestion(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "聆听用户问题并发送录音数据"); - AiVoiceView *view_ = AiVoiceView::GetInstance(); - if (view_ == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::GetInstance fail!!"); - return; - } - if ((view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID) != nullptr) && - (view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->IsVisible())) - { -#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) - { - streamingRecordAndSend_AI(type); // 实时发送录音数据 - } - else if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) - { - // uapi_start_asr_StartTranscription();录音同步移动到开启asr了,所有这里不调用 - } -#else - std::string audioPath = AiVoiceModel::GetInstance().GetAIAudioPath(); - if (uapi_delete_files(audioPath.c_str())) // 先删除文件 - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_delete_files,%s", audioPath.c_str()); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "uapi_delete_files fail!!"); - } -#if CURRENT_AIAUDIO_TYPE == AIAUDIO_TYPE_PCM - const char *defaultArgs[6] = {"01", "pcm", "16000", "1", "16", audioPath.c_str()}; -#elif CURRENT_AIAUDIO_TYPE == AIAUDIO_TYPE_SBC - const char *defaultArgs[6] = {"01", "sbc", "16000", "1", "16", audioPath.c_str()}; -#elif CURRENT_AIAUDIO_TYPE == AIAUDIO_TYPE_MSBC - const char *defaultArgs[6] = {"01", "msbc", "16000", "1", "16", audioPath.c_str()}; -#endif - uapi_save_runtime_log(RUNTIME_LOG_RECORD_START_AI); // TOOD* - AudioCaptureSample(6, (const char **)defaultArgs); -#endif - } - return; - } - - // 停止聆听用户问题 - void AiVoiceModel::StopListenAndRecordingUserQuestion(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "停止录音"); - if (GetSelect4gorbt() == AI_SELECT_4G) // 选的是4G需要关闭asr - { -#ifdef SUPPORT_AI_SERVICE - uapi_stop_AI_asr(); -#endif - } - else if (GetSelect4gorbt() == AI_SELECT_BT) - { - int32_t argc = 1; - uint8_t *argv = (uint8_t *)"stop"; - AudioCaptureSample(argc, (const char **)&argv); - } - uapi_save_runtime_log(RUNTIME_LOG_RECORD_STOP_AI); // TOOD* - return; - } - - void AiVoiceModel::sendAIIsReady() - { -#ifdef SUPPORT_BLE_SERVICE - auto it = selectAiModelToTextId.find(GetSelectAiModel()); - if (it != selectAiModelToTextId.end()) - { - - if (get_ble_interval() >= BLE_CONNECT_INTERVAL_SLOW) - { - uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH); - } - send_AI_is_ready(it->second.second); - } -#endif - } - - void AiVoiceModel::StatusResume(void) - { - ClearQuestionAndAiAnswerStr(); - StopListenAndRecordingUserQuestion(); - AiVoiceConnectStatus = false; - - for (int i = 0; i < ChatContentListCount; i++) - { - chatTtems[i].index = 0; - chatTtems[i].text = ""; - chatTtems[i].isAiAnswer = false; - } - ChatContentListCount = 0; - entryTextViewState = false; - isClickable = false; - isLimitDisplayed = false; - AI_4G_state = false; - AI_BT_state = false; - select4gorbt = -1; - // init_4gai_task = false;//TOOD:之后需要销毁 - } - - /* -------------------------------------------------------------------------- */ - // 声明定时器变量 - static osTimerId_t g_timer = nullptr; - static int Time = DEFAULT_TIMEOUT_10S; - /*定时器到期时的处理*/ - static void AIVoice_TimerCallbackProc(int data) - { - // 等待AI思考完成的定时器 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIVoice_TimerCallbackProc,Time = %d", Time); - if (Time < 0) // 如果思考时间超时10s,进入连接超时界面 - { - AiVoiceModel::GetInstance().AIVoice_StopTimer(); - AiVoiceModel::GetInstance().SetErrnote("连接超时,请重新开始对话"); - std::string str = AiVoiceModel::GetInstance().GetErrnote(); - - if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) - { - // dinit_ai_task(); // 所有服务都删除重新连一下服务器 -#ifdef SUPPORT_AI_SERVICE - uapi_stop_all_websocket_servers(); - uapi_destroy_all_websocket_servers(); -#endif - } - - SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length()); - } - else - { - if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) - { - if (AiVoiceModel::GetInstance().is_need_to_jump_result_view()) - { - SendMsgToUIService(UI_AI_JUMP_TO_RESULT_VIEW, 0, nullptr, 0); - } - return; - } - else if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT) - { - if (AiVoiceModel::GetInstance().GetAPPBluetoothIsConnect() == false) // 蓝牙的连接状态判断,如果AI思考过程中途断连,直接弹窗提示,不在硬等 - { - AiVoiceModel::GetInstance().SetErrnote("手机蓝牙已断开"); - std::string str = AiVoiceModel::GetInstance().GetErrnote(); - SendMsgToUIService(UI_AI_JUMP_TO_RESPONDERR_VIEW, 0, (void *)str.c_str(), str.length()); - } - } - } - return; - } - - /* - * @brief 回调函数 - */ - static void AIVoice_TimerCallback(int data) - { - Time -= 1; - GraphicService::GetInstance()->PostGraphicEvent(std::bind(AIVoice_TimerCallbackProc, data)); - } - - /* - * @brief 开启定时器函数 - * @param interval 时间间隔,单位ms - */ - void AiVoiceModel::AIVoice_StartTimer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::AIVoice_StartTimer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_timer = osTimerNew((osTimerFunc_t)AIVoice_TimerCallback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_timer == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_timer != nullptr) - { - ret = osTimerDelete(g_timer); - } - g_timer = nullptr; - return; - } - } - - /* - * @brief 停止定时器 - */ - void AiVoiceModel::AIVoice_StopTimer(void) - { - // 检查定时器是否存在 - if (g_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::AIVoice_StopTimer"); - osTimerStop(g_timer); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_timer = nullptr; - Time = DEFAULT_TIMEOUT_10S; - } - } - - // 声明定时器变量 - static osTimerId_t g_screen60s_timer = nullptr; - static int8_t SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S; // 60s - - static void ai_start_screen60s_timer_callbackProc(int data) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME); - SCREEN_60S_TIME -= DEFAULT_TIMEOUT_30S; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer_callbackProc,time = %d", SCREEN_60S_TIME); - if (SCREEN_60S_TIME <= 0) - { - // 60s后息屏停止定时 - AiVoiceModel::GetInstance().ai_stop_screen60s_timer(); - if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT) - { - ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); // 取消常亮屏 - } - } - } - static void ai_start_screen60s_timer_callback(int data) - { - // GraphicService::GetInstance()->PostGraphicEvent(std::bind(ai_start_screen60s_timer_callbackProc, data)); - ai_start_screen60s_timer_callbackProc(data); - } - void AiVoiceModel::ai_start_screen60s_timer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_start_screen60s_timer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_screen60s_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_screen60s_timer = osTimerNew((osTimerFunc_t)ai_start_screen60s_timer_callback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_screen60s_timer == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_screen60s_timer, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_screen60s_timer != nullptr) - { - ret = osTimerDelete(g_screen60s_timer); - } - g_screen60s_timer = nullptr; - return; - } - } - void AiVoiceModel::ai_stop_screen60s_timer(void) - { - // 检查定时器是否存在 - if (g_screen60s_timer != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::ai_stop_screen60s_timer"); - osTimerStop(g_screen60s_timer); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_screen60s_timer); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_screen60s_timer = nullptr; - SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S; - } - } - void AiVoiceModel::reset_ai_screen60s_timer_time() - { - SCREEN_60S_TIME = DEFAULT_TIMEOUT_60S; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "reset_ai_screen60s_timer_time %d", SCREEN_60S_TIME); - if (nullptr == g_screen60s_timer) - { - ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); // 重新常亮屏 - ai_start_screen60s_timer(); // 开启定时器 - } - } - - bool AiVoiceModel::get_screen60s_timer_is_stop(void) - { - if (g_screen60s_timer == nullptr) - return true; - else - return false; - } - static osTimerId_t g_listeningEndHandle = nullptr; - static int8_t LISTENING_TIMEOUT = 10; // 10s钟无操作关闭该视图 - static void AIListeningCallbackProc(int data) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AIListeningCallbackProc %d", LISTENING_TIMEOUT); - LISTENING_TIMEOUT--; - if (LISTENING_TIMEOUT <= 0) - { - AiVoiceModel::GetInstance().stop_listening_timer(); // 停止聆听定时器 - AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance(); - if (AiVoicePresenter::GetInstance() && AivoiceListeningView::GetInstance()) - { - // uapi_UI_stop_asr(); - AiVoicePresenter::GetInstance()->ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); // 切换到思考中界面 - } - } - else - { - if (AivoiceListeningView::GetInstance()) - { - AivoiceListeningView::GetInstance()->GetShowtimeoutLabel()->SetText(std::to_string(LISTENING_TIMEOUT).c_str()); - AivoiceListeningView::GetInstance()->GetShowtimeoutLabel()->Invalidate(); - } - } - return; - } - static void AIListeningCallback(int data) - { - GraphicService::GetInstance()->PostGraphicEvent(std::bind(AIListeningCallbackProc, data)); - } - // 开启一个AI录音的定时器 - void AiVoiceModel::start_listening_timer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_listening_timer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_listeningEndHandle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_listeningEndHandle = osTimerNew((osTimerFunc_t)AIListeningCallback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_listeningEndHandle == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_listeningEndHandle, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_listeningEndHandle != nullptr) - { - ret = osTimerDelete(g_listeningEndHandle); - } - g_listeningEndHandle = nullptr; - return; - } - } - - // 停止一个AI录音的定时器 - void AiVoiceModel::stop_listening_timer(void) - { - // 检查定时器是否存在 - if (g_listeningEndHandle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::stop_listening_timer"); - osTimerStop(g_listeningEndHandle); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_listeningEndHandle); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_listeningEndHandle = nullptr; - LISTENING_TIMEOUT = 10; - } - } - - static osTimerId_t g_ai_is_ready_Handle = nullptr; // 处理查询AI是否就绪定时器 - static int8_t AI_IS_READY_TIMEOUT = DEFAULT_TIMEOUT_5S; // 5s钟超时 - static void AI_IS_READY_CallbackProc(int data) - { - if (AI_IS_READY_TIMEOUT <= 0) // 模型连接失败有5秒超时 - { - AiVoiceModel::GetInstance().stop_ai_isready_timer(); - AiVoiceView *view_ = AiVoiceView::GetInstance(); - AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance(); - if (view_ != nullptr && p_AiVoicePresenter != nullptr) - { - if ((view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr) && - (view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible())) - { - if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) - { - // dinit_ai_task(); // 所有服务都删除重新连一下服务器 -#ifdef SUPPORT_AI_SERVICE - uapi_stop_all_websocket_servers(); - uapi_destroy_all_websocket_servers(); -#endif - } - p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID); - } - } - } - else - { - if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "GetSelect4gorbt() == AI_SELECT_4G"); - if (AiVoiceModel::GetInstance().GetInit_4gai_task()) - { - uint8_t state = 0; - // state = get_asr_is_ready_start(); - state = get_asr_is_ready_start_old(); - if (state) - { - bool state = true; - SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool)); - } - } - } - } - return; - } - static void AI_IS_READY_Callback(int data) - { - AI_IS_READY_TIMEOUT--; - GraphicService::GetInstance()->PostGraphicEvent(std::bind(AI_IS_READY_CallbackProc, data)); - } - - // 开启一个查询AI是否准备就绪的定时器 - void AiVoiceModel::start_ai_isready_timer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_ai_isready_timer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_ai_is_ready_Handle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_ai_is_ready_Handle = osTimerNew((osTimerFunc_t)AI_IS_READY_Callback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_ai_is_ready_Handle == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_ai_is_ready_Handle, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_ai_is_ready_Handle != nullptr) - { - ret = osTimerDelete(g_ai_is_ready_Handle); - } - g_ai_is_ready_Handle = nullptr; - return; - } - return; - } - - // 停止一个查询AI是否准备就绪的定时器 - void AiVoiceModel::stop_ai_isready_timer(void) - { - // 检查定时器是否存在 - if (g_ai_is_ready_Handle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::stop_ai_isready_timer"); - osTimerStop(g_ai_is_ready_Handle); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_ai_is_ready_Handle); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_ai_is_ready_Handle = nullptr; - AI_IS_READY_TIMEOUT = DEFAULT_TIMEOUT_5S; - } - } - - /* -------------------------------------------------------------------------- */ - static osTimerId_t g_ai4g_is_suc_connected_Handle = nullptr; // 处理AI4G连接定时器 - static uint8_t AI4G_IS_SUC_CON_TIME = 25; - static int8_t AI4G_IS_SUC_CON_TIMEOUT = AI4G_IS_SUC_CON_TIME; // AI4G_IS_SUC_CON_TIME秒超时 - static void AI4G_IS_SUC_CON_CallbackProc(int data) - { - AiVoiceView *view_ = AiVoiceView::GetInstance(); - AiVoicePresenter *p_AiVoicePresenter = AiVoicePresenter::GetInstance(); - if (AI4G_IS_SUC_CON_TIMEOUT <= 0) // 4g服务器连接失败 - { - AiVoiceModel::GetInstance().stop_ai4g_connect_timer(); - if (view_ != nullptr && p_AiVoicePresenter != nullptr) - { - if ((view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW) != nullptr) && - (view_->GetAiVoiceScrollView(AIVOICE_4GSERVICECON_VIEW)->IsVisible())) - { - // dinit_ai_task(); // 所有服务都删除重新连一下服务器 -#ifdef SUPPORT_AI_SERVICE - uapi_stop_all_websocket_servers(); - uapi_destroy_all_websocket_servers(); -#endif - p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID); - } - } - } - else - { - if (view_ != nullptr && p_AiVoicePresenter != nullptr) - { - if (AiVoiceModel::GetInstance().GetInit_4gai_task()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "4gAi服务初始化成功"); - AiVoiceModel::GetInstance().stop_ai4g_connect_timer(); - p_AiVoicePresenter->ChangeViewAndLogicOperator(AIVOICE_4GSERVICECON_VIEW, AIVOICE_AIMODE_CONNECTING); - } - } - } - return; - } - static void AI4G_IS_SUC_CON_Callback(int data) - { - AI4G_IS_SUC_CON_TIMEOUT--; - GraphicService::GetInstance()->PostGraphicEvent(std::bind(AI4G_IS_SUC_CON_CallbackProc, data)); - } - /*处理AI4G连接定时器到期时的处理*/ - void AiVoiceModel::start_ai4g_connect_timer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_ai4g_connect_timer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_ai4g_is_suc_connected_Handle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_ai4g_is_suc_connected_Handle = osTimerNew((osTimerFunc_t)AI4G_IS_SUC_CON_Callback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_ai4g_is_suc_connected_Handle == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_ai4g_is_suc_connected_Handle, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_ai4g_is_suc_connected_Handle != nullptr) - { - ret = osTimerDelete(g_ai4g_is_suc_connected_Handle); - } - g_ai4g_is_suc_connected_Handle = nullptr; - return; - } - return; - } - - void AiVoiceModel::stop_ai4g_connect_timer(void) - { - // 检查定时器是否存在 - if (g_ai4g_is_suc_connected_Handle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::stop_ai4g_connect_timer"); - osTimerStop(g_ai4g_is_suc_connected_Handle); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_ai4g_is_suc_connected_Handle); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_ai4g_is_suc_connected_Handle = nullptr; - AI4G_IS_SUC_CON_TIMEOUT = AI4G_IS_SUC_CON_TIME; - } - } - - /* -------------------------------- tts播放定时器 -------------------------------- */ - static osTimerId_t g_ai4g_is_start_tts_play_Handle = nullptr; - static constexpr const int8_t NUMBER_TEN = 15; - static int8_t AI4G_IS_START_TTS_PLAY_CNT = NUMBER_TEN; - static uint8_t tts_record_flag = 0; - // 添加一个静态变量用于跟踪连续出现0的次数 - static int s_tts_tick_zero_count = 0; - static void AI4G_IS_START_TTS_CallbackProc(int data) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AI4G_IS_START_TTS_CallbackProc:%s", AiVoiceModel::GetInstance().GetAccumulatedText().c_str()); - AiVoiceModel::GetInstance().GetInit_4gai_task(); // 获取4gai服务状态 - uint8_t tts_state = 0; -#if AI_VOICE_ENABLE - tts_state = get_ai_tts_server_init_flag(); -#endif - if (tts_state == 0) // tts服务如果断开了,就停止定时器 - { - s_tts_tick_zero_count++; // 增加连续0的次数 - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "s_tts_tick_zero_count count: %d", s_tts_tick_zero_count); - if (s_tts_tick_zero_count >= 10) // 如果连续出现10次0,就停止定时器 - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "tts_server disconnect..."); - AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); - return; - } - } - - // 无文本时停止定时器 - if (AiVoiceModel::GetInstance().GetAccumulatedText().empty()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "没有文本了准备发送:stop_ai4g_tts_play_timer"); - AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); - return; - } - -#if AI_VOICE_ENABLE - if (!get_ai_osal_msg_queue_is_full()) - { - AiVoiceModel::GetInstance().ProcessTextByPunctuation(); - } -#endif - return; - } - - static void AI4G_IS_START_TTS_Callback(int data) - { - AI4G_IS_START_TTS_CallbackProc(data); - // GraphicService::GetInstance()->PostGraphicEvent(std::bind(AI4G_IS_START_TTS_CallbackProc, data)); - } - - void AiVoiceModel::start_ai4g_tts_play_timer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_ai4g_tts_play_timer"); - // AI4G_IS_START_TTS_PLAY_CNT = NUMBER_TEN; - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_ai4g_is_start_tts_play_Handle != nullptr) - { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_ai4g_is_start_tts_play_Handle = osTimerNew((osTimerFunc_t)AI4G_IS_START_TTS_Callback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_ai4g_is_start_tts_play_Handle == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_ai4g_is_start_tts_play_Handle, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_ai4g_is_start_tts_play_Handle != nullptr) - { - ret = osTimerDelete(g_ai4g_is_start_tts_play_Handle); - } - g_ai4g_is_start_tts_play_Handle = nullptr; - return; - } - return; - } - - void AiVoiceModel::stop_ai4g_tts_play_timer(void) - { - // 检查定时器是否存在 - if (g_ai4g_is_start_tts_play_Handle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop_ai4g_tts_play_timer"); - osTimerStop(g_ai4g_is_start_tts_play_Handle); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_ai4g_is_start_tts_play_Handle); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_ai4g_is_start_tts_play_Handle = nullptr; - AI4G_IS_START_TTS_PLAY_CNT = NUMBER_TEN; - s_tts_tick_zero_count = 0; // 重置计数器 - fouce_count = 0; - - start_uapi_stop_tts_timer(); - } - } - - static osTimerId_t g_start_ai_answer_update_Handle = nullptr; - static constexpr const int8_t NUMBER_THREE = 3; - static int8_t START_UPDATE_AIANSWER_CNT = NUMBER_THREE; - static void AI4G_START_AI_ANSWER_CallbackProc(int data) - { - START_UPDATE_AIANSWER_CNT--; - if (START_UPDATE_AIANSWER_CNT <= 0) - { - AiVoiceModel::GetInstance().stop_update_ai_answer_timer(); - } - else - { - // if(AiVoiceModel::GetInstance().GetUserQuestionStr() !=) - // SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0); - - SendMsgToUIService(UI_UPDATE_AI_ANSWER_STR, 0, nullptr, 0); - } - } - - static void AI4G_START_AI_ANSWER_Callback(int data) - { - AI4G_START_AI_ANSWER_CallbackProc(data); - // GraphicService::GetInstance()->PostGraphicEvent(std::bind(AI4G_START_AI_ANSWER_CallbackProc, data)); - } - - void AiVoiceModel::start_update_ai_answer_timer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_update_ai_answer_timer"); - START_UPDATE_AIANSWER_CNT = NUMBER_THREE; - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_start_ai_answer_update_Handle != nullptr) - { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_start_ai_answer_update_Handle = osTimerNew((osTimerFunc_t)AI4G_START_AI_ANSWER_Callback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_start_ai_answer_update_Handle == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_start_ai_answer_update_Handle, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_start_ai_answer_update_Handle != nullptr) - { - ret = osTimerDelete(g_start_ai_answer_update_Handle); - } - g_start_ai_answer_update_Handle = nullptr; - return; - } - return; - } - - void AiVoiceModel::stop_update_ai_answer_timer(void) - { - if (g_start_ai_answer_update_Handle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop_update_ai_answer_timer"); - osTimerStop(g_start_ai_answer_update_Handle); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_start_ai_answer_update_Handle); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_start_ai_answer_update_Handle = nullptr; - START_UPDATE_AIANSWER_CNT = NUMBER_THREE; - } - } - - static osTimerId_t g_uapi_stop_tts_Handle = nullptr; - static void AI4G_UAPI_STOP_TTS_CallbackProc(int data) - { - AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer(); - } - - static void AI4G_UAPI_STOP_TTS_Callback(int data) - { - AI4G_UAPI_STOP_TTS_CallbackProc(data); - // GraphicService::GetInstance()->PostGraphicEvent(std::bind(AI4G_UAPI_STOP_TTS_CallbackProc, data)); - } - - void AiVoiceModel::start_uapi_stop_tts_timer(uint32_t interval) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceModel::start_uapi_stop_tts_timer"); - /* -------------------------- 1.检查定时器是否已经存在,如果存在则返回 ------------------------- */ - if (g_uapi_stop_tts_Handle != nullptr) - { - // WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer already exists!!"); - return; - } - /* --------------------------------- 2.创建定时器 -------------------------------- */ - g_uapi_stop_tts_Handle = osTimerNew((osTimerFunc_t)AI4G_UAPI_STOP_TTS_Callback, osTimerPeriodic, nullptr, nullptr); - // 检查定时器创建是否成功 - if (g_uapi_stop_tts_Handle == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Timer create failed!!"); - return; - } - /* ----------------------------- 3.将毫秒转换为系统时钟节拍数 ---------------------------- */ - int tick = osMs2Tick(interval); - /* --------------------------------- 4.启动定时器 -------------------------------- */ - osStatus_t ret = osTimerStart(g_uapi_stop_tts_Handle, tick); - /* -------------------- 5.检查定时器启动是否成功,如果启动失败,删除定时器并置为 nullptr -------------------- */ - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - if (g_uapi_stop_tts_Handle != nullptr) - { - ret = osTimerDelete(g_uapi_stop_tts_Handle); - } - g_uapi_stop_tts_Handle = nullptr; - return; - } - } - - void AiVoiceModel::stop_uapi_stop_tts_timer(void) - { - // 检查定时器是否存在 - if (g_uapi_stop_tts_Handle != nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "stop_uapi_stop_tts_timer"); - osTimerStop(g_uapi_stop_tts_Handle); - // 删除定时器并置为 nullptr - osStatus_t ret = osTimerDelete(g_uapi_stop_tts_Handle); - if (ret != osOK) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "osTimerDelete failed, ret = %lx!!", ret); - } - g_uapi_stop_tts_Handle = nullptr; - if (g_ai4g_is_start_tts_play_Handle == nullptr) - { - hasTtsStartSucceeded = false; -#if AI_VOICE_ENABLE - uapi_stop_tts(); -#endif - } - } - } - - // 设置选择的ai模型 - void AiVoiceModel::SetSelectAiModel(int index) - { -#if defined(AI_VOICE_N9) - ConfigModel::GetInstance()->SetSelectAiModel(0); -#else - ConfigModel::GetInstance()->SetSelectAiModel(index); -#endif - } - - int AiVoiceModel::GetSelectAiModel(void) - { - return ConfigModel::GetInstance()->GetSelectAiModel(); - } - - void AiVoiceModel::SetAI_4G_state(bool state) - { - AI_4G_state = state; - } - bool AiVoiceModel::GetAI_4G_state(void) - { - return AI_4G_state; - } - void AiVoiceModel::SetAI_BT_state(bool state) - { - AI_BT_state = state; - } - bool AiVoiceModel::GetAI_BT_state(void) - { - return AI_BT_state; - } - void AiVoiceModel::SetInit_4gai_task(bool state) - { - init_4gai_task = state; - } - bool AiVoiceModel::GetInit_4gai_task(void) - { - init_4gai_task = are_all_services_ready(); - return init_4gai_task; - } - - void AiVoiceModel::SetSelect4gorbt(int state) - { - select4gorbt = state; - } - int AiVoiceModel::GetSelect4gorbt(void) - { - return select4gorbt; - } - - // 是否需要跳转到结果视图 - bool AiVoiceModel::is_need_to_jump_result_view(void) - { - if (userQuestionStr.empty()) - { - return false; - } - return true; - } - - bool AiVoiceModel::getentryTextViewState(void) - { - return entryTextViewState; - } - - bool AiVoiceModel::get_is_first_receive() - { - return isFirstReceive; - } - - void AiVoiceModel::set_is_first_receive(bool val) - { - isFirstReceive = val; - } - - // 删除开始的换行符 - void AiVoiceModel::delete_start_line_break_str(std::string &str) - { - if (GetSelect4gorbt() == AI_SELECT_4G && GetAiModelTextId() == STR_AIMODELS_DOUBAO) - { - if (isFirstReceive) - { - isFirstReceive = false; - // 检查是否以"\n\n"开头 - if (str.size() >= 2 && str[0] == '\n' && str[1] == '\n') - { - // 去除开头的两个换行符 - str = str.substr(2); - } - } - } - } - - /*获取已选择的ai模型的textid*/ - int AiVoiceModel::GetAiModelTextId() - { -#if 0 - int language = ConfigModel::GetInstance()->GetLanguage(); - int textId; - - if (language == 0) - { - selectAiModelToTextId = { - {0, {STR_AIMODES_WENXINYIYAN, 0}}, - {1, {STR_AIMODES_KIMI, 2}}, - {2, {STR_AIMODELS_DOUBAO, 3}}, - // {3, {STR_TONGYI_QIANWEN, 4}}, - {3, {STR_DEEPSEEK, 4}}, - {4, {STR_IFLYTEK_SPARK, 5}}, - {5, {STR_AIMODES_CHATGPT, 1}}, - }; - textId = STR_AIMODES_WENXINYIYAN; - } - else - { - selectAiModelToTextId = { - {0, {STR_AIMODES_CHATGPT, 1}}, - {1, {STR_AIMODES_WENXINYIYAN, 0}}, - {2, {STR_AIMODES_KIMI, 2}}, - {3, {STR_AIMODELS_DOUBAO, 3}}, - // {4, {STR_TONGYI_QIANWEN, 4}}, - {4, {STR_DEEPSEEK, 4}}, - {5, {STR_IFLYTEK_SPARK, 5}}, - }; - textId = STR_AIMODES_CHATGPT; - } -#endif -#ifdef AI_VOICE_JIUTIAN - int textId = 0; - selectAiModelToTextId = { - {0, {STR_DEEPSEEK, 4}}, - {1, {STR_JIUTIAN, 5}}, - {2, {STR_AIMODELS_DOUBAO, 3}}, - {3, {STR_AIMODES_WENXINYIYAN, 0}}, - {4, {STR_AIMODES_KIMI, 2}}, - {5, {STR_AIMODES_CHATGPT, 1}}, - }; - textId = STR_DEEPSEEK; -#elif defined(AI_VOICE_N9) - int textId = 0; - selectAiModelToTextId = { - {0, {STR_AIMODELS_DOUBAO, 3}}, - }; - textId = STR_AIMODELS_DOUBAO; -#else - // 客户新需求需要改模型顺序: - int textId = 0; - selectAiModelToTextId = { - {0, {STR_DEEPSEEK, 4}}, - {1, {STR_JIUTIAN, 5}}, - {2, {STR_AIMODELS_DOUBAO, 3}}, - {3, {STR_AIMODES_WENXINYIYAN, 0}}, - {4, {STR_AIMODES_KIMI, 2}}, - {5, {STR_AIMODES_CHATGPT, 1}}, - }; - textId = STR_DEEPSEEK; - - // 根据视图ID设置文本ID - auto it = selectAiModelToTextId.find(GetSelectAiModel()); - if (it != selectAiModelToTextId.end()) - { - return it->second.first; - } -#endif - return textId; - } -} - -#ifdef __cplusplus -#if __cplusplus -extern "C" -{ -#endif /* __cplusplus */ -#endif /* __cplusplus */ - uint8_t getselect4gorbtai(void) // 获取AI模型选择的是4G还是蓝牙 - { - if (OHOS::AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) - { - return 1; - } - return 0; - } - -#ifdef BLE_INSTRUCT - - /** - * @brief 过滤字符串中无法显示的文字(使用GetGlyphPathData接口) - * @param input_str 输入字符串 - * @param output_str 输出字符串缓冲区 - * @param max_len 输出缓冲区最大长度 - * @return 过滤后的字符串长度,-1表示失败 - */ - int32_t chat_filter_unsupported_chars(const char *input_str, char *output_str, uint32_t max_len) - { - if (input_str == NULL || output_str == NULL || max_len == 0) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Invalid parameters for asr_filter_unsupported_chars\n"); - return -1; - } - - // 初始化输出缓冲区 - memset(output_str, 0, max_len); - - uint32_t input_len = strlen(input_str); - uint32_t output_pos = 0; - uint32_t input_pos = 0; - - while (input_pos < input_len && output_pos < max_len - 1) - { - uint32_t char_start = input_pos; - uint32_t char_end = input_pos; - - // 获取下一个UTF-8字符 - uint32_t unicode_char = 0; - bool valid_utf8 = false; - - // 简单的UTF-8解码 - if ((unsigned char)input_str[input_pos] < 0x80) - { - // ASCII字符 - unicode_char = (unsigned char)input_str[input_pos]; - char_end = input_pos + 1; - valid_utf8 = true; - } - else if ((unsigned char)input_str[input_pos] >= 0xC0 && (unsigned char)input_str[input_pos] < 0xE0) - { - // 2字节UTF-8字符 - if (input_pos + 1 < input_len) - { - unicode_char = ((unsigned char)input_str[input_pos] & 0x1F) << 6 | - ((unsigned char)input_str[input_pos + 1] & 0x3F); - char_end = input_pos + 2; - valid_utf8 = true; - } - } - else if ((unsigned char)input_str[input_pos] >= 0xE0 && (unsigned char)input_str[input_pos] < 0xF0) - { - // 3字节UTF-8字符 - if (input_pos + 2 < input_len) - { - unicode_char = ((unsigned char)input_str[input_pos] & 0x0F) << 12 | - ((unsigned char)input_str[input_pos + 1] & 0x3F) << 6 | - ((unsigned char)input_str[input_pos + 2] & 0x3F); - char_end = input_pos + 3; - valid_utf8 = true; - } - } - else if ((unsigned char)input_str[input_pos] >= 0xF0 && (unsigned char)input_str[input_pos] < 0xF8) - { - // 4字节UTF-8字符 - if (input_pos + 3 < input_len) - { - unicode_char = ((unsigned char)input_str[input_pos] & 0x07) << 18 | - ((unsigned char)input_str[input_pos + 1] & 0x3F) << 12 | - ((unsigned char)input_str[input_pos + 2] & 0x3F) << 6 | - ((unsigned char)input_str[input_pos + 3] & 0x3F); - char_end = input_pos + 4; - valid_utf8 = true; - } - } - - if (!valid_utf8) - { - // 无效的UTF-8字符,跳过 - input_pos++; - continue; - } - - // 使用GetGlyphPathData接口检查字符是否可以在字体中显示 - bool char_supported = true; - - // 对于ASCII字符,直接支持 - if (unicode_char < 0x80) - { - char_supported = true; - } - else - { - // 使用字体引擎检查字符是否支持 - OHOS::UIFont *fontEngine = OHOS::UIFont::GetInstance(); - if (fontEngine != NULL) - { - // 使用GetGlyphPathData检查字符是否支持 - OHOS::GlyphPathData path; - if (!fontEngine->GetGlyphPathData(unicode_char, 0, path)) - { - // 字符不支持,标记为不支持 - char_supported = false; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Character 0x%X not supported by font engine\n", unicode_char); - } - else - { - // 字符支持 - char_supported = true; - } - } - else - { - // 字体引擎不可用,使用简化的字符范围检查 - if (unicode_char >= 0x4E00 && unicode_char <= 0x9FFF) - { - // 中文字符范围 - char_supported = true; - } - else if (unicode_char >= 0xAC00 && unicode_char <= 0xD7AF) - { - // 韩文字符范围 - char_supported = true; - } - else if (unicode_char >= 0x3040 && unicode_char <= 0x309F) - { - // 平假名 - char_supported = true; - } - else if (unicode_char >= 0x30A0 && unicode_char <= 0x30FF) - { - // 片假名 - char_supported = true; - } - else if (unicode_char >= 0x2000 && unicode_char <= 0x206F) - { - // 标点符号 - char_supported = true; - } - else - { - // 其他字符,标记为不支持 - char_supported = false; - } - } - } - - if (char_supported) - { - // 字符支持,复制到输出缓冲区 - uint32_t char_len = char_end - char_start; - if (output_pos + char_len < max_len) - { - memcpy(&output_str[output_pos], &input_str[char_start], char_len); - output_pos += char_len; - } - else - { - break; // 输出缓冲区已满 - } - } - else - { - // 字符不支持,跳过不支持的字符 - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Unsupported character: 0x%X, skipping\n", unicode_char); - } - - input_pos = char_end; - } - - // 确保输出字符串以null结尾 - output_str[output_pos] = '\0'; - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Filtered string: '%s' -> '%s' (length: %d)\n", - input_str, output_str, output_pos); - - return output_pos; - } - - /** - * @brief 过滤chat结果中的无法显示字符 - * @param result chat识别结果字符串 - * @return 过滤后的字符串长度,-1表示失败 - */ - int32_t chat_filter_result_chars(char *result) - { - if (result == NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, " result string is NULL\n"); - return -1; - } - - uint32_t max_len = strlen(result) + 1; - char *temp_buffer = (char *)malloc(max_len); - if (temp_buffer == NULL) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Failed to allocate memory for temp buffer\n"); - return -1; - } - - int32_t filtered_len = chat_filter_unsupported_chars(result, temp_buffer, max_len); - if (filtered_len >= 0) - { - strcpy(result, temp_buffer); - } - - free(temp_buffer); - return filtered_len; - } - -#include "bleEvent.h" -#include "bleInstruct.h" - - void ble_set_ai_Question_str_(char *buf) - { - printf("ble_set_ai_Question_str_ %s\n",buf); - OHOS::AiVoiceModel::GetInstance().SetUserQuestionStr(std::string(buf)); - } - - void ble_set_ai_Answer_str_(char *buf, uint8_t type) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ble_set_ai_Answer_str_:%s,type:%d",buf,type); - // chat_filter_result_chars(buf); - OHOS::AiVoiceModel::GetInstance().SetAiAnswerStrStr(std::string(buf), type); - } - - void ble_app_reply_(bool data) - { - bool state = data; - printf("ble_app_reply_:%d\n",state); - SendMsgToUIService(UI_AI_JUMP_TO_LISTENING_VIEW, 0, &state, sizeof(bool)); - } - - extern bleInstruct_t_ bleInstruct_t; - - void ble_AI_init(void) - { - bleInstruct_t.ble_set_ai_Question_str = ble_set_ai_Question_str_; - - bleInstruct_t.ble_set_ai_Answer_str = ble_set_ai_Answer_str_; - bleInstruct_t.ble_app_reply = ble_app_reply_; - } - - /* - * WebSocket 聊天结果过滤回调包装,匹配 ws_register_chat_filter_callback 的签名 - */ - static void ws_chat_filter_cb_wrapper(char *result) - { - /* 复用现有过滤实现,忽略返回长度 */ - chat_filter_result_chars(result); - } - - void net4g_AI_init(void) - { - ws_register_chat_filter_callback(ws_chat_filter_cb_wrapper); - ws_register_ai_question_callback(ble_set_ai_Question_str_); - ws_register_ai_answer_callback(ble_set_ai_Answer_str_); - } - -#endif - -#ifdef __cplusplus -#if __cplusplus -} -#endif /* __cplusplus */ -#endif /* __cplusplus */ \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp deleted file mode 100644 index 8c5b80028..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoicePresenter.cpp +++ /dev/null @@ -1,868 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-20 15:11:17 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-19 10:24:14 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp - */ -#include "AppViewIDs.h" -#include "NativeAbility.h" -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AiVoiceView.h" -#include "aivoice/include/AiVoiceModel.h" -#include "common/key_code.h" -#include -#include "UiConfig.h" -#include "iostream" -#include // For std::string -#include // For std::unordered_map - -#ifdef SUPPORT_BLE_SERVICE -#include -#include "bleService.h" -#endif - -#include -#include "gfx_utils/mem_check.h" -#include "player/include/PlayersModel.h" -#include "NativeRegisterManager.h" -#include "aivoice/include/AiVoiceSelectView.h" -#include "graphic_service.h" -#include "websocket_server_manager.h" -#include "custom_utils.h" -namespace OHOS -{ - - REGIST_MENU_PRO(VIEW_AI_VOICE, AiVoiceView, AiVoicePresenter, - PNG_APPLIST_AIVOICE_IMAGE_BIG, PNG_APPLIST_AIVOICE_IMAGE, PNG_APPLIST_AIVOICE_IMAGE, "星辰AI", STR_AI_FAMILY_MEALS); - -#ifdef __cplusplus - extern "C" - { -#endif -#include "pm.h" -#include "pm_veto.h" -#include -#include -#include - - void remove_4GAI_vote(void) - { - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_4G_AI); - if (cnt == 1) - { - uapi_pm_remove_sleep_veto(PM_ID_4G_AI); - } - } - - void add_4GAI_vote(void) - { - uint8_t cnt = pm_veto_get_id_cnt(PM_ID_4G_AI); - if (cnt == 0) - { - uapi_pm_add_sleep_veto(PM_ID_4G_AI); - } - } - -#ifdef __cplusplus - } -#endif -#define BLE_CONNECT_INTERVAL_HIGH_AI 10 - // 当前Presenter属性实例化的内存指针 - static AiVoicePresenter *g_pAiVoicePresenter = nullptr; - - AiVoicePresenter::AiVoicePresenter() - { -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(true); -#endif - model = &AiVoiceModel::GetInstance(); - g_pAiVoicePresenter = this; - } - - AiVoicePresenter::~AiVoicePresenter() - { -#ifdef MEM_CHECK - MemCheck::GetInstance()->EnableLeakCheck(false); -#endif - g_pAiVoicePresenter = nullptr; - } - - AiVoicePresenter *AiVoicePresenter::GetInstance() - { - return g_pAiVoicePresenter; - } - - // 启动时执行的逻辑 - void AiVoicePresenter::OnStart() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStart"); - ScreenAlwaysOnCtr(OPEN_SCREEN_ALWAYS_ON); - // 开启一个60s取消长亮屏timer - model->ai_start_screen60s_timer(); - add_4GAI_vote(); // 4g投票 - - net4g_AI_init(); - uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_HIGH_AI); - Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_VOICE_ASSISTANT, 100); - } - - // 页面完全置于后台时的逻辑。 - void AiVoicePresenter::OnStop(void) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop start"); - ScreenAlwaysOnCtr(CANCEL_SCREEN_ALWAYS_ON); - model->StatusResume(); - model->AIVoice_StopTimer(); - model->ai_stop_screen60s_timer(); - model->stop_listening_timer(); - model->stop_ai_isready_timer(); - model->stop_ai4g_connect_timer(); - model->stop_ai4g_tts_play_timer(); - model->stop_update_ai_answer_timer(); - model->stop_uapi_stop_tts_timer(); - remove_4GAI_vote(); // 移除4g投票 - -#ifdef SUPPORT_AI_SERVICE - uapi_stop_all_websocket_servers(); - uapi_destroy_all_websocket_servers(); -#endif - - uapi_ble_connect_param_update(BLE_CONNECT_INTERVAL_SLOW); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnStop end"); - return; - } - - void AiVoicePresenter::OnResume() - { - RootView::GetInstance()->SetOnKeyActListener(this); - } - - /*调转到返回结果界面*/ - bool AiVoicePresenter::JumpToReturnResultTextView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView"); - if (model->GetSelect4gorbt() == AI_SELECT_4G) - { - preHeight = 0; - if (model->GetCurView() == AIVOICE_LISTENING_VIEWID || model->GetCurView() == AIVOICE_THINKING_VIEWID) - { - if (view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID) || view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)) - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_RETURN_RESULT_TEXT_VIEWID); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::JumpToReturnResultTextView fail"); - return false; - } - } - } - else if (model->GetSelect4gorbt() == AI_SELECT_BT) - { - 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; - } - - /*跳转到AI聆听界面界面*/ - bool AiVoicePresenter::ChangeToAIVoiceListeningView(bool val) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeToAIVoiceListeningView"); - if (model->GetSelect4gorbt() == AI_SELECT_4G) - { - if (val) /*如果查询的AI模型可用跳转到聆听中界面*/ - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_LISTENING_VIEWID); - } - else - { - if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT) // 如果当前是在chatgpt模型*/ - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - } - else - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID); - } - } - } - else if (model->GetSelect4gorbt() == AI_SELECT_BT) - { - if (view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING) != nullptr && view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->IsVisible()) - { - if (val) /*如果查询的AI模型可用跳转到聆听中界面*/ - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_LISTENING_VIEWID); - } - else - { - if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT) // 如果当前是在chatgpt模型*/ - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - } - else - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID); - } - } - } - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeToAIVoiceListeningView fail"); - return false; - } - return true; - } - - bool AiVoicePresenter::ChangeToAIVoiceConnectTimeoutView() - { - if ((view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID) != nullptr) && - (view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->IsVisible())) - { - ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_CONNECT_TIMEOUT_VIEWID); - AivoiceConnectTimeoutView *p_AivoiceConnectTimeoutView = AivoiceConnectTimeoutView::GetInstance(); - if (p_AivoiceConnectTimeoutView) - { - p_AivoiceConnectTimeoutView->UpdateNoteText(); - } - } - return true; - } - - void AiVoicePresenter::FunctionKeyOnClickToChangeAIModel(void) - { - if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true) - { - int index = model->GetSelectAiModel() + 1; - if (index >= AIMODES_MAX_NUM) - { - index = 0; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiModelsPresenter::index = %d", index); - model->SetSelectAiModel(index); - view_->ChangeAiModelAndUpdateComponentsStatus(); - model->reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer - } - return; - } - - // 右滑切换模型 - void AiVoicePresenter::DragLeftToRightChangeAIModel(void) - { - if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true) - { - int index = model->GetSelectAiModel() - 1; - if (index < 0) - { - index = AIMODES_CHATGPT; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiModelsPresenter::index = %d", index); - model->SetSelectAiModel(index); - view_->ChangeAiModelAndUpdateComponentsStatus(); - } - return; - } - - // 左滑切换模型 - void AiVoicePresenter::DragRightToLetfChangeAIModel(void) - { - if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true) - { - int index = model->GetSelectAiModel() + 1; - if (index >= AIMODES_MAX_NUM) - { - index = 0; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiModelsPresenter::index = %d", index); - model->SetSelectAiModel(index); - view_->ChangeAiModelAndUpdateComponentsStatus(); - } - return; - } - - bool AiVoicePresenter::ChangeViewAndLogicOperator(int16_t hideView, int16_t showView) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::ChangeViewOperator"); - - // 加锁,作用域结束时自动释放锁 - // std::lock_guard lock(m_mutex); - - bool isSameView = (hideView == showView); - if (isSameView) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Same view no need to change"); - return false; - } - if (hideView > MAX_AIVOICE_VIEWID) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Overstep ones bounds"); - return false; - } - - /* ------------------------ 进行界面切换的时候重置60s取消常亮屏timer ------------------------ */ - model->reset_ai_screen60s_timer_time(); - /* -------------------------------------------------------------------------- */ - view_->ChangeView(hideView, showView); // 默认先进行视图切换 - - switch (hideView) - { - case AIVOICE_STARTCHAT_VIEWID: - break; - - case AIVOICE_AIMODE_CONNECTING: - model->stop_ai_isready_timer(); // 停止定时器 - break; - - case AIVOICE_LISTENING_VIEWID: - model->StopListenAndRecordingUserQuestion(); - model->stop_listening_timer(); - break; - - case AIVOICE_THINKING_VIEWID: - model->AIVoice_StopTimer(); - break; - - case AIVOICE_RETURN_RESULT_TEXT_VIEWID: - AiVoiceModel::GetInstance().ClearQuestionAndAiAnswerStr(); // 清空上次用户问题和Ai回答字符串 - AiVoiceModel::GetInstance().SetIsClickable(false); - AiVoiceModel::GetInstance().SetIsLimitDisplayed(false); - AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); - AiVoiceModel::GetInstance().stop_update_ai_answer_timer(); - AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer(); - break; - - case AIVOICE_4GSERVICECON_VIEW: - model->stop_ai4g_connect_timer(); - break; - default: - // Handle other cases if needed - break; - } - - switch (showView) - { - case AIVOICE_AIMODE_CONNECTING: - model->QuerySelectedAiModelIsConnect(); - AiVoiceModel::GetInstance().start_ai_isready_timer(); - break; - case AIVOICE_RETURN_RESULT_TEXT_VIEWID: - break; - case AIVOICE_LISTENING_VIEWID: - AiVoiceModel::GetInstance().StartListenAndRecordingUserQuestion(); - AiVoiceModel::GetInstance().start_listening_timer(); - break; - - case AIVOICE_THINKING_VIEWID: - AiVoiceModel::GetInstance().AIVoice_StartTimer(); - break; - - default: - break; - } - - return true; - } - - void AiVoicePresenter::JumpThinkingView(void) - { - if ((view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID) != nullptr) && - (view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->IsVisible())) - { - ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); - } - return; - } - - // 处理手点击屏幕切换AI模型 - bool AiVoicePresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnClick"); - - model->reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer - - if (strcmp(view.GetViewId(), AIVOICE_IMGAE_VIEW_ID) == 0) /*点击的是Ai模型就切换模型*/ - { - int index = model->GetSelectAiModel() + 1; - if (index >= AIMODES_MAX_NUM) - { - index = 0; - } - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiModelsPresenter::index = %d", index); - model->SetSelectAiModel(index); - view_->ChangeAiModelAndUpdateComponentsStatus(); - } - - return true; - } - - bool AiVoicePresenter::OnPress(UIView &view, const PressEvent &event) - { - UNUSED(event); - std::string viewId = view.GetViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnPress %s", viewId.c_str()); - /* ----------------------------- 重置60s取消常亮屏timer ---------------------------- */ - model->reset_ai_screen60s_timer_time(); - /* -------------------------------------------------------------------------- */ - if (viewId == AIVOICE_APIKEYS_BUTTON_VIEW_ID) // 如果点击的是API Keys按钮(注:暂时不用) - { - if (model->IsExistOpenAIAPIKeys() == true) - { - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_SETAPIKEYS); /*开始对话界面->API Keys set界面*/ - } - else - { - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - } - return true; - } - else if (viewId == AIVOICE_START_CHAT_BUTTON_VIEW_ID) // 如果点击的是开始对话按钮 - { - PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐 - PlayersModel::GetInstance()->PlayerPause(); // 暂停手机音乐 - /* - * 进入对话流程: - * 1.当手表4G网络正常+与app连接正常 -> 通过4G调用大模型 - * 2.只有手表4G网络正常 -> 通过4G调用大模型 - * 3.只有与APP蓝牙连接正常 -> 通过蓝牙连接APP调用大模型 - * 4.两者连接都异常 -> 返回错误 - */ - bool netWork4GState = model->GetMobileDataIsOpen(); - bool appBluetoothConnectState = model->GetAPPBluetoothIsConnect(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "netWork4GState = %d,appBluetoothConnectState = %d", netWork4GState, appBluetoothConnectState); - - model->SetAI_4G_state(netWork4GState); - model->SetAI_BT_state(appBluetoothConnectState); - if ((netWork4GState && appBluetoothConnectState)) - { - // 获取用户上次的选择 - int lastSelectedType = model->GetSelect4gorbt(); - // 两者都可用,检查是否有上次的选择 - if (lastSelectedType == AI_SELECT_4G) - { - // 使用4G - model->SetSelect4gorbt(AI_SELECT_4G); - if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT) // 如果当前是在chatgpt模型*/ - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - return true; - } - if (!model->GetInit_4gai_task()) - { -// init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType()); -#ifdef SUPPORT_AI_SERVICE - uapi_init_all_websocket_servers(); - uapi_start_all_websocket_servers(0); // 连接服务器 -#endif - model->start_ai4g_connect_timer(); - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING - } - else - { - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING - } - } - else if (lastSelectedType == AI_SELECT_BT) - { - // 使用蓝牙 - model->SetSelect4gorbt(AI_SELECT_BT); - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING - } - else - { - // 没有上次的选择,让用户选择 - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_SELECT_VIEW); // LOADING - } - } - else if (netWork4GState) // 1.手表4G网络正常 - { - // 通过4G调用大模型 - model->SetSelect4gorbt(AI_SELECT_4G); - if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT) // 如果当前是在chatgpt模型*/ - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - return true; - } - if (!model->GetInit_4gai_task()) - { - /* -------------------------------------------------------------------------- */ - // init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType()); -#ifdef SUPPORT_AI_SERVICE - uapi_init_all_websocket_servers(); - uapi_start_all_websocket_servers(0); // 连接服务器 -#endif - /* -------------------------------------------------------------------------- */ - model->start_ai4g_connect_timer(); - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_4GSERVICECON_VIEW); // LOADING - } - else - { - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING - } - } - else if (appBluetoothConnectState) // 3.只有与APP蓝牙连接正常 - { - // 通过蓝牙连接APP调用大模型 - model->SetSelect4gorbt(AI_SELECT_BT); - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_AIMODE_CONNECTING); // LOADING - } - else // 4.两者连接都异常 - { - // 返回错误 - model->SetSelect4gorbt(AI_SELECT_DEFAULT); - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID); - } - return true; - } - else if (viewId == FINISH_SPEAKING_BUTTON_VIEW_ID) // 如果点击的是说话完毕按钮 - { - ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_THINKING_VIEWID); - return true; - } - else if (viewId == AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID) // 如果点击的是4G连接方式 - { - // 通过4G调用大模型 - model->SetSelect4gorbt(AI_SELECT_4G); - if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT) // 如果当前是在chatgpt模型*/ - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - return true; - } - if (!model->GetInit_4gai_task()) - { - // init_ai_task(AiVoiceModel::GetInstance().GetCurUsing4GAiModelType()); -#ifdef SUPPORT_AI_SERVICE - uapi_init_all_websocket_servers(); - uapi_start_all_websocket_servers(0); // 连接服务器 -#endif - model->start_ai4g_connect_timer(); - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_4GSERVICECON_VIEW); // LOADING - } - else - { - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_AIMODE_CONNECTING); // LOADING - } - return true; - } - else if (viewId == AIVOICE_SELECT_VIEW_BUTTONBT_VIEW_ID) // 如果点击的是蓝牙连接方式 - { - model->SetSelect4gorbt(AI_SELECT_BT); - ChangeViewAndLogicOperator(model->GetCurView(), AIVOICE_AIMODE_CONNECTING); - return true; - } - - std::unordered_map> viewIdMap = { - {AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面,并清除手表聊天记录 - {AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID, {AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_LISTENING_VIEWID}}, // 返回继续聆听,并清除手表聊天记录 - }; - auto it = viewIdMap.find(viewId); - if (it != viewIdMap.end()) - { - if (it->first == AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID) // 点击继续对话按钮要发取消当前对话指令,避免AI回应中途按继续对话按钮没有取消上一次对话问题 - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "CancelCurAIChat"); - PlayersModel::GetInstance()->HandPausePhoneMusic(); // 暂停手机音乐 - PlayersModel::GetInstance()->PlayerPause(); // 暂停手机音乐 - if (model->GetSelect4gorbt() == AI_SELECT_4G) - { - AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); - AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer(); - ChangeViewAndLogicOperator(AIVOICE_RETURN_RESULT_TEXT_VIEWID, AIVOICE_AIMODE_CONNECTING); - return true; - } - else if (model->GetSelect4gorbt() == AI_SELECT_BT) - { - AiVoiceModel::GetInstance().CancelCurAIChat(); - AiVoiceModel::GetInstance().sendAIIsReady(); - } - } - else if (it->first == AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID) - { - if (model->GetSelect4gorbt() == AI_SELECT_4G) - { - AiVoiceModel::GetInstance().stop_ai4g_tts_play_timer(); - AiVoiceModel::GetInstance().stop_uapi_stop_tts_timer(); -#ifdef SUPPORT_AI_SERVICE - uapi_stop_all_websocket_servers(); - uapi_destroy_all_websocket_servers(); -#endif - } - } - ChangeViewAndLogicOperator(it->second.first, it->second.second); - return true; - } - - std::unordered_map> viewIdMap2 = { - {ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID, {AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - {AIMODEL_CONNECT_FAILED_ENSURE_BUTTON_VIEW_ID, {AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - {AIVOICECONNECTTIMEOUT_ENSURE_BUTTON_VIEW_ID, {AIVOICE_CONNECT_TIMEOUT_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - {CANCEL_THINKING_BUTTON_VIEW_ID, {AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - {AIVOICECONNECTINGVIEW_CANCEL_BUTTON_VIEW_ID, {AIVOICE_AIMODE_CONNECTING, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面 - }; - it = viewIdMap2.find(viewId); - if (it != viewIdMap2.end()) - { - if (it->first != ALERT_APPBLUETOOTH_AND_4GNETWORK_ENSURE_BUTTON_VIEW_ID) - { - if (model->GetSelect4gorbt() == AI_SELECT_4G) - { - // dinit_ai_task(); -#ifdef SUPPORT_AI_SERVICE - uapi_stop_all_websocket_servers(); - uapi_destroy_all_websocket_servers(); -#endif - } - } - ChangeViewAndLogicOperator(it->second.first, it->second.second); - return true; - } - return true; - } - bool AiVoicePresenter::OnRelease(UIView &view, const ReleaseEvent &event) - { - return true; - } - - bool AiVoicePresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - AiVoicePresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool AiVoicePresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnDragEnd"); - UIScrollView *scrollView = dynamic_cast(&view); - if (scrollView == nullptr) - { - return false; - } - - model->reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer - - if (event.GetDragDirection() == DragEvent::DIRECTION_RIGHT_TO_LEFT) /*左滑*/ - { - DragRightToLetfChangeAIModel(); - } - else if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && AiVoicePresenter::X_DRAG_FLAG) /*右滑*/ - { - if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)) - { - // 开始对话界面,右滑切换界面 - DragLeftToRightChangeAIModel(); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID)) - { - /*APP蓝牙与4G网络都连接异常界面右滑退回到开始对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, AIVOICE_STARTCHAT_VIEWID); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID)) - { - /*模型连接失败弹窗界面右滑退回到开始对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, AIVOICE_STARTCHAT_VIEWID); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)) - { - if (model->GetSelect4gorbt() == AI_SELECT_4G) - { - return true; - } - /*聆听中界面右滑退回到AI对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_LISTENING_VIEWID, AIVOICE_STARTCHAT_VIEWID); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)) - { - if (model->GetSelect4gorbt() == AI_SELECT_4G) - { - return true; - } - /*思考中界面右滑退到AI对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_CONNECT_TIMEOUT_VIEWID)) - { - /*连接超时界面右滑退到AI对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_CONNECT_TIMEOUT_VIEWID, AIVOICE_STARTCHAT_VIEWID); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)) - { - /*连接超时界面右滑退到AI对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_AIMODE_CONNECTING, AIVOICE_STARTCHAT_VIEWID); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_SELECT_VIEW)) - { - /*连接超时界面右滑退到AI对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_SELECT_VIEW, AIVOICE_STARTCHAT_VIEWID); - } - else if (scrollView == view_->GetAiVoiceScrollView(AIVOICE_VOLUME_VIEW)) - { - /*连接超时界面右滑退到AI对话界面*/ - ChangeViewAndLogicOperator(AIVOICE_VOLUME_VIEW, AIVOICE_STARTCHAT_VIEWID); - } - AiVoicePresenter::X_DRAG_FLAG = false; - } - else if (model->GetAiModelTextId() == STR_AIMODES_CHATGPT && event.GetDragDirection() == DragEvent::DIRECTION_BOTTOM_TO_TOP) /*上滑*/ - { - // 如果选择的模型是在chatgpt - if (model->IsExistOpenAIAPIKeys() == true) - { - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_SETAPIKEYS); /*开始对话界面->API Keys set界面*/ - } - else - { - ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/ - } - } - return true; - } - - bool AiVoicePresenter::OnKeyAct(UIView &view, const KeyEvent &event) // 增加按键事件 - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnKeyAct"); - uint16_t keyID = event.GetKeyId(); - uint16_t keyState = event.GetState(); - // 如果是power键,且是亮屏状态,按键释放就返回上一级 - if (keyID == static_cast(ZliteKeyCode::ZLITE_KEY_POWER) && keyState == 1 && uapi_get_screen_state() == 0) - { - NativeAbility::GetInstance().Back(); - if (model->GetSelect4gorbt() == AI_SELECT_BT) - { - AiVoiceModel::GetInstance().CancelCurAIChat(); - } - } - return true; - } - - void AiVoicePresenter::OnPickerStoped(UIPicker &picker) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnPickerStoped,%d", picker.GetSelected()); - if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true) - { - model->SetSelectAiModel(picker.GetSelected()); - view_->ChangeAiModelAndUpdateComponentsStatus(); - } - return; - } - - // 计算聊天内容ItemView的高度 - void AiVoicePresenter::calculateChatContentItemViewHeight(std::string text, bool flag) - { - const char *Text = text.c_str(); - UILabel label; - label.SetPosition(53, 100); - label.Resize(flag ? 280 : 200, 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_EN, 26); - - if (label.GetTextHeight() > preHeight) - { - preHeight = label.GetTextHeight(); - isScroll = true; - 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; - } - - void AiVoicePresenter::ChangeVolume(UIView &view, const RotateEvent &event) - { - if ((view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID) != nullptr) && - (view_->GetAiVoiceScrollView(AIVOICE_RETURN_RESULT_TEXT_VIEWID)->IsVisible())) - { - UISlider *slider = dynamic_cast(&view); - if (slider) - { - int value = slider->GetValue(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "volume:%d front", value); - if (event.GetRotate() <= 0) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "222"); - value += 20; - if (value > 100) - { - value = 100; - } - } - else - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "111"); - value -= 20; - if (value < 0) - { - value = 0; - } - } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "volume:%d end", value); - do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_TYPE_CHANGE_SYSTEM_VOLUME, (void *)(&value), sizeof(value)); - } - } - } - - bool AiVoicePresenter::OnRotate(UIView &view, const RotateEvent &event) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotate"); - static uint32_t lastCallTime = 0; - const uint32_t MIN_INTERVAL = 500; // 最小间隔500ms - - uint32_t currentTime = event.GetTimeStamp(); - - // 计算时间间隔 - uint32_t interval = currentTime - lastCallTime; - - // 仅当间隔大于500ms时才调用ChangeVolume - if (interval >= MIN_INTERVAL) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotate: 允许调用ChangeVolume, 间隔: %ums", interval); - ChangeVolume(view, event); - lastCallTime = currentTime; - } - else - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotate: 忽略调用ChangeVolume, 间隔: %ums (需要>500ms)", interval); - } - - return true; - } - - bool AiVoicePresenter::OnRotateEnd(UIView &view, const RotateEvent &event) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRotateEnd"); - // if (view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID) && view_->GetAiVoiceScrollView(AIVOICE_STARTCHAT_VIEWID)->IsVisible() == true) - // { - // ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_VOLUME_VIEW); - // } - ChangeVolume(view, event); - return true; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceSelectView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceSelectView.cpp deleted file mode 100644 index 934c24202..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceSelectView.cpp +++ /dev/null @@ -1,175 +0,0 @@ -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AiVoiceSelectView.h" -#include "wearable_log.h" - -namespace OHOS -{ - static AiVoiceSelectView *g_pAivoiceSelectView{nullptr}; - AiVoiceSelectView::AiVoiceSelectView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::AiVoiceSelectView"); - g_pAivoiceSelectView = this; - } - AiVoiceSelectView::~AiVoiceSelectView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::~AiVoiceSelectView"); - ClearAll(); - g_pAivoiceSelectView = nullptr; - } - - AiVoiceSelectView *AiVoiceSelectView::GetInstance(void) - { - return g_pAivoiceSelectView; - } - - void AiVoiceSelectView::ClearAll(void) - { - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - delete title; - title = nullptr; - delete label4g; - label4g = nullptr; - delete labelbt; - labelbt = nullptr; - delete button4g; - button4g = nullptr; - delete buttonbt; - buttonbt = nullptr; - delete scrollView; - scrollView = nullptr; - } - } - - UIScrollView *AiVoiceSelectView::CreateAiVoiceSelectView(void) - { - if (scrollView == nullptr) - { - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::scrollView new fail!"); - return nullptr; - } - } - scrollView->SetPosition(0, 0, 466, 466); - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::dragListener new fail!"); - return nullptr; - } - scrollView->SetOnDragListener(dragListener); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - /* -------------------------------------------------------------------------- */ - if (title == nullptr) - { - title = new UILabelExt(); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!"); - return nullptr; - } - } - title->SetPosition(83, 50, 300, 35); - title->SetStyle(STYLE_TEXT_FONT, 30); - title->SetStyle(STYLE_LINE_HEIGHT, 35); - title->SetText("AI对话"); - title->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); - title->SetRollSpeed(23); - title->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - title->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - scrollView->Add(title); - /* -------------------------------------------------------------------------- */ - int y1 = 123; - if (label4g == nullptr) - { - label4g = new UILabelExt(); - if (label4g == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!"); - return nullptr; - } - } - label4g->SetPosition(83, y1 + 33, 300, 35); - label4g->SetStyle(STYLE_TEXT_FONT, 30); - label4g->SetStyle(STYLE_LINE_HEIGHT, 35); - label4g->SetText("4G连接"); - label4g->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); - label4g->SetRollSpeed(23); - label4g->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label4g->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - /* -------------------------------------------------------------------------- */ - int y2 = 243; - if (labelbt == nullptr) - { - labelbt = new UILabelExt(); - if (labelbt == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!"); - return nullptr; - } - } - labelbt->SetPosition(83, y2 + 33, 300, 35); - labelbt->SetStyle(STYLE_TEXT_FONT, 30); - labelbt->SetStyle(STYLE_LINE_HEIGHT, 35); - labelbt->SetText("蓝牙连接"); - labelbt->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); - labelbt->SetRollSpeed(23); - labelbt->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - labelbt->SetFont(DEFAULT_VECTOR_FONT_FILENAME, 30); - /* -------------------------------------------------------------------------- */ - if (button4g == nullptr) - { - button4g = new UIButton(); - if (button4g == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!"); - return nullptr; - } - } - button4g->SetPosition(43, 123, 380, 100); - button4g->SetViewId(AIVOICE_SELECT_VIEW_BUTTON4G_VIEW_ID); - button4g->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button4g->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button4g->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - UIView::OnTouchListener *listener4g = static_cast(AiVoicePresenter::GetInstance()); - if (listener4g == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::listener4g new fail!"); - return nullptr; - } - button4g->SetOnTouchListener(listener4g); - /* -------------------------------------------------------------------------- */ - if (buttonbt == nullptr) - { - buttonbt = new UIButton(); - if (buttonbt == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::title new fail!"); - return nullptr; - } - } - buttonbt->SetPosition(43, 243, 380, 100); - buttonbt->SetViewId(AIVOICE_SELECT_VIEW_BUTTONBT_VIEW_ID); - buttonbt->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - buttonbt->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - buttonbt->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - UIView::OnTouchListener *listenerbt = static_cast(AiVoicePresenter::GetInstance()); - if (listenerbt == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::listenerbt new fail!"); - return nullptr; - } - buttonbt->SetOnTouchListener(listenerbt); - - scrollView->Add(button4g); - scrollView->Add(buttonbt); - scrollView->Add(label4g); - scrollView->Add(labelbt); - - return scrollView; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceView.cpp deleted file mode 100644 index a0a8fd7b0..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceView.cpp +++ /dev/null @@ -1,1202 +0,0 @@ -/* -* @Author: luozheng 1732036298@qq.com -* @Date: 2024-05-07 11:25:58 -* @LastEditors: luozheng 1732036298@qq.com -* @LastEditTime: 2025-03-06 16:07:08 -* @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 "ConfigModel.h" -#include "uiservice/include/ui_service.h" -namespace OHOS -{ - - static AiVoiceView *g_pAiVoiceView{nullptr}; - - AiVoiceView::AiVoiceView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::AiVoiceView"); - g_pAiVoiceView = this; - } - - AiVoiceView::~AiVoiceView() - { - ClearAll(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::~AiVoiceView"); - g_pAiVoiceView = nullptr; - } - - AiVoiceView *AiVoiceView::GetInstance() - { - return g_pAiVoiceView; - } - - void AiVoiceView::ClearAllAiVoiceScrollView(void) - { - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - delete scrollView; - scrollView = nullptr; - - delete VolumeProcess; - VolumeProcess = nullptr; - - delete title; - title = 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 buttonBgImage; - buttonBgImage = nullptr; - - delete upImage; - upImage = nullptr; - } - } - - void AiVoiceView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ClearAll"); - ClearAllAiVoiceScrollView(); - - if (p_AiVoiceBluetoothFailedStartView != nullptr) - { - delete p_AiVoiceBluetoothFailedStartView; - p_AiVoiceBluetoothFailedStartView = nullptr; - } - - if (p_AivoiceMobileDataFailedStartView != nullptr) - { - delete p_AivoiceMobileDataFailedStartView; - p_AivoiceMobileDataFailedStartView = nullptr; - } - - if (p_AivoiceConnectTimeoutView != nullptr) - { - delete p_AivoiceConnectTimeoutView; - p_AivoiceConnectTimeoutView = nullptr; - } - - if (p_AivoiceListeningView != nullptr) - { - delete p_AivoiceListeningView; - p_AivoiceListeningView = nullptr; - } - - if (p_AivoiceThinkingView != nullptr) - { - delete p_AivoiceThinkingView; - p_AivoiceThinkingView = nullptr; - } - - if (p_AivoiceReturnResultTextView != nullptr) - { - delete p_AivoiceReturnResultTextView; - p_AivoiceReturnResultTextView = nullptr; - } - - if (p_SetApiKeysView != nullptr) - { - delete p_SetApiKeysView; - p_SetApiKeysView = nullptr; - } - - if (p_NotSetApiKeysView != nullptr) - { - delete p_NotSetApiKeysView; - p_NotSetApiKeysView = nullptr; - } - - if (p_ApiKeysDeleteView != nullptr) - { - delete p_ApiKeysDeleteView; - p_ApiKeysDeleteView = nullptr; - } - - if (p_AiVoiceConnectingView != nullptr) - { - delete p_AiVoiceConnectingView; - p_AiVoiceConnectingView = nullptr; - } - if (p_AiVoiceSelectView != nullptr) - { - delete p_AiVoiceSelectView; - p_AiVoiceSelectView = nullptr; - } - if (p_Aivoice4gServiceConView != nullptr) - { - delete p_Aivoice4gServiceConView; - p_Aivoice4gServiceConView = nullptr; - } - if (p_AiVoiceVolumeView) - { - delete p_AiVoiceVolumeView; - p_AiVoiceVolumeView = nullptr; - } - for (int i = 0; i < MAX_AIVOICE_VIEWID; i++) - { - if (AiVoiceScrollView[i] != nullptr) - { - AiVoiceScrollView[i] = nullptr; - } - } - } - - UILabelExt *AiVoiceView::AiVoiceViewLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetRollSpeed(23); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - UIImageView *AiVoiceView::AiVoiceViewImageView(ImageConfig &imageconfig) - { - UIImageView *Image = new UIImageView(); - if (Image == nullptr) - { - return nullptr; - } - Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); - Image->SetSrc(imageconfig.src); - return Image; - } - - UIButton *AiVoiceView::AiVoiceViewButtonInit(ButtonConfig &buttonconfig) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff4fc34c); - button->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0x00, UIButton::PRESSED); - button->SetOnTouchListener(presenter_); - - return button; - } - - bool AiVoiceView::CreateAiVoiceViewLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewLabel"); - LabelConfig labelConfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = AiVoiceModel::GetInstance().GetAiModelTextId(), - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - title = AiVoiceViewLabelInit(labelConfig); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "title new fail!"); - return false; - } - /* ----------------------------- startChatLabel ----------------------------- */ - labelConfig = { - .left = 133, - .top = 348, - .width = 200, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_START_CHAT, /*开始对话*/ - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - startChatLabel = AiVoiceViewLabelInit(labelConfig); - if (startChatLabel == nullptr) - { - 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; - } - - bool AiVoiceView::CreateAiVoiceViewImageView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewImageView"); - ImageConfig imagecinfig = { - .x = 173, - .y = 143, - .w = 120, - .h = 120, - .src = "", - }; - - // 根据视图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::aiModelImage is nullptr!!"); - return false; - } - aiModelImage->SetTouchable(true); - aiModelImage->SetViewId(AIVOICE_IMGAE_VIEW_ID); - aiModelImage->SetOnClickListener(presenter_); - /* -------------------------------- buttonBgImage -------------------------------- */ - imagecinfig = { - .x = 208, - .y = 340, - .w = 48, - .h = 56, - .src = "/user/res/AIVoice/ai_chart_icon.bin", - }; - buttonBgImage = AiVoiceViewImageView(imagecinfig); - if (buttonBgImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::aiModelImage is nullptr!!"); - return false; - } - /* --------------------------------- upImage -------------------------------- */ - imagecinfig = { - .x = 213, - .y = static_cast(buttonBgImage->GetY() + buttonBgImage->GetHeight() + 10), - .w = 40, - .h = 40, - .src = "/user/res/Sleep/up.bin", - }; - upImage = AiVoiceViewImageView(imagecinfig); - if (upImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::aiModelImage is nullptr!!"); - return false; - } - upImage->SetVisible(false); - return true; - } - - bool AiVoiceView::CreateAiVoiceViewButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewButton"); - /* ----------------------------- startChatButton ---------------------------- */ - ButtonConfig buttonconfig = { - .x = 43, - .y = 328, - .w = 380, - .h = 80, - .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); - const char *image = "/user/res/AIVoice/ai_chart_icon_bg.bin"; - startChatButton->SetImageSrc(image, image); - /* ------------------------------- chatButton ------------------------------- */ - buttonconfig = { - .x = 43, - .y = 328, - .w = 380, - .h = 80, - // .ViewId = AIVOICE_CHAT_BUTTON_VIEW_ID, - .ViewId = AIVOICE_START_CHAT_BUTTON_VIEW_ID, - }; - chatButton = AiVoiceViewButtonInit(buttonconfig); - if (chatButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "chatButton new fail!"); - return false; - } - chatButton->SetVisible(false); - chatButton->SetImageSrc(image, image); - /* ------------------------------ 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, 0x00); - aiModelPicker->SetStyle(STYLE_BORDER_RADIUS, 150); - aiModelPicker->SetItemHeight(40); - aiModelPicker->SetLoopState(true); -#if defined(AI_VOICE_FD230) || defined(AI_VOICE_N9) -#else - aiModelPicker->SetRotateFactor(1.0); - aiModelPicker->RequestFocus(); -#endif - aiModelPicker->RegisterSelectedListener(presenter_); - // 设置文本颜色为透明 - aiModelPicker->SetTextColor(Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x00), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0x00)); - const char *uiPicker1Data[] = {"0", "1", "2", "3", "4", "5"}; - aiModelPicker->SetValues(uiPicker1Data, sizeof(uiPicker1Data) / sizeof(uiPicker1Data[0])); - // aiModelPicker->SetVisible(false);//屏蔽picker组件 - } - - return true; - } - - bool AiVoiceView::CreateAiVoiceScrollView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceScrollView"); - if (scrollView == nullptr) - { - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceScrollView[AIVOICE_STARTCHAT_VIEWID] new fail!"); - return false; - } - } - scrollView->SetPosition(0, 0, 466, 466); - scrollView->SetHorizontalScrollState(false); - scrollView->SetVerticalScrollState(false); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - scrollView->SetOnDragListener(presenter_); - return true; - } - - bool AiVoiceView::CreateAiVoiceVoiceView(void) - { - /* ------------------------------ VolumeProcess ----------------------------- */ - if (VolumeProcess == nullptr) - { - VolumeProcess = new UISlider(); - if (VolumeProcess == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "VolumeProcess new fail"); - return false; - } - VolumeProcess->SetSliderColor(Color::Gray(), Color::Silver()); - VolumeProcess->SetPosition(-200, 77, 130, 310); - VolumeProcess->SetDirection(UISlider::Direction::DIR_BOTTOM_TO_TOP); - VolumeProcess->SetRange(100, 0); - VolumeProcess->SetStyle(STYLE_BORDER_RADIUS, 100); - VolumeProcess->SetBackgroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); - VolumeProcess->SetForegroundStyle(STYLE_LINE_CAP, CapType::CAP_ROUND); - VolumeProcess->SetSliderColor(Color::GetColorFromRGBA(0x19, 0x19, 0x19, 0xff), Color::GetColorFromRGBA(0xff, 0xff, 0xff, 0xff)); - VolumeProcess->SetForegroundStyle(STYLE_BACKGROUND_OPA, 0xff); - VolumeProcess->SetKnobStyle(StyleDefault::GetSliderKnobStyle()); - VolumeProcess->RequestFocus(); - VolumeProcess->SetRotateFactor(5.0); - VolumeProcess->SetVisible(false); - VolumeProcess->SetOnRotateListener(presenter_); - AddViewToRootContainer(VolumeProcess); - } - return true; - } - - UIScrollView *AiVoiceView::CreateAiVoiceView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView"); - if (!CreateAiVoiceScrollView() || !CreateAiVoiceViewImageView() || !CreateAiVoiceViewPicker() || - !CreateAiVoiceViewLabel() || !CreateAiVoiceViewButton()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceView fail!"); - return nullptr; - } - // scrollView->Add(VolumeProcess); - scrollView->Add(title); - scrollView->Add(aiModelPicker); - scrollView->Add(aiModelImage); - scrollView->Add(startChatButton); - scrollView->Add(startChatLabel); - scrollView->Add(chatButton); - scrollView->Add(chatLabel); - scrollView->Add(apiKeysButton); - scrollView->Add(apiKeysLabel); - scrollView->Add(buttonBgImage); - scrollView->Add(upImage); - - return scrollView; - } - - void AiVoiceView::OnStart() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::OnStart"); - ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_AIMODE_CONNECTING); - GetAiVoiceScrollView(AIVOICE_AIMODE_CONNECTING)->SetVisible(false); - ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_LISTENING_VIEWID); - GetAiVoiceScrollView(AIVOICE_LISTENING_VIEWID)->SetVisible(false); - ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_THINKING_VIEWID); - GetAiVoiceScrollView(AIVOICE_THINKING_VIEWID)->SetVisible(false); - ChangeView(MAX_AIVOICE_VIEWID, AIVOICE_STARTCHAT_VIEWID); -#if defined(AI_VOICE_FD230) || defined(AI_VOICE_N9) - CreateAiVoiceVoiceView(); -#endif - - SetAiVoiceViewAllComponentsVisibilityStatus(); - - return; - } - - /*切换到开始对话Ai界面*/ - bool AiVoiceView::ChangeAiVoiceStartChatView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoiceStartChatView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - UIScrollView *scrollview = CreateAiVoiceView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - else - { - if (VolumeProcess) - { - VolumeProcess->RequestFocus(); - } - } - if (AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_BT) - { - AiVoiceModel::GetInstance().CancelCurAIChat(); - } - return true; - } - - /*切换到APP蓝牙或4G网络未连接界面界面*/ - bool AiVoiceView::ChangeAiVoiceBluetoothFailedStartView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoiceBluetoothFailedStartView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AiVoiceBluetoothFailedStartView = new AiVoiceBluetoothFailedStartView(); - if (p_AiVoiceBluetoothFailedStartView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_AiVoiceBluetoothFailedStartView->CreateAiVoiceBluetoothFailedStartView(); - UIScrollView *scrollview = p_AiVoiceBluetoothFailedStartView->CreateAiVoiceBluetoothFailedStartView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - return true; - } - - /*切换到模型连接失败界面*/ - bool AiVoiceView::ChangeAiVoiceMobileDataFailedStartView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoiceMobileDataFailedStartView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AivoiceMobileDataFailedStartView = new AivoiceMobileDataFailedStartView(); - if (p_AivoiceMobileDataFailedStartView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_AivoiceMobileDataFailedStartView->CreateAivoiceMobileDataFailedStartView(); - UIScrollView *scrollview = p_AivoiceMobileDataFailedStartView->CreateAivoiceMobileDataFailedStartView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - return true; - } - - /*切换到连接超时界面*/ - bool AiVoiceView::ChangeAiVoicConnectTimeoutView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicConnectTimeoutView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AivoiceConnectTimeoutView = new AivoiceConnectTimeoutView(); - if (p_AivoiceConnectTimeoutView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_AivoiceConnectTimeoutView->CreateAivoiceConnectTimeoutView(); - UIScrollView *scrollview = p_AivoiceConnectTimeoutView->CreateAivoiceConnectTimeoutView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - - return true; - } - - /*切换到聆听中界面*/ - bool AiVoiceView::ChangeAiVoicListeningView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicListeningView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AivoiceListeningView = new AivoiceListeningView(); - if (p_AivoiceListeningView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_AivoiceListeningView->CreateAivoiceListeningView(); - UIScrollView *scrollview = p_AivoiceListeningView->CreateAivoiceListeningView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - if (p_AivoiceListeningView) - { - p_AivoiceListeningView->StartOrStopAivoiceListeningImageAnimatorView(true); - p_AivoiceListeningView->GetShowtimeoutLabel()->SetText("10"); - p_AivoiceListeningView->GetShowtimeoutLabel()->Invalidate(); - } - return true; - } - - /*切换到思考中界面*/ - bool AiVoiceView::ChangeAiVoicThinkingView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicThinkingView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AivoiceThinkingView = new AivoiceThinkingView(); - if (p_AivoiceThinkingView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_AivoiceThinkingView->CreateAivoiceThinkingView(); - UIScrollView *scrollview = p_AivoiceThinkingView->CreateAivoiceThinkingView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - if (p_AivoiceThinkingView) - { - p_AivoiceThinkingView->StartOrStopAiVoiceThinkingImageAnimatorView(true); - } - return true; - } - - /*切换到返回结果文本界面*/ - bool AiVoiceView::ChangeAiVoicReturnResultTextView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicReturnResultTextView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - AiVoiceModel::GetInstance().SetChatContentListCount(0); - p_AivoiceReturnResultTextView = new AivoiceReturnResultTextView(); - if (p_AivoiceReturnResultTextView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_AivoiceReturnResultTextView->CreateAivoiceReturnResultTextView(); - UIScrollView *scrollview = p_AivoiceReturnResultTextView->CreateAivoiceReturnResultTextView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - if (!AiVoiceModel::GetInstance().GetUserQuestionStr().empty()) - { - SendMsgToUIService(UI_UPDATE_USER_QUESTION_STR, 0, nullptr, 0); - } - if(AiVoiceModel::GetInstance().GetSelect4gorbt() == AI_SELECT_4G) - { - if (VolumeProcess) - { - VolumeProcess->SetVisible(true); - } - } - return true; - } - - /*切换到setapikeys界面*/ - bool AiVoiceView::ChangeAiVoicSetApiKeysView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicSetApiKeysView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_SetApiKeysView = new SetApiKeysView(); - if (p_SetApiKeysView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_SetApiKeysView->CreateSetApiKeysView(); - UIScrollView *scrollview = p_SetApiKeysView->CreateSetApiKeysView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - return true; - } - - /*切换到notsetapikeys界面*/ - bool AiVoiceView::ChangeAiVoicNotSetApiKeysView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicNotSetApiKeysView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_NotSetApiKeysView = new NotSetApiKeysView(); - if (p_NotSetApiKeysView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_NotSetApiKeysView->CreateNotSetApiKeysView(); - UIScrollView *scrollview = p_NotSetApiKeysView->CreateNotSetApiKeysView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - return true; - } - - /*切换到apikeys删除界面*/ - bool AiVoiceView::ChangeAiVoicApiKeysDeleteView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicApiKeysDeleteView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_ApiKeysDeleteView = new ApiKeysDeleteView(); - if (p_ApiKeysDeleteView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_ApiKeysDeleteView->CreateApiKeysDeleteView(); - UIScrollView *scrollview = p_ApiKeysDeleteView->CreateApiKeysDeleteView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - return true; - } - - /*切换到AI正在连接中视图*/ - bool AiVoiceView::ChangeAiVoicConnectingView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicConnectingView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AiVoiceConnectingView = new AiVoiceConnectingView(); - if (p_AiVoiceConnectingView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - // AiVoiceScrollView[thisView] = p_AiVoiceConnectingView->CreateAiVoiceConnectingView(); - UIScrollView *scrollview = p_AiVoiceConnectingView->CreateAiVoiceConnectingView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - if(p_AiVoiceConnectingView) - { - p_AiVoiceConnectingView->StartOrStopAiVoiceConnectingImageAnimatorView(true); - } - return true; - } - - bool AiVoiceView::ChangeAiVoicSelectView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicSelectView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AiVoiceSelectView = new AiVoiceSelectView(); - if (p_AiVoiceSelectView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - UIScrollView *scrollview = p_AiVoiceSelectView->CreateAiVoiceSelectView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - return true; - } - - bool AiVoiceView::ChangeAiVoic4gServiceConView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoic4gServiceConView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_Aivoice4gServiceConView = new AiVoice4gServiceConView(); - if (p_Aivoice4gServiceConView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - UIScrollView *scrollview = p_Aivoice4gServiceConView->CreateAiVoice4gServiceConView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - if(p_Aivoice4gServiceConView) - { - p_Aivoice4gServiceConView->StartOrStopAiVoice4gServiceConImageAnimatorView(true); - } - return true; - } - - bool AiVoiceView::ChangeAiVoicVolumeView(int16_t thisView) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoic4gServiceConView"); - if (AiVoiceScrollView[thisView] == nullptr) - { - p_AiVoiceVolumeView = new AiVoiceVolumeView(); - if (p_AiVoiceVolumeView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - UIScrollView *scrollview = p_AiVoiceVolumeView->CreateAiVoiceVolumeView(); - if (scrollview == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "new AiVoiceScrollView[%d] fail", thisView); - return false; - } - AiVoiceScrollView[thisView] = scrollview; - AddViewToRootContainer(AiVoiceScrollView[thisView]); - } - return true; - } - - struct AiVoiceViewMapper - { - const int16_t viewId; - bool (AiVoiceView::*func)(int16_t thisView); - }; - - static const AiVoiceViewMapper ViewMapper[] = { - {AIVOICE_STARTCHAT_VIEWID, &AiVoiceView::ChangeAiVoiceStartChatView}, - {AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, &AiVoiceView::ChangeAiVoiceBluetoothFailedStartView}, - {AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, &AiVoiceView::ChangeAiVoiceMobileDataFailedStartView}, - {AIVOICE_CONNECT_TIMEOUT_VIEWID, &AiVoiceView::ChangeAiVoicConnectTimeoutView}, - {AIVOICE_LISTENING_VIEWID, &AiVoiceView::ChangeAiVoicListeningView}, - {AIVOICE_THINKING_VIEWID, &AiVoiceView::ChangeAiVoicThinkingView}, - {AIVOICE_RETURN_RESULT_TEXT_VIEWID, &AiVoiceView::ChangeAiVoicReturnResultTextView}, - {AIVOICE_SETAPIKEYS, &AiVoiceView::ChangeAiVoicSetApiKeysView}, - {AIVOICE_NOTSETAPIKEYS, &AiVoiceView::ChangeAiVoicNotSetApiKeysView}, - {AIVOICE_APIKEYS_DELETE, &AiVoiceView::ChangeAiVoicApiKeysDeleteView}, - {AIVOICE_AIMODE_CONNECTING, &AiVoiceView::ChangeAiVoicConnectingView}, - {AIVOICE_SELECT_VIEW, &AiVoiceView::ChangeAiVoicSelectView}, - {AIVOICE_4GSERVICECON_VIEW, &AiVoiceView::ChangeAiVoic4gServiceConView}, - {AIVOICE_VOLUME_VIEW, &AiVoiceView::ChangeAiVoicVolumeView}, - }; - - bool AiVoiceView::ClickFunc(int16_t interface) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ClickFunc"); - int funcSize = sizeof(ViewMapper) / sizeof(ViewMapper[0]); - for (int i = 0; i < funcSize; i++) - { - if (interface == ViewMapper[i].viewId) - { - bool jug = (this->*(ViewMapper[i].func))(interface); - if (jug == false) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ClickFunc err."); - return false; - } - return true; - } - } - return false; - } - - bool AiVoiceView::CheckViewParam(int16_t hideView, int16_t showView) - { - if (showView < 0 || showView >= MAX_AIVOICE_VIEWID) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CheckViewParam showView err."); - return false; - } - - if (hideView < 0 || hideView > MAX_AIVOICE_VIEWID) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CheckViewParam hideView err."); - return false; - } - - return true; - } - - static const int16 AiVoiceDestroyMapper[] = { - // AIVOICE_AIMODE_CONNECTING, - AIVOICE_4GSERVICECON_VIEW, - // AIVOICE_LISTENING_VIEWID, - // AIVOICE_THINKING_VIEWID, - AIVOICE_SELECT_VIEW, - AIVOICE_CONNECT_TIMEOUT_VIEWID, - AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID, - AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID, - // AIVOICE_STARTCHAT_VIEWID, - AIVOICE_RETURN_RESULT_TEXT_VIEWID, - AIVOICE_VOLUME_VIEW, - }; - - void AiVoiceView::DestroyTempView(int16_t hideView) - { - int viewSize = sizeof(AiVoiceDestroyMapper) / sizeof(AiVoiceDestroyMapper[0]); - for (int i = 0; i < viewSize; i++) - { - if (hideView == AiVoiceDestroyMapper[i]) - { - if (AiVoiceScrollView[hideView] != nullptr) - { - GetRootContainer()->Remove(AiVoiceScrollView[hideView]); - AiVoiceScrollView[hideView] = nullptr; - } - break; - } - } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "DestroyTempView:%d",hideView); - switch (hideView) - { - case AIVOICE_AIMODE_CONNECTING: - if (p_AiVoiceConnectingView) - { - // delete p_AiVoiceConnectingView; - // p_AiVoiceConnectingView = nullptr; - p_AiVoiceConnectingView->StartOrStopAiVoiceConnectingImageAnimatorView(false); - } - break; - case AIVOICE_4GSERVICECON_VIEW: - if (p_Aivoice4gServiceConView) - { - delete p_Aivoice4gServiceConView; - p_Aivoice4gServiceConView = nullptr; - // p_Aivoice4gServiceConView->StartOrStopAiVoice4gServiceConImageAnimatorView(false); - } - 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; - case AIVOICE_SELECT_VIEW: - if (p_AiVoiceSelectView) - { - delete p_AiVoiceSelectView; - p_AiVoiceSelectView = nullptr; - } - break; - case AIVOICE_CONNECT_TIMEOUT_VIEWID: - if (p_AivoiceConnectTimeoutView) - { - delete p_AivoiceConnectTimeoutView; - p_AivoiceConnectTimeoutView = nullptr; - } - break; - case AIVOICE_AIMODEL_CONNECT_FAILED_VIEWID: - if (p_AivoiceMobileDataFailedStartView) - { - delete p_AivoiceMobileDataFailedStartView; - p_AivoiceMobileDataFailedStartView = nullptr; - } - break; - case AIVOICE_ALERT_APPBLUETOOTH_AND_4GNETWORK_VIEWID: - if (p_AiVoiceBluetoothFailedStartView) - { - delete p_AiVoiceBluetoothFailedStartView; - p_AiVoiceBluetoothFailedStartView = nullptr; - } - break; - case AIVOICE_STARTCHAT_VIEWID: - // ClearAllAiVoiceScrollView(); - break; - case AIVOICE_RETURN_RESULT_TEXT_VIEWID: - if (p_AivoiceReturnResultTextView) - { - delete p_AivoiceReturnResultTextView; - p_AivoiceReturnResultTextView = nullptr; - } - break; - case AIVOICE_VOLUME_VIEW: - if (p_AiVoiceVolumeView) - { - delete p_AiVoiceVolumeView; - p_AiVoiceVolumeView = nullptr; - } - break; - default: - break; - } - } - - void AiVoiceView::ChangeView(int16_t hideView, int16_t showView) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeView hideView:%d, showView:%d", hideView, showView); - if (!CheckViewParam(hideView, showView)) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CheckViewParam failed."); - return; - } - if (hideView != MAX_AIVOICE_VIEWID) - { - if (AiVoiceScrollView[hideView] == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceScrollView[%d] is nullptr", hideView); - return; - } - AiVoiceScrollView[hideView]->SetVisible(false); - } - ClickFunc(showView); - if (AiVoiceScrollView[showView] != nullptr) - { - AiVoiceScrollView[showView]->SetVisible(true); - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceScrollView[%d] is nullptr", showView); - } - Draw(); - DestroyTempView(hideView); - AiVoiceModel::GetInstance().SetCurView(showView); - return; - } - - UIScrollView *AiVoiceView::GetAiVoiceScrollView(int16_t index) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::GetAiVoiceScrollView"); - if (index >= 0 && index < MAX_AIVOICE_VIEWID) - { - return AiVoiceScrollView[index]; - } - else - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "Overstep ones bounds"); - 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(upImage, isAiModeChatGpt); - - // SetComponentVisibility(startChatLabel, !isAiModeChatGpt); - SetComponentVisibility(startChatButton, !isAiModeChatGpt); - } - - void AiVoiceView::SetComponentVisibility(UIView *component, bool isVisible) - { - if (component) - { - component->SetVisible(isVisible); - } - } - - void AiVoiceView::ChangeAiModelAndUpdateComponentsStatus(void) - { - WEARABLE_LOGD(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(); - - /*更新title的textid*/ - if (p_AiVoiceBluetoothFailedStartView) - { - p_AiVoiceBluetoothFailedStartView->UpdateTitleTextId(textId); - } - if (p_AivoiceReturnResultTextView) - { - p_AivoiceReturnResultTextView->UpdateTitleTextId(textId); - } - if (p_AivoiceMobileDataFailedStartView) - { - p_AivoiceMobileDataFailedStartView->UpdateTitleTextId(textId); - } - if (p_AivoiceConnectTimeoutView) - { - p_AivoiceConnectTimeoutView->UpdateTitleTextId(textId); - } - } - -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceVolumeView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceVolumeView.cpp deleted file mode 100644 index 81317191b..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AiVoiceVolumeView.cpp +++ /dev/null @@ -1,77 +0,0 @@ -#include "aivoice/include/AiVoiceVolumeView.h" -#include "aivoice/include/AiVoicePresenter.h" -#include "wearable_log.h" -#include -namespace OHOS -{ - static AiVoiceVolumeView *g_pAiVoiceVolumeView{nullptr}; - AiVoiceVolumeView::AiVoiceVolumeView() - { - g_pAiVoiceVolumeView = this; - } - - AiVoiceVolumeView::~AiVoiceVolumeView() - { - ClearAll(); - g_pAiVoiceVolumeView = nullptr; - } - - AiVoiceVolumeView *AiVoiceVolumeView::GetInstance(void) - { - return g_pAiVoiceVolumeView; - } - - void AiVoiceVolumeView::ClearAll() - { - delete p_SoundAndVibrationVolumeSettingView; - p_SoundAndVibrationVolumeSettingView = nullptr; - SystemVolumeScrollView = nullptr; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolumeView::ClearAll end!!"); - } - void AiVoiceVolumeView::SetRequestFocus() - { - if (p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()) - { - p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->RequestFocus(); - } - } - - UIScrollView *AiVoiceVolumeView::CreateAiVoiceVolumeView(void) - { - if (p_SoundAndVibrationVolumeSettingView == nullptr) - { - p_SoundAndVibrationVolumeSettingView = new SoundAndVibrationVolumeSettingView(SYSTEM_VOLUME); - if (p_SoundAndVibrationVolumeSettingView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "p_SoundAndVibrationVolumeSettingView is nullptr!"); - return nullptr; - } - } - if (SystemVolumeScrollView == nullptr) - { - SystemVolumeScrollView = p_SoundAndVibrationVolumeSettingView->SetUpVolumeProcess(); - if (SystemVolumeScrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SystemVolumeScrollView is nullptr!"); - return nullptr; - } - } - - SetRequestFocus(); - - int SystemVolume = uapi_systemVolumeGet(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SystemVolume = %d", SystemVolume); - p_SoundAndVibrationVolumeSettingView->GetVolumeProcess()->SetValue(SystemVolume); - - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::dragListener new fail!"); - return nullptr; - } - SystemVolumeScrollView->SetOnDragListener(dragListener); - - return SystemVolumeScrollView; - } - -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/Aivoice4gServiceConView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/Aivoice4gServiceConView.cpp deleted file mode 100644 index 2089b3018..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/Aivoice4gServiceConView.cpp +++ /dev/null @@ -1,145 +0,0 @@ -#include "aivoice/include/Aivoice4gServiceConView.h" -#include "aivoice/include/AiVoicePresenter.h" -#include "wearable_log.h" -#include "common/image_cache_manager.h" -#include "UiConfig.h" -namespace OHOS -{ - static const int16_t AI4GANILABEL_X_FIRST = 83; - static const int16_t AI4GANILABEL_Y_FIRST = 257; - static const int16_t AI4GANILABEL_WIDTH_FIRST = 300; - static const int16_t AI4GANILABEL_HEIGHT_FIRST = 48; - static const char *AI4GANILABEL_TEXT_FIRST = (char *)"服务器连接中"; - static const int16_t AI4GANILABEL_FONT_FIRST = 38; - - const char *AI4GsearchImagePath[] = { - PNG_A019_080_IMAGE_PATH, - PNG_A019_081_IMAGE_PATH, - PNG_A019_082_IMAGE_PATH, - PNG_A019_083_IMAGE_PATH, - PNG_A019_084_IMAGE_PATH, - PNG_A019_085_IMAGE_PATH, - PNG_A019_086_IMAGE_PATH, - PNG_A019_087_IMAGE_PATH, - }; - - static const int16_t AI4GALIPAY_BIND_IMAGE_X = 162; - static const int16_t AI4GALIPAY_BIND_IMAGE_Y = 112; - static const int16_t AI4GALIPAY_BIND_IMAGE_WIDTH = 128; - static const int16_t AI4GALIPAY_BIND_IMAGE_HEIGHT = 128; - static const int16_t AI4GALIPAY_BIND_IMAGE_DELAY = 100; - - static AiVoice4gServiceConView *g_pAiVoice4gServiceConView{nullptr}; - AiVoice4gServiceConView::AiVoice4gServiceConView() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoice4gServiceConView::AiVoice4gServiceConView"); - g_pAiVoice4gServiceConView = this; - } - - AiVoice4gServiceConView::~AiVoice4gServiceConView() - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoice4gServiceConView::~AiVoice4gServiceConView"); - ClearAll(); - g_pAiVoice4gServiceConView = nullptr; - } - - AiVoice4gServiceConView *AiVoice4gServiceConView::GetInstance(void) - { - return g_pAiVoice4gServiceConView; - } - - void AiVoice4gServiceConView::ClearAll(void) - { - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - delete label; - label = nullptr; - if (AI4GImageAni) - { - AI4GImageAni->Stop(); - delete AI4GImageAni; - AI4GImageAni = nullptr; - for (int i = 0; i < 8; i++) - { - ImageCacheManager::GetInstance().UnloadSingleRes(AI4GsearchImagePath[i]); - } - } - delete scrollView; - scrollView = nullptr; - } - } - - UIScrollView *AiVoice4gServiceConView::CreateAiVoice4gServiceConView(void) - { - if (scrollView == nullptr) - { - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::scrollView new fail!"); - return nullptr; - } - } - scrollView->SetPosition(0, 0, 466, 466); - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceSelectView::dragListener new fail!"); - return nullptr; - } - scrollView->SetOnDragListener(dragListener); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - /* -------------------------------------------------------------------------- */ - label = new UILabelExt(); - if (label == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayBindAni::InitExit new label fail"); - return nullptr; - } - label->SetPosition(AI4GANILABEL_X_FIRST, AI4GANILABEL_Y_FIRST, AI4GANILABEL_WIDTH_FIRST, AI4GANILABEL_HEIGHT_FIRST); - label->SetText(AI4GANILABEL_TEXT_FIRST); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, AI4GANILABEL_FONT_FIRST); - label->SetStyle(STYLE_TEXT_FONT, AI4GANILABEL_FONT_FIRST); - label->SetAlign(TEXT_ALIGNMENT_CENTER); - label->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); - scrollView->Add(label); - /* -------------------------------------------------------------------------- */ - AI4GImageAni = new UIImageAnimatorView(); - if (AI4GImageAni == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayBindAni::AlipayInitImageAni new AI4GImageAni fail"); - return nullptr; - } - for (uint8_t i = 0; i < 8; i++) - { - AI4GsearchImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(AI4GsearchImagePath[i]); - AI4GsearchImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; - AI4GsearchImageInfo[i].pos.x = AI4GALIPAY_BIND_IMAGE_X; - AI4GsearchImageInfo[i].pos.y = AI4GALIPAY_BIND_IMAGE_Y; - AI4GsearchImageInfo[i].width = AI4GALIPAY_BIND_IMAGE_WIDTH; - AI4GsearchImageInfo[i].height = AI4GALIPAY_BIND_IMAGE_HEIGHT; - } - AI4GImageAni->SetPosition(AI4GALIPAY_BIND_IMAGE_X, AI4GALIPAY_BIND_IMAGE_Y, AI4GALIPAY_BIND_IMAGE_WIDTH, AI4GALIPAY_BIND_IMAGE_HEIGHT); - AI4GImageAni->SetImageAnimatorSrc(AI4GsearchImageInfo, 8, AI4GALIPAY_BIND_IMAGE_DELAY); - AI4GImageAni->SetRepeat(true); - AI4GImageAni->SetAutoEnable(false); - AI4GImageAni->SetResizeMode(UIImageView::FILL); - scrollView->Add(AI4GImageAni); - AI4GImageAni->Start(); - - return scrollView; - } - - void AiVoice4gServiceConView::StartOrStopAiVoice4gServiceConImageAnimatorView(bool val) - { - if (AI4GImageAni != nullptr) - { - if (val) - AI4GImageAni->Start(); - else - AI4GImageAni->Stop(); - } - } -} diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceChatContentListAdapter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceChatContentListAdapter.cpp deleted file mode 100644 index 19e8f74a1..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceChatContentListAdapter.cpp +++ /dev/null @@ -1,134 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-03-28 14:27:05 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-10-19 17:16:50 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/language/src/AivoiceChatContentListAdapter.cpp - */ -#include "aivoice/include/AivoiceChatContentListAdapter.h" -#include "wearable_log.h" -#include - -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(); - } - - std::list &AivoiceChatContentListAdapter::GetChatContentItem() - { - return listData; - } - - void AivoiceChatContentListAdapter::SetData(std::list &data) - { - if (!listData.empty()) - { - listData.clear(); - } - std::list::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(); - aiAnswerFlag = flag; - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Text = %s,aiAnswerFlag = %d\n", Text, aiAnswerFlag); - - UILabel label; - label.SetPosition(53, 100); - label.Resize(aiAnswerFlag ? 280 : 200, 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_EN, 26); - - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "label.GetHeight = %d,label.GetTextHeight = %d\n", 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::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, aiAnswerFlag); - } - else - { - item = dynamic_cast(inView); - item->ResetItemView(itemViewHeight, aiAnswerFlag); - } - item->SetViewIndex(index); - 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 diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp deleted file mode 100644 index 48c92bd58..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-06-29 17:27:25 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-19 10:12:45 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AivoiceChatContentListItemView.cpp - */ - -#include "aivoice/include/AivoiceChatContentListItemView.h" -#include "aivoice/include/AiVoiceModel.h" -#include "wearable_log.h" - -namespace OHOS -{ - - static constexpr const int16_t ITEM_VIEW_X = 0; /*itemview x坐标*/ - static constexpr const int16_t ITEM_VIEW_Y = 0; /*itemview y坐标*/ - static constexpr const int16_t ITEM_VIEW_W = 360; /*itemview 宽*/ - static constexpr const int16_t ITEM_VIEW_H = 80; /*itemview 高*/ - - static constexpr const int16_t CHATCONTENTLABEL_X = 40; - static constexpr const int16_t CHATCONTENTLABEL_Y = 25; - static constexpr const int16_t CHATCONTENTLABEL_TEXT_FONT = 26; - static constexpr const int16_t CHATCONTENTLABEL_LINE_HEIGHT = 30; - - static constexpr const int16_t MINDLABEL_X = 40; - static constexpr const int16_t MINDLABEL_Y = 25; - static constexpr const int16_t MINDLABEL_TEXT_FONT = 20; - static constexpr const int16_t MINDLABEL_LINE_HEIGHT = 26; - - static constexpr const int64_t RADIUS = 20; - - static constexpr const int16_t QUESTION_CHATCONTENTIMAGE_X = 0; - static constexpr const int16_t ANSWER_CHATCONTENTIMAGE_X = 289; - - static constexpr const int16_t QUESTION_CHATCONTENTSCROLLVIEW_X = 20; - static constexpr const int16_t ANSWER_CHATCONTENTSCROLLVIEW_X = 59; - - static constexpr const int16_t QUESTION_CHATCONTENTSCROLLVIEW_W = 340; - static constexpr const int16_t ANSWER_CHATCONTENTSCROLLVIEW_W = 280; - - static constexpr const int16_t QUESTION_CHATCONTENTLABEL_W = 280; - static constexpr const int16_t ANSWER_CHATCONTENTLABEL_W = 200; - - static constexpr const char *QUESTION_ITEM_IMAGE_SRC = "/user/res/AIVoice/AI_RecGreen.bin"; - static constexpr const char *ANSWER_ITEM_IMAGE_SRC = "/user/res/AIVoice/AI_RecBlack.bin"; - - static constexpr const int64_t QUESTION_ITEM_VIEW_COLOR = 0xff4fc34c; /*0xff4fc34c*/ - static constexpr const int64_t ANSWER_ITEM_VIEW_COLOR = 0xff191919; /*0xff191919*/ - - AivoiceChatContentListItemView::AivoiceChatContentListItemView(int viewHeight, bool isAiAnswerFlag) - : m_viewHeight(viewHeight), m_isAiAnswerFalg(isAiAnswerFlag) - { - SetPosition(ITEM_VIEW_X, ITEM_VIEW_Y); - Resize(ITEM_VIEW_W, m_viewHeight + ITEM_VIEW_H); - SetStyle(STYLE_BACKGROUND_COLOR, Color::Black().full); - SetStyle(STYLE_BACKGROUND_OPA, 0xff); - SetTouchable(true); - SetUpChild(); - Add(&chatContentImage); - chatContentScrollView.Add(&chatContentLabel); - chatContentScrollView.Add(&mindLabel); - Add(&chatContentScrollView); - } - - AivoiceChatContentListItemView::~AivoiceChatContentListItemView() - { - Remove(&chatContentImage); - chatContentScrollView.Remove(&chatContentLabel); - chatContentScrollView.Remove(&mindLabel); - Remove(&chatContentScrollView); - } - - void AivoiceChatContentListItemView::SetItemInfo(const ChatContentItem &itemInfo) - { - chatContentLabel.SetText(itemInfo.text.c_str()); - } - - void AivoiceChatContentListItemView::ResetItemView(int viewHeight, bool isAiAnswerFlag) - { - if (viewHeight < 120 * CHATCONTENTLABEL_LINE_HEIGHT + 30) // itemView最高为120 * label行高 - Resize(ITEM_VIEW_W, viewHeight + ITEM_VIEW_H); - - chatContentImage.SetPosition(isAiAnswerFlag ? QUESTION_CHATCONTENTIMAGE_X : ANSWER_CHATCONTENTIMAGE_X, 0, 70, 30); - chatContentImage.SetSrc(isAiAnswerFlag ? ANSWER_ITEM_IMAGE_SRC : QUESTION_ITEM_IMAGE_SRC); - - chatContentScrollView.SetPosition(isAiAnswerFlag ? QUESTION_CHATCONTENTSCROLLVIEW_X : ANSWER_CHATCONTENTSCROLLVIEW_X, 0); - if (viewHeight < 120 * CHATCONTENTLABEL_LINE_HEIGHT + 30) // scrollviewView最高为120 * label行高 - chatContentScrollView.Resize(isAiAnswerFlag ? QUESTION_CHATCONTENTSCROLLVIEW_W : ANSWER_CHATCONTENTSCROLLVIEW_W, GetHeight() - 30); - chatContentScrollView.SetStyle(STYLE_BACKGROUND_COLOR, isAiAnswerFlag ? ANSWER_ITEM_VIEW_COLOR : QUESTION_ITEM_VIEW_COLOR); - - if (viewHeight < 120 * CHATCONTENTLABEL_LINE_HEIGHT) // label最高为120 * label行高 - { - chatContentLabel.Resize(isAiAnswerFlag ? QUESTION_CHATCONTENTLABEL_W : ANSWER_CHATCONTENTLABEL_W, viewHeight); - } - else - { - if (!AiVoiceModel::GetInstance().GetIsLimitDisplayed()) - { - AiVoiceModel::GetInstance().SetIsLimitDisplayed(true); - chatContentLabel.SetLineBreakMode(isAiAnswerFlag ? UILabel::LINE_BREAK_ELLIPSIS : UILabel::LINE_BREAK_WRAP); // 超过高度在末尾用省略号替换 - } - } - - if(isAiAnswerFlag) - { - chatContentScrollView.Resize(isAiAnswerFlag ? QUESTION_CHATCONTENTSCROLLVIEW_W : ANSWER_CHATCONTENTSCROLLVIEW_W, GetHeight()); - mindLabel.SetY(chatContentScrollView.GetY() + chatContentScrollView.GetHeight()- 40); - mindLabel.SetVisible(true); - } - else - { - chatContentScrollView.Resize(isAiAnswerFlag ? QUESTION_CHATCONTENTSCROLLVIEW_W : ANSWER_CHATCONTENTSCROLLVIEW_W, GetHeight() - 30); - mindLabel.SetVisible(false); - } - } - - void AivoiceChatContentListItemView::SetUpChild() - { - chatContentImage.SetPosition(m_isAiAnswerFalg ? QUESTION_CHATCONTENTIMAGE_X : ANSWER_CHATCONTENTIMAGE_X, 0, 70, 30); - chatContentImage.SetSrc(m_isAiAnswerFalg ? ANSWER_ITEM_IMAGE_SRC : QUESTION_ITEM_IMAGE_SRC); - - chatContentScrollView.SetPosition(m_isAiAnswerFalg ? QUESTION_CHATCONTENTSCROLLVIEW_X : ANSWER_CHATCONTENTSCROLLVIEW_X, 0); - chatContentScrollView.Resize(m_isAiAnswerFalg ? QUESTION_CHATCONTENTSCROLLVIEW_W : ANSWER_CHATCONTENTSCROLLVIEW_W, GetHeight() - 30); - chatContentScrollView.SetStyle(STYLE_BACKGROUND_COLOR, m_isAiAnswerFalg ? ANSWER_ITEM_VIEW_COLOR : QUESTION_ITEM_VIEW_COLOR); - chatContentScrollView.SetStyle(STYLE_BACKGROUND_OPA, 0xff); - chatContentScrollView.SetStyle(STYLE_BORDER_RADIUS, RADIUS); - chatContentScrollView.SetTouchable(false); - - chatContentLabel.SetPosition(CHATCONTENTLABEL_X, CHATCONTENTLABEL_Y); - chatContentLabel.Resize(m_isAiAnswerFalg ? QUESTION_CHATCONTENTLABEL_W : ANSWER_CHATCONTENTLABEL_W, m_viewHeight); - 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_EN, CHATCONTENTLABEL_TEXT_FONT); - - mindLabel.SetPosition(MINDLABEL_X, MINDLABEL_Y); - mindLabel.Resize(0, 26); - mindLabel.SetVisible(false); - mindLabel.SetText("内容由AI生成,仅供参考"); - mindLabel.SetStyle(STYLE_TEXT_FONT, MINDLABEL_TEXT_FONT); - mindLabel.SetStyle(STYLE_LINE_HEIGHT, MINDLABEL_LINE_HEIGHT); - mindLabel.SetLineBreakMode(UILabel::LINE_BREAK_ADAPT); - mindLabel.SetAlign(TEXT_ALIGNMENT_LEFT, TEXT_ALIGNMENT_CENTER); - mindLabel.SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, MINDLABEL_TEXT_FONT); - mindLabel.SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); - } - -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp deleted file mode 100644 index fab01ccb9..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceConnectTimeoutView.cpp +++ /dev/null @@ -1,288 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-05-07 11:25:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-14 17:29:47 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceConnectTimeoutView.cpp - */ -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AivoiceConnectTimeoutView.h" -#include "aivoice/include/AiVoiceModel.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -#include -#include "ConfigModel.h" -namespace OHOS -{ - static constexpr const int16_t LABEL_ROLL_SPEED = 70; - - static AivoiceConnectTimeoutView *g_pAivoiceConnectTimeoutView{nullptr}; - - AivoiceConnectTimeoutView::AivoiceConnectTimeoutView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::AivoiceConnectTimeoutView"); - g_pAivoiceConnectTimeoutView = this; - } - - AivoiceConnectTimeoutView::~AivoiceConnectTimeoutView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::~AivoiceConnectTimeoutView"); - ClearAll(); - g_pAivoiceConnectTimeoutView = nullptr; - } - - AivoiceConnectTimeoutView *AivoiceConnectTimeoutView::GetInstance() - { - return g_pAivoiceConnectTimeoutView; - } - - void AivoiceConnectTimeoutView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::ClearAll"); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - if (title != nullptr) - { - delete title; - title = nullptr; - } - if (attentionImage != nullptr) - { - delete attentionImage; - attentionImage = nullptr; - } - if (NoteLabel != nullptr) - { - delete NoteLabel; - NoteLabel = nullptr; - } - if (ensure != nullptr) - { - delete ensure; - ensure = nullptr; - } - if (ensureButton != nullptr) - { - delete ensureButton; - ensureButton = nullptr; - } - delete scrollView; - scrollView = nullptr; - } - } - - UILabelExt *AivoiceConnectTimeoutView::AivoiceConnectTimeoutLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - label->SetRollSpeed(LABEL_ROLL_SPEED); - return label; - } - - UIButton *AivoiceConnectTimeoutView::AivoiceConnectTimeoutButtonInit(ButtonConfig &buttonconfig) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - - return button; - } - - UIImageView *AivoiceConnectTimeoutView::AivoiceConnectTimeoutImageInit(ImageConfig &imageconfig) - { - UIImageView *Image = new UIImageView(); - if (Image == nullptr) - { - return nullptr; - } - Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); - return Image; - } - - bool AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutScrollView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutScrollView"); - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::scrollView new fail!"); - return false; - } - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::dragListener new fail!"); - return false; - } - scrollView->SetOnDragListener(dragListener); - scrollView->SetPosition(0, 0, 466, 466); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - - return true; - } - - bool AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutLabel"); - LabelConfig labelconfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = AiVoiceModel::GetInstance().GetAiModelTextId(), - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - title = AivoiceConnectTimeoutLabelInit(labelconfig); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::title is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - NoteLabel = new UILabelExt(); - if (NoteLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NoteLabel is nullptr!"); - return false; - } - NoteLabel->SetPosition(53, 222, 360, 70); - NoteLabel->SetStyle(STYLE_TEXT_FONT, 30); - NoteLabel->SetStyle(STYLE_LINE_HEIGHT, 35); - NoteLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); - NoteLabel->SetRollSpeed(23); - NoteLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - NoteLabel->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 30); - /* -------------------------------------------------------------------------- */ - labelconfig = { - .left = 133, - .top = 368, - .width = 200, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_OK, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - ensure = AivoiceConnectTimeoutLabelInit(labelconfig); - if (ensure == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::ensure is nullptr!"); - return false; - } - - return true; - } - - bool AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutButton"); - ButtonConfig buttonconfig = { - .x = 93, - .y = 340, - .w = 280, - .h = 90, - .ViewId = AIVOICECONNECTTIMEOUT_ENSURE_BUTTON_VIEW_ID, - }; - ensureButton = AivoiceConnectTimeoutButtonInit(buttonconfig); - if (ensureButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ensureButton new fail!"); - return false; - } - UIView::OnTouchListener *touchListener = static_cast(AiVoicePresenter::GetInstance()); - if (touchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::touchListener can not be nullptr!"); - return false; - } - ensureButton->SetOnTouchListener(touchListener); - - return true; - } - - bool AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutImage(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutImage"); - ImageConfig imageconfig = { - .x = 193, - .y = 120, - .w = 80, - .h = 80, - }; - attentionImage = AivoiceConnectTimeoutImageInit(imageconfig); - if (attentionImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "attentionImage new fail!"); - return false; - } - attentionImage->SetStyle(STYLE_BORDER_RADIUS, 100); - attentionImage->SetSrc(PNG_ATTENTION_IMAGE); - - return true; - } - - UIScrollView *AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutView"); - if (scrollView == nullptr) - { - if (!CreateAivoiceConnectTimeoutScrollView() || !CreateAivoiceConnectTimeoutLabel() || - !CreateAivoiceConnectTimeoutButton() || !CreateAivoiceConnectTimeoutImage()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceConnectTimeoutView::CreateAivoiceConnectTimeoutView fail!!"); - return nullptr; - } - scrollView->Add(title); - scrollView->Add(attentionImage); - scrollView->Add(NoteLabel); - scrollView->Add(ensureButton); - scrollView->Add(ensure); - } - return scrollView; - } - - void AivoiceConnectTimeoutView::UpdateTitleTextId(int textId) - { - if (title) - { - title->SetTextId(textId); - title->ForceResetText(); - } - } - - // 更新错误信息内容 - void AivoiceConnectTimeoutView::UpdateNoteText() - { - if (NoteLabel) - { - // NoteLabel->SetText(""); - std::string text = AiVoiceModel::GetInstance().GetErrnote(); - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "text = %s", text.c_str()); - NoteLabel->SetText(text.c_str()); - NoteLabel->SetLineBreakMode(UILabel::LINE_BREAK_OSCILLATION); - NoteLabel->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - NoteLabel->Invalidate(); - } - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceListeningView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceListeningView.cpp deleted file mode 100644 index 41e1b2b0a..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceListeningView.cpp +++ /dev/null @@ -1,408 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-05-07 11:25:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:09:40 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceListeningView.cpp - */ -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AivoiceListeningView.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -#include -#include "uicomponents/UIComponents.h" -// #include "common/image_cache_manager.h" -namespace OHOS -{ - const char *listening_path_array[] = { - "/user/res/AIVoice/AIVoiceListening/1.bin", - "/user/res/AIVoice/AIVoiceListening/2.bin", - "/user/res/AIVoice/AIVoiceListening/3.bin", - "/user/res/AIVoice/AIVoiceListening/4.bin", - "/user/res/AIVoice/AIVoiceListening/5.bin", - "/user/res/AIVoice/AIVoiceListening/6.bin", - "/user/res/AIVoice/AIVoiceListening/7.bin", - "/user/res/AIVoice/AIVoiceListening/8.bin", - "/user/res/AIVoice/AIVoiceListening/9.bin", - "/user/res/AIVoice/AIVoiceListening/10.bin", - "/user/res/AIVoice/AIVoiceListening/11.bin", - "/user/res/AIVoice/AIVoiceListening/12.bin", - "/user/res/AIVoice/AIVoiceListening/13.bin", - "/user/res/AIVoice/AIVoiceListening/14.bin", - "/user/res/AIVoice/AIVoiceListening/15.bin", - "/user/res/AIVoice/AIVoiceListening/16.bin", - "/user/res/AIVoice/AIVoiceListening/17.bin", - "/user/res/AIVoice/AIVoiceListening/18.bin", - "/user/res/AIVoice/AIVoiceListening/19.bin", - "/user/res/AIVoice/AIVoiceListening/20.bin", - "/user/res/AIVoice/AIVoiceListening/21.bin", - "/user/res/AIVoice/AIVoiceListening/22.bin", - "/user/res/AIVoice/AIVoiceListening/23.bin", - "/user/res/AIVoice/AIVoiceListening/24.bin", - "/user/res/AIVoice/AIVoiceListening/25.bin", - "/user/res/AIVoice/AIVoiceListening/26.bin", - "/user/res/AIVoice/AIVoiceListening/27.bin", - "/user/res/AIVoice/AIVoiceListening/28.bin", - "/user/res/AIVoice/AIVoiceListening/29.bin", - "/user/res/AIVoice/AIVoiceListening/30.bin", - "/user/res/AIVoice/AIVoiceListening/31.bin", - "/user/res/AIVoice/AIVoiceListening/32.bin", - "/user/res/AIVoice/AIVoiceListening/33.bin", - "/user/res/AIVoice/AIVoiceListening/34.bin", - "/user/res/AIVoice/AIVoiceListening/35.bin", - "/user/res/AIVoice/AIVoiceListening/36.bin", - "/user/res/AIVoice/AIVoiceListening/37.bin", - "/user/res/AIVoice/AIVoiceListening/38.bin", - "/user/res/AIVoice/AIVoiceListening/39.bin", - "/user/res/AIVoice/AIVoiceListening/40.bin", - }; - - static AivoiceListeningView *g_pAivoiceListeningView{nullptr}; - - AivoiceListeningView::AivoiceListeningView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::AivoiceListeningView"); - g_pAivoiceListeningView = this; - } - - AivoiceListeningView::~AivoiceListeningView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::~AivoiceListeningView"); - ClearAll(); - g_pAivoiceListeningView = nullptr; - } - - AivoiceListeningView *AivoiceListeningView::GetInstance() - { - return g_pAivoiceListeningView; - } - - void AivoiceListeningView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::ClearAll"); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - - if (title != nullptr) - { - delete title; - title = nullptr; - } - - if (AiVoiceListeningImageAnimatorView != nullptr) - { - AiVoiceListeningImageAnimatorView->Stop(); - delete AiVoiceListeningImageAnimatorView; - AiVoiceListeningImageAnimatorView = nullptr; - for (int i = 0; i < AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) - { - ImageCacheManager::GetInstance().UnloadSingleRes(listening_path_array[i]); - } - } - - if (showtimeout != nullptr) - { - delete showtimeout; - showtimeout = nullptr; - } - - if (finishSpeak != nullptr) - { - delete finishSpeak; - finishSpeak = nullptr; - } - - if (finishSpeakButton != nullptr) - { - delete finishSpeakButton; - finishSpeakButton = nullptr; - } - - delete scrollView; - scrollView = nullptr; - } - } - - UILabelExt *AivoiceListeningView::AivoiceListeningLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetRollSpeed(23); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - UIButton *AivoiceListeningView::AivoiceListeningButtonInit(ButtonConfig &buttonconfig) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); - - return button; - } - - UIImageAnimatorView *AivoiceListeningView::AivoiceListeningImageAnimatorInit(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 = imageanimatorconfig.pathsArray[i]; - // imageanimatorconfig.imageInfoArray[i].imagePath = (imageanimatorconfig.pathsArray[i]); - // imageanimatorconfig.imageInfoArray[i].imageType = IMG_SRC_FILE_PATH; - imageanimatorconfig.imageInfoArray[i].imageType = IMG_SRC_IMAGE_INFO; - 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->SetSizeFixed(true); - // animatorView->SetAutoEnable(false); - // animatorView->SetResizeMode(UIImageAnimatorView::FILL); - // animatorView->Start(); - - return animatorView; - } - - bool AivoiceListeningView::CreateAivoiceListeningScrollView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningScrollView"); - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::scrollView new fail!"); - return false; - } - scrollView->SetPosition(0, 0, 466, 466); - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::dragListener new fail!"); - return false; - } - scrollView->SetOnDragListener(dragListener); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - - return true; - } - - bool AivoiceListeningView::CreateAivoiceListeningLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningLabel"); - LabelConfig labelconfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_LISTENING, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - title = AivoiceListeningLabelInit(labelconfig); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::title is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - labelconfig = { - .left = 133, - .top = 368, - .width = 200, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_FINISH_SPEAKING, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - finishSpeak = AivoiceListeningLabelInit(labelconfig); - if (finishSpeak == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::finishSpeak is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - showtimeout = new UILabelExt(); - if (showtimeout == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::showtimeout is nullptr!"); - return false; - } - showtimeout->SetPosition(60, 258, 240, 60); - showtimeout->SetStyle(STYLE_TEXT_FONT, 50); - showtimeout->SetStyle(STYLE_LINE_HEIGHT, 60); - showtimeout->SetLineBreakMode(UILabel::LINE_BREAK_ELLIPSIS); - showtimeout->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - showtimeout->SetFont(DEFAULT_VECTOR_FONT_FILENAME_EN, 50); - - return true; - } - - bool AivoiceListeningView::CreateAivoiceListeningButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningButton"); - ButtonConfig buttonconfig = { - .x = 93, - .y = 340, - .w = 280, - .h = 90, - .ViewId = FINISH_SPEAKING_BUTTON_VIEW_ID, - }; - finishSpeakButton = AivoiceListeningButtonInit(buttonconfig); - if (finishSpeakButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "finishSpeakButton new fail!"); - return false; - } - UIView::OnTouchListener *touchListener = static_cast(AiVoicePresenter::GetInstance()); - if (touchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::touchListener can not be nullptr!"); - return false; - } - finishSpeakButton->SetOnTouchListener(touchListener); - - return true; - } - - bool AivoiceListeningView::CreateAivoiceListeningImageAnimator(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningImageAnimator"); - if (AiVoiceListeningImageAnimatorView == nullptr) - { - AiVoiceListeningImageAnimatorView = new UIImageAnimatorView(); - if (AiVoiceListeningImageAnimatorView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AlipayBindAni::AlipayInitImageAni new AI4GImageAni fail"); - return false; - } - } - for (uint8_t i = 0; i < AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) - { - AiVoiceListeningImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(listening_path_array[i]); - AiVoiceListeningImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; - AiVoiceListeningImageInfo[i].pos.x = AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_X; - AiVoiceListeningImageInfo[i].pos.y = AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_Y; - AiVoiceListeningImageInfo[i].width = AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_W; - AiVoiceListeningImageInfo[i].height = AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_H; - } - AiVoiceListeningImageAnimatorView->SetPosition(AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_X, AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_Y, - AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_W, AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_H); - AiVoiceListeningImageAnimatorView->SetImageAnimatorSrc(AiVoiceListeningImageInfo, AIVOICE_LISTENING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, AIVOICE_LISTENING_IMAGE_ANIMATOR_DELAY); - AiVoiceListeningImageAnimatorView->SetRepeat(true); - AiVoiceListeningImageAnimatorView->SetAutoEnable(false); - AiVoiceListeningImageAnimatorView->SetResizeMode(UIImageView::FILL); - - 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"); -#if 0 - if (scrollView == nullptr) - { - if (!CreateAivoiceListeningScrollView() || !CreateAivoiceListeningLabel() || - !CreateAivoiceListeningButton() || !CreateAivoiceListeningImageAnimator()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningView fail!!"); - return nullptr; - } - scrollView->Add(title); - scrollView->Add(AiVoiceListeningImageAnimatorView); - scrollView->Add(finishSpeakButton); - scrollView->Add(finishSpeak); - } -#else - if (!CreateAivoiceListeningScrollView()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningScrollView fail!!"); - } - if (!CreateAivoiceListeningLabel()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningLabel fail!!"); - } - if (!CreateAivoiceListeningButton()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningButton fail!!"); - } - if (!CreateAivoiceListeningImageAnimator()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceListeningView::CreateAivoiceListeningImageAnimator fail!!"); - } - if (scrollView == nullptr) - { - return nullptr; - } - else - { - if (title) - { - scrollView->Add(title); - } - if (AiVoiceListeningImageAnimatorView) - { - scrollView->Add(AiVoiceListeningImageAnimatorView); - } - if (showtimeout) - { - showtimeout->SetX((scrollView->GetWidth() - showtimeout->GetWidth()) / 2); - scrollView->Add(showtimeout); - } - if (finishSpeakButton) - { - scrollView->Add(finishSpeakButton); - } - if (finishSpeak) - { - scrollView->Add(finishSpeak); - } - return scrollView; - } -#endif - } - - UILabelExt *AivoiceListeningView::GetShowtimeoutLabel(void) - { - return showtimeout; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp deleted file mode 100644 index 01423d8eb..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceMobileDataFailedStartView.cpp +++ /dev/null @@ -1,283 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-05-07 11:25:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-03 11:49:39 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceMobileDataFailedStartView.cpp - */ -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AivoiceMobileDataFailedStartView.h" -#include "aivoice/include/AiVoiceModel.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -#include -#include "ConfigModel.h" -namespace OHOS -{ - - static AivoiceMobileDataFailedStartView *g_pAivoiceMobileDataFailedStartView{nullptr}; - - AivoiceMobileDataFailedStartView::AivoiceMobileDataFailedStartView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::AivoiceMobileDataFailedStartView"); - g_pAivoiceMobileDataFailedStartView = this; - } - - AivoiceMobileDataFailedStartView::~AivoiceMobileDataFailedStartView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::~AivoiceMobileDataFailedStartView"); - ClearAll(); - g_pAivoiceMobileDataFailedStartView = nullptr; - } - - AivoiceMobileDataFailedStartView *AivoiceMobileDataFailedStartView::GetInstance() - { - return g_pAivoiceMobileDataFailedStartView; - } - - void AivoiceMobileDataFailedStartView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::ClearAll"); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - - if (title != nullptr) - { - delete title; - title = nullptr; - } - - if (attentionImage != nullptr) - { - delete attentionImage; - attentionImage = nullptr; - } - - for (int i = 0; i < 2; i++) - { - if (label[i] != nullptr) - { - delete label[i]; - label[i]; - } - } - - if (ensure != nullptr) - { - delete ensure; - ensure = nullptr; - } - - if (ensureButton != nullptr) - { - delete ensureButton; - ensureButton = nullptr; - } - - delete scrollView; - scrollView = nullptr; - } - } - - UILabelExt *AivoiceMobileDataFailedStartView::AivoiceMobileDataFailedStartLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetRollSpeed(23); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - UIButton *AivoiceMobileDataFailedStartView::AivoiceMobileDataFailedStartButtonInit(ButtonConfig &buttonconfig) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - - return button; - } - - UIImageView *AivoiceMobileDataFailedStartView::AivoiceMobileDataFailedStartImageInit(ImageConfig &imageconfig) - { - UIImageView *Image = new UIImageView(); - if (Image == nullptr) - { - return nullptr; - } - Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); - return Image; - } - - bool AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartScrollView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartScrollView"); - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::scrollView new fail!"); - return false; - } - scrollView->SetPosition(0, 0, 466, 466); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::dragListener new fail!"); - return false; - } - scrollView->SetOnDragListener(dragListener); - - return true; - } - - bool AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartLabel"); - LabelConfig labelconfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = AiVoiceModel::GetInstance().GetAiModelTextId(), - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - title = AivoiceMobileDataFailedStartLabelInit(labelconfig); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::title is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - labelconfig.left = 53; - labelconfig.width = 360; - int textId[] = {STR_CONNECTION_FAIL, STR_PTALORTM}; /*连接失败,请稍后再重试或更换模型*/ - for (int i = 0; i < sizeof(textId) / sizeof(textId[0]); i++) - { - labelconfig.top = 222 + i * 35; - labelconfig.textId = textId[i]; - label[i] = AivoiceMobileDataFailedStartLabelInit(labelconfig); - if (label[i] == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::label[%d] is nullptr!", i); - return false; - } - } - /* -------------------------------------------------------------------------- */ - labelconfig = { - .left = 133, - .top = 368, - .width = 200, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_OK, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - ensure = AivoiceMobileDataFailedStartLabelInit(labelconfig); - if (ensure == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::ensure is nullptr!"); - return false; - } - - return true; - } - - bool AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartButton"); - ButtonConfig buttonconfig = { - .x = 93, - .y = 340, - .w = 280, - .h = 90, - .ViewId = AIMODEL_CONNECT_FAILED_ENSURE_BUTTON_VIEW_ID, - }; - ensureButton = AivoiceMobileDataFailedStartButtonInit(buttonconfig); - if (ensureButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ensureButton new fail!"); - return false; - } - UIView::OnTouchListener *touchListener = static_cast(AiVoicePresenter::GetInstance()); - if (touchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::touchListener can not be nullptr!"); - return false; - } - ensureButton->SetOnTouchListener(touchListener); - - return true; - } - - bool AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartImage(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartImage"); - ImageConfig imageconfig = { - .x = 193, - .y = 120, - .w = 80, - .h = 80, - }; - attentionImage = AivoiceMobileDataFailedStartImageInit(imageconfig); - if (attentionImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "attentionImage new fail!"); - return false; - } - attentionImage->SetStyle(STYLE_BORDER_RADIUS, 100); - attentionImage->SetSrc(PNG_ATTENTION_IMAGE); - - return true; - } - - UIScrollView *AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartView"); - if (scrollView == nullptr) - { - if (!CreateAivoiceMobileDataFailedStartScrollView() || !CreateAivoiceMobileDataFailedStartLabel() || - !CreateAivoiceMobileDataFailedStartButton() || !CreateAivoiceMobileDataFailedStartImage()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceMobileDataFailedStartView::CreateAivoiceMobileDataFailedStartView fail!!"); - return nullptr; - } - scrollView->Add(title); - scrollView->Add(attentionImage); - scrollView->Add(label[0]); - scrollView->Add(label[1]); - scrollView->Add(ensureButton); - scrollView->Add(ensure); - } - return scrollView; - } - - void AivoiceMobileDataFailedStartView::UpdateTitleTextId(int textId) - { - if (title) - { - title->SetTextId(textId); - title->ForceResetText(); - } - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp deleted file mode 100644 index be4722755..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceReturnResultTextView.cpp +++ /dev/null @@ -1,380 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-05-07 11:25:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2025-03-07 09:54:21 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceReturnResultTextView.cpp - */ -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AivoiceReturnResultTextView.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -#include "aivoice/include/AiVoiceModel.h" -#include -#include -#include "string" -#include "ConfigModel.h" -namespace OHOS -{ - - /* -------------------------------------------------------------------------- */ - static constexpr const int16_t CHATCONTENT_LIST_X = 53; - static constexpr const int16_t CHATCONTENT_LIST_Y = 100; - static constexpr const int16_t CHATCONTENT_LIST_W = 360; - static constexpr const int16_t CHATCONTENT_LIST_H = 200; - static constexpr const int16_t REBOUNDSIZE = 30; - 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 RETURN_BUTTON_X = 73; - static constexpr const int16_t RETURN_BUTTON_Y = CHATCONTENT_LIST_Y + CHATCONTENT_LIST_H + 10; - 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 = 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; - /* -------------------------------------------------------------------------- */ - static constexpr const int16_t CONTINUECHAT_X = CONTINUECHAT_BUTTON_X + 45; - static constexpr const int16_t CONTINUECHAT_Y = CONTINUECHAT_BUTTON_Y + 33; - static constexpr const int16_t CONTINUECHAT_W = 120; - static constexpr const int16_t CONTINUECHAT_H = 35; - - static constexpr const int16_t ONE_HALF_NUM = 2; - - static constexpr const int16_t LABEL_ROLL_SPEED = 70; - - static AivoiceReturnResultTextView *g_pAivoiceReturnResultTextView{nullptr}; - - AivoiceReturnResultTextView::AivoiceReturnResultTextView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::AivoiceReturnResultTextView"); - g_pAivoiceReturnResultTextView = this; - } - - AivoiceReturnResultTextView::~AivoiceReturnResultTextView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::~AivoiceReturnResultTextView"); - ClearAll(); - g_pAivoiceReturnResultTextView = nullptr; - } - - AivoiceReturnResultTextView *AivoiceReturnResultTextView::GetInstance() - { - return g_pAivoiceReturnResultTextView; - } - - void AivoiceReturnResultTextView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::ClearAll"); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - - if (title != nullptr) - { - delete title; - title = nullptr; - } - - if (chatContentListAdapter != nullptr) - { - delete chatContentListAdapter; - chatContentListAdapter = nullptr; - } - - if (chatContentList != nullptr) - { - delete chatContentList; - chatContentList = nullptr; - } - - if (returnButton != nullptr) - { - delete returnButton; - returnButton = nullptr; - } - - if (continueChatButton != nullptr) - { - delete continueChatButton; - continueChatButton = nullptr; - } - - if (continueChat != nullptr) - { - delete continueChat; - continueChat = nullptr; - } - - delete scrollView; - scrollView = nullptr; - } - } - void AivoiceReturnResultTextView::SetRequestFocus() - { - if (chatContentList) - { - chatContentList->RequestFocus(); - } - } - - UILabelExt *AivoiceReturnResultTextView::AivoiceReturnResultTextLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeight); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - label->SetRollSpeed(LABEL_ROLL_SPEED); - return label; - } - - UIButton *AivoiceReturnResultTextView::AivoiceReturnResultTextButtonInit(ButtonConfig &buttonconfig) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - - return button; - } - - UIImageView *AivoiceReturnResultTextView::AivoiceReturnResultTextImageInit(ImageConfig &imageconfig) - { - UIImageView *Image = new UIImageView(); - if (Image == nullptr) - { - return nullptr; - } - Image->SetPosition(imageconfig.x, imageconfig.y, imageconfig.w, imageconfig.h); - Image->SetSrc(imageconfig.src); - return Image; - } - - bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextScrollView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextScrollView"); - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::scrollView new fail!"); - return false; - } - scrollView->SetPosition(0, 0, 466, 466); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - scrollView->SetDirection(UIScrollView::VERTICAL); - - return true; - } - - bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextLabel"); - LabelConfig labelconfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeight = 35, - .textId = AiVoiceModel::GetInstance().GetAiModelTextId(), - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - title = AivoiceReturnResultTextLabelInit(labelconfig); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::title is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - labelconfig = { - .left = CONTINUECHAT_X, - .top = CONTINUECHAT_Y, - .width = CONTINUECHAT_W, - .height = CONTINUECHAT_H, - .fontSize = 30, - .lineHeight = 35, - .textId = STR_CONTINUE_CHAT, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - continueChat = AivoiceReturnResultTextLabelInit(labelconfig); - if (continueChat == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::continueChat is nullptr!"); - return false; - } - - return true; - } - - bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextList(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextList"); - chatContentListAdapter = new AivoiceChatContentListAdapter(); - if (chatContentListAdapter == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::chatContentListAdapter is nullptr"); - return false; - } - UIView::OnClickListener *clickListener = static_cast(AiVoicePresenter::GetInstance()); - if (clickListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::chatContentListAdapter is nullptr"); - return false; - } - chatContentListAdapter->SetItemClickListener(clickListener); - - chatContentList = new UIList(UIList::VERTICAL); - if (chatContentList == 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->SetSwipeACCLevel(200); // 800: compensation distance - chatContentList->SetDragACCLevel(5); // 5: drag acceleration - // chatContentList->SetRotateFactor(2); - // chatContentList->RequestFocus(); - // chatContentList->SetIntercept(true); - chatContentList->SetAdapter(chatContentListAdapter); - chatContentList->RefreshList(); - /* -------------------------------------------------------------------------- */ - // AiVoiceModel::GetInstance().InitchatContentItems(); - /* -------------------------------------------------------------------------- */ - return true; - } - - bool AivoiceReturnResultTextView::CreateAivoiceReturnResultTextButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextButton"); - ButtonConfig buttonconfig = { - .x = RETURN_BUTTON_X, - .y = RETURN_BUTTON_Y, - .w = RETURN_BUTTON_W, - .h = RETURN_BUTTON_H, - .ViewId = AIVOICERETURNRESULTTEXT_RETURN_BUTTON_VIEW_ID, - }; - returnButton = AivoiceReturnResultTextButtonInit(buttonconfig); - if (returnButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "returnButton new fail!"); - return false; - } - returnButton->SetImagePosition(39, 39); - returnButton->SetImageSrc(RETURN_BUTTON_PATH, RETURN_BUTTON_PATH); - UIView::OnTouchListener *touchListener = static_cast(AiVoicePresenter::GetInstance()); - if (touchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::touchListener can not be nullptr!"); - return false; - } - returnButton->SetOnTouchListener(touchListener); - /* -------------------------------------------------------------------------- */ - buttonconfig = { - .x = CONTINUECHAT_BUTTON_X, - .y = CONTINUECHAT_BUTTON_Y, - .w = CONTINUECHAT_BUTTON_W, - .h = CONTINUECHAT_BUTTON_H, - .ViewId = AIVOICERETURNRESULTTEXT_CONTINUECHAT_BUTTON_VIEW_ID, - }; - continueChatButton = AivoiceReturnResultTextButtonInit(buttonconfig); - if (continueChatButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "continueChatButton new fail!"); - return false; - } - continueChatButton->SetOnTouchListener(touchListener); - - return true; - } - - UIScrollView *AivoiceReturnResultTextView::CreateAivoiceReturnResultTextView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextView"); - if (scrollView == nullptr) - { - if (!CreateAivoiceReturnResultTextScrollView() || !CreateAivoiceReturnResultTextLabel() || - !CreateAivoiceReturnResultTextList() || !CreateAivoiceReturnResultTextButton()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::CreateAivoiceReturnResultTextView fail!!"); - return nullptr; - } - /* ----------------------------------- Add ---------------------------------- */ - scrollView->Add(title); - 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->AddListItem(item); - } - - AivoiceChatContentListAdapter *AivoiceReturnResultTextView::GetAivoiceChatContentListAdapter(void) - { - return chatContentListAdapter; - } - - UIList *AivoiceReturnResultTextView::GetChatContentList(void) - { - return chatContentList; - } - - void AivoiceReturnResultTextView::UpdateTitleTextId(int textId) - { - if (title) - { - title->SetTextId(textId); - title->ForceResetText(); - } - } - - void AivoiceReturnResultTextView::IsScrollChatContentList(bool isScroll) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceReturnResultTextView::IsScrollChatContentList"); - if (isScroll) - { - scrollView->RequestFocus(); - chatContentList->SetTouchable(false); - chatContentList->SetDraggable(false); - } - else - { - chatContentList->RequestFocus(); - chatContentList->SetTouchable(true); - chatContentList->SetDraggable(true); - } - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceThinkingView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceThinkingView.cpp deleted file mode 100644 index 30984de7f..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/AivoiceThinkingView.cpp +++ /dev/null @@ -1,369 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-05-07 11:25:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:18:14 - * @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AivoiceThinkingView.cpp - */ -#include "aivoice/include/AiVoicePresenter.h" -#include "aivoice/include/AivoiceThinkingView.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -#include -#include "uicomponents/UIComponents.h" -// #include "common/image_cache_manager.h" -namespace OHOS -{ - - const char *thinking_path_array[] = { - "/user/res/AIVoice/AIVoiceThinking/1.bin", - "/user/res/AIVoice/AIVoiceThinking/2.bin", - "/user/res/AIVoice/AIVoiceThinking/3.bin", - "/user/res/AIVoice/AIVoiceThinking/4.bin", - "/user/res/AIVoice/AIVoiceThinking/5.bin", - "/user/res/AIVoice/AIVoiceThinking/6.bin", - "/user/res/AIVoice/AIVoiceThinking/7.bin", - "/user/res/AIVoice/AIVoiceThinking/8.bin", - "/user/res/AIVoice/AIVoiceThinking/9.bin", - "/user/res/AIVoice/AIVoiceThinking/10.bin", - "/user/res/AIVoice/AIVoiceThinking/11.bin", - "/user/res/AIVoice/AIVoiceThinking/12.bin", - "/user/res/AIVoice/AIVoiceThinking/13.bin", - "/user/res/AIVoice/AIVoiceThinking/14.bin", - "/user/res/AIVoice/AIVoiceThinking/15.bin", - "/user/res/AIVoice/AIVoiceThinking/16.bin", - "/user/res/AIVoice/AIVoiceThinking/17.bin", - "/user/res/AIVoice/AIVoiceThinking/18.bin", - "/user/res/AIVoice/AIVoiceThinking/19.bin", - "/user/res/AIVoice/AIVoiceThinking/20.bin", - "/user/res/AIVoice/AIVoiceThinking/21.bin", - "/user/res/AIVoice/AIVoiceThinking/22.bin", - "/user/res/AIVoice/AIVoiceThinking/23.bin", - "/user/res/AIVoice/AIVoiceThinking/24.bin", - "/user/res/AIVoice/AIVoiceThinking/25.bin", - "/user/res/AIVoice/AIVoiceThinking/26.bin", - "/user/res/AIVoice/AIVoiceThinking/27.bin", - "/user/res/AIVoice/AIVoiceThinking/28.bin", - "/user/res/AIVoice/AIVoiceThinking/29.bin", - "/user/res/AIVoice/AIVoiceThinking/30.bin", - "/user/res/AIVoice/AIVoiceThinking/31.bin", - "/user/res/AIVoice/AIVoiceThinking/32.bin", - "/user/res/AIVoice/AIVoiceThinking/33.bin", - "/user/res/AIVoice/AIVoiceThinking/34.bin", - "/user/res/AIVoice/AIVoiceThinking/35.bin", - "/user/res/AIVoice/AIVoiceThinking/36.bin", - "/user/res/AIVoice/AIVoiceThinking/37.bin", - "/user/res/AIVoice/AIVoiceThinking/38.bin", - "/user/res/AIVoice/AIVoiceThinking/39.bin", - "/user/res/AIVoice/AIVoiceThinking/40.bin", - }; - - static AivoiceThinkingView *g_pAivoiceThinkingView{nullptr}; - - AivoiceThinkingView::AivoiceThinkingView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::AivoiceThinkingView"); - g_pAivoiceThinkingView = this; - } - - AivoiceThinkingView::~AivoiceThinkingView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::~AivoiceThinkingView"); - ClearAll(); - g_pAivoiceThinkingView = nullptr; - } - - AivoiceThinkingView *AivoiceThinkingView::GetInstance() - { - return g_pAivoiceThinkingView; - } - - void AivoiceThinkingView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::ClearAll"); - if (scrollView != nullptr) - { - scrollView->RemoveAll(); - - if (title != nullptr) - { - delete title; - title = nullptr; - } - - if (AiVoiceThinkingImageAnimatorView != nullptr) - { - AiVoiceThinkingImageAnimatorView->Stop(); - delete AiVoiceThinkingImageAnimatorView; - AiVoiceThinkingImageAnimatorView = nullptr; - - for (int i = 0; i < AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) - { - ImageCacheManager::GetInstance().UnloadSingleRes(thinking_path_array[i]); - } - - } - - if (cancelThink != nullptr) - { - delete cancelThink; - cancelThink = nullptr; - } - - if (cancelThinkButton != nullptr) - { - delete cancelThinkButton; - cancelThinkButton = nullptr; - } - - delete scrollView; - scrollView = nullptr; - } - } - - UILabelExt *AivoiceThinkingView::AivoiceThinkingLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetRollSpeed(23); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - UIButton *AivoiceThinkingView::AivoiceThinkingButtonInit(ButtonConfig &buttonconfig) - { - UIButton *button = new UIButton(); - if (button == nullptr) - { - return nullptr; - } - button->SetPosition(buttonconfig.x, buttonconfig.y, buttonconfig.w, buttonconfig.h); - button->SetViewId(buttonconfig.ViewId); - button->SetStyle(STYLE_BACKGROUND_COLOR, 0xff191919); - button->SetStyle(STYLE_BACKGROUND_OPA, 0xff); - button->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff191919, UIButton::PRESSED); - - return button; - } - - UIImageAnimatorView *AivoiceThinkingView::AivoiceThinkingImageAnimatorInit(ImageAnimatorConfig &imageanimatorconfig) - { - UIImageAnimatorView *animatorView = new UIImageAnimatorView(); - if (animatorView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceThinkingImageAnimatorView::AiVoiceThinkingImageAnimatorView new fail"); - return nullptr; - } - - for (uint8_t i = 0; i < imageanimatorconfig.numFrames; i++) - { - imageanimatorconfig.imageInfoArray[i].imageInfo = (imageanimatorconfig.pathsArray[i]); - // imageanimatorconfig.imageInfoArray[i].imagePath = (imageanimatorconfig.pathsArray[i]); - // imageanimatorconfig.imageInfoArray[i].imageType = IMG_SRC_FILE_PATH; - imageanimatorconfig.imageInfoArray[i].imageType = IMG_SRC_IMAGE_INFO; - 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->SetSizeFixed(true); - // animatorView->SetAutoEnable(false); - // animatorView->SetResizeMode(UIImageAnimatorView::FILL); - // animatorView->Start(); - - return animatorView; - } - - bool AivoiceThinkingView::CreateAivoiceThinkingScrollView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingScrollView"); - scrollView = new UIScrollView(); - if (scrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::scrollView new fail!"); - return false; - } - scrollView->SetPosition(0, 0, 466, 466); - UIView::OnDragListener *dragListener = static_cast(AiVoicePresenter::GetInstance()); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::dragListener new fail!"); - return false; - } - scrollView->SetOnDragListener(dragListener); - scrollView->SetTouchable(true); - scrollView->SetDraggable(true); - - return true; - } - - bool AivoiceThinkingView::CreateAivoiceThinkingLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingLabel"); - LabelConfig labelconfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_THINKING, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - title = AivoiceThinkingLabelInit(labelconfig); - if (title == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::title is nullptr!"); - return false; - } - /* -------------------------------------------------------------------------- */ - labelconfig = { - .left = 133, - .top = 368, - .width = 200, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_CANCEL, - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - cancelThink = AivoiceThinkingLabelInit(labelconfig); - if (cancelThink == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::cancelThink is nullptr!"); - return false; - } - cancelThink->SetTextColor(Color::GetColorFromRGBA(0xfd, 0x52, 0x03, 0xff)); - - return true; - } - - bool AivoiceThinkingView::CreateAivoiceThinkingButton(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingButton"); - ButtonConfig buttonconfig = { - .x = 93, - .y = 340, - .w = 280, - .h = 90, - .ViewId = CANCEL_THINKING_BUTTON_VIEW_ID, - }; - cancelThinkButton = AivoiceThinkingButtonInit(buttonconfig); - if (cancelThinkButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "cancelThinkButton new fail!"); - return false; - } - UIView::OnTouchListener *touchListener = static_cast(AiVoicePresenter::GetInstance()); - if (touchListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::touchListener can not be nullptr!"); - return false; - } - cancelThinkButton->SetOnTouchListener(touchListener); - - return true; - } - - bool AivoiceThinkingView::CreateAivoiceThinkingImageAnimator(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingImageAnimator"); - if (AiVoiceThinkingImageAnimatorView == nullptr) - { - AiVoiceThinkingImageAnimatorView = new UIImageAnimatorView(); - if (AiVoiceThinkingImageAnimatorView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::AivoiceThinkingImageAnimatorView new fail"); - return false; - } - } - for (uint8_t i = 0; i < AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES; i++) - { - AiVoiceThinkingImageInfo[i].imageInfo = ImageCacheManager::GetInstance().LoadSingleRes(thinking_path_array[i]); - AiVoiceThinkingImageInfo[i].imageType = IMG_SRC_IMAGE_INFO; - AiVoiceThinkingImageInfo[i].pos.x = AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_X; - AiVoiceThinkingImageInfo[i].pos.y = AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_Y; - AiVoiceThinkingImageInfo[i].width = AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_W; - AiVoiceThinkingImageInfo[i].height = AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_H; - } - AiVoiceThinkingImageAnimatorView->SetPosition(AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_X, AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_Y, - AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_W, AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_H); - AiVoiceThinkingImageAnimatorView->SetImageAnimatorSrc(AiVoiceThinkingImageInfo, AIVOICE_THINKING_IMAGE_ANIMATOR_VIEW_NUM_FRAMES, AIVOICE_THINKING_IMAGE_ANIMATOR_DELAY); - AiVoiceThinkingImageAnimatorView->SetRepeat(true); - AiVoiceThinkingImageAnimatorView->SetAutoEnable(false); - AiVoiceThinkingImageAnimatorView->SetResizeMode(UIImageView::FILL); - - 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"); - if (!CreateAivoiceThinkingScrollView()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingScrollView fail!!"); - } - if (!CreateAivoiceThinkingLabel()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingLabel fail!!"); - } - if (!CreateAivoiceThinkingButton()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingButton fail!!"); - } - if (!CreateAivoiceThinkingImageAnimator()) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingImageAnimator fail!!"); - } - - if (scrollView != nullptr) - { - if (title != nullptr) - { - scrollView->Add(title); - } - if (AiVoiceThinkingImageAnimatorView != nullptr) - { - scrollView->Add(AiVoiceThinkingImageAnimatorView); - } - if (cancelThinkButton != nullptr) - { - scrollView->Add(cancelThinkButton); - } - if (cancelThink != nullptr) - { - scrollView->Add(cancelThink); - } - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AivoiceThinkingView::CreateAivoiceThinkingView success!!"); - return scrollView; - } - else - { - return nullptr; - } - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/ApiKeysDeleteView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/ApiKeysDeleteView.cpp deleted file mode 100644 index 0d2138a99..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/ApiKeysDeleteView.cpp +++ /dev/null @@ -1,197 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:03:58 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-07-30 16:22:42 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/ApiKeysDeleteView.cpp - */ - -#include "aivoice/include/apikeys/ApiKeysDeleteView.h" -#include "aivoice/include/apikeys/ApiKeysPresenter.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -#include "UiConfig.h" -namespace OHOS -{ - ApiKeysDeleteView::ApiKeysDeleteView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::ApiKeysDeleteView"); - } - - ApiKeysDeleteView::~ApiKeysDeleteView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::~ApiKeysDeleteView"); - ClearAll(); - } - - void ApiKeysDeleteView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::ClearAll"); - - if (ApiKeysDeleteScrollView != nullptr) - { - ApiKeysDeleteScrollView->RemoveAll(); - if (clickListener != nullptr) - { - delete clickListener; - clickListener = nullptr; - } - if (dragListener != nullptr) - { - delete dragListener; - dragListener = nullptr; - } - if (ApiKeysDeleteTitleLabel != nullptr) - { - delete ApiKeysDeleteTitleLabel; - ApiKeysDeleteTitleLabel = nullptr; - } - - if (ApiKeysDeleteNoteLabel != nullptr) - { - delete ApiKeysDeleteNoteLabel; - ApiKeysDeleteNoteLabel = nullptr; - } - if (ApiKeysDeleteButton != nullptr) - { - delete ApiKeysDeleteButton; - ApiKeysDeleteButton = nullptr; - } - if (ApiKeysCancelDeleteButton != nullptr) - { - delete ApiKeysCancelDeleteButton; - ApiKeysCancelDeleteButton = nullptr; - } - delete ApiKeysDeleteScrollView; - ApiKeysDeleteScrollView = nullptr; - } - } - - UILabelExt *ApiKeysDeleteView::ApiKeysDeleteViewLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetRollSpeed(23); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - bool ApiKeysDeleteView::CreateApiKeysDeleteViewLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewLabel"); - LabelConfig labelConfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_API_KEYS, /*API Keys*/ - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - ApiKeysDeleteTitleLabel = ApiKeysDeleteViewLabelInit(labelConfig); - if (ApiKeysDeleteTitleLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::ApiKeysDeleteTitleLabel new fail!"); - return false; - } - ApiKeysDeleteScrollView->Add(ApiKeysDeleteTitleLabel); - /* -------------------------------------------------------------------------- */ - labelConfig.textId = STR_DYWTDAK; - labelConfig.top = 187; - ApiKeysDeleteNoteLabel = ApiKeysDeleteViewLabelInit(labelConfig); - if (ApiKeysDeleteNoteLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::ApiKeysDeleteNoteLabel new fail!"); - return false; - } - ApiKeysDeleteNoteLabel->SetTextColor(Color::GetColorFromRGBA(0x99, 0x99, 0x99, 0xff)); - - ApiKeysDeleteScrollView->Add(ApiKeysDeleteNoteLabel); - - return true; - } - - /*删除API Keys视图*/ - UIScrollView *ApiKeysDeleteView::CreateApiKeysDeleteView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::CreateApiKeysDeleteView"); - if (ApiKeysDeleteScrollView == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::CreateAiVoiceScrollView"); - ApiKeysDeleteScrollView = new UIScrollView(); - if (ApiKeysDeleteScrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::CreateApiKeysDeleteScrollView new fail!"); - return nullptr; - } - ApiKeysDeleteScrollView->SetPosition(0, 0, 466, 466); - ApiKeysDeleteScrollView->SetViewId(APIKEYS_DELETE_SCROLLVIEW_VIEWID); - ApiKeysDeleteScrollView->SetTouchable(true); - ApiKeysDeleteScrollView->SetDraggable(true); - if (dragListener == nullptr) - { - dragListener = new ApiKeysPresenter(); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::dragListener new fail!"); - } - } - ApiKeysDeleteScrollView->SetOnDragListener(dragListener); - /* -------------------------------------------------------------------------- */ - ApiKeysCancelDeleteButton = new UIButton(); - if (ApiKeysCancelDeleteButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::ApiKeysCancelDeleteButton new fail!"); - return nullptr; - } - ApiKeysCancelDeleteButton->SetPosition(111, 299, 100, 100); - ApiKeysCancelDeleteButton->SetViewId(APIKEYS_CANCEL_DELETE_BUTTON_VIEWID); - ApiKeysCancelDeleteButton->SetImageSrc(PNG_SYSTEM_CHECK_OFF_IMAGE,PNG_SYSTEM_CHECK_OFF_IMAGE); - ApiKeysCancelDeleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - ApiKeysCancelDeleteButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - ApiKeysCancelDeleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - ApiKeysDeleteScrollView->Add(ApiKeysCancelDeleteButton); - /* -------------------------------------------------------------------------- */ - ApiKeysDeleteButton = new UIButton(); - if (ApiKeysDeleteButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::ApiKeysDeleteButton new fail!"); - return nullptr; - } - ApiKeysDeleteButton->SetPosition(256, 299, 100, 100); - ApiKeysDeleteButton->SetViewId(APIKEYS_DELETE_BUTTON_VIEWID); - ApiKeysDeleteButton->SetImageSrc(PNG_SYSTEM_CHECK_ON_IMAGE,PNG_SYSTEM_CHECK_ON_IMAGE); - ApiKeysDeleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xff000000); - ApiKeysDeleteButton->SetStyle(STYLE_BACKGROUND_OPA, 0x00); - ApiKeysDeleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - ApiKeysDeleteScrollView->Add(ApiKeysDeleteButton); - /* -------------------------------------------------------------------------- */ - if (clickListener == nullptr) - { - clickListener = new ApiKeysPresenter(); - if (clickListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::clickListener new fail!"); - } - } - ApiKeysCancelDeleteButton->SetOnClickListener(clickListener); - ApiKeysDeleteButton->SetOnClickListener(clickListener); - /* -------------------------------------------------------------------------- */ - if (!CreateApiKeysDeleteViewLabel()) - { - return nullptr; - } - } - return ApiKeysDeleteScrollView; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp deleted file mode 100644 index cdea2d367..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp +++ /dev/null @@ -1,119 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:14:16 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-09-07 12:19:09 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/ApiKeysPresenter.cpp - */ - -#include "aivoice/include/apikeys/ApiKeysPresenter.h" -#include "aivoice/include/apikeys/SetApiKeysView.h" -#include "aivoice/include/apikeys/NotSetApiKeysView.h" -#include "aivoice/include/AiVoiceView.h" -#include "aivoice/include/AiVoiceModel.h" -#include "wearable_log.h" -#include "UiConfig.h" -#include "iostream" -#include "string" -#include "map" -namespace OHOS -{ - - static ApiKeysPresenter *g_pApiKeysPresenter = nullptr; - ApiKeysPresenter::ApiKeysPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::ApiKeysPresenter"); - g_pApiKeysPresenter = this; - } - - ApiKeysPresenter::~ApiKeysPresenter() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::ApiKeysPresenter"); - g_pApiKeysPresenter = nullptr; - } - - ApiKeysPresenter *ApiKeysPresenter::GetInstance() - { - return g_pApiKeysPresenter; - } - - bool ApiKeysPresenter::OnClick(UIView &view, const ClickEvent &event) - { - UNUSED(event); - std::string viewId = view.GetViewId(); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::OnClick ,viewId = %s", viewId.c_str()); - - AiVoiceModel::GetInstance().reset_ai_screen60s_timer_time(); // 重置60s取消常亮屏timer - - AiVoiceView *p_AiVoiceView = AiVoiceView::GetInstance(); - - std::map> viewMap = { - {SETAPIKEYS_DELETE_BUTTON_VIEWID, {AIVOICE_SETAPIKEYS, AIVOICE_APIKEYS_DELETE}}, /*进入到删除apikeys界面*/ - {NOTSETAPIKEYS_ENSURE_BUTTON_VIEWID, {AIVOICE_NOTSETAPIKEYS, AIVOICE_STARTCHAT_VIEWID}}, /*退到AI对话界面*/ - {APIKEYS_DELETE_BUTTON_VIEWID, {AIVOICE_APIKEYS_DELETE, AIVOICE_STARTCHAT_VIEWID}}, /*删除完apikeys退到AI对话界面*/ - {APIKEYS_CANCEL_DELETE_BUTTON_VIEWID, {AIVOICE_APIKEYS_DELETE, AIVOICE_SETAPIKEYS}}, /*退到已设置apikeys界面*/ - }; - - auto it = viewMap.find(viewId); - if (it != viewMap.end() && p_AiVoiceView != nullptr) - { - if (it->first == APIKEYS_DELETE_BUTTON_VIEWID) - { - AiVoiceModel::GetInstance().DeleteLocalOpenAIAPIKeys(); /*删除本地APIKeys*/ - } - p_AiVoiceView->ChangeView(it->second.first, it->second.second); - } - return true; - } - - bool ApiKeysPresenter::OnDrag(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::OnDrag"); - if ((event.GetDeltaX() > X_DRAG_OFFSET) && (event.GetDeltaX() > (DOUBLES * MATH_ABS(event.GetDeltaY())))) // 拖动过程中判断是否是水平滑动 - { - ApiKeysPresenter::X_DRAG_FLAG = true; - } - return true; - } - - bool ApiKeysPresenter::OnDragEnd(UIView &view, const DragEvent &event) - { - UNUSED(view); - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::OnDragEnd"); - std::string viewId = view.GetViewId(); - AiVoiceView *p_AiVoiceView = AiVoiceView::GetInstance(); - if (p_AiVoiceView == nullptr) - { - return false; - } - if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG) - { - std::map> viewMap = { - // {SETAPIKEYS_SCROLLVIEW_VIEWID, {AIVOICE_SETAPIKEYS, AIVOICE_STARTCHAT_VIEWID}}, - // {NOTSETAPIKEYS_SCROLLVIEW_VIEWID, {AIVOICE_NOTSETAPIKEYS, AIVOICE_STARTCHAT_VIEWID}}, - {APIKEYS_DELETE_SCROLLVIEW_VIEWID, {AIVOICE_APIKEYS_DELETE, AIVOICE_SETAPIKEYS}}, - }; - - auto it = viewMap.find(viewId); - if (it != viewMap.end()) - { - p_AiVoiceView->ChangeView(it->second.first, it->second.second); - } - X_DRAG_FLAG = false; - } - else if (event.GetDragDirection() == DragEvent::DIRECTION_TOP_TO_BOTTOM) /*下滑*/ - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "DIRECTION_TOP_TO_BOTTOM"); - if (viewId == SETAPIKEYS_SCROLLVIEW_VIEWID) - { - p_AiVoiceView->ChangeView(AIVOICE_SETAPIKEYS, AIVOICE_STARTCHAT_VIEWID); /*API Keys set界面->开始对话界面*/ - } - else if (viewId == NOTSETAPIKEYS_SCROLLVIEW_VIEWID) - { - p_AiVoiceView->ChangeView(AIVOICE_NOTSETAPIKEYS, AIVOICE_STARTCHAT_VIEWID); /*API Keys notset界面->开始对话界面*/ - } - } - return true; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/NotSetApiKeysView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/NotSetApiKeysView.cpp deleted file mode 100644 index 6c4c11dce..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/NotSetApiKeysView.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:04:23 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:20:24 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/NotSetApiKeysView.cpp - */ - -#include "aivoice/include/apikeys/NotSetApiKeysView.h" -#include "aivoice/include/apikeys/ApiKeysPresenter.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -namespace OHOS -{ - NotSetApiKeysView::NotSetApiKeysView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::NotSetApiKeysView"); - } - - NotSetApiKeysView::~NotSetApiKeysView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::~NotSetApiKeysView"); - ClearAll(); - } - - void NotSetApiKeysView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::ClearAll"); - - if (NotSetApiKeysScrollView != nullptr) - { - NotSetApiKeysScrollView->RemoveAll(); - if (clickListener != nullptr) - { - delete clickListener; - clickListener = nullptr; - } - if (dragListener != nullptr) - { - delete dragListener; - dragListener = nullptr; - } - if (NotSetApiKeysTitleLabel != nullptr) - { - delete NotSetApiKeysTitleLabel; - NotSetApiKeysTitleLabel = nullptr; - } - for (int i = 0; i < static_cast(sizeof(NotSetApiKeysNoteLabel) / sizeof(NotSetApiKeysNoteLabel[0])); i++) - { - if (NotSetApiKeysNoteLabel[i] != nullptr) - { - delete NotSetApiKeysNoteLabel[i]; - NotSetApiKeysNoteLabel[i] = nullptr; - } - } - if (NotSetApiKeysEnsureLabel != nullptr) - { - delete NotSetApiKeysEnsureLabel; - NotSetApiKeysEnsureLabel = nullptr; - } - if (NotSetApiKeysEnsureButton != nullptr) - { - delete NotSetApiKeysEnsureButton; - NotSetApiKeysEnsureButton = nullptr; - } - delete NotSetApiKeysScrollView; - NotSetApiKeysScrollView = nullptr; - } - } - - UILabelExt *NotSetApiKeysView::NotSetApiKeysViewLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetRollSpeed(23); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - bool NotSetApiKeysView::CreateNotSetApiKeysViewLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewLabel"); - LabelConfig labelConfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_API_KEYS, /*API Keys*/ - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - NotSetApiKeysTitleLabel = NotSetApiKeysViewLabelInit(labelConfig); - if (NotSetApiKeysTitleLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::NotSetApiKeysTitleLabel new fail!"); - return false; - } - NotSetApiKeysScrollView->Add(NotSetApiKeysTitleLabel); - /* -------------------------------------------------------------------------- */ - int textId[] = {STR_PGTTAF, STR_DAFBS, STR_OPENAI_API_KEYS}; - for (int i = 0; i < static_cast((sizeof(textId) / sizeof(textId[0]))); i++) - { - labelConfig.left = 53; - labelConfig.top = 161 + i * 35; - labelConfig.width = 360; - labelConfig.textId = textId[i]; - NotSetApiKeysNoteLabel[i] = NotSetApiKeysViewLabelInit(labelConfig); - if (NotSetApiKeysNoteLabel[i] == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::NotSetApiKeysNoteLabel[%d] new fail!", i); - return false; - } - NotSetApiKeysScrollView->Add(NotSetApiKeysNoteLabel[i]); - } - /* -------------------------------------------------------------------------- */ - labelConfig.left = 133; - labelConfig.top = 368; - labelConfig.width = 200; - labelConfig.textId = STR_OK; /*确定*/ - NotSetApiKeysEnsureLabel = NotSetApiKeysViewLabelInit(labelConfig); - if (NotSetApiKeysEnsureLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::NotSetApiKeysEnsureLabel new fail!"); - return false; - } - NotSetApiKeysScrollView->Add(NotSetApiKeysEnsureLabel); - return true; - } - - /*未配置了API Keys视图*/ - UIScrollView *NotSetApiKeysView::CreateNotSetApiKeysView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::CreateNotSetApiKeysView"); - if (NotSetApiKeysScrollView == nullptr) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::CreateAiVoiceScrollView"); - NotSetApiKeysScrollView = new UIScrollView(); - if (NotSetApiKeysScrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::CreateNotSetApiKeysScrollView new fail!"); - return nullptr; - } - NotSetApiKeysScrollView->SetPosition(0, 0, 466, 466); - NotSetApiKeysScrollView->SetViewId(NOTSETAPIKEYS_SCROLLVIEW_VIEWID); - NotSetApiKeysScrollView->SetTouchable(true); - NotSetApiKeysScrollView->SetDraggable(true); - if (dragListener == nullptr) - { - dragListener = new ApiKeysPresenter(); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::dragListener new fail!"); - } - } - NotSetApiKeysScrollView->SetOnDragListener(dragListener); - /* -------------------------------------------------------------------------- */ - NotSetApiKeysEnsureButton = new UIButton(); - if (NotSetApiKeysEnsureButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::NotSetApiKeysEnsureButton new fail!"); - return nullptr; - } - NotSetApiKeysEnsureButton->SetPosition(93, 340, 280, 90); - NotSetApiKeysEnsureButton->SetViewId(NOTSETAPIKEYS_ENSURE_BUTTON_VIEWID); - NotSetApiKeysEnsureButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xfffd5213); - NotSetApiKeysEnsureButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - if (clickListener == nullptr) - { - clickListener = new ApiKeysPresenter(); - if (clickListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::clickListener new fail!"); - } - } - NotSetApiKeysEnsureButton->SetOnClickListener(clickListener); - NotSetApiKeysScrollView->Add(NotSetApiKeysEnsureButton); - /* -------------------------------------------------------------------------- */ - if (!CreateNotSetApiKeysViewLabel()) - { - return nullptr; - } - } - return NotSetApiKeysScrollView; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/SetApiKeysView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/SetApiKeysView.cpp deleted file mode 100644 index 6ba568783..000000000 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/aivoice/src/apikeys/SetApiKeysView.cpp +++ /dev/null @@ -1,210 +0,0 @@ -/* - * @Author: luozheng 1732036298@qq.com - * @Date: 2024-07-29 16:04:23 - * @LastEditors: luozheng 1732036298@qq.com - * @LastEditTime: 2024-11-05 11:20:35 - * @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/SetApiKeysView.cpp - */ - -#include "aivoice/include/apikeys/SetApiKeysView.h" -#include "aivoice/include/apikeys/ApiKeysPresenter.h" -#include "wearable_log.h" -#include "ui_resource_string.h" -namespace OHOS -{ - SetApiKeysView::SetApiKeysView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::SetApiKeysView"); - } - - SetApiKeysView::~SetApiKeysView() - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::~SetApiKeysView"); - ClearAll(); - } - - void SetApiKeysView::ClearAll(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::ClearAll"); - - if (SetApiKeysScrollView != nullptr) - { - SetApiKeysScrollView->RemoveAll(); - if (clickListener != nullptr) - { - delete clickListener; - clickListener = nullptr; - } - if (dragListener != nullptr) - { - delete dragListener; - dragListener = nullptr; - } - if (SetApiKeysTitleLabel != nullptr) - { - delete SetApiKeysTitleLabel; - SetApiKeysTitleLabel = nullptr; - } - if (SetApiKeysImage != nullptr) - { - delete SetApiKeysImage; - SetApiKeysImage = nullptr; - } - if (SetApiKeysDeleteLabel != nullptr) - { - delete SetApiKeysDeleteLabel; - SetApiKeysDeleteLabel = nullptr; - } - if (SetApiKeysNoteLabel[0] != nullptr) - { - delete SetApiKeysNoteLabel[0]; - SetApiKeysNoteLabel[0] = nullptr; - } - if (SetApiKeysNoteLabel[1] != nullptr) - { - delete SetApiKeysNoteLabel[1]; - SetApiKeysNoteLabel[1] = nullptr; - } - if (SetApiKeysDeleteButton != nullptr) - { - delete SetApiKeysDeleteButton; - SetApiKeysDeleteButton = nullptr; - } - delete SetApiKeysScrollView; - SetApiKeysScrollView = nullptr; - } - } - - UILabelExt *SetApiKeysView::SetApiKeysViewLabelInit(LabelConfig &labelconfig) - { - UILabelExt *label = new UILabelExt(); - if (label == nullptr) - { - return nullptr; - } - label->SetPosition(labelconfig.left, labelconfig.top, labelconfig.width, labelconfig.height); - label->SetStyle(STYLE_TEXT_FONT, labelconfig.fontSize); - label->SetStyle(STYLE_LINE_HEIGHT, labelconfig.lineHeigh); - label->SetTextId(labelconfig.textId); - label->SetLineBreakMode(labelconfig.lineBreakMode); - label->SetAlign(TEXT_ALIGNMENT_CENTER, TEXT_ALIGNMENT_CENTER); - label->SetRollSpeed(23); - label->SetFont(DEFAULT_VECTOR_FONT_FILENAME, labelconfig.fontSize); - return label; - } - - bool SetApiKeysView::CreateSetApiKeysViewLabel(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::CreateSetApiKeysViewLabel"); - LabelConfig labelConfig = { - .left = 83, - .top = 50, - .width = 300, - .height = 35, - .fontSize = 30, - .lineHeigh = 35, - .textId = STR_API_KEYS, /*API Keys*/ - .lineBreakMode = UILabel::LINE_BREAK_OSCILLATION, - }; - SetApiKeysTitleLabel = SetApiKeysViewLabelInit(labelConfig); - if (SetApiKeysTitleLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::SetApiKeysTitleLabel new fail!"); - return false; - } - SetApiKeysScrollView->Add(SetApiKeysTitleLabel); - /* -------------------------------------------------------------------------- */ - int textId[] = {STR_KHBB, STR_GTAS}; - for (int i = 0; i < static_cast((sizeof(textId) / sizeof(textId[0]))); i++) - { - labelConfig.left = 53; - labelConfig.top = 235 + i * 35; - labelConfig.width = 360; - labelConfig.textId = textId[i]; - SetApiKeysNoteLabel[i] = SetApiKeysViewLabelInit(labelConfig); - if (SetApiKeysNoteLabel[i] == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::SetApiKeysNoteLabel[%d] new fail!", i); - return false; - } - SetApiKeysScrollView->Add(SetApiKeysNoteLabel[i]); - } - /* -------------------------------------------------------------------------- */ - labelConfig.left = 133; - labelConfig.top = 368; - labelConfig.width = 200; - labelConfig.textId = STR_DELETE; /*删除*/ - SetApiKeysDeleteLabel = SetApiKeysViewLabelInit(labelConfig); - if (SetApiKeysDeleteLabel == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::SetApiKeysDeleteLabel new fail!"); - return false; - } - SetApiKeysScrollView->Add(SetApiKeysDeleteLabel); - return true; - } - - /*成功配置了API Keys视图*/ - UIScrollView *SetApiKeysView::CreateSetApiKeysView(void) - { - WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::CreateSetApiKeysView"); - if (SetApiKeysScrollView == nullptr) - { - SetApiKeysScrollView = new UIScrollView(); - if (SetApiKeysScrollView == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::CreateSetApiKeysScrollView new fail!"); - return nullptr; - } - SetApiKeysScrollView->SetPosition(0, 0, 466, 466); - SetApiKeysScrollView->SetViewId(SETAPIKEYS_SCROLLVIEW_VIEWID); - SetApiKeysScrollView->SetTouchable(true); - SetApiKeysScrollView->SetDraggable(true); - if (dragListener == nullptr) - { - dragListener = new ApiKeysPresenter(); - if (dragListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::dragListener new fail!"); - } - } - SetApiKeysScrollView->SetOnDragListener(dragListener); - /* -------------------------------------------------------------------------- */ - SetApiKeysImage = new UIImageView(); - if (SetApiKeysImage == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::SetApiKeysImage new fail!"); - } - SetApiKeysImage->SetPosition(193, 121, 80, 80); - SetApiKeysImage->SetSrc(SETAPIKEYS_IMAGE_PATH); - SetApiKeysScrollView->Add(SetApiKeysImage); - /* -------------------------------------------------------------------------- */ - SetApiKeysDeleteButton = new UIButton(); - if (SetApiKeysDeleteButton == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::SetApiKeysDeleteButton new fail!"); - return nullptr; - } - SetApiKeysDeleteButton->SetPosition(93, 340, 280, 90); - SetApiKeysDeleteButton->SetViewId(SETAPIKEYS_DELETE_BUTTON_VIEWID); - SetApiKeysDeleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xfffd5213); - SetApiKeysDeleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED); - if (clickListener == nullptr) - { - clickListener = new ApiKeysPresenter(); - if (clickListener == nullptr) - { - WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::clickListener new fail!"); - } - } - SetApiKeysDeleteButton->SetOnClickListener(clickListener); - SetApiKeysScrollView->Add(SetApiKeysDeleteButton); - /* -------------------------------------------------------------------------- */ - if (!CreateSetApiKeysViewLabel()) - { - return nullptr; - } - } - return SetApiKeysScrollView; - } -} \ No newline at end of file diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/PlayersView.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/PlayersView.cpp index 12a73c1ba..842da114a 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/PlayersView.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/player/src/PlayersView.cpp @@ -1572,7 +1572,7 @@ namespace OHOS } if (musicPlayerConnectingView != nullptr) { - StartOrStopAiVoiceConnectingImageAnimatorView(true); + musicPlayerConnectingView->StartOrStopAiVoiceConnectingImageAnimatorView(true); } PlayersModel::GetInstance()->PlayerMusic_StartTimer(); return true; diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp index 1fd98fa0c..b55fc95bb 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/rebootandshutdown/src/RebootAndShutdownModel.cpp @@ -16,7 +16,6 @@ #include "settings/include/SettingModel.h" #include #include "themestyle/include/ThemeStyleModel.h" -#include "aivoice/include/AiVoiceModel.h" #include "graphic_service.h" #ifdef SUPPORT_BLE_SERVICE #include @@ -274,10 +273,6 @@ namespace OHOS if (display_api->get_screen_state() == SCREEN_ON) { uint16_t curSliceId = NativeAbility::GetInstance().GetCurSliceId(); - if (curSliceId == VIEW_AI_VOICE) // 如果当前已在ai语音界面就切换模型 - { - AiVoiceModel::GetInstance().FunctionKeyOnClickToChangeAIModel(); - } } return; @@ -422,15 +417,6 @@ namespace OHOS return; } } - if (curSliceId == VIEW_AI_VOICE) // 如果当前已在ai语音界面单击切换模型 - { - AiVoiceModel::GetInstance().FunctionKeyOnClickToChangeAIModel(); - return; - } - else - { - NativeAbility::GetInstance().EnterSlice(VIEW_AI_VOICE); // 切换到Ai语音界面 - } } else { diff --git a/code/sdk/application/wearable/fd272/nativeapp/nativeui/uiservice/src/ui_service.cpp b/code/sdk/application/wearable/fd272/nativeapp/nativeui/uiservice/src/ui_service.cpp index c393b370b..16fe7b1bf 100644 --- a/code/sdk/application/wearable/fd272/nativeapp/nativeui/uiservice/src/ui_service.cpp +++ b/code/sdk/application/wearable/fd272/nativeapp/nativeui/uiservice/src/ui_service.cpp @@ -49,7 +49,6 @@ #include "record/include/RecordingModel.h" #include "message/include/MessageModel.h" #include "heartrate/include/HeartModel.h" -#include "aivoice/include/AiVoiceModel.h" #include "weather/include/WeatherModel.h" #include "alarm/include/AlarmClockModel.h" #include "uiservice/include/ui_service.h" @@ -563,24 +562,18 @@ void HandleUpdateMusicPlayerList(Request *request) void HandleAiJumpToResultView(Request *request) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleAiJumpToResultView"); - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::AiVoiceModel::ChangeToReturnResultTextView, &OHOS::AiVoiceModel::GetInstance())); } // 处理更新用户问题字符串 void HandleUpdateUserQuestionStr(Request *request) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleUpdateUserQuestionStr"); - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::AiVoiceModel::UpdateUserQuestionStr, &OHOS::AiVoiceModel::GetInstance())); } // 处理更新AI答案字符串 void HandleUpdateAIAnswerStr(Request *request) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleUpdateAIAnswerStr"); - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::AiVoiceModel::UpdateAiAnswerStr, &OHOS::AiVoiceModel::GetInstance())); } // 处理手表第一次启动用来跳转主界面的 @@ -604,16 +597,12 @@ void HandleAiJumpToListeningMessage(Request *request) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleAiJumpToListeningMessage"); bool state = *((bool *)request->data); - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::AiVoiceModel::ChangeToAIVoiceListeningView, &OHOS::AiVoiceModel::GetInstance(), state)); } // 处理跳转AI回应错误界面 void HandleAiJumpToRespondErrMessage(Request *request) { WEARABLE_LOGI(WEARABLE_LOG_MODULE_UI_SERVICE, "HandleAiJumpToRespondErrMessage"); - GraphicService::GetInstance()->PostGraphicEvent( - std::bind(&OHOS::AiVoiceModel::ChangeToAIVoiceConnectTimeoutView, &OHOS::AiVoiceModel::GetInstance())); } // 处理更新录音进度条 diff --git a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/findwatch_notification.cpp b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/findwatch_notification.cpp index 42d41c092..f8effa38b 100644 --- a/code/sdk/application/wearable/fd272/service/msg_center/src/notify/findwatch_notification.cpp +++ b/code/sdk/application/wearable/fd272/service/msg_center/src/notify/findwatch_notification.cpp @@ -12,7 +12,6 @@ #include "vibrator_service.h" #include "custom_runtime.h" #include -#include "aivoice/include/AiVoiceModel.h" #include #include "findwatch_notification.h" diff --git a/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp b/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp index 9bb87f6cf..3b17979f5 100644 --- a/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp +++ b/code/sdk/zhihui/services/ble_service/blemoder/ble_instruct_init.cpp @@ -13,12 +13,15 @@ #include "app_store.h" #include "rebootandshutdown/include/RebootAndShutdownModelC.h" #include "ScheduleModel.h" +#ifndef BOARD_FD272 #include "AiVoiceModelC.h" - +#endif void ble_instruct_init(void) { + #ifndef BOARD_FD272 ble_AI_init(); + #endif ble_Schedule_init();