145 lines
5.5 KiB
C++
145 lines
5.5 KiB
C++
#include "TjdUiAppVoiceAssistantPresenter.h"
|
|
#include "NativeAbility.h"
|
|
#include "TjdUiAppIds.h"
|
|
#include "dock/input_device.h"
|
|
#include "sys_config.h"
|
|
#include "TjdUiAppVoiceAssistantView.h"
|
|
#include "TjdUiAppVocassistModel.h"
|
|
#include "TjdUiAppPlayerModel.h"
|
|
#include "TjdUiRegisterManager.h"
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#include "ble_api.h"
|
|
#include "ble_port_protocol.h"
|
|
|
|
// extern uint8_t g_server_id;
|
|
// extern uint8_t g_server_conn_id;
|
|
// extern uint16_t g_server_handle;
|
|
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
using namespace OHOS;
|
|
|
|
#define ENABLE_PRINT_INFO 1
|
|
#if ENABLE_PRINT_INFO
|
|
#define static_print_info(...) sys_ui_log_i(__VA_ARGS__) // 一般信息打印宏控制
|
|
#define static_print_warn(...) sys_ui_log_w(__VA_ARGS__) // 警告信息打印一般常开
|
|
#define static_print_error(...) sys_ui_log_e(__VA_ARGS__) // 错误信息打印一般常开
|
|
#define static_print_debug(...) sys_ui_log_d(__VA_ARGS__) // 调试信息打印
|
|
#else
|
|
#define static_print_info(...)
|
|
#define static_print_warn(...)
|
|
#define static_print_error(...)
|
|
#define static_print_debug(...)
|
|
#endif
|
|
|
|
namespace TJD {
|
|
|
|
// TJD_REGIST_NATIVE_MENU(TJD_APP_VIEW_VOICE_ASSISTANT, TjdUiAppVoiceAssistantView, TjdUiAppVoiceAssistantPresenter, IMG_MENU_LIST_MENU_AI, STR_ID_26);
|
|
|
|
static TjdUiAppVoiceAssistantPresenter *g_pv_AppVoiceAssistantPresenter = nullptr;
|
|
|
|
TjdUiAppVoiceAssistantPresenter::TjdUiAppVoiceAssistantPresenter() { g_pv_AppVoiceAssistantPresenter = this; }
|
|
|
|
TjdUiAppVoiceAssistantPresenter::~TjdUiAppVoiceAssistantPresenter() { g_pv_AppVoiceAssistantPresenter = nullptr; }
|
|
|
|
TjdUiAppVoiceAssistantPresenter *TjdUiAppVoiceAssistantPresenter::GetInstance(void) { return g_pv_AppVoiceAssistantPresenter; }
|
|
|
|
void TjdUiAppVoiceAssistantPresenter::OnStart()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->SetOnKeyActListener(this, KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
void TjdUiAppVoiceAssistantPresenter::OnStop()
|
|
{
|
|
TjdUiCommonOnKeyListener::GetInstance()->ClearOnKeyActListener(KeyModelType::APP_KEY_TYPE);
|
|
}
|
|
|
|
bool TjdUiAppVoiceAssistantPresenter::OnKeyAct(OHOS::UIView &view, const OHOS::KeyEvent &event)
|
|
{
|
|
if (!TjdUiCommonOnKeyListener::CheckIsExitEvent(event)){
|
|
return true;
|
|
}
|
|
ExitVoiceAssistantView();
|
|
|
|
return false;
|
|
}
|
|
|
|
bool TjdUiAppVoiceAssistantPresenter::OnClick(UIView &view, const ClickEvent &event)
|
|
{
|
|
if (view.GetViewId() == "ContinueButton") {
|
|
if(TjdUiAppPlayerModel::GetInstance()->GetPlayerCtr() != NULL){
|
|
TjdUiAppPlayerModel::GetInstance()->GetPlayerCtr()->Pause();
|
|
}
|
|
TjdUiVocassistModel::GetInstance()->SetHasOneCmd(false);
|
|
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_AWAKENIEW);
|
|
return true;
|
|
} else if (view.GetViewId() == "ReturnButton") {
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
void TjdUiAppVoiceAssistantPresenter::ExitVoiceAssistantView(void)
|
|
{
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
}
|
|
|
|
void TjdUiAppVoiceAssistantPresenter::ViewExitEvent(bool isSwipe)
|
|
{
|
|
TjdUiAppVoiceAssistantView *gameView = TjdUiAppVoiceAssistantView::GetInstance();
|
|
if (gameView == nullptr) {
|
|
return;
|
|
}
|
|
switch (TjdUiAppVoiceAssistantView::currentViewIndex_) {
|
|
case VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW:
|
|
case VoiceAssistantIndex::VOICEASSISTANT_AWAKENIEW:
|
|
OHOS::NativeAbility::GetInstance().ChangePreSlice();
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
// void TjdUiAppVoiceAssistantPresenter::VocAssistDeal(int flag)
|
|
// {
|
|
// if (VoiceAssistance::GetInstance() == nullptr) {
|
|
// return;
|
|
// }
|
|
|
|
// if (VocassistModel::GetInstance()->GetPhoneDetailStatus() == ONE_ROAD_AND_INCOMING &&
|
|
// flag != SWITCH_TO_MAKECALL && flag != SWITCH_TO_CUTCALL && flag != SWITCH_TO_UNKNOWN) { // 来电只支持接听挂断电话
|
|
// int replyText = NO_SUPPORT_SCENE;
|
|
// VoiceAssistance::GetInstance()->DetermineCause(&replyText);
|
|
// } else if (!PlayersModel::GetInstance()->HasPlayerPlayed() && ((PRE_SONG <= flag && flag <= NEXT_SONG) ||
|
|
// (PAUSE_PLAYBACK <= flag && flag <= RESUME_PLAYBACK))) { // 得先播放音乐才能执行暂停,停止,继续播放,上下首
|
|
// int replyText = NONE_SONG_PLAY;
|
|
// VoiceAssistance::GetInstance()->DetermineCause(&replyText);
|
|
// } else { // 其他情况
|
|
// if (flag == SWITCH_TO_XIAOYI) { // 切换到小艺小艺
|
|
// VoiceAssistance::GetInstance()->SwitchMedium(flag);
|
|
// VocassistModel::GetInstance()->SetRegFlag(SWITCH_TO_VOCASSIST); // 切换到波形图标
|
|
// VoiceAssistance::GetInstance()->DelayDisplayTime(DELAY_TWO_SECONDS);
|
|
// return;
|
|
// } else if (SWITCH_TO_MAKECALL <= flag && flag <= SWITCH_TO_UNKNOWN) { // 播放音乐,接挂电话, 未知命令
|
|
// VoiceAssistance::GetInstance()->SwitchMedium(flag);
|
|
// } else { // 未开发的命令
|
|
// WEARABLE_LOGD(WEARABLE_LOG_MODULE_APP, "Undeveloped Commands!!");
|
|
// VocassistModel::GetInstance()->SetToggleFlag(ALREADY_CLOSE_VOCASSIST_IMAGE);
|
|
// }
|
|
// }
|
|
|
|
// VocassistModel::GetInstance()->SetExitStatus(CONTINUTE_EXIT_MODE1);
|
|
// VoiceAssistance::GetInstance()->DelayDisplayTime(DELAY_SIX_SECONDS); // 开启定时器,太长时间未操作退出语音助手
|
|
// }
|
|
|
|
} // namespace TJD
|
|
|