diff options
author | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2012-08-03 13:53:19 +0100 |
---|---|---|
committer | Przemyslaw Szczepaniak <pszczepaniak@google.com> | 2012-08-03 17:07:33 +0100 |
commit | e1d2b7fb78c3b7c411b80da55c2444f39dfaa25c (patch) | |
tree | b70017d7887290659e330e2d89830a121f90d268 /src/com/android/settings/tts | |
parent | 6a20ce5e515141b0934bd4093dbad53c14a19a6e (diff) | |
download | packages_apps_settings-e1d2b7fb78c3b7c411b80da55c2444f39dfaa25c.zip packages_apps_settings-e1d2b7fb78c3b7c411b80da55c2444f39dfaa25c.tar.gz packages_apps_settings-e1d2b7fb78c3b7c411b80da55c2444f39dfaa25c.tar.bz2 |
Fixes list of TTS voices after changing voice data
Added one BroadcastListener that listens for TextToSpeech.Engine.ACTION_TTS_DATA_INSTALLED intents.
If it gets one, it will call TextToSpeech.Engine.ACTION_CHECK_TTS_DATA to update list of TTS voices.
It expects TTS engine to broadcast TTS_DATA_INSTALLED also when removing voice data.
In order to catch changes done when user sits in Text-to-speech output main activity,
TextToSpeech.Engine.ACTION_CHECK_TTS_DATA is called on start of tts engine config fragment.
Change-Id: Ic1e299ea3ffc45d938083f1ab5b2bf101fe25f26
Diffstat (limited to 'src/com/android/settings/tts')
-rw-r--r-- | src/com/android/settings/tts/TtsEngineSettingsFragment.java | 58 |
1 files changed, 50 insertions, 8 deletions
diff --git a/src/com/android/settings/tts/TtsEngineSettingsFragment.java b/src/com/android/settings/tts/TtsEngineSettingsFragment.java index b39d5e9..267b8e1 100644 --- a/src/com/android/settings/tts/TtsEngineSettingsFragment.java +++ b/src/com/android/settings/tts/TtsEngineSettingsFragment.java @@ -16,11 +16,11 @@ package com.android.settings.tts; -import com.android.settings.R; -import com.android.settings.SettingsPreferenceFragment; - import android.content.ActivityNotFoundException; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.os.Bundle; import android.preference.ListPreference; import android.preference.Preference; @@ -32,6 +32,9 @@ import android.speech.tts.TtsEngines; import android.text.TextUtils; import android.util.Log; +import com.android.settings.R; +import com.android.settings.SettingsPreferenceFragment; + import java.util.ArrayList; 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_INSTALL_DATA = "tts_install_data"; + private static final int VOICE_DATA_INTEGRITY_CHECK = 1977; + private TtsEngines mEnginesHelper; private ListPreference mLocalePreference; private Preference mEngineSettingsPreference; private Preference mInstallVoicesPreference; private Intent mEngineSettingsIntent; + private Intent mVoiceDataDetails; 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() { super(); } @@ -103,26 +119,52 @@ public class TtsEngineSettingsFragment extends SettingsPreferenceFragment implem mLocalePreference.setEnabled(false); + mVoiceDataDetails = getArguments().getParcelable(TtsEnginePreference.FRAGMENT_ARGS_VOICES); + updateVoiceDetails(); mTts = new TextToSpeech(getActivity().getApplicationContext(), mTtsInitListener, getEngineName()); + + // Check if data packs changed + checkTtsData(); + + getActivity().registerReceiver(mLanguagesChangedReceiver, + new IntentFilter(TextToSpeech.Engine.ACTION_TTS_DATA_INSTALLED)); } @Override public void onDestroy() { + getActivity().unregisterReceiver(mLanguagesChangedReceiver); mTts.shutdown(); super.onDestroy(); } + private final void checkTtsData() { + Intent intent = new Intent(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); + intent.setPackage(getEngineName()); + 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 + ")"); + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data) { + if (requestCode == VOICE_DATA_INTEGRITY_CHECK) { + mVoiceDataDetails = data; + updateVoiceDetails(); + } + } + private void updateVoiceDetails() { - final Intent voiceDataDetails = getArguments().getParcelable( - TtsEnginePreference.FRAGMENT_ARGS_VOICES); - if (DBG) Log.d(TAG, "Parsing voice data details, data: " + voiceDataDetails.toUri(0)); + if (DBG) Log.d(TAG, "Parsing voice data details, data: " + mVoiceDataDetails.toUri(0)); - final ArrayList<String> available = voiceDataDetails.getStringArrayListExtra( + final ArrayList<String> available = mVoiceDataDetails.getStringArrayListExtra( TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES); - final ArrayList<String> unavailable = voiceDataDetails.getStringArrayListExtra( + final ArrayList<String> unavailable = mVoiceDataDetails.getStringArrayListExtra( TextToSpeech.Engine.EXTRA_UNAVAILABLE_VOICES); if (available == null){ |