Use API 21.

This commit is contained in:
Reece H. Dunn
2014-10-28 18:30:16 +00:00
parent 6ac54860a1
commit 3d2308e285
5 changed files with 67 additions and 31 deletions
+2 -2
View File
@@ -19,11 +19,11 @@ dependencies {
android {
buildToolsVersion '19.1'
compileSdkVersion 19
compileSdkVersion 21
defaultConfig {
minSdkVersion 14
targetSdkVersion 19
targetSdkVersion 21
}
sourceSets {
@@ -30,11 +30,11 @@ public class TextToSpeechTest extends TextToSpeechTestCase
{
assertThat(getEngine(), is(notNullValue()));
Locale initialLocale = getEngine().getLanguage();
Locale initialLocale = getLanguage(getEngine());
assertThat(getEngine().isLanguageAvailable(new Locale("cel")), isTtsLangCode(TextToSpeech.LANG_NOT_SUPPORTED));
assertThat(getEngine().getLanguage().getLanguage(), is(initialLocale.getLanguage()));
assertThat(getEngine().getLanguage().getCountry(), is(initialLocale.getCountry()));
assertThat(getEngine().getLanguage().getVariant(), is(initialLocale.getVariant()));
assertThat(getLanguage(getEngine()).getLanguage(), is(initialLocale.getLanguage()));
assertThat(getLanguage(getEngine()).getCountry(), is(initialLocale.getCountry()));
assertThat(getLanguage(getEngine()).getVariant(), is(initialLocale.getVariant()));
}
public void testLanguages()
@@ -60,44 +60,44 @@ public class TextToSpeechTest extends TextToSpeechTestCase
context = "iana1";
assertThat(getEngine().isLanguageAvailable(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(iana1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));
context = "iana2";
assertThat(getEngine().isLanguageAvailable(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(iana2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
context = "iana3";
assertThat(getEngine().isLanguageAvailable(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(iana3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(""));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
context = "java1";
assertThat(getEngine().isLanguageAvailable(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().setLanguage(java1), isTtsLangCode(TextToSpeech.LANG_COUNTRY_VAR_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(data.variant));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(data.variant));
context = "java2";
assertThat(getEngine().isLanguageAvailable(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().setLanguage(java2), isTtsLangCode(TextToSpeech.LANG_COUNTRY_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(data.javaCountry));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(data.javaCountry));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
context = "java3";
assertThat(getEngine().isLanguageAvailable(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().setLanguage(java3), isTtsLangCode(TextToSpeech.LANG_AVAILABLE));
assertThat(getEngine().getLanguage().getLanguage(), is(data.javaLanguage));
assertThat(getEngine().getLanguage().getCountry(), is(""));
assertThat(getEngine().getLanguage().getVariant(), is(""));
assertThat(getLanguage(getEngine()).getLanguage(), is(data.javaLanguage));
assertThat(getLanguage(getEngine()).getCountry(), is(""));
assertThat(getLanguage(getEngine()).getVariant(), is(""));
}
catch (AssertionError e)
{
@@ -16,6 +16,7 @@
package com.reecedunn.espeak.test;
import android.os.Build;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.test.AndroidTestCase;
@@ -93,4 +94,19 @@ public class TextToSpeechTestCase extends AndroidTestCase
{
return mEngine;
}
@SuppressWarnings("deprecation")
public static Locale getLanguage(TextToSpeech engine) {
if (engine != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
android.speech.tts.Voice voice = engine.getVoice();
if (voice != null) {
return voice.getLocale();
}
} else {
return engine.getLanguage();
}
}
return null;
}
}
@@ -17,6 +17,7 @@
package com.reecedunn.espeak;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
@@ -27,6 +28,7 @@ import java.util.Locale;
/*
* Returns the sample text string for the language requested
*/
@SuppressLint("NewApi")
public class GetSampleText extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -89,8 +89,13 @@ public class eSpeakActivity extends Activity {
findViewById(R.id.speak).setOnClickListener(new View.OnClickListener() {
@Override
@SuppressWarnings("deprecation")
public void onClick(View v) {
mTts.speak(mText.getText().toString(), TextToSpeech.QUEUE_ADD, null);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mTts.speak(mText.getText().toString(), TextToSpeech.QUEUE_ADD, null, null);
} else {
mTts.speak(mText.getText().toString(), TextToSpeech.QUEUE_ADD, null);
}
}
});
@@ -189,15 +194,28 @@ public class eSpeakActivity extends Activity {
mTts = new TextToSpeech(this, mInitListener);
}
@SuppressWarnings("deprecation")
private Locale getTtsLanguage() {
if (mTts != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
android.speech.tts.Voice voice = mTts.getVoice();
if (voice != null) {
return voice.getLocale();
}
} else {
return mTts.getLanguage();
}
}
return null;
}
private void populateInformationView() {
mInformation.clear();
if (mTts != null) {
Locale language = mTts.getLanguage();
if (language != null) {
final String currentLocale = getString(R.string.current_tts_locale);
mInformation.add(new Pair<String,String>(currentLocale, mTts.getLanguage().getDisplayName()));
}
Locale language = getTtsLanguage();
if (language != null) {
final String currentLocale = getString(R.string.current_tts_locale);
mInformation.add(new Pair<String, String>(currentLocale, language.getDisplayName()));
}
final String availableVoices = getString(R.string.available_voices);