Skip to content

Commit

Permalink
Update the progress bar with the install progress.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhdunn committed Oct 12, 2015
1 parent 6b24a67 commit d19f4fb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
9 changes: 6 additions & 3 deletions android/res/layout/download_voice_data.xml
Expand Up @@ -7,10 +7,13 @@
android:padding="16dp" >

<ProgressBar
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp" />
android:layout_marginBottom="16dp"
android:id="@+id/progress"
android:indeterminate="false"
android:longClickable="false" />

<TextView
android:id="@+id/installing_voice_data"
Expand Down
29 changes: 19 additions & 10 deletions android/src/com/reecedunn/espeak/DownloadVoiceData.java
Expand Up @@ -23,30 +23,32 @@
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;

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) {
Expand Down Expand Up @@ -80,15 +82,14 @@ protected void onDestroy() {

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;
}
}
Expand All @@ -97,11 +98,13 @@ private static class AsyncExtract extends AsyncTask<Void, ExtractProgress, Integ
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
Expand Down Expand Up @@ -153,9 +156,6 @@ protected Integer doInBackground(Void... params) {
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();
Expand All @@ -169,5 +169,14 @@ protected Integer doInBackground(Void... params) {

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);
}
}
}
}

0 comments on commit d19f4fb

Please sign in to comment.