Browse Source

eSpeakActivity: use the BROADCAST_LANGUAGES_UPDATED event to handle voice installation

master
Reece H. Dunn 12 years ago
parent
commit
8bdb644285
1 changed files with 15 additions and 24 deletions
  1. 15
    24
      android/src/com/reecedunn/espeak/eSpeakActivity.java

+ 15
- 24
android/src/com/reecedunn/espeak/eSpeakActivity.java View File

package com.reecedunn.espeak; package com.reecedunn.espeak;


import android.app.Activity; import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
private static final int TTS_INITIALIZED = 1; private static final int TTS_INITIALIZED = 1;


private static final int REQUEST_CHECK = 1; private static final int REQUEST_CHECK = 1;
private static final int REQUEST_DOWNLOAD = 2;
private static final int REQUEST_DEFAULT = 3; private static final int REQUEST_DEFAULT = 3;


private static final String TAG = "eSpeakActivity"; private static final String TAG = "eSpeakActivity";
* Launches the voice data installer. * Launches the voice data installer.
*/ */
private void downloadVoiceData() { private void downloadVoiceData() {
final Intent checkIntent = new Intent(this, DownloadVoiceData.class);
final IntentFilter filter = new IntentFilter(DownloadVoiceData.BROADCAST_LANGUAGES_UPDATED);
registerReceiver(mDownloadReceiver, filter);


startActivityForResult(checkIntent, REQUEST_DOWNLOAD);
final Intent checkIntent = new Intent(this, DownloadVoiceData.class);
startActivity(checkIntent);
} }


/** /**
populateInformationView(); populateInformationView();
} }


/**
* Handles the result of voice data installation. Either shows a failure
* dialog or launches the voice data verifier.
*
* @param resultCode
*/
private void onDataDownloaded(int resultCode) {
if (resultCode != RESULT_OK) {
Log.e(TAG, "Voice data download failed.");
setState(State.DOWNLOAD_FAILED);
return;
}

mDownloadedVoiceData = true;

checkVoiceData();
}

/** /**
* Handles the result of TTS engine initialization. Either displays an error * Handles the result of TTS engine initialization. Either displays an error
* dialog or populates the activity's UI. * dialog or populates the activity's UI.
case REQUEST_CHECK: case REQUEST_CHECK:
onDataChecked(resultCode, data); onDataChecked(resultCode, data);
break; break;
case REQUEST_DOWNLOAD:
onDataDownloaded(resultCode);
break;
case REQUEST_DEFAULT: case REQUEST_DEFAULT:
initializeEngine(); initializeEngine();
break; break;
} }
startActivityForResult(intent, REQUEST_DEFAULT); startActivityForResult(intent, REQUEST_DEFAULT);
} }

private final BroadcastReceiver mDownloadReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mDownloadedVoiceData = true;
checkVoiceData();
}
};
} }

Loading…
Cancel
Save