mirror of
https://github.com/rhasspy/espeak-ng.git
synced 2026-11-01 05:46:19 +00:00
Update the progress bar with the install progress.
This commit is contained in:
@@ -23,13 +23,13 @@ import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.LinkedList;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
@@ -37,16 +37,18 @@ public class DownloadVoiceData extends Activity {
|
||||
public static final String BROADCAST_LANGUAGES_UPDATED = "com.reecedunn.espeak.LANGUAGES_UPDATED";
|
||||
|
||||
private AsyncExtract mAsyncExtract;
|
||||
private ProgressBar mProgress;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.download_voice_data);
|
||||
mProgress = (ProgressBar)findViewById(R.id.progress);
|
||||
|
||||
final File dataPath = CheckVoiceData.getDataPath(this).getParentFile();
|
||||
|
||||
mAsyncExtract = new AsyncExtract(this, R.raw.espeakdata, dataPath) {
|
||||
mAsyncExtract = new AsyncExtract(this, R.raw.espeakdata, dataPath, mProgress) {
|
||||
@Override
|
||||
protected void onPostExecute(Integer result) {
|
||||
switch (result) {
|
||||
@@ -80,15 +82,14 @@ public class DownloadVoiceData extends Activity {
|
||||
|
||||
private static final int PROGRESS_STARTING = 0;
|
||||
private static final int PROGRESS_EXTRACTING = 1;
|
||||
private static final int PROGRESS_FINISHED = 2;
|
||||
|
||||
private static class ExtractProgress {
|
||||
long total;
|
||||
long progress = 0;
|
||||
int total;
|
||||
int progress = 0;
|
||||
int state = PROGRESS_STARTING;
|
||||
File file;
|
||||
|
||||
public ExtractProgress(long total) {
|
||||
public ExtractProgress(int total) {
|
||||
this.total = total;
|
||||
}
|
||||
}
|
||||
@@ -97,11 +98,13 @@ public class DownloadVoiceData extends Activity {
|
||||
private final Context mContext;
|
||||
private final int mRawResId;
|
||||
private final File mOutput;
|
||||
private final ProgressBar mProgress;
|
||||
|
||||
public AsyncExtract(Context context, int rawResId, File output) {
|
||||
public AsyncExtract(Context context, int rawResId, File output, ProgressBar progress) {
|
||||
mContext = context;
|
||||
mRawResId = rawResId;
|
||||
mOutput = output;
|
||||
mProgress = progress;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -153,9 +156,6 @@ public class DownloadVoiceData extends Activity {
|
||||
final File outputFile = new File(mOutput, "espeak-data/version");
|
||||
|
||||
FileUtils.write(outputFile, version);
|
||||
|
||||
progress.state = PROGRESS_FINISHED;
|
||||
publishProgress(progress);
|
||||
return RESULT_OK;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
@@ -169,5 +169,14 @@ public class DownloadVoiceData extends Activity {
|
||||
|
||||
return RESULT_CANCELED;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProgressUpdate(ExtractProgress... progress) {
|
||||
if (progress[0].state == PROGRESS_STARTING) {
|
||||
mProgress.setMax(progress[0].total);
|
||||
} else {
|
||||
mProgress.setProgress(progress[0].progress);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user