Pluging in all TTS subsystems (android and core parts).

This commit is contained in:
Vladimir Byko-Ianko 2015-08-06 11:03:58 +03:00 committed by Alex Zolotarev
parent 6d911ac640
commit a563ca7604
5 changed files with 29 additions and 19 deletions

View file

@ -81,6 +81,7 @@ LOCAL_SRC_FILES := \
com/mapswithme/maps/bookmarks/data/Bookmark.cpp \
com/mapswithme/maps/bookmarks/data/BookmarkManager.cpp \
com/mapswithme/maps/bookmarks/data/BookmarkCategory.cpp \
com/mapswithme/maps/sound/tts.cpp \
com/mapswithme/maps/VideoTimer.cpp \
com/mapswithme/maps/MapFragment.cpp \
com/mapswithme/maps/MWMApplication.cpp \

View file

@ -1,6 +1,6 @@
#include "../../Framework.hpp"
#include "../Framework.hpp"
#include "../../../core/jni_helper.hpp"
#include "../../core/jni_helper.hpp"
namespace
@ -25,7 +25,8 @@ extern "C"
JNIEXPORT void JNICALL
Java_com_mapswithme_maps_sound_TTSPlayer_nativeSetTurnNotificationsLocale(JNIEnv * env, jclass thiz, jstring jLocale)
{
frm()->SetTurnNotificationsLocale(jni::ToNativeString(env, jLocale));
if (frm())
frm()->SetTurnNotificationsLocale(jni::ToNativeString(env, jLocale));
}
JNIEXPORT jstring JNICALL

View file

@ -445,6 +445,9 @@ public class MWMActivity extends BaseMwmFragmentActivity
setContentView(R.layout.activity_map);
initViews();
// Initializing TTS player instance.
TTSPlayer.get();
// Do not turn off the screen while benchmarking
if (MWMApplication.get().nativeIsBenchmarking())
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

View file

@ -35,11 +35,17 @@ public class TTSPlayer
public static TTSPlayer get()
{
if (ourInstance == null)
if (ourInstance == null || !ourInstance.isLocaleEquals(Locale.getDefault()))
ourInstance = new TTSPlayer();
return ourInstance;
}
private boolean isLocaleEquals(Locale locale)
{
return locale.equals(mTts.getLanguage());
}
private void setLocaleIfAvailable(final Locale locale)
{
if (mTts != null && mTts.getLanguage().equals(locale))
@ -58,28 +64,26 @@ public class TTSPlayer
return;
}
if (mTts.setLanguage(locale) != TextToSpeech.LANG_AVAILABLE)
mTts.setLanguage(Locale.UK); // Assuming that Locale.UK is always available.
final int avail = mTts.isLanguageAvailable(locale);
Locale loc = locale;
if (avail != TextToSpeech.LANG_AVAILABLE && avail != TextToSpeech.LANG_COUNTRY_AVAILABLE
&& avail != TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE)
{
loc = Locale.UK; // No translation for TTS for Locale.getDefault() language.
}
mTts.setLanguage(locale);
nativeSetTurnNotificationsLocale(locale.getLanguage());
Log.i(TAG, "setLocaleIfAvailable() nativeSetTurnNotificationsLocale(" + locale.getLanguage() + ")");
}
});
final Locale loc = getLocale();
if (loc != null)
nativeSetTurnNotificationsLocale(loc.getLanguage());
}
private Locale getLocale()
{
if (mTts == null)
return null;
return mTts.getLanguage();
}
public void speak(String textToSpeak)
{
if (mTts == null)
{
Log.e(TAG, "speakText is called while mTts == null");
Log.w(TAG, "TTSPlayer.speak() is called while mTts == null.");
return;
}

View file

@ -1618,10 +1618,11 @@ void Framework::SetupMeasurementSystem()
{
Settings::Units units = Settings::Metric;
Settings::Get("Units", units);
LOG(LDEBUG, ("Units =", units));
// @TODO(vbykoianko) Try to rewrite code to use only one structure fo LengthUnits
m_routingSession.SetTurnNotificationsUnits(units == Settings::Foot ?
routing::turns::sound::LengthUnits::Feet :
routing::turns::sound::LengthUnits::Meters);
this->EnableTurnNotifications(true);
m_informationDisplay.measurementSystemChanged();
Invalidate();