summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--res/values/strings.xml3
-rw-r--r--src/com/android/settings/nfc/AndroidBeam.java16
-rw-r--r--src/com/android/settings/tts/TextToSpeechSettings.java55
3 files changed, 60 insertions, 14 deletions
diff --git a/res/values/strings.xml b/res/values/strings.xml
index a9b1b35..af7371b 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -3438,6 +3438,9 @@
all the text that will be spoken, including personal data like passwords and credit
card numbers. It comes from the <xliff:g id="tts_plugin_engine_name">%s</xliff:g> engine.
Enable the use of this speech synthesis engine?</string>
+ <!-- Warning message about required internet conectivity for TTS synthesis, displayed as a dialog
+ message when the user selects to play an example for network only locale and there's no internet connectivity. -->
+ <string name="tts_engine_network_required">This language requires a working network connection for text-to-speech output.</string>
<!-- On main TTS Settings screen, text for divider under which all TTS engines are listed -->
<string name="tts_engines_section">Engines</string>
<!-- On main TTS Settings screen, text preceded by the TTS engine name, clicking this button will launch the engine settings -->
diff --git a/src/com/android/settings/nfc/AndroidBeam.java b/src/com/android/settings/nfc/AndroidBeam.java
index 032681a..bf02c13 100644
--- a/src/com/android/settings/nfc/AndroidBeam.java
+++ b/src/com/android/settings/nfc/AndroidBeam.java
@@ -38,7 +38,6 @@ public class AndroidBeam extends Fragment
private ImageView mImageView;
private NfcAdapter mNfcAdapter;
private Switch mActionBarSwitch;
- private CharSequence mOldActivityTitle;
@Override
@@ -50,6 +49,7 @@ public class AndroidBeam extends Fragment
if (activity instanceof PreferenceActivity) {
PreferenceActivity preferenceActivity = (PreferenceActivity) activity;
+ if (preferenceActivity.onIsHidingHeaders() || !preferenceActivity.onIsMultiPane()) {
final int padding = activity.getResources().getDimensionPixelSize(
R.dimen.action_bar_switch_padding);
mActionBarSwitch.setPadding(0, 0, padding, 0);
@@ -59,10 +59,8 @@ public class AndroidBeam extends Fragment
ActionBar.LayoutParams.WRAP_CONTENT,
ActionBar.LayoutParams.WRAP_CONTENT,
Gravity.CENTER_VERTICAL | Gravity.END));
- if (!preferenceActivity.onIsMultiPane() || preferenceActivity.onIsHidingHeaders()) {
- mOldActivityTitle = getActivity().getTitle();
- activity.getActionBar().setTitle(R.string.android_beam_settings_title);
- }
+ activity.getActionBar().setTitle(R.string.android_beam_settings_title);
+ }
}
mActionBarSwitch.setOnCheckedChangeListener(this);
@@ -78,14 +76,6 @@ public class AndroidBeam extends Fragment
initView(mView);
return mView;
}
- @Override
- public void onDestroyView() {
- getActivity().getActionBar().setCustomView(null);
- if (mOldActivityTitle != null) {
- getActivity().getActionBar().setTitle(mOldActivityTitle);
- }
- super.onDestroyView();
- }
private void initView(View view) {
mActionBarSwitch.setOnCheckedChangeListener(this);
diff --git a/src/com/android/settings/tts/TextToSpeechSettings.java b/src/com/android/settings/tts/TextToSpeechSettings.java
index 6718ab0..847c708 100644
--- a/src/com/android/settings/tts/TextToSpeechSettings.java
+++ b/src/com/android/settings/tts/TextToSpeechSettings.java
@@ -36,14 +36,17 @@ import android.preference.PreferenceCategory;
import android.provider.Settings;
import android.provider.Settings.SettingNotFoundException;
import android.speech.tts.TextToSpeech;
+import android.speech.tts.UtteranceProgressListener;
import android.speech.tts.TextToSpeech.EngineInfo;
import android.speech.tts.TtsEngines;
import android.text.TextUtils;
import android.util.Log;
import android.widget.Checkable;
+import java.util.HashMap;
import java.util.List;
import java.util.Locale;
+import java.util.Set;
public class TextToSpeechSettings extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener,
@@ -137,9 +140,28 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener);
mEnginesHelper = new TtsEngines(getActivity().getApplicationContext());
+ setTtsUtteranceProgressListener();
initSettings();
}
+ private void setTtsUtteranceProgressListener() {
+ if (mTts == null) {
+ return;
+ }
+ mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() {
+ @Override
+ public void onStart(String utteranceId) {}
+
+ @Override
+ public void onDone(String utteranceId) {}
+
+ @Override
+ public void onError(String utteranceId) {
+ Log.e(TAG, "Error while trying to synthesize sample text");
+ }
+ });
+ }
+
@Override
public void onDestroy() {
super.onDestroy();
@@ -258,6 +280,12 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
return null;
}
+ private boolean isNetworkRequiredForSynthesis() {
+ Set<String> features = mTts.getFeatures(mTts.getLanguage());
+ return features.contains(TextToSpeech.Engine.KEY_FEATURE_NETWORK_SYNTHESIS) &&
+ !features.contains(TextToSpeech.Engine.KEY_FEATURE_EMBEDDED_SYNTHESIS);
+ }
+
private void onSampleTextReceived(int resultCode, Intent data) {
String sample = getDefaultSampleString();
@@ -273,7 +301,18 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
if (sample != null && mTts != null) {
// The engine is guaranteed to have been initialized here
// because this preference is not enabled otherwise.
- mTts.speak(sample, TextToSpeech.QUEUE_FLUSH, null);
+
+ final boolean networkRequired = isNetworkRequiredForSynthesis();
+ if (!networkRequired || networkRequired &&
+ (mTts.isLanguageAvailable(mTts.getLanguage()) >= TextToSpeech.LANG_AVAILABLE)) {
+ HashMap<String, String> params = new HashMap<String, String>();
+ params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "Sample");
+
+ mTts.speak(sample, TextToSpeech.QUEUE_FLUSH, params);
+ } else {
+ Log.w(TAG, "Network required for sample synthesis for requested language");
+ displayNetworkAlert();
+ }
} else {
// TODO: Display an error here to the user.
Log.e(TAG, "Did not have a sample string for the requested language");
@@ -340,6 +379,18 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
dialog.show();
}
+ private void displayNetworkAlert() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
+ builder.setTitle(android.R.string.dialog_alert_title);
+ builder.setIconAttribute(android.R.attr.alertDialogIcon);
+ builder.setMessage(getActivity().getString(R.string.tts_engine_network_required));
+ builder.setCancelable(false);
+ builder.setPositiveButton(android.R.string.ok, null);
+
+ AlertDialog dialog = builder.create();
+ dialog.show();
+ }
+
private void updateDefaultEngine(String engine) {
if (DBG) Log.d(TAG, "Updating default synth to : " + engine);
@@ -369,6 +420,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
// the app binds successfully to the engine.
if (DBG) Log.d(TAG, "Updating engine : Attempting to connect to engine: " + engine);
mTts = new TextToSpeech(getActivity().getApplicationContext(), mUpdateListener, engine);
+ setTtsUtteranceProgressListener();
}
/*
@@ -390,6 +442,7 @@ public class TextToSpeechSettings extends SettingsPreferenceFragment implements
// null if the previous bind to this engine failed.
mTts = new TextToSpeech(getActivity().getApplicationContext(), mInitListener,
mPreviousEngine);
+ setTtsUtteranceProgressListener();
}
mPreviousEngine = null;
}