From 12cd5ceeba4a231dba70fb90631834b44099cddf Mon Sep 17 00:00:00 2001 From: Nataliia Kamyshna Date: Tue, 3 Oct 2017 10:33:04 +0300 Subject: TizenRefApp-9371 Implement move to standby mode on user's touch. TizenRefApp-9370 Implement activation from standby mode on user's touch Change-Id: Ieb9a369be42748b57c21c9bb95d1f4a163e95b9b Signed-off-by: Nataliia Kamyshna --- voice-app/inc/Model/ConnectionManager.h | 8 +++++ voice-app/inc/OperationDefaultController.h | 1 + voice-app/inc/Voice/CommandController.h | 1 + voice-app/inc/Voice/VoiceInputController.h | 28 ++++++++++++++++ voice-app/src/Model/ConnectionManager.cpp | 19 +++++++++-- voice-app/src/OperationDefaultController.cpp | 9 ++++++ voice-app/src/Voice/CommandController.cpp | 12 +++++++ voice-app/src/Voice/VoiceInputController.cpp | 48 ++++++++++++++++++++++++---- 8 files changed, 117 insertions(+), 9 deletions(-) diff --git a/voice-app/inc/Model/ConnectionManager.h b/voice-app/inc/Model/ConnectionManager.h index 5f4b325..3213499 100644 --- a/voice-app/inc/Model/ConnectionManager.h +++ b/voice-app/inc/Model/ConnectionManager.h @@ -65,6 +65,12 @@ namespace Model */ void setCurrentConnectionChangedCallback(CurrentConnectionChangedCallback callback); + /** + * @brief Set Connection manager to "stand by" mode. + * @param[in] isStandByMode Should Connection manager be in "stand by" mode or not + */ + void setStandByMode(bool isStandByMode); + private: void setCurrentConnection(Connection *connection); void promoteConnection(Connection *connection); @@ -76,6 +82,8 @@ namespace Model std::vector m_Connections; Connection *m_CurrentConnection; CurrentConnectionChangedCallback m_OnCurrentConnectionChanged; + + bool m_IsStandByMode; }; } diff --git a/voice-app/inc/OperationDefaultController.h b/voice-app/inc/OperationDefaultController.h index ee1d73c..567fc66 100644 --- a/voice-app/inc/OperationDefaultController.h +++ b/voice-app/inc/OperationDefaultController.h @@ -54,6 +54,7 @@ private: virtual void onRequest(const char *operation, app_control_h request) override; void onComponentInitialized(Component component); void onCurrentConnectionChanged(Model::Connection *connection); + void onStandByModeChanged(bool isStandByMode); void setActiveController(Voice::VoiceInputController *controller); void createFeedbackView(); diff --git a/voice-app/inc/Voice/CommandController.h b/voice-app/inc/Voice/CommandController.h index a401b18..7771aaa 100644 --- a/voice-app/inc/Voice/CommandController.h +++ b/voice-app/inc/Voice/CommandController.h @@ -49,6 +49,7 @@ namespace Voice virtual void onServiceChanged(vc_service_state_e state) override; virtual void onResult(vc_result_event_e event, vc_cmd_list_h list, const char *result) override; + virtual void changeStandByMode(bool isStandByMode) override; CommandMatch findCommand(vc_cmd_list_h list); void showInputText(const char *text); diff --git a/voice-app/inc/Voice/VoiceInputController.h b/voice-app/inc/Voice/VoiceInputController.h index 8094d11..b237cfd 100644 --- a/voice-app/inc/Voice/VoiceInputController.h +++ b/voice-app/inc/Voice/VoiceInputController.h @@ -26,6 +26,12 @@ namespace Voice class VoiceInputController { public: + /** + * @brief Called when "stand by" mode is changed. + * @param[in] isStandByMode Whether Voice input controller is in "stand by"mode + */ + typedef std::function StandByModeChangedCallback; + /** * @brief Create voice input controller. * @param[in] voiceControl Voice control manager @@ -43,6 +49,18 @@ namespace Voice */ void initialize(Voice::FeedbackView *feedbackView, Voice::FloatingView *floatingView); + /** + * @brief Set "stand by" mode change callback. + * @param[in] callback "stand by" mode change callback + */ + void setStandByModeChangedCallback(StandByModeChangedCallback callback); + + /** + * @brief Set Voice input controller to "stand by" mode. + * @param[in] isStandByMode Should Voice input controller be in "stand by" mode or not + */ + void setStandByMode(bool isStandByMode); + /** * @brief Activate controller. */ @@ -80,6 +98,12 @@ namespace Voice */ virtual void cancelActivity(); + /** + * @brief Change Voice input controller to "stand by" mode. + * @param[in] isStandByMode Whether Voice input controller is in "stand by" mode + */ + virtual void changeStandByMode(bool isStandByMode); + /** * @brief Called when voice control service state is changed. * @param[in] state Current service state @@ -132,7 +156,11 @@ namespace Voice Model::VoiceControlManager &m_VoiceControl; Voice::FeedbackView *m_FeedbackView; + Voice::FloatingView *m_FloatingView; + + bool m_IsStandByMode; + StandByModeChangedCallback m_OnStandByModeChanged; }; } diff --git a/voice-app/src/Model/ConnectionManager.cpp b/voice-app/src/Model/ConnectionManager.cpp index 6fce304..32d59b3 100644 --- a/voice-app/src/Model/ConnectionManager.cpp +++ b/voice-app/src/Model/ConnectionManager.cpp @@ -22,7 +22,7 @@ using namespace Model; using namespace std::placeholders; ConnectionManager::ConnectionManager() - : m_CurrentConnection(nullptr) + : m_CurrentConnection(nullptr), m_IsStandByMode(false) { srand(time(nullptr)); } @@ -70,6 +70,19 @@ void ConnectionManager::setCurrentConnectionChangedCallback(CurrentConnectionCha m_OnCurrentConnectionChanged = std::move(callback); } +void ConnectionManager::setStandByMode(bool isStandByMode) +{ + m_IsStandByMode = isStandByMode; + + if (m_CurrentConnection) { + if (m_IsStandByMode) { + m_CurrentConnection->setState(StateDeactivated); + } else { + m_CurrentConnection->setState(StateActivated); + } + } +} + void ConnectionManager::setCurrentConnection(Connection *connection) { if (connection == m_CurrentConnection) { @@ -85,7 +98,9 @@ void ConnectionManager::setCurrentConnection(Connection *connection) m_CurrentConnection = connection; if (m_CurrentConnection) { - m_CurrentConnection->setState(StateActivated); + if (!m_IsStandByMode) { + m_CurrentConnection->setState(StateActivated); + } promoteConnection(connection); } diff --git a/voice-app/src/OperationDefaultController.cpp b/voice-app/src/OperationDefaultController.cpp index 888acda..60d4e03 100644 --- a/voice-app/src/OperationDefaultController.cpp +++ b/voice-app/src/OperationDefaultController.cpp @@ -74,6 +74,8 @@ void OperationDefaultController::onComponentInitialized(Component component) m_CommandController.initialize(m_FloatingView, m_FloatingView); m_RequestController.initialize(m_FeedbackView, m_FloatingView); + m_CommandController.setStandByModeChangedCallback(std::bind(&OperationDefaultController::onStandByModeChanged, this, _1)); + m_RequestController.setStandByModeChangedCallback(std::bind(&OperationDefaultController::onStandByModeChanged, this, _1)); if (m_PendingConnections.empty()) { setActiveController(&m_CommandController); @@ -96,6 +98,13 @@ void OperationDefaultController::onCurrentConnectionChanged(Model::Connection *c } } +void OperationDefaultController::onStandByModeChanged(bool isStandByMode) +{ + m_RequestController.setStandByMode(isStandByMode); + m_CommandController.setStandByMode(isStandByMode); + m_ConnectionManager.setStandByMode(isStandByMode); +} + void OperationDefaultController::setActiveController(Voice::VoiceInputController *controller) { if (m_ActiveController == controller) { diff --git a/voice-app/src/Voice/CommandController.cpp b/voice-app/src/Voice/CommandController.cpp index 27a85bf..d023868 100644 --- a/voice-app/src/Voice/CommandController.cpp +++ b/voice-app/src/Voice/CommandController.cpp @@ -132,6 +132,18 @@ void CommandController::onResult(vc_result_event_e event, vc_cmd_list_h list, co showInputText(result); } +void CommandController::changeStandByMode(bool isStandByMode) +{ + VoiceInputController::changeStandByMode(isStandByMode); + + if (!isStandByMode) { + getFeedbackView()->showFeedback("How can I help you?", [this] { + setCommandList(m_List); + record(); + }); + } +} + CommandController::CommandMatch CommandController::findCommand(vc_cmd_list_h list) { int err = VC_ERROR_NONE; diff --git a/voice-app/src/Voice/VoiceInputController.cpp b/voice-app/src/Voice/VoiceInputController.cpp index 2acdb8b..29455bc 100644 --- a/voice-app/src/Voice/VoiceInputController.cpp +++ b/voice-app/src/Voice/VoiceInputController.cpp @@ -31,7 +31,8 @@ namespace } VoiceInputController::VoiceInputController(VoiceControlManager &voiceControl) - : m_VoiceControl(voiceControl), m_FeedbackView(nullptr), m_FloatingView(nullptr) + : m_VoiceControl(voiceControl), m_FeedbackView(nullptr), m_FloatingView(nullptr), + m_IsStandByMode(false) { } @@ -42,6 +43,16 @@ void VoiceInputController::initialize(Voice::FeedbackView *feedbackView, m_FloatingView = floatingView; } +void VoiceInputController::setStandByModeChangedCallback(StandByModeChangedCallback callback) +{ + m_OnStandByModeChanged = std::move(callback); +} + +void VoiceInputController::setStandByMode(bool isStandByMode) +{ + m_IsStandByMode = isStandByMode; +} + void VoiceInputController::activate() { subscribe(); @@ -79,6 +90,8 @@ void VoiceInputController::subscribe() m_VoiceControl.setErrorCallback(std::bind(&VoiceInputController::onError, this, _1, _2)); m_VoiceControl.setResultCallback(std::bind(&VoiceInputController::onResult, this, _1, _2, _3)); m_VoiceControl.setPreResultCallback(std::bind(&VoiceInputController::onPreResult, this, _1)); + m_FloatingView->setBgPressCallback(std::bind(&VoiceInputController::changeStandByMode, this, true)); + m_FloatingView->setButtonPressCallback(std::bind(&VoiceInputController::changeStandByMode, this, false)); setTimeOutTimer(); } @@ -89,6 +102,8 @@ void VoiceInputController::unsubscribe() m_VoiceControl.setTimeOutTimer(0.0, nullptr); m_VoiceControl.setResultCallback(nullptr); m_VoiceControl.setPreResultCallback(nullptr); + m_FloatingView->setBgPressCallback(nullptr); + m_FloatingView->setButtonPressCallback(nullptr); } void VoiceInputController::cancelActivity() @@ -122,13 +137,32 @@ void VoiceInputController::onError(int error, const char *message) void VoiceInputController::onTimeOut() { - m_FeedbackView->showFeedback("I'm going to stand-by.", [this] { - onInterrupted(); + changeStandByMode(true); +} - //TODO: Go to stand-by mode - m_FloatingView->close(); - ui_app_exit(); - }); +void VoiceInputController::changeStandByMode(bool isStandByMode) +{ + if (m_IsStandByMode == isStandByMode) { + return; + } + + if (isStandByMode) { + m_FeedbackView->showFeedback("I'm going to stand-by.", [this] { + m_FeedbackView->hideFeedback(); + m_FloatingView->setFullScreen(false); + m_FloatingView->setButtonEnabled(true); + onInterrupted(); + }); + } else { + m_FloatingView->setFullScreen(true); + m_FloatingView->setButtonEnabled(false); + } + + if (m_OnStandByModeChanged) { + m_OnStandByModeChanged(isStandByMode); + } + + setStandByMode(isStandByMode); } void VoiceInputController::setTimeOutTimer() -- cgit v1.2.3