From bf8da13f0599da71dea7f42ba0206f633ed2db9b Mon Sep 17 00:00:00 2001 From: Manuel Martin Date: Mon, 15 Jun 2020 22:12:48 +0200 Subject: [PATCH] Handle voice state when pausing/resuming the activity. (#3504) --- .../ui/widgets/dialogs/VoiceSearchWidget.java | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java index 50fdf8fe3..1e968be56 100644 --- a/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java +++ b/app/src/common/shared/org/mozilla/vrbrowser/ui/widgets/dialogs/VoiceSearchWidget.java @@ -68,6 +68,8 @@ public interface VoiceSearchDelegate { private ClipDrawable mVoiceInputClipDrawable; private AnimatedVectorDrawable mSearchingAnimation; private VRBrowserApplication mApplication; + private boolean mIsSpeechRecognitionRunning = false; + private boolean mWasSpeechRecognitionRunning = false; public VoiceSearchWidget(Context aContext) { super(aContext); @@ -231,6 +233,8 @@ public void startVoiceSearch() { storeData = false; } + mIsSpeechRecognitionRunning = true; + SpeechServiceSettings.Builder builder = new SpeechServiceSettings.Builder() .withLanguage(locale) .withStoreSamples(storeData) @@ -250,6 +254,8 @@ public void stopVoiceSearch() { Log.d(LOGTAG, e.getLocalizedMessage() != null ? e.getLocalizedMessage() : "Unknown voice error"); e.printStackTrace(); } + + mIsSpeechRecognitionRunning = false; } @Override @@ -355,12 +361,17 @@ public void onActivityStarted(Activity activity) { @Override public void onActivityResumed(Activity activity) { - startVoiceSearch(); + if (mWasSpeechRecognitionRunning) { + startVoiceSearch(); + } } @Override public void onActivityPaused(Activity activity) { - stopVoiceSearch(); + mWasSpeechRecognitionRunning = mIsSpeechRecognitionRunning; + if (mIsSpeechRecognitionRunning) { + stopVoiceSearch(); + } } @Override