TtsService.java: ensure that the voice data is installed/upgraded correctly.

When using assistive technology like TalkBack and not accessing
either the eSpeak application or the Android TTS settings
directly, the voice data would previously not be installed/upgraded
correctly.

The approach here is to move the logic to onIsLanguageAvailable so
that if the espeak voice data is not installed or is upgradable
then trigger an install of the voice data and return
TextToSpeech.LANG_MISSING_DATA.
This commit is contained in:
Reece H. Dunn
2013-02-12 12:21:34 +00:00
parent 199029e97e
commit 48fa803bc4
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2012 Reece H. Dunn
* Copyright (C) 2012-2013 Reece H. Dunn
* Copyright (C) 2011 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -62,7 +62,6 @@ public class TtsService extends TextToSpeechService {
private SpeechSynthesis mEngine;
private SynthesisCallback mCallback;
private boolean mEngineInitialized = false;
private List<Voice> mAvailableVoices;
private Voice mMatchingVoice = null;
@@ -73,21 +72,8 @@ public class TtsService extends TextToSpeechService {
@Override
public void onCreate() {
super.onCreate();
if (!CheckVoiceData.hasBaseResources(this)) {
final IntentFilter filter =
new IntentFilter(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED);
registerReceiver(mBroadcastReceiver, filter);
final Intent intent = new Intent(this, DownloadVoiceData.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return;
}
initializeTtsEngine();
super.onCreate();
}
/**
@@ -100,7 +86,6 @@ public class TtsService extends TextToSpeechService {
}
mEngine = new SpeechSynthesis(this, mSynthCallback);
mEngineInitialized = true;
mAvailableVoices = mEngine.getAvailableVoices();
}
@@ -114,9 +99,14 @@ public class TtsService extends TextToSpeechService {
@Override
protected int onIsLanguageAvailable(String language, String country, String variant) {
if (!mEngineInitialized ||
!CheckVoiceData.hasBaseResources(this) ||
CheckVoiceData.canUpgradeResources(this)) {
if (!CheckVoiceData.hasBaseResources(this) || CheckVoiceData.canUpgradeResources(this)) {
final IntentFilter filter = new IntentFilter(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED);
registerReceiver(mBroadcastReceiver, filter);
final Intent intent = new Intent(this, DownloadVoiceData.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
return TextToSpeech.LANG_MISSING_DATA;
}