Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVladimir Byko-Ianko <v.bykoianko@corp.mail.ru>2015-09-04 16:41:32 +0300
committerAlex Zolotarev <alex@maps.me>2015-09-23 03:03:48 +0300
commitac57f8d4da92af07513664613bcc5c085bf098a0 (patch)
tree74930659ddb64385cf838f147a53b986780ef2b4 /android
parent98a51d6c07614eb6bc35c94a2bf87ea8ca9f8916 (diff)
Android. Initialization of TTS on the first switching on.
Diffstat (limited to 'android')
-rw-r--r--android/src/com/mapswithme/maps/MwmActivity.java10
-rw-r--r--android/src/com/mapswithme/maps/sound/TtsPlayer.java38
2 files changed, 27 insertions, 21 deletions
diff --git a/android/src/com/mapswithme/maps/MwmActivity.java b/android/src/com/mapswithme/maps/MwmActivity.java
index 1c634f9a3b..a8e8eef77b 100644
--- a/android/src/com/mapswithme/maps/MwmActivity.java
+++ b/android/src/com/mapswithme/maps/MwmActivity.java
@@ -451,8 +451,6 @@ public class MwmActivity extends BaseMwmFragmentActivity
setContentView(R.layout.activity_map);
initViews();
- TtsPlayer.INSTANCE.init();
-
if (MwmApplication.get().nativeIsBenchmarking())
Utils.keepScreenOn(true, getWindow());
@@ -880,13 +878,8 @@ public class MwmActivity extends BaseMwmFragmentActivity
mLayoutRouting.updateRouteInfo();
mMainMenu.updateRoutingInfo();
- // TODO think about moving TtsPlayer logic to RoutingLayout to minimize native calls.
if (state == RoutingLayout.State.TURN_INSTRUCTIONS)
- {
- final String[] turnNotifications = Framework.nativeGenerateTurnSound();
- if (turnNotifications != null)
- TtsPlayer.INSTANCE.speak(turnNotifications);
- }
+ TtsPlayer.INSTANCE.playTurnNotifications();
}
}
@@ -969,6 +962,7 @@ public class MwmActivity extends BaseMwmFragmentActivity
{
super.onStart();
+ TtsPlayer.INSTANCE.reinitIfLocaleChanged();
if (!mIsFragmentContainer)
popFragment();
}
diff --git a/android/src/com/mapswithme/maps/sound/TtsPlayer.java b/android/src/com/mapswithme/maps/sound/TtsPlayer.java
index 2a49eb80d8..89d78bc409 100644
--- a/android/src/com/mapswithme/maps/sound/TtsPlayer.java
+++ b/android/src/com/mapswithme/maps/sound/TtsPlayer.java
@@ -5,6 +5,7 @@ import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.widget.Toast;
+import com.mapswithme.maps.Framework;
import com.mapswithme.maps.MwmApplication;
import java.util.Locale;
@@ -25,16 +26,22 @@ public enum TtsPlayer
TtsPlayer() {}
- public void init()
+ public void reinitIfLocaleChanged()
{
- Locale systemLanguage = Locale.getDefault();
- if (systemLanguage == null)
- systemLanguage = DEFAULT_LOCALE;
+ if (!isValid())
+ return; // TtsPlayer was not inited yet.
- if (mTtsLocale == null || !isLocaleEqual(systemLanguage))
+ final Locale systemLanguage = getDefaultLocale();
+ if (!isLocaleEqual(systemLanguage))
initTts(systemLanguage);
}
+ private Locale getDefaultLocale()
+ {
+ final Locale systemLanguage = Locale.getDefault();
+ return systemLanguage == null ? DEFAULT_LOCALE : systemLanguage;
+ }
+
private boolean isLocaleEqual(Locale locale)
{
return locale.getLanguage().equals(mTtsLocale.getLanguage()) &&
@@ -107,13 +114,16 @@ public enum TtsPlayer
});
}
- private boolean readyToPlay()
+ private boolean isValid()
{
return !mIsLocaleChanging && mTts != null && mTtsLocale != null;
}
private void speak(String textToSpeak)
{
+ if (textToSpeak.isEmpty())
+ return;
+
// @TODO(vbykoianko) removes these two toasts below when the test period is finished.
Toast.makeText(MwmApplication.get(), textToSpeak, Toast.LENGTH_SHORT).show();
if (mTts.speak(textToSpeak, TextToSpeech.QUEUE_ADD, null) == TextToSpeech.ERROR)
@@ -123,16 +133,16 @@ public enum TtsPlayer
}
}
- public void speak(String[] turnNotifications)
+ public void playTurnNotifications()
{
- if (!readyToPlay())
+ if (!isValid())
return; // speak() is called while TTS is not ready or could not be initialized.
- if (turnNotifications == null)
- return;
-
- for (String textToSpeak : turnNotifications)
- speak(textToSpeak);
+ // TODO think about moving TtsPlayer logic to RoutingLayout to minimize native calls.
+ final String[] turnNotifications = Framework.nativeGenerateTurnSound();
+ if (turnNotifications != null)
+ for (String textToSpeak : turnNotifications)
+ speak(textToSpeak);
}
public void stop()
@@ -148,6 +158,8 @@ public enum TtsPlayer
public void enable(boolean enabled)
{
+ if (!isValid())
+ initTts(getDefaultLocale());
nativeEnableTurnNotifications(enabled);
}