* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:14:43
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-27 17:22:08
+ * @LastEditTime: 2024-07-30 15:47:01
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/include/AiVoiceModel.h
*/
#ifndef AI_VOICE_MODEL_H
bool CreateIfNotExists();
void StatusResume(void);
- // 获取设备状态
+ bool IsExistOpenAIAPIKeys();
+ void DeleteLocalOpenAIAPIKeys();
bool GetBluetoothIsOpen(void);
bool GetMobileDataIsOpen(void);
bool GetAiVoiceConnectStatus(void);
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-08 09:36:01
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-29 18:28:04
+ * @LastEditTime: 2024-07-30 15:15:46
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/respiratorytraining/include/AiVoiceView.h
*/
#ifndef AI_VOICE_VIEW_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 "ui_resource_string.h"
#include "iostream"
#include "string"
static constexpr const char *AIMODEL_DOUBAO_PATH = "/user/res/AIVoice/aimodels/aimodels_doubao.bin"; /*豆包*/
static constexpr const char *AIVOICE_START_CHAT_BUTTON_VIEW_ID = "aivoice_start_chat_button_view_id"; // 开始对话
- static constexpr const char *AIVOICE_CHAT_BUTTON_VIEW_ID = AIVOICE_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";
AIVOICE_LISTENING_VIEWID, // 聆听中界面
AIVOICE_THINKING_VIEWID, // 思考中界面
AIVOICE_RETURN_RESULT_TEXT_VIEWID, // 返回结果文本界面
- AIVOICE_APIKEYS, // API Keys界面
+ AIVOICE_SETAPIKEYS, // API Keys set界面
+ AIVOICE_NOTSETAPIKEYS, // API Keys notset界面
+ AIVOICE_APIKEYS_DELETE, // API Keys 删除界面
MAX_AIVOICE_VIEWID,
} AIVOICEVIEWID;
bool ChangeAiVoicListeningView(int16_t thisView);
bool ChangeAiVoicThinkingView(int16_t thisView);
bool ChangeAiVoicReturnResultTextView(int16_t thisView);
- bool ChangeAiVoicApiKeysView(int16_t thisView);
+ bool ChangeAiVoicSetApiKeysView(int16_t thisView);
+ bool ChangeAiVoicNotSetApiKeysView(int16_t thisView);
+ bool ChangeAiVoicApiKeysDeleteView(int16_t thisView);
void SetAiVoiceViewAllComponentsVisibilityStatus();
void ChangeAiModelAndUpdateComponentsStatus(void);
AivoiceThinkingView *p_AivoiceThinkingView{nullptr};
AivoiceReturnResultTextView *p_AivoiceReturnResultTextView{nullptr};
SetApiKeysView *p_SetApiKeysView{nullptr};
+ NotSetApiKeysView *p_NotSetApiKeysView{nullptr};
+ ApiKeysDeleteView *p_ApiKeysDeleteView{nullptr};
private:
UILabelExt *AiVoiceViewLabelInit(LabelConfig &labelconfig);
+/*
+ * @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
+/*
+ * @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
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:14:50
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-29 09:50:45
+ * @LastEditTime: 2024-07-30 18:33:12
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoiceModel.cpp
*/
#include "aivoice/include/AiVoiceModel.h"
return true;
}
+ /*获取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");
+ }
+
// 获取蓝牙是否打开
bool AiVoiceModel::GetBluetoothIsOpen(void)
{
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-06-20 15:11:17
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-29 18:43:03
+ * @LastEditTime: 2024-07-30 18:35:35
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/AiVoicePresenter.cpp
*/
#include "AppViewIDs.h"
std::string viewId = view.GetViewId();
WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoicePresenter::OnRelease %s", viewId.c_str());
- if (viewId == AIVOICE_START_CHAT_BUTTON_VIEW_ID) // 如果点击的是开始对话按钮
+ if ((viewId == AIVOICE_CHAT_BUTTON_VIEW_ID) && model->IsExistOpenAIAPIKeys() == false) // 如果点击的是(对话按钮)且未配置apikey
{
-#if 0
- if (model->GetMobileDataIsOpen() == false) // 判断移动数据是否开启
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/
+ return true;
+ }
+ else if (viewId == AIVOICE_APIKEYS_BUTTON_VIEW_ID) // 如果点击的是API Keys按钮
+ {
+ if (model->IsExistOpenAIAPIKeys() == true)
{
- view_->ChangeView(AIVOICE_STARTCHAT_VIEWID, AIVOICE_MOBILEDATA_FAILEDSTART_VIEWID); // 开始对话->移动数据未开启界面
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_SETAPIKEYS); /*开始对话界面->API Keys set界面*/
}
else
{
- ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID,AIVOICE_LISTENING_VIEWID);
+ ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_NOTSETAPIKEYS); /*开始对话界面->API Keys notset界面*/
}
-#else
+ return true;
+ }
+ else if (viewId == AIVOICE_START_CHAT_BUTTON_VIEW_ID) // 如果点击的是开始对话按钮
+ {
+ /*
+ * 进入对话流程:
+ * 1.当手表4G网络正常+与app连接正常 -> 通过4G调用大模型
+ * 2.只有手表4G网络正常 -> 通过4G调用大模型
+ * 3.只有与APP蓝牙连接正常 -> 通过蓝牙连接APP调用大模型
+ * 4.两者连接都异常 -> 返回错误
+ */
bool state = model->GetBluetoothIsOpen();
(state == false)
? ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_BLUETOOTH_FAILEDSTART_VIEWID)
: ChangeViewAndLogicOperator(AIVOICE_STARTCHAT_VIEWID, AIVOICE_LISTENING_VIEWID);
-#endif
+
return true;
}
{CANCEL_THINKING_BUTTON_VIEW_ID, {AIVOICE_THINKING_VIEWID, AIVOICE_STARTCHAT_VIEWID}}, // 返回一级界面
{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}}, // 返回继续聆听,并清除手表聊天记录
- {AIVOICE_APIKEYS_BUTTON_VIEW_ID, {AIVOICE_STARTCHAT_VIEWID, AIVOICE_APIKEYS}}, // 进入api keys界面
};
auto it = viewIdMap.find(viewId);
if (it != viewIdMap.end())
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-05-07 11:25:58
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-29 18:54:16
+ * @LastEditTime: 2024-07-30 17:23:59
* @FilePath: /FD230/code/sdk/application/wearable/fd230app/nativeui/AiVoice/src/AiVoiceView.cpp
*/
#include "aivoice/include/AiVoicePresenter.h"
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;
+ }
}
}
return true;
}
- /*切换到apikeys界面*/
- bool AiVoiceView::ChangeAiVoicApiKeysView(int16_t thisView)
+ /*切换到setapikeys界面*/
+ bool AiVoiceView::ChangeAiVoicSetApiKeysView(int16_t thisView)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicReturnResultTextView");
+ WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "AiVoiceView::ChangeAiVoicSetApiKeysView");
if (AiVoiceScrollView[thisView] == nullptr)
{
p_SetApiKeysView = new SetApiKeysView();
return true;
}
+ /*切换到notsetapikeys界面*/
+ bool AiVoiceView::ChangeAiVoicNotSetApiKeysView(int16_t thisView)
+ {
+ WEARABLE_LOGE(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();
+ container_->Add(AiVoiceScrollView[thisView]);
+ }
+ return true;
+ }
+
+ /*切换到apikeys删除界面*/
+ bool AiVoiceView::ChangeAiVoicApiKeysDeleteView(int16_t thisView)
+ {
+ WEARABLE_LOGE(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();
+ container_->Add(AiVoiceScrollView[thisView]);
+ }
+ return true;
+ }
+
struct AiVoiceViewMapper
{
const int16_t viewId;
{AIVOICE_LISTENING_VIEWID, &AiVoiceView::ChangeAiVoicListeningView},
{AIVOICE_THINKING_VIEWID, &AiVoiceView::ChangeAiVoicThinkingView},
{AIVOICE_RETURN_RESULT_TEXT_VIEWID, &AiVoiceView::ChangeAiVoicReturnResultTextView},
- {AIVOICE_APIKEYS, &AiVoiceView::ChangeAiVoicApiKeysView},
+ {AIVOICE_SETAPIKEYS, &AiVoiceView::ChangeAiVoicSetApiKeysView},
+ {AIVOICE_NOTSETAPIKEYS, &AiVoiceView::ChangeAiVoicNotSetApiKeysView},
+ {AIVOICE_APIKEYS_DELETE, &AiVoiceView::ChangeAiVoicApiKeysDeleteView},
};
bool AiVoiceView::ClickFunc(int16_t interface)
+/*
+ * @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_LOGE(WEARABLE_LOG_MODULE_APP, "ApiKeysDeleteView::ApiKeysDeleteView");
+ }
+
+ ApiKeysDeleteView::~ApiKeysDeleteView()
+ {
+ WEARABLE_LOGE(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(70);
+ 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
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-07-29 16:14:16
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-29 18:25:52
+ * @LastEditTime: 2024-07-30 15:52:11
* @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
{
bool ApiKeysPresenter::OnClick(UIView &view, const ClickEvent &event)
{
UNUSED(event);
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::OnClick");
std::string viewId = view.GetViewId();
- if (viewId == SETAPIKEYS_DELETE_BUTTON_VIEWID)
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::OnClick ,viewId = %s", viewId.c_str());
+
+ AiVoiceView *p_AiVoiceView = AiVoiceView::GetInstance();
+
+ std::map<std::string, std::pair<int, int>> 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)
{
- WEARABLE_LOGE(WEARABLE_LOG_MODULE_APP, "SETAPIKEYS_DELETE_BUTTON_VIEWID");
+ if (it->first == APIKEYS_DELETE_BUTTON_VIEWID)
+ {
+ AiVoiceModel::GetInstance().DeleteLocalOpenAIAPIKeys(); /*删除本地APIKeys*/
+ }
+ p_AiVoiceView->ChangeView(it->second.first, it->second.second);
}
return true;
}
UNUSED(view);
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "ApiKeysPresenter::OnDragEnd");
std::string viewId = view.GetViewId();
+
if (event.GetDragDirection() == DragEvent::DIRECTION_LEFT_TO_RIGHT && X_DRAG_FLAG)
{
AiVoiceView *p_AiVoiceView = AiVoiceView::GetInstance();
- if (p_AiVoiceView != nullptr && viewId == SETAPIKEYS_SCROLLVIEW_VIEWID)
+
+ std::map<std::string, std::pair<int, int>> 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 != nullptr)
{
- p_AiVoiceView->ChangeView(AIVOICE_APIKEYS, AIVOICE_STARTCHAT_VIEWID);
+ p_AiVoiceView->ChangeView(it->second.first, it->second.second);
}
X_DRAG_FLAG = false;
}
+/*
+ * @Author: luozheng 1732036298@qq.com
+ * @Date: 2024-07-29 16:04:23
+ * @LastEditors: luozheng 1732036298@qq.com
+ * @LastEditTime: 2024-07-30 18:34:01
+ * @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_LOGE(WEARABLE_LOG_MODULE_APP, "NotSetApiKeysView::NotSetApiKeysView");
+ }
+
+ NotSetApiKeysView::~NotSetApiKeysView()
+ {
+ WEARABLE_LOGE(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<int>(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(70);
+ 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<int>((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
* @Author: luozheng 1732036298@qq.com
* @Date: 2024-07-29 16:04:23
* @LastEditors: luozheng 1732036298@qq.com
- * @LastEditTime: 2024-07-29 19:12:42
+ * @LastEditTime: 2024-07-30 16:22:06
* @FilePath: /xts_origin/FD230/code/sdk/application/wearable/fd230app/nativeui/aivoice/src/apikeys/SetApiKeysView.cpp
*/
bool SetApiKeysView::CreateSetApiKeysViewLabel(void)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "AiVoiceView::CreateAiVoiceViewLabel");
+ WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::CreateSetApiKeysViewLabel");
LabelConfig labelConfig = {
.left = 83,
.top = 50,
WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::CreateSetApiKeysView");
if (SetApiKeysScrollView == nullptr)
{
- WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "SetApiKeysView::CreateAiVoiceScrollView");
SetApiKeysScrollView = new UIScrollView();
if (SetApiKeysScrollView == nullptr)
{
SetApiKeysDeleteButton->SetPosition(93, 340, 280, 90);
SetApiKeysDeleteButton->SetViewId(SETAPIKEYS_DELETE_BUTTON_VIEWID);
SetApiKeysDeleteButton->SetStyle(STYLE_BACKGROUND_COLOR, 0xfffd5213);
- SetApiKeysDeleteButton->SetStyleForState(STYLE_BORDER_COLOR, 0xff0b1928, UIButton::PRESSED);
+ SetApiKeysDeleteButton->SetStyleForState(STYLE_BACKGROUND_COLOR, 0xff383838, UIButton::PRESSED);
if (clickListener == nullptr)
{
clickListener = new ApiKeysPresenter();
CONFIGMOFEL_ITEM_DMP_CHINA_MOBILE_ADDRESS,//移动入库地址默认测试是适配地址 b.fxltsbl.com 出正式需要修改商用地址 a.fxltsbl.com
CONFIGMODEL_ITEM_SELECT_AIMODEL,//ai模型
CONFIGMODEL_ITEM_FIRSTTIMESTART,//手表是否是第一次启动
+ CONFIGMODEL_ITEM_OPEN_AI_API_KEYS,//API Keys
CONFIGMODEL_ITEM_MAX,
} ;
/* -------------------------------------------------------------------------- */
void SetisFirstTimeStart(bool value);
bool GetisFirstTimeStart(void);
+ /* ---------------------------- 设置OpenAI APIKeys ---------------------------- */
+ void SetOpenAIAPIKeys(char * value);
+ std::string GetOpenAIAPIKeys(void);
/* --------------------------------- 用户配置信息 --------------------------------- */
void SetUserAge(int age);
int GetUserAge();
{ConfigDataType::DATATYPE_STRING, "dmp_china_mobile_address", "b.fxltsbl.com"},//CONFIGMOFEL_ITEM_DMP_CHINA_MOBILE_ADDRESS 移动入库地址 测试使用适配地址 IP = b.fxltsbl.com 出正式使用商用地址 IP = a.fxltsbl.com
{ConfigDataType::DATATYPE_INT, "select_aimodel", "0" },//CONFIGMODEL_ITEM_SELECT_AIMODEL
{ConfigDataType::DATATYPE_BOOL, "is_first_time_start", "true" }, //CONFIGMODEL_ITEM_FIRSTTIMESTART true :手表第一次启动,否则不是
+ {ConfigDataType::DATATYPE_STRING, "open_ai_api_keys", "-1" }, //CONFIGMODEL_ITEM_OPEN_AI_API_KEYS
};
ConfigModel(); // 私有构造函数,确保无法在外部实例化
ConfigModel(const ConfigModel &) = delete; // 禁止拷贝构造
{
return get_configData_bool(CONFIGMODEL_ITEM_FIRSTTIMESTART);
}
+
+ /*设置API Keys*/
+ void ConfigModel::SetOpenAIAPIKeys(char * value)
+ {
+ set_condigData_String(CONFIGMODEL_ITEM_OPEN_AI_API_KEYS,value);
+ }
+
+ /*获取API Keys*/
+ std::string ConfigModel::GetOpenAIAPIKeys(void)
+ {
+ return get_configData_string(CONFIGMODEL_ITEM_OPEN_AI_API_KEYS);
+ }
/* -------------------------------------------------------------------------- */
/*设置用户年龄[后续使用结构体统一配置]*/
void ConfigModel::SetUserAge(int age)