Use new TTS engine API in TTS settings
Requires TTS engine API added in change I7614ff788e11f897e87052f684f1b4938d539fb7 Bug: 4148725 Change-Id: I5f3fa3bbcbf4e62af23bb701bcb6e8e5d8511341
This commit is contained in:
@@ -24,25 +24,22 @@ import static android.provider.Settings.Secure.TTS_DEFAULT_VARIANT;
|
|||||||
import static android.provider.Settings.Secure.TTS_ENABLED_PLUGINS;
|
import static android.provider.Settings.Secure.TTS_ENABLED_PLUGINS;
|
||||||
import static android.provider.Settings.Secure.TTS_USE_DEFAULTS;
|
import static android.provider.Settings.Secure.TTS_USE_DEFAULTS;
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.ResolveInfo;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.CheckBoxPreference;
|
import android.preference.CheckBoxPreference;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
import android.preference.PreferenceGroup;
|
import android.preference.PreferenceGroup;
|
||||||
import android.preference.PreferenceScreen;
|
|
||||||
import android.preference.Preference.OnPreferenceClickListener;
|
|
||||||
import android.provider.Settings;
|
import android.provider.Settings;
|
||||||
import android.provider.Settings.SettingNotFoundException;
|
import android.provider.Settings.SettingNotFoundException;
|
||||||
import android.speech.tts.TextToSpeech;
|
import android.speech.tts.TextToSpeech;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@@ -54,9 +51,9 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
|
Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
|
||||||
TextToSpeech.OnInitListener {
|
TextToSpeech.OnInitListener {
|
||||||
|
|
||||||
|
private static final boolean DBG = true;
|
||||||
private static final String TAG = "TextToSpeechSettings";
|
private static final String TAG = "TextToSpeechSettings";
|
||||||
|
|
||||||
private static final String SYSTEM_TTS = "com.svox.pico";
|
|
||||||
private static final String KEY_TTS_PLAY_EXAMPLE = "tts_play_example";
|
private static final String KEY_TTS_PLAY_EXAMPLE = "tts_play_example";
|
||||||
private static final String KEY_TTS_INSTALL_DATA = "tts_install_data";
|
private static final String KEY_TTS_INSTALL_DATA = "tts_install_data";
|
||||||
private static final String KEY_TTS_USE_DEFAULT = "toggle_use_default_tts_settings";
|
private static final String KEY_TTS_USE_DEFAULT = "toggle_use_default_tts_settings";
|
||||||
@@ -65,6 +62,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
private static final String KEY_TTS_DEFAULT_COUNTRY = "tts_default_country";
|
private static final String KEY_TTS_DEFAULT_COUNTRY = "tts_default_country";
|
||||||
private static final String KEY_TTS_DEFAULT_VARIANT = "tts_default_variant";
|
private static final String KEY_TTS_DEFAULT_VARIANT = "tts_default_variant";
|
||||||
private static final String KEY_TTS_DEFAULT_SYNTH = "tts_default_synth";
|
private static final String KEY_TTS_DEFAULT_SYNTH = "tts_default_synth";
|
||||||
|
private static final String KEY_TTS_ENGINES = "tts_engines_section";
|
||||||
|
|
||||||
private static final String KEY_PLUGIN_ENABLED_PREFIX = "ENABLED_";
|
private static final String KEY_PLUGIN_ENABLED_PREFIX = "ENABLED_";
|
||||||
private static final String KEY_PLUGIN_SETTINGS_PREFIX = "SETTINGS_";
|
private static final String KEY_PLUGIN_SETTINGS_PREFIX = "SETTINGS_";
|
||||||
@@ -76,19 +74,17 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
|
|
||||||
private static final String LOCALE_DELIMITER = "-";
|
private static final String LOCALE_DELIMITER = "-";
|
||||||
|
|
||||||
private static final String FALLBACK_TTS_DEFAULT_SYNTH =
|
|
||||||
TextToSpeech.Engine.DEFAULT_SYNTH;
|
|
||||||
|
|
||||||
private Preference mPlayExample = null;
|
private Preference mPlayExample = null;
|
||||||
private Preference mInstallData = null;
|
private Preference mInstallData = null;
|
||||||
private CheckBoxPreference mUseDefaultPref = null;
|
private CheckBoxPreference mUseDefaultPref = null;
|
||||||
private ListPreference mDefaultRatePref = null;
|
private ListPreference mDefaultRatePref = null;
|
||||||
private ListPreference mDefaultLocPref = null;
|
private ListPreference mDefaultLocPref = null;
|
||||||
private ListPreference mDefaultSynthPref = null;
|
private ListPreference mDefaultSynthPref = null;
|
||||||
|
private PreferenceGroup mEnginesGroup;
|
||||||
|
|
||||||
private String mDefaultLanguage = null;
|
private String mDefaultLanguage = null;
|
||||||
private String mDefaultCountry = null;
|
private String mDefaultCountry = null;
|
||||||
private String mDefaultLocVariant = null;
|
private String mDefaultLocVariant = null;
|
||||||
private String mDefaultEng = "";
|
|
||||||
private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
|
private int mDefaultRate = TextToSpeech.Engine.DEFAULT_RATE;
|
||||||
|
|
||||||
// Index of the current string to use for the demo.
|
// Index of the current string to use for the demo.
|
||||||
@@ -112,10 +108,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
addPreferencesFromResource(R.xml.tts_settings);
|
addPreferencesFromResource(R.xml.tts_settings);
|
||||||
|
|
||||||
final Activity activity = getActivity();
|
getActivity().setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
||||||
addEngineSpecificSettings(activity);
|
|
||||||
|
|
||||||
activity.setVolumeControlStream(TextToSpeech.Engine.DEFAULT_STREAM);
|
|
||||||
|
|
||||||
mEnableDemo = false;
|
mEnableDemo = false;
|
||||||
mTtsStarted = false;
|
mTtsStarted = false;
|
||||||
@@ -125,10 +118,24 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
mDefaultCountry = currentLocale.getISO3Country();
|
mDefaultCountry = currentLocale.getISO3Country();
|
||||||
mDefaultLocVariant = currentLocale.getVariant();
|
mDefaultLocVariant = currentLocale.getVariant();
|
||||||
|
|
||||||
mTts = new TextToSpeech(activity, this);
|
mPlayExample = findPreference(KEY_TTS_PLAY_EXAMPLE);
|
||||||
initClickers();
|
mPlayExample.setOnPreferenceClickListener(this);
|
||||||
}
|
|
||||||
|
|
||||||
|
mInstallData = findPreference(KEY_TTS_INSTALL_DATA);
|
||||||
|
mInstallData.setOnPreferenceClickListener(this);
|
||||||
|
|
||||||
|
mUseDefaultPref = (CheckBoxPreference) findPreference(KEY_TTS_USE_DEFAULT);
|
||||||
|
mDefaultSynthPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_SYNTH);
|
||||||
|
mDefaultRatePref = (ListPreference) findPreference(KEY_TTS_DEFAULT_RATE);
|
||||||
|
mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG);
|
||||||
|
|
||||||
|
mEnginesGroup = (PreferenceGroup) findPreference(KEY_TTS_ENGINES);
|
||||||
|
|
||||||
|
mTts = new TextToSpeech(getActivity().getApplicationContext(), this);
|
||||||
|
|
||||||
|
initDefaultSettings();
|
||||||
|
addEngineSpecificSettings();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
@@ -142,7 +149,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
@@ -165,64 +171,52 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addEngineSpecificSettings(Context context) {
|
private void addEngineSpecificSettings() {
|
||||||
PreferenceGroup enginesCategory = (PreferenceGroup) findPreference("tts_engines_section");
|
Context context = getActivity();
|
||||||
Intent intent = new Intent("android.intent.action.START_TTS_ENGINE");
|
List<TextToSpeech.EngineInfo> engines = mTts.getEngines();
|
||||||
ResolveInfo[] enginesArray = new ResolveInfo[0];
|
for (TextToSpeech.EngineInfo engine : engines) {
|
||||||
PackageManager pm = getPackageManager();
|
|
||||||
enginesArray = pm.queryIntentActivities(intent, 0).toArray(enginesArray);
|
|
||||||
for (int i = 0; i < enginesArray.length; i++) {
|
|
||||||
String prefKey = "";
|
String prefKey = "";
|
||||||
final String pluginPackageName = enginesArray[i].activityInfo.packageName;
|
final String engineName = engine.name;
|
||||||
if (!enginesArray[i].activityInfo.packageName.equals(SYSTEM_TTS)) {
|
if (!engineName.equals(TextToSpeech.Engine.DEFAULT_ENGINE)) {
|
||||||
CheckBoxPreference chkbxPref = new CheckBoxPreference(context);
|
CheckBoxPreference enablePref = new CheckBoxPreference(context);
|
||||||
prefKey = KEY_PLUGIN_ENABLED_PREFIX + pluginPackageName;
|
prefKey = KEY_PLUGIN_ENABLED_PREFIX + engineName;
|
||||||
chkbxPref.setKey(prefKey);
|
enablePref.setKey(prefKey);
|
||||||
chkbxPref.setTitle(enginesArray[i].loadLabel(pm));
|
enablePref.setTitle(engine.label);
|
||||||
enginesCategory.addPreference(chkbxPref);
|
mEnginesGroup.addPreference(enablePref);
|
||||||
}
|
}
|
||||||
if (pluginHasSettings(pluginPackageName)) {
|
if (engineHasSettings(engineName)) {
|
||||||
Preference pref = new Preference(context);
|
Preference pref = new Preference(context);
|
||||||
prefKey = KEY_PLUGIN_SETTINGS_PREFIX + pluginPackageName;
|
prefKey = KEY_PLUGIN_SETTINGS_PREFIX + engineName;
|
||||||
pref.setKey(prefKey);
|
pref.setKey(prefKey);
|
||||||
pref.setTitle(enginesArray[i].loadLabel(pm));
|
pref.setTitle(engine.label);
|
||||||
CharSequence settingsLabel = getResources().getString(
|
CharSequence settingsLabel = getResources().getString(
|
||||||
R.string.tts_engine_name_settings, enginesArray[i].loadLabel(pm));
|
R.string.tts_engine_name_settings, engine.label);
|
||||||
pref.setSummary(settingsLabel);
|
pref.setSummary(settingsLabel);
|
||||||
pref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
|
// TODO: add a new API for this
|
||||||
public boolean onPreferenceClick(Preference preference){
|
// pref.setOnPreferenceClickListener(new OnPreferenceClickListener(){
|
||||||
Intent i = new Intent();
|
// public boolean onPreferenceClick(Preference preference){
|
||||||
i.setClassName(pluginPackageName,
|
// Intent i = new Intent();
|
||||||
pluginPackageName + ".EngineSettings");
|
// i.setClassName(pluginPackageName,
|
||||||
startActivity(i);
|
// pluginPackageName + ".EngineSettings");
|
||||||
return true;
|
// startActivity(i);
|
||||||
}
|
// return true;
|
||||||
});
|
// }
|
||||||
enginesCategory.addPreference(pref);
|
// });
|
||||||
|
mEnginesGroup.addPreference(pref);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean pluginHasSettings(String pluginPackageName) {
|
private boolean engineHasSettings(String enginePackageName) {
|
||||||
PackageManager pm = getPackageManager();
|
PackageManager pm = getPackageManager();
|
||||||
Intent i = new Intent();
|
Intent i = new Intent();
|
||||||
i.setClassName(pluginPackageName, pluginPackageName + ".EngineSettings");
|
i.setClassName(enginePackageName, enginePackageName + ".EngineSettings");
|
||||||
if (pm.resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY) != null){
|
if (pm.resolveActivity(i, PackageManager.MATCH_DEFAULT_ONLY) != null){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void initClickers() {
|
|
||||||
mPlayExample = findPreference(KEY_TTS_PLAY_EXAMPLE);
|
|
||||||
mPlayExample.setOnPreferenceClickListener(this);
|
|
||||||
|
|
||||||
mInstallData = findPreference(KEY_TTS_INSTALL_DATA);
|
|
||||||
mInstallData.setOnPreferenceClickListener(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private void initDefaultSettings() {
|
private void initDefaultSettings() {
|
||||||
ContentResolver resolver = getContentResolver();
|
ContentResolver resolver = getContentResolver();
|
||||||
|
|
||||||
@@ -230,32 +224,16 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
// settings if they are not found.
|
// settings if they are not found.
|
||||||
|
|
||||||
// "Use Defaults"
|
// "Use Defaults"
|
||||||
int useDefault = 0;
|
int useDefault = Settings.Secure.getInt(resolver, TTS_USE_DEFAULTS,
|
||||||
mUseDefaultPref = (CheckBoxPreference) findPreference(KEY_TTS_USE_DEFAULT);
|
TextToSpeech.Engine.USE_DEFAULTS);
|
||||||
try {
|
|
||||||
useDefault = Settings.Secure.getInt(resolver, TTS_USE_DEFAULTS);
|
|
||||||
} catch (SettingNotFoundException e) {
|
|
||||||
// "use default" setting not found, initialize it
|
|
||||||
useDefault = TextToSpeech.Engine.USE_DEFAULTS;
|
|
||||||
Settings.Secure.putInt(resolver, TTS_USE_DEFAULTS, useDefault);
|
|
||||||
}
|
|
||||||
mUseDefaultPref.setChecked(useDefault == 1);
|
mUseDefaultPref.setChecked(useDefault == 1);
|
||||||
mUseDefaultPref.setOnPreferenceChangeListener(this);
|
mUseDefaultPref.setOnPreferenceChangeListener(this);
|
||||||
|
|
||||||
// Default synthesis engine
|
// Default synthesis engine
|
||||||
mDefaultSynthPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_SYNTH);
|
|
||||||
loadEngines();
|
loadEngines();
|
||||||
mDefaultSynthPref.setOnPreferenceChangeListener(this);
|
mDefaultSynthPref.setOnPreferenceChangeListener(this);
|
||||||
String engine = Settings.Secure.getString(resolver, TTS_DEFAULT_SYNTH);
|
|
||||||
if (engine == null) {
|
|
||||||
// TODO move FALLBACK_TTS_DEFAULT_SYNTH to TextToSpeech
|
|
||||||
engine = FALLBACK_TTS_DEFAULT_SYNTH;
|
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_SYNTH, engine);
|
|
||||||
}
|
|
||||||
mDefaultEng = engine;
|
|
||||||
|
|
||||||
// Default rate
|
// Default rate
|
||||||
mDefaultRatePref = (ListPreference) findPreference(KEY_TTS_DEFAULT_RATE);
|
|
||||||
try {
|
try {
|
||||||
mDefaultRate = Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE);
|
mDefaultRate = Settings.Secure.getInt(resolver, TTS_DEFAULT_RATE);
|
||||||
} catch (SettingNotFoundException e) {
|
} catch (SettingNotFoundException e) {
|
||||||
@@ -265,34 +243,27 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
}
|
}
|
||||||
mDefaultRatePref.setValue(String.valueOf(mDefaultRate));
|
mDefaultRatePref.setValue(String.valueOf(mDefaultRate));
|
||||||
mDefaultRatePref.setOnPreferenceChangeListener(this);
|
mDefaultRatePref.setOnPreferenceChangeListener(this);
|
||||||
// apply the default rate so the TTS demo in the Settings screen uses it, even if
|
|
||||||
// the use of default settings is not enforced
|
|
||||||
mTts.setSpeechRate(mDefaultRate/100.0f);
|
|
||||||
|
|
||||||
// Default language / country / variant : these three values map to a single ListPref
|
// Default language / country / variant : these three values map to a single ListPref
|
||||||
// representing the matching Locale
|
// representing the matching Locale
|
||||||
mDefaultLocPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_LANG);
|
|
||||||
initDefaultLang();
|
initDefaultLang();
|
||||||
mDefaultLocPref.setOnPreferenceChangeListener(this);
|
mDefaultLocPref.setOnPreferenceChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Ask the current default engine to launch the matching CHECK_TTS_DATA activity
|
* Ask the current default engine to launch the matching CHECK_TTS_DATA activity
|
||||||
* to check the required TTS files are properly installed.
|
* to check the required TTS files are properly installed.
|
||||||
*/
|
*/
|
||||||
private void checkVoiceData() {
|
private void checkVoiceData() {
|
||||||
PackageManager pm = getPackageManager();
|
String defaultEngine = mTts.getDefaultEngine();
|
||||||
Intent intent = new Intent();
|
if (TextUtils.isEmpty(defaultEngine)) return;
|
||||||
intent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
|
Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
|
||||||
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
|
intent.setPackage(defaultEngine);
|
||||||
// query only the package that matches that of the default engine
|
try {
|
||||||
for (int i = 0; i < resolveInfos.size(); i++) {
|
Log.v(TAG, "Checking voice data: " + intent.toUri(0));
|
||||||
ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo;
|
startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK);
|
||||||
if (mDefaultEng.equals(currentActivityInfo.packageName)) {
|
} catch (ActivityNotFoundException ex) {
|
||||||
intent.setClassName(mDefaultEng, currentActivityInfo.name);
|
Log.e(TAG, "Failed to check TTS data, no acitivty found for " + intent + ")");
|
||||||
this.startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -302,18 +273,16 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
* so the required TTS files are properly installed.
|
* so the required TTS files are properly installed.
|
||||||
*/
|
*/
|
||||||
private void installVoiceData() {
|
private void installVoiceData() {
|
||||||
PackageManager pm = getPackageManager();
|
String defaultEngine = mTts.getDefaultEngine();
|
||||||
Intent intent = new Intent();
|
if (TextUtils.isEmpty(defaultEngine)) return;
|
||||||
intent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
|
Intent intent = new Intent(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
|
intent.setPackage(defaultEngine);
|
||||||
// query only the package that matches that of the default engine
|
try {
|
||||||
for (int i = 0; i < resolveInfos.size(); i++) {
|
Log.v(TAG, "Installing voice data: " + intent.toUri(0));
|
||||||
ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo;
|
startActivity(intent);
|
||||||
if (mDefaultEng.equals(currentActivityInfo.packageName)) {
|
} catch (ActivityNotFoundException ex) {
|
||||||
intent.setClassName(mDefaultEng, currentActivityInfo.name);
|
Log.e(TAG, "Failed to install TTS data, no acitivty found for " + intent + ")");
|
||||||
this.startActivity(intent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,26 +291,21 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
* spoken to the user.
|
* spoken to the user.
|
||||||
*/
|
*/
|
||||||
private void getSampleText() {
|
private void getSampleText() {
|
||||||
PackageManager pm = getPackageManager();
|
String defaultEngine = mTts.getDefaultEngine();
|
||||||
Intent intent = new Intent();
|
if (TextUtils.isEmpty(defaultEngine)) return;
|
||||||
// TODO (clchen): Replace Intent string with the actual
|
Intent intent = new Intent(TextToSpeech.Engine.ACTION_GET_SAMPLE_TEXT);
|
||||||
// Intent defined in the list of platform Intents.
|
|
||||||
intent.setAction("android.speech.tts.engine.GET_SAMPLE_TEXT");
|
|
||||||
intent.putExtra("language", mDefaultLanguage);
|
intent.putExtra("language", mDefaultLanguage);
|
||||||
intent.putExtra("country", mDefaultCountry);
|
intent.putExtra("country", mDefaultCountry);
|
||||||
intent.putExtra("variant", mDefaultLocVariant);
|
intent.putExtra("variant", mDefaultLocVariant);
|
||||||
List<ResolveInfo> resolveInfos = pm.queryIntentActivities(intent, 0);
|
intent.setPackage(defaultEngine);
|
||||||
// query only the package that matches that of the default engine
|
try {
|
||||||
for (int i = 0; i < resolveInfos.size(); i++) {
|
Log.v(TAG, "Getting sample text: " + intent.toUri(0));
|
||||||
ActivityInfo currentActivityInfo = resolveInfos.get(i).activityInfo;
|
startActivityForResult(intent, GET_SAMPLE_TEXT);
|
||||||
if (mDefaultEng.equals(currentActivityInfo.packageName)) {
|
} catch (ActivityNotFoundException ex) {
|
||||||
intent.setClassName(mDefaultEng, currentActivityInfo.name);
|
Log.e(TAG, "Failed to get sample text, no acitivty found for " + intent + ")");
|
||||||
this.startActivityForResult(intent, GET_SAMPLE_TEXT);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the TTS engine is initialized.
|
* Called when the TTS engine is initialized.
|
||||||
*/
|
*/
|
||||||
@@ -358,7 +322,6 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
mDefaultLocVariant = new String();
|
mDefaultLocVariant = new String();
|
||||||
}
|
}
|
||||||
mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
||||||
initDefaultSettings();
|
|
||||||
updateWidgetState();
|
updateWidgetState();
|
||||||
checkVoiceData();
|
checkVoiceData();
|
||||||
mTtsStarted = true;
|
mTtsStarted = true;
|
||||||
@@ -370,142 +333,155 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
updateWidgetState();
|
updateWidgetState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when voice data integrity check returns
|
* Called when voice data integrity check returns
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
|
if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
|
||||||
if (data == null){
|
onVoiceDataIntegrityCheckDone(data);
|
||||||
// The CHECK_TTS_DATA activity for the plugin did not run properly;
|
|
||||||
// disable the preview and install controls and return.
|
|
||||||
mEnableDemo = false;
|
|
||||||
mVoicesMissing = false;
|
|
||||||
updateWidgetState();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<String> available =
|
|
||||||
data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
|
|
||||||
ArrayList<String> unavailable =
|
|
||||||
data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
|
|
||||||
if ((available == null) || (unavailable == null)){
|
|
||||||
// The CHECK_TTS_DATA activity for the plugin did not run properly;
|
|
||||||
// disable the preview and install controls and return.
|
|
||||||
mEnableDemo = false;
|
|
||||||
mVoicesMissing = false;
|
|
||||||
updateWidgetState();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (available.size() > 0){
|
|
||||||
if (mTts == null) {
|
|
||||||
mTts = new TextToSpeech(getActivity(), this);
|
|
||||||
}
|
|
||||||
ListPreference ttsLanguagePref =
|
|
||||||
(ListPreference) findPreference("tts_default_lang");
|
|
||||||
CharSequence[] entries = new CharSequence[available.size()];
|
|
||||||
CharSequence[] entryValues = new CharSequence[available.size()];
|
|
||||||
int selectedLanguageIndex = -1;
|
|
||||||
String selectedLanguagePref = mDefaultLanguage;
|
|
||||||
if (mDefaultCountry.length() > 0) {
|
|
||||||
selectedLanguagePref = selectedLanguagePref + LOCALE_DELIMITER +
|
|
||||||
mDefaultCountry;
|
|
||||||
}
|
|
||||||
if (mDefaultLocVariant.length() > 0) {
|
|
||||||
selectedLanguagePref = selectedLanguagePref + LOCALE_DELIMITER +
|
|
||||||
mDefaultLocVariant;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < available.size(); i++) {
|
|
||||||
String[] langCountryVariant = available.get(i).split("-");
|
|
||||||
Locale loc = null;
|
|
||||||
if (langCountryVariant.length == 1){
|
|
||||||
loc = new Locale(langCountryVariant[0]);
|
|
||||||
} else if (langCountryVariant.length == 2){
|
|
||||||
loc = new Locale(langCountryVariant[0], langCountryVariant[1]);
|
|
||||||
} else if (langCountryVariant.length == 3){
|
|
||||||
loc = new Locale(langCountryVariant[0], langCountryVariant[1],
|
|
||||||
langCountryVariant[2]);
|
|
||||||
}
|
|
||||||
if (loc != null){
|
|
||||||
entries[i] = loc.getDisplayName();
|
|
||||||
entryValues[i] = available.get(i);
|
|
||||||
if (entryValues[i].equals(selectedLanguagePref)) {
|
|
||||||
selectedLanguageIndex = i;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ttsLanguagePref.setEntries(entries);
|
|
||||||
ttsLanguagePref.setEntryValues(entryValues);
|
|
||||||
if (selectedLanguageIndex > -1) {
|
|
||||||
ttsLanguagePref.setValueIndex(selectedLanguageIndex);
|
|
||||||
}
|
|
||||||
mEnableDemo = true;
|
|
||||||
// Make sure that the default language can be used.
|
|
||||||
int languageResult = mTts.setLanguage(
|
|
||||||
new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
|
||||||
if (languageResult < TextToSpeech.LANG_AVAILABLE){
|
|
||||||
Locale currentLocale = Locale.getDefault();
|
|
||||||
mDefaultLanguage = currentLocale.getISO3Language();
|
|
||||||
mDefaultCountry = currentLocale.getISO3Country();
|
|
||||||
mDefaultLocVariant = currentLocale.getVariant();
|
|
||||||
languageResult = mTts.setLanguage(
|
|
||||||
new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
|
||||||
// If the default Locale isn't supported, just choose the first available
|
|
||||||
// language so that there is at least something.
|
|
||||||
if (languageResult < TextToSpeech.LANG_AVAILABLE){
|
|
||||||
parseLocaleInfo(ttsLanguagePref.getEntryValues()[0].toString());
|
|
||||||
mTts.setLanguage(
|
|
||||||
new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
|
||||||
}
|
|
||||||
ContentResolver resolver = getContentResolver();
|
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, mDefaultLanguage);
|
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, mDefaultCountry);
|
|
||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, mDefaultLocVariant);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mEnableDemo = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (unavailable.size() > 0){
|
|
||||||
mVoicesMissing = true;
|
|
||||||
} else {
|
|
||||||
mVoicesMissing = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
updateWidgetState();
|
|
||||||
} else if (requestCode == GET_SAMPLE_TEXT) {
|
} else if (requestCode == GET_SAMPLE_TEXT) {
|
||||||
if (resultCode == TextToSpeech.LANG_AVAILABLE) {
|
onSampleTextReceived(resultCode, data);
|
||||||
String sample = getActivity().getString(R.string.tts_demo);
|
}
|
||||||
if ((data != null) && (data.getStringExtra("sampleText") != null)) {
|
}
|
||||||
sample = data.getStringExtra("sampleText");
|
|
||||||
}
|
private void onVoiceDataIntegrityCheckDone(Intent data) {
|
||||||
if (mTts != null) {
|
if (data == null){
|
||||||
mTts.speak(sample, TextToSpeech.QUEUE_FLUSH, null);
|
Log.e(TAG, "TTS data check failed data = null");
|
||||||
}
|
// The CHECK_TTS_DATA activity for the plugin did not run properly;
|
||||||
} else {
|
// disable the preview and install controls and return.
|
||||||
// TODO: Display an error here to the user.
|
mEnableDemo = false;
|
||||||
Log.e(TAG, "Did not have a sample string for the requested language");
|
mVoicesMissing = false;
|
||||||
|
updateWidgetState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Log.v(TAG, "TTS data check completed, data = " + data.toUri(0));
|
||||||
|
ArrayList<String> available =
|
||||||
|
data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
|
||||||
|
ArrayList<String> unavailable =
|
||||||
|
data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
|
||||||
|
if (available == null || unavailable == null){
|
||||||
|
Log.e(TAG, "TTS data check failed (available == == null)");
|
||||||
|
// The CHECK_TTS_DATA activity for the plugin did not run properly;
|
||||||
|
// disable the preview and install controls and return.
|
||||||
|
mEnableDemo = false;
|
||||||
|
mVoicesMissing = false;
|
||||||
|
updateWidgetState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (available.size() > 0){
|
||||||
|
if (mTts == null) {
|
||||||
|
mTts = new TextToSpeech(getActivity(), this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateDefaultLocPref(available);
|
||||||
|
|
||||||
|
mEnableDemo = true;
|
||||||
|
// Make sure that the default language can be used.
|
||||||
|
int languageResult = mTts.setLanguage(
|
||||||
|
new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
||||||
|
if (languageResult < TextToSpeech.LANG_AVAILABLE){
|
||||||
|
Locale currentLocale = Locale.getDefault();
|
||||||
|
mDefaultLanguage = currentLocale.getISO3Language();
|
||||||
|
mDefaultCountry = currentLocale.getISO3Country();
|
||||||
|
mDefaultLocVariant = currentLocale.getVariant();
|
||||||
|
languageResult = mTts.setLanguage(
|
||||||
|
new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
||||||
|
// If the default Locale isn't supported, just choose the first available
|
||||||
|
// language so that there is at least something.
|
||||||
|
if (languageResult < TextToSpeech.LANG_AVAILABLE){
|
||||||
|
parseLocaleInfo(mDefaultLocPref.getEntryValues()[0].toString());
|
||||||
|
mTts.setLanguage(
|
||||||
|
new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
||||||
|
}
|
||||||
|
ContentResolver resolver = getContentResolver();
|
||||||
|
Settings.Secure.putString(resolver, TTS_DEFAULT_LANG, mDefaultLanguage);
|
||||||
|
Settings.Secure.putString(resolver, TTS_DEFAULT_COUNTRY, mDefaultCountry);
|
||||||
|
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, mDefaultLocVariant);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
mEnableDemo = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (unavailable.size() > 0){
|
||||||
|
mVoicesMissing = true;
|
||||||
|
} else {
|
||||||
|
mVoicesMissing = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWidgetState();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateDefaultLocPref(ArrayList<String> availableLangs) {
|
||||||
|
CharSequence[] entries = new CharSequence[availableLangs.size()];
|
||||||
|
CharSequence[] entryValues = new CharSequence[availableLangs.size()];
|
||||||
|
int selectedLanguageIndex = -1;
|
||||||
|
String selectedLanguagePref = mDefaultLanguage;
|
||||||
|
if (mDefaultCountry.length() > 0) {
|
||||||
|
selectedLanguagePref = selectedLanguagePref + LOCALE_DELIMITER +
|
||||||
|
mDefaultCountry;
|
||||||
|
}
|
||||||
|
if (mDefaultLocVariant.length() > 0) {
|
||||||
|
selectedLanguagePref = selectedLanguagePref + LOCALE_DELIMITER +
|
||||||
|
mDefaultLocVariant;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < availableLangs.size(); i++) {
|
||||||
|
String[] langCountryVariant = availableLangs.get(i).split("-");
|
||||||
|
Locale loc = null;
|
||||||
|
if (langCountryVariant.length == 1){
|
||||||
|
loc = new Locale(langCountryVariant[0]);
|
||||||
|
} else if (langCountryVariant.length == 2){
|
||||||
|
loc = new Locale(langCountryVariant[0], langCountryVariant[1]);
|
||||||
|
} else if (langCountryVariant.length == 3){
|
||||||
|
loc = new Locale(langCountryVariant[0], langCountryVariant[1],
|
||||||
|
langCountryVariant[2]);
|
||||||
|
}
|
||||||
|
if (loc != null){
|
||||||
|
entries[i] = loc.getDisplayName();
|
||||||
|
entryValues[i] = availableLangs.get(i);
|
||||||
|
if (entryValues[i].equals(selectedLanguagePref)) {
|
||||||
|
selectedLanguageIndex = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mDefaultLocPref.setEntries(entries);
|
||||||
|
mDefaultLocPref.setEntryValues(entryValues);
|
||||||
|
if (selectedLanguageIndex > -1) {
|
||||||
|
mDefaultLocPref.setValueIndex(selectedLanguageIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void onSampleTextReceived(int resultCode, Intent data) {
|
||||||
|
if (resultCode == TextToSpeech.LANG_AVAILABLE) {
|
||||||
|
String sample = getActivity().getString(R.string.tts_demo);
|
||||||
|
if (data != null && data.getStringExtra("sampleText") != null) {
|
||||||
|
sample = data.getStringExtra("sampleText");
|
||||||
|
}
|
||||||
|
Log.v(TAG, "Got sample text: " + sample);
|
||||||
|
if (mTts != null) {
|
||||||
|
mTts.speak(sample, TextToSpeech.QUEUE_FLUSH, null);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO: Display an error here to the user.
|
||||||
|
Log.e(TAG, "Did not have a sample string for the requested language");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
public boolean onPreferenceChange(Preference preference, Object objValue) {
|
||||||
if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) {
|
if (KEY_TTS_USE_DEFAULT.equals(preference.getKey())) {
|
||||||
// "Use Defaults"
|
// "Use Defaults"
|
||||||
int value = (Boolean)objValue ? 1 : 0;
|
int value = ((Boolean) objValue) ? 1 : 0;
|
||||||
Settings.Secure.putInt(getContentResolver(), TTS_USE_DEFAULTS,
|
Settings.Secure.putInt(getContentResolver(), TTS_USE_DEFAULTS, value);
|
||||||
value);
|
Log.i(TAG, "TTS 'use default' settings changed, now " + value);
|
||||||
Log.i(TAG, "TTS use default settings is "+objValue.toString());
|
|
||||||
} else if (KEY_TTS_DEFAULT_RATE.equals(preference.getKey())) {
|
} else if (KEY_TTS_DEFAULT_RATE.equals(preference.getKey())) {
|
||||||
// Default rate
|
// Default rate
|
||||||
mDefaultRate = Integer.parseInt((String) objValue);
|
mDefaultRate = Integer.parseInt((String) objValue);
|
||||||
try {
|
try {
|
||||||
Settings.Secure.putInt(getContentResolver(),
|
Settings.Secure.putInt(getContentResolver(), TTS_DEFAULT_RATE, mDefaultRate);
|
||||||
TTS_DEFAULT_RATE, mDefaultRate);
|
|
||||||
if (mTts != null) {
|
if (mTts != null) {
|
||||||
mTts.setSpeechRate(mDefaultRate/100.0f);
|
mTts.setSpeechRate(mDefaultRate / 100.0f);
|
||||||
}
|
}
|
||||||
Log.i(TAG, "TTS default rate is " + mDefaultRate);
|
Log.v(TAG, "TTS default rate changed, now " + mDefaultRate);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {
|
||||||
Log.e(TAG, "could not persist default TTS rate setting", e);
|
Log.e(TAG, "could not persist default TTS rate setting", e);
|
||||||
}
|
}
|
||||||
@@ -522,19 +498,19 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
mTts.setLanguage(new Locale(mDefaultLanguage, mDefaultCountry, mDefaultLocVariant));
|
||||||
}
|
}
|
||||||
int newIndex = mDefaultLocPref.findIndexOfValue((String)objValue);
|
int newIndex = mDefaultLocPref.findIndexOfValue((String)objValue);
|
||||||
Log.v("Settings", " selected is " + newIndex);
|
Log.v(TAG, " selected is " + newIndex);
|
||||||
mDemoStringIndex = newIndex > -1 ? newIndex : 0;
|
mDemoStringIndex = newIndex > -1 ? newIndex : 0;
|
||||||
} else if (KEY_TTS_DEFAULT_SYNTH.equals(preference.getKey())) {
|
} else if (KEY_TTS_DEFAULT_SYNTH.equals(preference.getKey())) {
|
||||||
mDefaultEng = objValue.toString();
|
String defaultEng = objValue.toString();
|
||||||
Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, mDefaultEng);
|
Settings.Secure.putString(getContentResolver(), TTS_DEFAULT_SYNTH, defaultEng);
|
||||||
if (mTts != null) {
|
if (mTts != null) {
|
||||||
mTts.setEngineByPackageName(mDefaultEng);
|
mTts.setEngineByPackageName(defaultEng);
|
||||||
mEnableDemo = false;
|
mEnableDemo = false;
|
||||||
mVoicesMissing = false;
|
mVoicesMissing = false;
|
||||||
updateWidgetState();
|
updateWidgetState();
|
||||||
checkVoiceData();
|
checkVoiceData();
|
||||||
}
|
}
|
||||||
Log.v("Settings", "The default synth is: " + objValue.toString());
|
Log.v(TAG, "The default synth is: " + objValue.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -550,58 +526,44 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
// the actual speaking
|
// the actual speaking
|
||||||
getSampleText();
|
getSampleText();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (preference == mInstallData) {
|
||||||
if (preference == mInstallData) {
|
|
||||||
installVoiceData();
|
installVoiceData();
|
||||||
// quit this activity so it needs to be restarted after installation of the voice data
|
// quit this activity so it needs to be restarted after installation of the voice data
|
||||||
finish();
|
finish();
|
||||||
return true;
|
return true;
|
||||||
}
|
} else if (preference.getKey().startsWith(KEY_PLUGIN_ENABLED_PREFIX)) {
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
|
||||||
if (Utils.isMonkeyRunning()) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (preference instanceof CheckBoxPreference) {
|
|
||||||
final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
|
final CheckBoxPreference chkPref = (CheckBoxPreference) preference;
|
||||||
if (!chkPref.getKey().equals(KEY_TTS_USE_DEFAULT)){
|
if (chkPref.isChecked()) {
|
||||||
if (chkPref.isChecked()) {
|
chkPref.setChecked(false);
|
||||||
chkPref.setChecked(false);
|
AlertDialog d = (new AlertDialog.Builder(getActivity()))
|
||||||
AlertDialog d = (new AlertDialog.Builder(getActivity()))
|
.setTitle(android.R.string.dialog_alert_title)
|
||||||
.setTitle(android.R.string.dialog_alert_title)
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
.setMessage(
|
||||||
.setMessage(
|
getActivity().getString(R.string.tts_engine_security_warning,
|
||||||
getActivity().getString(R.string.tts_engine_security_warning,
|
chkPref.getTitle()))
|
||||||
chkPref.getTitle()))
|
.setCancelable(true)
|
||||||
.setCancelable(true)
|
.setPositiveButton(android.R.string.ok,
|
||||||
.setPositiveButton(android.R.string.ok,
|
new DialogInterface.OnClickListener() {
|
||||||
new DialogInterface.OnClickListener() {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
chkPref.setChecked(true);
|
||||||
chkPref.setChecked(true);
|
loadEngines();
|
||||||
loadEngines();
|
}
|
||||||
}
|
})
|
||||||
})
|
.setNegativeButton(android.R.string.cancel,
|
||||||
.setNegativeButton(android.R.string.cancel,
|
new DialogInterface.OnClickListener() {
|
||||||
new DialogInterface.OnClickListener() {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
}
|
||||||
}
|
})
|
||||||
})
|
.create();
|
||||||
.create();
|
d.show();
|
||||||
d.show();
|
} else {
|
||||||
} else {
|
loadEngines();
|
||||||
loadEngines();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void updateWidgetState() {
|
private void updateWidgetState() {
|
||||||
mPlayExample.setEnabled(mEnableDemo);
|
mPlayExample.setEnabled(mEnableDemo);
|
||||||
mUseDefaultPref.setEnabled(mEnableDemo);
|
mUseDefaultPref.setEnabled(mEnableDemo);
|
||||||
@@ -716,36 +678,23 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, DEFAULT_VARIANT_VAL);
|
Settings.Secure.putString(resolver, TTS_DEFAULT_VARIANT, DEFAULT_VARIANT_VAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void loadEngines() {
|
private void loadEngines() {
|
||||||
mDefaultSynthPref = (ListPreference) findPreference(KEY_TTS_DEFAULT_SYNTH);
|
List<TextToSpeech.EngineInfo> engines = mTts.getEngines();
|
||||||
|
|
||||||
// TODO (clchen): Try to see if it is possible to be more efficient here
|
|
||||||
// and not search for plugins again.
|
|
||||||
Intent intent = new Intent("android.intent.action.START_TTS_ENGINE");
|
|
||||||
ResolveInfo[] enginesArray = new ResolveInfo[0];
|
|
||||||
PackageManager pm = getPackageManager();
|
|
||||||
enginesArray = pm.queryIntentActivities(intent, 0).toArray(enginesArray);
|
|
||||||
ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
|
ArrayList<CharSequence> entries = new ArrayList<CharSequence>();
|
||||||
ArrayList<CharSequence> values = new ArrayList<CharSequence>();
|
ArrayList<CharSequence> values = new ArrayList<CharSequence>();
|
||||||
String enabledEngines = "";
|
StringBuilder enabledEngines = new StringBuilder();
|
||||||
for (int i = 0; i < enginesArray.length; i++) {
|
|
||||||
String pluginPackageName = enginesArray[i].activityInfo.packageName;
|
for (TextToSpeech.EngineInfo engine : engines) {
|
||||||
if (pluginPackageName.equals(SYSTEM_TTS)) {
|
Log.v(TAG, "Engine: " + engine);
|
||||||
entries.add(enginesArray[i].loadLabel(pm));
|
if (isEngineEnabled(engine.name)) {
|
||||||
values.add(pluginPackageName);
|
entries.add(engine.label);
|
||||||
} else {
|
values.add(engine.name);
|
||||||
CheckBoxPreference pref = (CheckBoxPreference) findPreference(
|
if (enabledEngines.length() > 0) enabledEngines.append(' ');
|
||||||
KEY_PLUGIN_ENABLED_PREFIX + pluginPackageName);
|
enabledEngines.append(engine.name);
|
||||||
if ((pref != null) && pref.isChecked()){
|
|
||||||
entries.add(enginesArray[i].loadLabel(pm));
|
|
||||||
values.add(pluginPackageName);
|
|
||||||
enabledEngines = enabledEngines + pluginPackageName + " ";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ContentResolver resolver = getContentResolver();
|
ContentResolver resolver = getContentResolver();
|
||||||
Settings.Secure.putString(resolver, TTS_ENABLED_PLUGINS, enabledEngines);
|
Settings.Secure.putString(resolver, TTS_ENABLED_PLUGINS, enabledEngines.toString());
|
||||||
|
|
||||||
CharSequence entriesArray[] = new CharSequence[entries.size()];
|
CharSequence entriesArray[] = new CharSequence[entries.size()];
|
||||||
CharSequence valuesArray[] = new CharSequence[values.size()];
|
CharSequence valuesArray[] = new CharSequence[values.size()];
|
||||||
@@ -757,9 +706,18 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
|
|||||||
String selectedEngine = Settings.Secure.getString(getContentResolver(), TTS_DEFAULT_SYNTH);
|
String selectedEngine = Settings.Secure.getString(getContentResolver(), TTS_DEFAULT_SYNTH);
|
||||||
int selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(selectedEngine);
|
int selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(selectedEngine);
|
||||||
if (selectedEngineIndex == -1){
|
if (selectedEngineIndex == -1){
|
||||||
selectedEngineIndex = mDefaultSynthPref.findIndexOfValue(SYSTEM_TTS);
|
selectedEngineIndex =
|
||||||
|
mDefaultSynthPref.findIndexOfValue(TextToSpeech.Engine.DEFAULT_ENGINE);
|
||||||
}
|
}
|
||||||
mDefaultSynthPref.setValueIndex(selectedEngineIndex);
|
if (selectedEngineIndex >= 0) {
|
||||||
|
mDefaultSynthPref.setValueIndex(selectedEngineIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isEngineEnabled(String engineName) {
|
||||||
|
if (engineName.equals(TextToSpeech.Engine.DEFAULT_ENGINE)) return true;
|
||||||
|
String enginePref = KEY_PLUGIN_ENABLED_PREFIX + engineName;
|
||||||
|
return getPreferenceManager().getSharedPreferences().getBoolean(enginePref, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user