Browse Source

onDataChecked may be called *after* onInitialized is called, in which case mVoices will be null; set the voice count in onDataChecked to avoid problems

master
Reece H. Dunn 12 years ago
parent
commit
e27a218592
1 changed files with 17 additions and 4 deletions
  1. 17
    4
      android/src/com/googlecode/eyesfree/espeak/eSpeakActivity.java

+ 17
- 4
android/src/com/googlecode/eyesfree/espeak/eSpeakActivity.java View File

import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.speech.tts.TextToSpeech; import android.speech.tts.TextToSpeech;
import android.util.Log;
import android.view.View; import android.view.View;
import android.widget.TextView; import android.widget.TextView;


private static final int DIALOG_DOWNLOAD_FAILED = 2; private static final int DIALOG_DOWNLOAD_FAILED = 2;
private static final int DIALOG_ERROR = 3; private static final int DIALOG_ERROR = 3;


private static final String TAG = "eSpeakActivity";

private enum State { private enum State {
LOADING, LOADING,
FAILURE, FAILURE,
private void onDataChecked(int resultCode, Intent data) { private void onDataChecked(int resultCode, Intent data) {
if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { if (resultCode != TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
if (mDownloadedVoiceData) { if (mDownloadedVoiceData) {
Log.e(TAG, "Voice data check failed (error code: " + resultCode + ").");
setState(State.FAILURE); setState(State.FAILURE);
showDialog(DIALOG_ERROR); showDialog(DIALOG_ERROR);
} else { } else {


mVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES); mVoices = data.getStringArrayListExtra(TextToSpeech.Engine.EXTRA_AVAILABLE_VOICES);


if (mVoices == null) {
Log.e(TAG, "Data check failed -- voices is null.");
setState(State.FAILURE);
showDialog(DIALOG_ERROR);
return;
}

initializeEngine(); initializeEngine();

final TextView availableVoices = (TextView) findViewById(R.id.availableVoices);
availableVoices.setText(Integer.toString(mVoices.size()));
} }


/** /**
*/ */
private void onDataDownloaded(int resultCode) { private void onDataDownloaded(int resultCode) {
if (resultCode != RESULT_OK) { if (resultCode != RESULT_OK) {
Log.e(TAG, "Voice data download failed.");
setState(State.FAILURE); setState(State.FAILURE);
showDialog(DIALOG_DOWNLOAD_FAILED); showDialog(DIALOG_DOWNLOAD_FAILED);
return; return;
return; return;
} }


if (status == TextToSpeech.ERROR || mVoices == null) {
if (status == TextToSpeech.ERROR) {
Log.e(TAG, "Initialization failed (status: " + status + ").");
setState(State.FAILURE); setState(State.FAILURE);
showDialog(DIALOG_ERROR); showDialog(DIALOG_ERROR);
return; return;
final TextView currentLocale = (TextView) findViewById(R.id.currentLocale); final TextView currentLocale = (TextView) findViewById(R.id.currentLocale);
currentLocale.setText(mTts.getLanguage().getDisplayName()); currentLocale.setText(mTts.getLanguage().getDisplayName());


final TextView availableVoices = (TextView) findViewById(R.id.availableVoices);
availableVoices.setText(Integer.toString(mVoices.size()));

findViewById(R.id.updateVoices).setOnClickListener(mOnClickListener); findViewById(R.id.updateVoices).setOnClickListener(mOnClickListener);
findViewById(R.id.ttsSettings).setOnClickListener(mOnClickListener); findViewById(R.id.ttsSettings).setOnClickListener(mOnClickListener);
findViewById(R.id.engineSettings).setOnClickListener(mOnClickListener); findViewById(R.id.engineSettings).setOnClickListener(mOnClickListener);

Loading…
Cancel
Save