From 56963a80c6992f5f111470852b13e32c59c95be8 Mon Sep 17 00:00:00 2001 From: rsudev Date: Sun, 25 Aug 2013 17:08:54 +0200 Subject: Fixes #2770, TTS not starting Fixes #3177, TTS talking compass does not uses force English as well - moving checks to SpeechService, avoiding calling the intent - set requested locale to 'en' if 'forceEnglish' --- main/src/cgeo/geocaching/CompassActivity.java | 18 +----------------- main/src/cgeo/geocaching/speech/SpeechService.java | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 20 deletions(-) (limited to 'main/src') diff --git a/main/src/cgeo/geocaching/CompassActivity.java b/main/src/cgeo/geocaching/CompassActivity.java index 909f8bb..002f00e 100644 --- a/main/src/cgeo/geocaching/CompassActivity.java +++ b/main/src/cgeo/geocaching/CompassActivity.java @@ -22,7 +22,6 @@ import android.hardware.Sensor; import android.hardware.SensorManager; import android.media.AudioManager; import android.os.Bundle; -import android.speech.tts.TextToSpeech.Engine; import android.view.Menu; import android.view.MenuItem; import android.view.SubMenu; @@ -195,7 +194,7 @@ public class CompassActivity extends AbstractActivity { finish(); return true; case R.id.menu_tts_start: - initTextToSpeech(); + SpeechService.startService(this, dstCoords); return true; case R.id.menu_tts_stop: SpeechService.stopService(this); @@ -218,21 +217,6 @@ public class CompassActivity extends AbstractActivity { return false; } - private void initTextToSpeech() { - Intent intent = new Intent(Engine.ACTION_CHECK_TTS_DATA); - startActivityForResult(intent, REQUEST_TTS_DATA_CHECK); - } - - @Override - protected void onActivityResult(int request, int result, Intent data) { - if (request == REQUEST_TTS_DATA_CHECK && result == Engine.CHECK_VOICE_DATA_PASS) { - SpeechService.startService(this, dstCoords); - } else { - Log.i("TTS failed to start. Request: " + request + " result: " + result); - startActivity(new Intent(Engine.ACTION_INSTALL_TTS_DATA)); - } - } - private void setTitle() { if (StringUtils.isNotBlank(title)) { setTitle(title); diff --git a/main/src/cgeo/geocaching/speech/SpeechService.java b/main/src/cgeo/geocaching/speech/SpeechService.java index ae289ed..1907bfc 100644 --- a/main/src/cgeo/geocaching/speech/SpeechService.java +++ b/main/src/cgeo/geocaching/speech/SpeechService.java @@ -1,7 +1,9 @@ package cgeo.geocaching.speech; import cgeo.geocaching.DirectionProvider; +import cgeo.geocaching.R; import cgeo.geocaching.cgeoapplication; +import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.settings.Settings; import cgeo.geocaching.utils.GeoDirHandler; @@ -14,6 +16,7 @@ import android.app.Service; import android.content.Intent; import android.os.IBinder; import android.speech.tts.TextToSpeech; +import android.speech.tts.TextToSpeech.Engine; import android.speech.tts.TextToSpeech.OnInitListener; import java.util.Locale; @@ -144,11 +147,19 @@ public class SpeechService extends Service implements OnInitListener { return; } - int switchLocale = tts.setLanguage(Locale.getDefault()); + Locale locale = Locale.getDefault(); + if (Settings.isUseEnglish()) { + locale = Locale.ENGLISH; + } + + int switchLocale = tts.setLanguage(locale); - if (switchLocale == TextToSpeech.LANG_MISSING_DATA - || switchLocale == TextToSpeech.LANG_NOT_SUPPORTED) { + if (switchLocale == TextToSpeech.LANG_MISSING_DATA) { + startingActivity.startActivity(new Intent(Engine.ACTION_INSTALL_TTS_DATA)); + return; + } else if (switchLocale == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("Current languge not supported by text to speech."); + ActivityMixin.showToast(startingActivity, R.string.err_tts_lang_not_supported); return; } -- cgit v1.1