Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3491 Handle voice state when pausing/resuming the activity. #3504

Merged
merged 1 commit into from
Jun 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
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