762 lines
27 KiB
C++
762 lines
27 KiB
C++
#include "TjdUiAppVoiceAssistantView.h"
|
||
#include "NativeAbility.h"
|
||
#include "TjdUiImageIds.h"
|
||
#include "TjdUiMultiLanguageExt.h"
|
||
// #include "ble_port_protocol.h"
|
||
#include "common/image_cache_manager.h"
|
||
#include "sys_config.h"
|
||
#include "graphic_service.h"
|
||
// #include "gfx_utils/mem_check.h"
|
||
#include "smart_voice_service.h"
|
||
#include "TjdUiAppVocassistModel.h"
|
||
#include "TjdUiAppPlayerModel.h"
|
||
#include "TjdUiAppWalletView.h"
|
||
#include <limits>
|
||
#include "ohos_timer.h"
|
||
#include "graphic_timer.h"
|
||
#include "TjdUiAppIds.h"
|
||
#include "PlayersModel.h"
|
||
#include "CallerLogModel.h"
|
||
#include "power_display_service.h"
|
||
#include "TjdUiAppAlipayModel.h"
|
||
|
||
#ifdef __cplusplus
|
||
extern "C"
|
||
{
|
||
#endif
|
||
|
||
#include "ble_api.h"
|
||
|
||
#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 {
|
||
|
||
#define IMAGE_BIN_PATH TJD_IMAGE_PATH "img_voice_assistant.bin"
|
||
|
||
enum {
|
||
WITHOUT_OPERATE = PLAYER_RESPONESE_MAX,
|
||
NO_SUPPORT_VOC_IN_CALLING,
|
||
VOC_RESPONSE,
|
||
WITHOUT_INCOMING_PHONE,
|
||
RESPONESE_MAX
|
||
};
|
||
|
||
static constexpr uint16_t WORD_LENGTH = 60;
|
||
static constexpr uint16_t SWITCH_MAP_NUM = 16;
|
||
static constexpr int VOLUME_MAXIMUM = 100;
|
||
static constexpr int VOLUME_MINIMUM = 0;
|
||
static constexpr int VOLUME_PER_CHANGE = 10;
|
||
|
||
using viewFunct = int (TjdVoiceAssistance::*)();
|
||
|
||
using Viewmapper = struct {
|
||
uint16_t viewIndex;
|
||
viewFunct funct;
|
||
};
|
||
|
||
static constexpr Viewmapper g_switchMap[SWITCH_MAP_NUM] = {
|
||
{SWITCH_TO_XIAOYI, &TjdVoiceAssistance::VocResponse},
|
||
{SWITCH_TO_MAKECALL, &TjdVoiceAssistance::ChangeAcceptPhone},
|
||
{SWITCH_TO_CUTCALL, &TjdVoiceAssistance::ChangeHangupPhone},
|
||
{PRE_SONG, &TjdVoiceAssistance::ChangePreSong},
|
||
{NEXT_SONG, &TjdVoiceAssistance::ChangeNextSong},
|
||
{INCREASE_VOLUME, &TjdVoiceAssistance::ChangeIncreaseVolume},
|
||
{DECREASE_VOLUME, &TjdVoiceAssistance::ChangeDecreaseVolume},
|
||
{SWITCH_TO_PLAYER, &TjdVoiceAssistance::ChangeViewToPlayer},
|
||
{PAUSE_PLAYBACK, &TjdVoiceAssistance::ChangePausePlayback},
|
||
{RESUME_PLAYBACK, &TjdVoiceAssistance::ChangeResumePlayback},
|
||
{SWITCH_TO_EXERCISE, &TjdVoiceAssistance::ChangeOpenExecise},
|
||
{SWITCH_TO_MESSAGE, &TjdVoiceAssistance::ChangeOpenMessage},
|
||
{SWITCH_TO_ALARM, &TjdVoiceAssistance::ChangeOpenAlarm},
|
||
{SWITCH_TO_ALIPAY, &TjdVoiceAssistance::ChangeOpenAlipay},
|
||
{SWITCH_TO_WECHATPAY, &TjdVoiceAssistance::ChangeOpenWechatpay},
|
||
// {SWITCH_TO_UNKNOWN, &TjdVoiceAssistance::ResponseWithoutUse},
|
||
// {CREATE_CMD_LABEL, &TjdVoiceAssistance::CreateCmdLabel},
|
||
// {VOC_VIEW, &TjdVoiceAssistance::VocAssistChange},
|
||
// {WAVE_VIEW, &TjdVoiceAssistance::WaveFormChange},
|
||
// {VOC_TO_WAVE_VIEW, &TjdVoiceAssistance::WithDetectVocImg},
|
||
// {WAVE_TO_VOC_VIEW, &TjdVoiceAssistance::WithoutDetectVocImg}
|
||
};
|
||
|
||
static TjdUiAppVoiceAssistantView *g_pv_AppVoiceAssistantView = nullptr;
|
||
|
||
|
||
static char *const_text[4] = {
|
||
"试试对我说\n播放音乐\n",
|
||
"试试对我说播放音乐\n",
|
||
"暂未绑定,请前往App\n绑定后继续\n",
|
||
"我在我在,有什么吩咐?\n",
|
||
};
|
||
|
||
static constexpr char g_resStr[RESPONESE_MAX][WORD_LENGTH]{
|
||
{"我在我在,有什么吩咐?\n"},
|
||
{"检测到无电话信息\n"},
|
||
{"检测到无电话信息\n"},
|
||
{"音乐已切换\n"},
|
||
{"音乐已切换\n"},
|
||
{"音量已调整\n"},
|
||
{"音量已调整\n"},
|
||
{"音乐已播放\n"},
|
||
{"音乐已暂停\n"},
|
||
{"音乐继续播放\n"},
|
||
{"哎呀,小艺还不会这项技能,正在学习呢?\n"}
|
||
};
|
||
|
||
static inline int16_t HorizontalCenter(int16_t width) { return (OHOS::HORIZONTAL_RESOLUTION - width) / 2; }
|
||
static inline int16_t HorizontalCenter(int16_t width, int16_t parentWidth) { return (parentWidth - width) / 2; }
|
||
static inline void InitLabel(OHOS::UILabel &label, uint8_t size, int16_t y, const char *text)
|
||
{
|
||
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
||
label.SetText(text);
|
||
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
||
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
label.SetPosition(HorizontalCenter(label.GetWidth()), y);
|
||
}
|
||
|
||
static inline void InitImage(OHOS::UIImageView &imageView, int16_t x, int16_t y, uint32_t resId, const char *imageViewId)
|
||
{
|
||
imageView.SetPosition(x, y);
|
||
OHOS::ImageInfo *imgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(resId, IMAGE_BIN_PATH);
|
||
if (imgInfo != nullptr) {
|
||
imageView.SetSrc(imgInfo);
|
||
}
|
||
imageView.SetTouchable(true);
|
||
imageView.SetViewId(imageViewId);
|
||
}
|
||
|
||
static inline void InitButton(OHOS::UIButton &button, int16_t x, int16_t y, int16_t width, int16_t height,
|
||
uint32_t defaultResId, uint32_t traResId, const char *buttonViewId)
|
||
{
|
||
button.SetPosition(x, y, width, height);
|
||
button.SetViewId(buttonViewId);
|
||
button.SetStyle(STYLE_BACKGROUND_OPA, 0);
|
||
button.SetStyleForState(STYLE_BACKGROUND_OPA, 0, OHOS::UIButton::PRESSED);
|
||
OHOS::ImageInfo *defaultImgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(defaultResId, IMAGE_BIN_PATH);
|
||
OHOS::ImageInfo *traImgInfo = ImageCacheManager::GetInstance().LoadOneInMultiRes(traResId, IMAGE_BIN_PATH);
|
||
if (defaultImgInfo != nullptr && traImgInfo != nullptr) {
|
||
button.SetImageSrc(defaultImgInfo, traImgInfo);
|
||
}
|
||
button.SetOnClickListener(TjdUiAppVoiceAssistantPresenter::GetInstance());
|
||
button.SetVisible(true);
|
||
}
|
||
|
||
static inline void InitLabelHorCenter(OHOS::UILabel &label, uint8_t size, int16_t y, int16_t target, const char *text)
|
||
{
|
||
label.SetFont(TJD_VECTOR_FONT_FILENAME, size);
|
||
label.SetText(text);
|
||
label.SetLineBreakMode(OHOS::UILabel::LINE_BREAK_ADAPT);
|
||
label.SetAlign(OHOS::TEXT_ALIGNMENT_CENTER, OHOS::TEXT_ALIGNMENT_CENTER);
|
||
label.SetPosition(HorizontalCenter(label.GetWidth(), target), y);
|
||
}
|
||
|
||
VoiceAssistantIndex TjdUiAppVoiceAssistantView::currentViewIndex_ = VoiceAssistantIndex::VOICEASSISTANT_MAXTHVIEW;
|
||
|
||
// VoiceAssistantOnClickedListener TjdUiAppVoiceAssistantView::onclicklister_ = VoiceAssistantOnClickedListener();
|
||
|
||
static TjdUiAppVoiceAssistantView *g_TjdUiAppVoiceAssistantView = nullptr;
|
||
static VoiceAssistantMainView *g_VoiceAssistantMainView = nullptr;
|
||
static VoiceAssistantAwakeView *g_VoiceAssistantAwakeView = nullptr;
|
||
|
||
TjdUiAppVoiceAssistantView::TjdUiAppVoiceAssistantView()
|
||
{
|
||
// OHOS::MemCheck::GetInstance()->EnableLeakCheck(true);
|
||
static_print_info("TjdUiAppVoiceAssistantView()\n");
|
||
g_TjdUiAppVoiceAssistantView = this;
|
||
}
|
||
|
||
TjdUiAppVoiceAssistantView::~TjdUiAppVoiceAssistantView()
|
||
{
|
||
static_print_info("~TjdUiAppVoiceAssistantView()\n");
|
||
LocalAsrStop();
|
||
if (vocassistance != nullptr) {
|
||
delete vocassistance;
|
||
vocassistance = nullptr;
|
||
}
|
||
g_TjdUiAppVoiceAssistantView = nullptr;
|
||
// OHOS::MemCheck::GetInstance()->EnableLeakCheck(false);
|
||
}
|
||
|
||
TjdUiAppVoiceAssistantView *TjdUiAppVoiceAssistantView::GetInstance(void) { return g_TjdUiAppVoiceAssistantView; }
|
||
|
||
void TjdUiAppVoiceAssistantView::OnStart()
|
||
{
|
||
static_print_info("TjdUiAppVoiceAssistantView::OnStart\n");
|
||
View<TjdUiAppVoiceAssistantPresenter>::OnStart();
|
||
|
||
vocassistance = new TjdVoiceAssistance();
|
||
if(vocassistance == nullptr){
|
||
static_print_info("TjdUiAppVoiceAssistantView::OnStart vocassistance == nullptr\n");
|
||
return;
|
||
}
|
||
|
||
if (TjdUiAppVoiceAssistantPresenter::GetInstance() == nullptr) {
|
||
static_print_info("TjdUiAppVoiceAssistantPresenter::GetInstance is nullptr!!\n");
|
||
return;
|
||
}
|
||
|
||
OHOS::ImageCacheManager::GetInstance().LoadAllInMultiRes(IMAGE_BIN_PATH);
|
||
|
||
if (mainView_ == nullptr) {
|
||
mainView_ = new OHOS::UIScrollView();
|
||
}
|
||
mainView_->SetPosition(0, 0, OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
mainView_->SetOnDragListener(TjdUiAppVoiceAssistantPresenter::GetInstance());
|
||
// OHOS::RootView::GetInstance()->Add(mainView_);
|
||
AddViewToRootContainer(mainView_);
|
||
// AddViewToRootContainer(vocassistance);
|
||
// TjdUiVocassistModel::GetInstance()->Init();
|
||
|
||
TjdUiVocassistModel::GetInstance()->Init();
|
||
|
||
if(tjd_get_ble_is_connect()){
|
||
ShowView(VoiceAssistantIndex::VOICEASSISTANT_AWAKENIEW);
|
||
}else{
|
||
ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
}
|
||
|
||
|
||
}
|
||
|
||
void TjdUiAppVoiceAssistantView::OnStop()
|
||
{
|
||
static_print_info("TjdUiAppVoiceAssistantView::OnStop\n");
|
||
// OHOS::RootView::GetInstance()->Remove(mainView_);
|
||
if (mainView_ != nullptr) {
|
||
mainView_->RemoveAll();
|
||
delete mainView_;
|
||
mainView_ = nullptr;
|
||
}
|
||
|
||
for (int i = 0; i < VoiceAssistantIndex::VOICEASSISTANT_MAXTHVIEW; i++) {
|
||
if (viewManager_[i] != nullptr) {
|
||
viewManager_[i]->RemoveAll();
|
||
delete viewManager_[i];
|
||
viewManager_[i] = nullptr;
|
||
}
|
||
}
|
||
OHOS::ImageCacheManager::GetInstance().UnloadAllInMultiRes(IMAGE_BIN_PATH);
|
||
TjdUiVocassistModel::GetInstance()->UnInit();
|
||
}
|
||
|
||
void TJD::TjdUiAppVoiceAssistantView::ShowView(VoiceAssistantIndex showIndex)
|
||
{
|
||
if (showIndex < 0 || showIndex >= VoiceAssistantIndex::VOICEASSISTANT_MAXTHVIEW) {
|
||
return;
|
||
}
|
||
|
||
InitTargetView(showIndex);
|
||
|
||
if (currentViewIndex_ >= 0 && currentViewIndex_ < VoiceAssistantIndex::VOICEASSISTANT_MAXTHVIEW &&
|
||
viewManager_[currentViewIndex_] != nullptr) {
|
||
viewManager_[currentViewIndex_]->HideView();
|
||
}
|
||
if (viewManager_[showIndex] != nullptr) {
|
||
if(showIndex == VOICEASSISTANT_MAINVIEW && !isFirstInto_ && !TjdVoiceAssistance::GetInstance()->isTrueStopPlay_){
|
||
TjdUiAppPlayerModel::GetInstance()->AudioInit();
|
||
TjdUiAppPlayerModel::GetInstance()->PlayerStart();
|
||
}
|
||
viewManager_[showIndex]->ShowView();
|
||
}
|
||
|
||
currentViewIndex_ = showIndex;
|
||
}
|
||
|
||
void TJD::TjdUiAppVoiceAssistantView::InitTargetView(VoiceAssistantIndex index)
|
||
{
|
||
if (viewManager_[index] != nullptr) {
|
||
return;
|
||
}
|
||
|
||
// clang-format off
|
||
switch (index) {
|
||
case VOICEASSISTANT_MAINVIEW: viewManager_[index] = new VoiceAssistantMainView(); break;
|
||
case VOICEASSISTANT_AWAKENIEW: viewManager_[index] = new VoiceAssistantAwakeView(); break;
|
||
default: break;
|
||
}
|
||
// clang-format on
|
||
|
||
if (viewManager_[index] == nullptr) {
|
||
return;
|
||
}
|
||
|
||
viewManager_[index]->SetPosition(0, 0);
|
||
viewManager_[index]->SetVisible(false);
|
||
mainView_->Add(viewManager_[index]);
|
||
}
|
||
|
||
void VoiceTimerCallback(void *arg)
|
||
{
|
||
if(tjd_get_ble_is_connect()){
|
||
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
||
if(TjdUiAppPlayerModel::GetInstance()->GetPlayerCtr() != nullptr){
|
||
TjdUiAppPlayerModel::GetInstance()->GetPlayerCtr()->Pause();
|
||
}
|
||
TjdUiVocassistModel::GetInstance()->SetHasOneCmd(false);
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_AWAKENIEW);
|
||
});
|
||
}
|
||
}
|
||
|
||
void VoiceTimerReturnMainCallback(void *arg)
|
||
{
|
||
GraphicService::GetInstance()->PostGraphicEvent([]() {
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
static_print_debug("VoiceTimerReturnMainCallback...");
|
||
InitLabelHorCenter(VoiceAssistantMainView::GetInstance()->GetDescLabel(), 34, 248, 466 ,const_text[1]);
|
||
// VoiceAssistantMainView::GetInstance()->GetDescLabel().SetText(const_text[2]);
|
||
VoiceAssistantMainView::GetInstance()->Invalidate();
|
||
});
|
||
}
|
||
|
||
VoiceAssistantMainView::VoiceAssistantMainView()
|
||
{
|
||
g_VoiceAssistantMainView = this;
|
||
auto &image = OHOS::ImageCacheManager::GetInstance();
|
||
auto bgRes = image.LoadOneInMultiRes(IMG_VOICE_ASSISTANT_BJ, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
bg_.SetPosition(0, 0);
|
||
if (bgRes != nullptr) {
|
||
bg_.SetSrc(bgRes);
|
||
}
|
||
|
||
bgRes = image.LoadOneInMultiRes(IMG_VOICE_ASSISTANT_ICON, IMAGE_BIN_PATH);
|
||
icon_.SetPosition(145, 62);
|
||
if (bgRes != nullptr) {
|
||
icon_.SetSrc(bgRes);
|
||
}
|
||
|
||
if (tjd_get_ble_is_connect()) {
|
||
InitLabelHorCenter(desc_, 34, 248, 466, const_text[3]);
|
||
descButtom_.SetViewId("ContinueButton");
|
||
} else {
|
||
InitLabelHorCenter(desc_, 34, 248, 466, const_text[2]);
|
||
descButtom_.SetViewId("ReturnButton");
|
||
}
|
||
|
||
bgRes = image.LoadOneInMultiRes(IMG_VOICE_ASSISTANT_CONTINUE, IMAGE_BIN_PATH);
|
||
if (bgRes != nullptr) {
|
||
descButtom_.SetImageSrc(bgRes, bgRes);
|
||
}
|
||
descButtom_.SetOnClickListener(TjdUiAppVoiceAssistantPresenter::GetInstance());
|
||
|
||
descButtom_.SetPosition(52, 380, 362, 86);
|
||
descButtom_.SetStyleForState(STYLE_BORDER_COLOR, 0xff000000, UIButton::PRESSED);
|
||
descButtom_.SetTouchable(true);
|
||
if (timer_ == nullptr) {
|
||
timer_ = new GraphicTimer(2000, VoiceTimerCallback, this, false);
|
||
}
|
||
|
||
Add(&bg_);
|
||
Add(&icon_);
|
||
Add(&desc_);
|
||
Add(&descButtom_);
|
||
|
||
}
|
||
|
||
VoiceAssistantMainView::~VoiceAssistantMainView()
|
||
{
|
||
g_VoiceAssistantMainView = nullptr;
|
||
RemoveAll();
|
||
if (timer_ != nullptr) {
|
||
timer_->Stop();
|
||
delete timer_;
|
||
timer_ = nullptr;
|
||
}
|
||
}
|
||
|
||
void VoiceAssistantMainView::ShowView()
|
||
{
|
||
SetVisible(true);
|
||
TjdUiAppVoiceAssistantView::GetInstance()->isFirstInto_ = false;
|
||
}
|
||
|
||
void VoiceAssistantMainView::HideView() { SetVisible(false); }
|
||
|
||
VoiceAssistantMainView *VoiceAssistantMainView::GetInstance(void) { return g_VoiceAssistantMainView; }
|
||
|
||
VoiceAssistantAwakeView::VoiceAssistantAwakeView()
|
||
{
|
||
g_VoiceAssistantAwakeView = this;
|
||
auto &image = OHOS::ImageCacheManager::GetInstance();
|
||
auto bgRes = image.LoadOneInMultiRes(IMG_VOICE_ASSISTANT_BJ, IMAGE_BIN_PATH);
|
||
Resize(OHOS::HORIZONTAL_RESOLUTION, OHOS::VERTICAL_RESOLUTION);
|
||
bg_.SetPosition(0, 0);
|
||
if (bgRes != nullptr) {
|
||
bg_.SetSrc(bgRes);
|
||
}
|
||
bgRes = image.LoadOneInMultiRes(IMG_VOICE_ASSISTANT_ICON, IMAGE_BIN_PATH);
|
||
icon_.SetPosition(145, 62);
|
||
if (bgRes != nullptr) {
|
||
icon_.SetSrc(bgRes);
|
||
}
|
||
// if(desc_ == nullptr){
|
||
// desc_ = new UILabel();
|
||
// }
|
||
InitLabelHorCenter(desc_, 34, 315, 466, "试试对我说\n播放音乐");
|
||
Add(&bg_);
|
||
Add(&icon_);
|
||
Add(&desc_);
|
||
|
||
if (timer_ == nullptr) {
|
||
timer_ = new GraphicTimer(10000, VoiceTimerReturnMainCallback, this, false);
|
||
}
|
||
timer_->Start();
|
||
|
||
if (TjdUiVocassistModel::GetInstance()->GetPhoneDetailStatus() != ONE_OR_MORE_ROAD_AND_OTHER_STATUS) {
|
||
|
||
AsrWorkMode curMode = LocalAsrGetMode();
|
||
static_print_info("voice_assistant: local asr work mode: %d",curMode);
|
||
LocalAsrSetMode(curMode);
|
||
}
|
||
}
|
||
|
||
VoiceAssistantAwakeView::~VoiceAssistantAwakeView()
|
||
{
|
||
g_VoiceAssistantAwakeView = nullptr;
|
||
RemoveAll();
|
||
if (timer_ != nullptr) {
|
||
timer_->Stop();
|
||
delete timer_;
|
||
timer_ = nullptr;
|
||
}
|
||
|
||
// if(desc_ != nullptr){
|
||
// delete desc_;
|
||
// desc_ = nullptr;
|
||
// }
|
||
}
|
||
VoiceAssistantAwakeView * VoiceAssistantAwakeView::GetInstance(void){ return g_VoiceAssistantAwakeView; }
|
||
void VoiceAssistantAwakeView::ShowView()
|
||
{
|
||
timer_->Start();
|
||
SetVisible(true);
|
||
}
|
||
|
||
void VoiceAssistantAwakeView::HideView()
|
||
{
|
||
SetVisible(false);
|
||
}
|
||
|
||
std::string VoiceAssistantMainView::GetCmdContext()
|
||
{
|
||
return allWord;
|
||
}
|
||
|
||
void VoiceAssistantMainView::SetCmdContext(std::string str)
|
||
{
|
||
allWord = str;
|
||
}
|
||
|
||
static TjdVoiceAssistance *g_pVoiceAssistance = nullptr;
|
||
|
||
TjdVoiceAssistance::TjdVoiceAssistance()
|
||
{
|
||
g_pVoiceAssistance = this;
|
||
}
|
||
|
||
TjdVoiceAssistance::~TjdVoiceAssistance()
|
||
{
|
||
static_print_info("~VoiceAssistance!!");
|
||
RemoveAll();
|
||
g_pVoiceAssistance = nullptr;
|
||
// 切换为其它slice时将定时器删除
|
||
// if (g_closeVocassistHandle != nullptr) {
|
||
// delete g_closeVocassistHandle;
|
||
// g_closeVocassistHandle = nullptr;
|
||
// }
|
||
|
||
// delete voicePhoto;
|
||
// voicePhoto = nullptr;
|
||
// workFrame->RemoveAll();
|
||
// delete wordContext;
|
||
// wordContext = nullptr;
|
||
// delete workFrame;
|
||
// workFrame = nullptr;
|
||
}
|
||
|
||
TjdVoiceAssistance *TjdVoiceAssistance::GetInstance()
|
||
{
|
||
return g_pVoiceAssistance;
|
||
}
|
||
|
||
bool TjdVoiceAssistance::InitView(void * caller){ return true; }
|
||
|
||
void TjdVoiceAssistance::SwitchMedium(uint16_t targetView)
|
||
{
|
||
if (GraphicService::GetInstance() == nullptr) {
|
||
static_print_info("GraphicService instance is nullptr!!");
|
||
return;
|
||
}
|
||
GraphicService::GetInstance()->PostGraphicEvent(std::bind(&TjdVoiceAssistance::VocSwitchApp, this, targetView));
|
||
}
|
||
|
||
static viewFunct FindIndex(uint16_t target)
|
||
{
|
||
for (int i = 0; i < SWITCH_MAP_NUM; i++) {
|
||
if (g_switchMap[i].viewIndex == target) {
|
||
return (g_switchMap[i].funct);
|
||
}
|
||
}
|
||
return nullptr;
|
||
}
|
||
|
||
void TjdVoiceAssistance::VocSwitchApp(uint16_t targetView)
|
||
{
|
||
static_print_info("[VoiceAssistView] Start Operation!!");
|
||
if (TjdVoiceAssistance::GetInstance() == nullptr) {
|
||
static_print_info("VoiceAssistance instance is nullptr!!");
|
||
return;
|
||
}
|
||
viewFunct func = FindIndex(targetView);
|
||
if (func != nullptr) {
|
||
int retVal = (this->*(func))();
|
||
if (SWITCH_TO_XIAOYI <= targetView && targetView <= SWITCH_TO_UNKNOWN) {
|
||
// DetermineCause(&retVal); // 回复文本显示
|
||
VoiceAssistantMainView::GetInstance()->GetDescLabel().SetText(g_resStr[targetView]);
|
||
VoiceAssistantMainView::GetInstance()->GetDescLabel().SetPosition(HorizontalCenter(VoiceAssistantMainView::GetInstance()->GetDescLabel().GetWidth(), 466), 248);
|
||
VoiceAssistantMainView::GetInstance()->Invalidate();
|
||
}
|
||
}
|
||
}
|
||
|
||
int TjdVoiceAssistance::VocResponse()
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter VocResponse");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantMainView::GetInstance()->GetTimer()->Start();
|
||
return VOC_RESPONSE;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeViewToPlayer() // 播放音乐
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeViewToPlayer");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
// if (!TjdUiAppPlayerModel::GetInstance()->HasPlayerPlayed()) { // 播放过了就不用再初始化
|
||
// PlayersListGroup::GetInstance()->SetUpListCase();
|
||
// PlayersModel::GetInstance()->PlayerInit();
|
||
// }
|
||
// TjdUiAppPlayerModel::GetInstance()->PlayerInit();
|
||
if(TjdUiAppPlayerModel::GetInstance() == nullptr){
|
||
static_print_info("TjdUiAppPlayerModel::GetInstance() is null pointer!");
|
||
return -1;
|
||
}
|
||
TjdUiAppPlayerModel::GetInstance()->AudioInit();
|
||
int state = TjdUiAppPlayerModel::GetInstance()->GetPlayerState();
|
||
if (state == ERR_RET) {
|
||
static_print_info("Get Player State failed!!");
|
||
return -1;
|
||
}
|
||
if (state != PlayerStates::PLAYER_STARTED && state != PlayerStates::PLAYER_PAUSED &&
|
||
state != PlayerStates::PLAYER_STOPPED && state != PlayerStates::PLAYER_PLAYBACK_COMPLETE) {
|
||
TJD::PlayersListGroup::GetInstance()->SetUpListCase();
|
||
TjdUiAppPlayerModel::GetInstance()->PlayerInit();
|
||
}
|
||
isTrueStopPlay_ = false;
|
||
int ret = TjdUiAppPlayerModel::GetInstance()->PlayerStart();
|
||
return ret;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangePreSong() // 上一首
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangePreSong!!");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
TjdUiAppPlayerModel::GetInstance()->PreviousPlayout();
|
||
|
||
int ret = TjdUiAppPlayerModel::GetInstance()->PlayerStart();
|
||
if (ret != EXECUTE_FUNC_FAILED) {
|
||
return NORMAL;
|
||
}
|
||
|
||
return ret;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeNextSong() // 下一首
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeNextSong!!");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
TjdUiAppPlayerModel::GetInstance()->LoopingPlayout();
|
||
int ret = TjdUiAppPlayerModel::GetInstance()->PlayerStart();
|
||
if (ret != EXECUTE_FUNC_FAILED) {
|
||
return NORMAL;
|
||
}
|
||
return ret;
|
||
}
|
||
|
||
// int TjdVoiceAssistance::ChangeStopPlayback() // 停止播放
|
||
// {
|
||
// static_print_info("[VoiceAssistView] Enter ChangeStopPlaybcak!!");
|
||
// TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
// VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
// int ret = TjdUiAppPlayerModel::GetInstance()->PlayerStop();
|
||
// return ret;
|
||
// }
|
||
|
||
int TjdVoiceAssistance::ChangePausePlayback() // 暂停
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangePausePlayback!!");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
isTrueStopPlay_ = true;
|
||
int ret = TjdUiAppPlayerModel::GetInstance()->GetPlayerCtr()->Pause();
|
||
return ret;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeResumePlayback() // 继续播放
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeResumePlayback!!");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
isTrueStopPlay_ = false;
|
||
int ret = TjdUiAppPlayerModel::GetInstance()->PlayerStart();
|
||
return ret;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeIncreaseVolume()
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeIncreaseVolume!!");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
// int ret = TjdUiAppPlayerModel::GetInstance()->IncreaseVolume();
|
||
int curSound = AudioManager::GetInstance().GetVolume(AUDIO_STREAM_MUSIC);
|
||
static_print_info("Presound is %d", curSound);
|
||
if (curSound > VOLUME_MAXIMUM - VOLUME_PER_CHANGE) {
|
||
curSound = VOLUME_MAXIMUM;
|
||
} else {
|
||
curSound += VOLUME_PER_CHANGE;
|
||
}
|
||
int ret = AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, curSound);
|
||
// Audio::AudioManager::GetInstance().SetVolume(AUDIO_STREAM_MUSIC, volume); // 本地音量设置
|
||
return ret;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeDecreaseVolume()
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeDecreaseVolume!!");
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
int ret = PlayersModel::GetInstance()->DecreaseVolume();
|
||
return ret;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeAcceptPhone() // 接听电话
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeAcceptPhone!!");
|
||
|
||
int phoneStatus = TjdUiVocassistModel::GetInstance()->GetPhoneDetailStatus(); // 扫描设置此时通话的状态和个数
|
||
if (phoneStatus == ONE_ROAD_AND_INCOMING) {
|
||
int ret = AcceptIncomingCall();
|
||
if (ret == 0) {
|
||
static_print_info("AcceptPhone Success!!");
|
||
return NORMAL;
|
||
} else {
|
||
static_print_info("AcceptPhone Failed!!");
|
||
return EXECUTE_FUNC_FAILED;
|
||
}
|
||
} else {
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
return WITHOUT_INCOMING_PHONE;
|
||
}
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeHangupPhone() // 挂断电话
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeHangupPhone!!");
|
||
|
||
int phoneStatus = TjdUiVocassistModel::GetInstance()->GetPhoneDetailStatus(); // 扫描设置此时通话的状态和个数
|
||
if (phoneStatus == ONE_ROAD_AND_INCOMING) {
|
||
int ret = RejectIncomingCall();
|
||
if (ret == 0) {
|
||
static_print_info("HangupPhone Success!!");
|
||
return NORMAL;
|
||
} else {
|
||
static_print_info("HangupPhone Failed!!");
|
||
return EXECUTE_FUNC_FAILED;
|
||
}
|
||
} else {
|
||
TjdUiAppVoiceAssistantView::GetInstance()->ShowView(VoiceAssistantIndex::VOICEASSISTANT_MAINVIEW);
|
||
VoiceAssistantAwakeView::GetInstance()->GetTimer()->Stop();
|
||
return WITHOUT_INCOMING_PHONE;
|
||
}
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeOpenExecise() // 打开运动
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeOpenExecise!!");
|
||
const power_display_svr_api_t *display_api = power_display_svr_get_api();
|
||
if (display_api->get_screen_state() != SCREEN_ON) {
|
||
display_api->turn_on_screen();
|
||
}
|
||
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_SPORT);
|
||
return NORMAL;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeOpenMessage() // 打开短信
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeOpenMessage!!");
|
||
const power_display_svr_api_t *display_api = power_display_svr_get_api();
|
||
if (display_api->get_screen_state() != SCREEN_ON) {
|
||
display_api->turn_on_screen();
|
||
}
|
||
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_MESSAGE_TOTAL);
|
||
return NORMAL;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeOpenAlarm() // 打开闹钟
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeOpenAlarm!!");
|
||
const power_display_svr_api_t *display_api = power_display_svr_get_api();
|
||
if (display_api->get_screen_state() != SCREEN_ON) {
|
||
display_api->turn_on_screen();
|
||
}
|
||
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_ALARM);
|
||
return NORMAL;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeOpenAlipay() // 打开支付宝
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeOpenAlipay!!");
|
||
const power_display_svr_api_t *display_api = power_display_svr_get_api();
|
||
if (display_api->get_screen_state() != SCREEN_ON) {
|
||
display_api->turn_on_screen();
|
||
}
|
||
/* 设置快捷进入付款码标志位 */
|
||
TjdUiAppAlipayModel::GetInstance().SetQuickEnterFlag(true);
|
||
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_ALIPAY);
|
||
return NORMAL;
|
||
}
|
||
|
||
int TjdVoiceAssistance::ChangeOpenWechatpay() // 打开微信支付
|
||
{
|
||
static_print_info("[VoiceAssistView] Enter ChangeOpenWechatpay!!");
|
||
const power_display_svr_api_t *display_api = power_display_svr_get_api();
|
||
if (display_api->get_screen_state() != SCREEN_ON) {
|
||
display_api->turn_on_screen();
|
||
}
|
||
OHOS::NativeAbility::GetInstance().ChangeSlice(TJD_APP_VIEW_WALLET);
|
||
TjdUiAppWalletView::GetInstance()->ChooseWalletItem(WALLET_WECHAT_INDEX);
|
||
return NORMAL;
|
||
}
|
||
|
||
} // namespace TJD
|