| private List<Voice> mAvailableVoices; | private List<Voice> mAvailableVoices; | ||||
| private Voice mMatchingVoice = null; | private Voice mMatchingVoice = null; | ||||
| private BroadcastReceiver mOnLanguagesDownloaded = null; | |||||
| private String mLanguage = DEFAULT_LANGUAGE; | private String mLanguage = DEFAULT_LANGUAGE; | ||||
| private String mCountry = DEFAULT_COUNTRY; | private String mCountry = DEFAULT_COUNTRY; | ||||
| private String mVariant = DEFAULT_VARIANT; | private String mVariant = DEFAULT_VARIANT; | ||||
| @Override | @Override | ||||
| public void onDestroy() { | public void onDestroy() { | ||||
| super.onDestroy(); | super.onDestroy(); | ||||
| if (mBroadcastReceiver != null) { | |||||
| unregisterReceiver(mBroadcastReceiver); | |||||
| if (mOnLanguagesDownloaded != null) { | |||||
| unregisterReceiver(mOnLanguagesDownloaded); | |||||
| } | } | ||||
| } | } | ||||
| @Override | @Override | ||||
| protected int onIsLanguageAvailable(String language, String country, String variant) { | protected int onIsLanguageAvailable(String language, String country, String variant) { | ||||
| if (!CheckVoiceData.hasBaseResources(this) || CheckVoiceData.canUpgradeResources(this)) { | if (!CheckVoiceData.hasBaseResources(this) || CheckVoiceData.canUpgradeResources(this)) { | ||||
| if (mBroadcastReceiver == null) { | |||||
| mBroadcastReceiver = new BroadcastReceiver() { | |||||
| if (mOnLanguagesDownloaded == null) { | |||||
| mOnLanguagesDownloaded = new BroadcastReceiver() { | |||||
| @Override | @Override | ||||
| public void onReceive(Context context, Intent intent) { | public void onReceive(Context context, Intent intent) { | ||||
| initializeTtsEngine(); | initializeTtsEngine(); | ||||
| }; | }; | ||||
| final IntentFilter filter = new IntentFilter(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED); | final IntentFilter filter = new IntentFilter(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED); | ||||
| registerReceiver(mBroadcastReceiver, filter); | |||||
| registerReceiver(mOnLanguagesDownloaded, filter); | |||||
| } | } | ||||
| final Intent intent = new Intent(this, DownloadVoiceData.class); | final Intent intent = new Intent(this, DownloadVoiceData.class); | ||||
| mCallback.done(); | mCallback.done(); | ||||
| } | } | ||||
| }; | }; | ||||
| /** | |||||
| * Listens for language update broadcasts and initializes the eSpeak engine. | |||||
| */ | |||||
| private BroadcastReceiver mBroadcastReceiver = null; | |||||
| } | } |