am 104ab231
: Merge "Fixes list of TTS voices after changing voice data" into jb-mr1-dev
* commit '104ab231e5b8541b84460f32d30578755e60a765': Fixes list of TTS voices after changing voice data
This commit is contained in:
committed by
Android Git Automerger
commit
31eab6973c
@@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
package com.android.settings.tts;
|
package com.android.settings.tts;
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.SettingsPreferenceFragment;
|
|
||||||
|
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
|
import android.content.BroadcastReceiver;
|
||||||
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.ListPreference;
|
import android.preference.ListPreference;
|
||||||
import android.preference.Preference;
|
import android.preference.Preference;
|
||||||
@@ -32,6 +32,9 @@ import android.speech.tts.TtsEngines;
|
|||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.android.settings.R;
|
||||||
|
import com.android.settings.SettingsPreferenceFragment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
@@ -45,11 +48,14 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
|
|||||||
private static final String KEY_ENGINE_SETTINGS = "tts_engine_settings";
|
private static final String KEY_ENGINE_SETTINGS = "tts_engine_settings";
|
||||||
private static final String KEY_INSTALL_DATA = "tts_install_data";
|
private static final String KEY_INSTALL_DATA = "tts_install_data";
|
||||||
|
|
||||||
|
private static final int VOICE_DATA_INTEGRITY_CHECK = 1977;
|
||||||
|
|
||||||
private TtsEngines mEnginesHelper;
|
private TtsEngines mEnginesHelper;
|
||||||
private ListPreference mLocalePreference;
|
private ListPreference mLocalePreference;
|
||||||
private Preference mEngineSettingsPreference;
|
private Preference mEngineSettingsPreference;
|
||||||
private Preference mInstallVoicesPreference;
|
private Preference mInstallVoicesPreference;
|
||||||
private Intent mEngineSettingsIntent;
|
private Intent mEngineSettingsIntent;
|
||||||
|
private Intent mVoiceDataDetails;
|
||||||
|
|
||||||
private TextToSpeech mTts;
|
private TextToSpeech mTts;
|
||||||
|
|
||||||
@@ -69,6 +75,16 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private final BroadcastReceiver mLanguagesChangedReceiver = new BroadcastReceiver() {
|
||||||
|
@Override
|
||||||
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
// Installed or uninstalled some data packs
|
||||||
|
if (TextToSpeech.Engine.ACTION_TTS_DATA_INSTALLED.equals(intent.getAction())) {
|
||||||
|
checkTtsData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public TtsEngineSettingsFragment() {
|
public TtsEngineSettingsFragment() {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@@ -103,26 +119,52 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem
|
|||||||
|
|
||||||
mLocalePreference.setEnabled(false);
|
mLocalePreference.setEnabled(false);
|
||||||
|
|
||||||
|
mVoiceDataDetails = getArguments().getParcelable(TtsEnginePreference.FRAGMENT_ARGS_VOICES);
|
||||||
|
|
||||||
updateVoiceDetails();
|
updateVoiceDetails();
|
||||||
|
|
||||||
mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener,
|
mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener,
|
||||||
getEngineName());
|
getEngineName());
|
||||||
|
|
||||||
|
// Check if data packs changed
|
||||||
|
checkTtsData();
|
||||||
|
|
||||||
|
getActivity().registerReceiver(mLanguagesChangedReceiver,
|
||||||
|
new IntentFilter(TextToSpeech.Engine.ACTION_TTS_DATA_INSTALLED));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
getActivity().unregisterReceiver(mLanguagesChangedReceiver);
|
||||||
mTts.shutdown();
|
mTts.shutdown();
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateVoiceDetails() {
|
private final void checkTtsData() {
|
||||||
final Intent voiceDataDetails = getArguments().getParcelable(
|
Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
|
||||||
TtsEnginePreference.FRAGMENT_ARGS_VOICES);
|
intent.setPackage(getEngineName());
|
||||||
if (DBG) Log.d(TAG, "Parsing voice data details, data: " + voiceDataDetails.toUri(0));
|
try {
|
||||||
|
if (DBG) Log.d(TAG, "Updating engine: Checking voice data: " + intent.toUri(0));
|
||||||
|
startActivityForResult(intent, VOICE_DATA_INTEGRITY_CHECK);
|
||||||
|
} catch (ActivityNotFoundException ex) {
|
||||||
|
Log.e(TAG, "Failed to check TTS data, no activity found for " + intent + ")");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
final ArrayList<String> available = voiceDataDetails.getStringArrayListExtra(
|
@Override
|
||||||
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
|
if (requestCode == VOICE_DATA_INTEGRITY_CHECK) {
|
||||||
|
mVoiceDataDetails = data;
|
||||||
|
updateVoiceDetails();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateVoiceDetails() {
|
||||||
|
if (DBG) Log.d(TAG, "Parsing voice data details, data: " + mVoiceDataDetails.toUri(0));
|
||||||
|
|
||||||
|
final ArrayList<String> available = mVoiceDataDetails.getStringArrayListExtra(
|
||||||
TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
|
TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);
|
||||||
final ArrayList<String> unavailable = voiceDataDetails.getStringArrayListExtra(
|
final ArrayList<String> unavailable = mVoiceDataDetails.getStringArrayListExtra(
|
||||||
TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
|
TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES);
|
||||||
|
|
||||||
if (available == null){
|
if (available == null){
|
||||||
|
Reference in New Issue
Block a user