Skip to content

Commit

Permalink
Handle voice state when pausing/resuming the activity. (#3504)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo committed Jun 15, 2020
1 parent c3c4c74 commit bf8da13
Showing 1 changed file with 13 additions and 2 deletions.
Expand Up @@ -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);
Expand Down Expand Up @@ -231,6 +233,8 @@ public void startVoiceSearch() {
storeData = false;
}

mIsSpeechRecognitionRunning = true;

SpeechServiceSettings.Builder builder = new SpeechServiceSettings.Builder()
.withLanguage(locale)
.withStoreSamples(storeData)
Expand All @@ -250,6 +254,8 @@ public void stopVoiceSearch() {
Log.d(LOGTAG, e.getLocalizedMessage() != null ? e.getLocalizedMessage() : "Unknown voice error");
e.printStackTrace();
}

mIsSpeechRecognitionRunning = false;
}

@Override
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit bf8da13

Please sign in to comment.