Я нашел отличный класс UnZip с поддержкой индикаторов хода выполнения для Android. Однако индикатор выполнения не обновляется при нажатии extract в моем приложении. Раскатка работает отлично.Прогресс-бар, не обновляющийся на Android
Может кто-нибудь, пожалуйста, скажите мне, что я делаю неправильно?
public class UnZip1 extends AsyncTask<Void, Integer, Integer> {
{
}
private String _zipFile;
private String _location;
private ProgressDialog mProgressDialog;
private int per = 0;
private Context _conti;
private ProgressBar bar1;
public UnZip1(Context conti,String zipFile, String location) {
_conti = conti;
_zipFile = zipFile;
_location = location;
bar1 = (ProgressBar)findViewById(R.id.pb1);
_dirChecker("");
}
public void streamCopy(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[32 * 1024]; // play with sizes..
int readCount;
while ((readCount = in.read(buffer)) != -1) {
out.write(buffer, 0, readCount);
}
}
protected Integer doInBackground(Void... params) {
try {
ZipFile zip = new ZipFile(_zipFile);
FileInputStream fin = new FileInputStream(_zipFile);
ZipInputStream zin = new ZipInputStream(fin);
ZipEntry ze = null;
while ((ze = zin.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + ze.getName());
if(ze.isDirectory()) {
_dirChecker(ze.getName());
} else {
// Here I am doing the update of my progress bar
Log.v("Decompress", "more " + ze.getName());
per++;
publishProgress(per);
FileOutputStream fout = new FileOutputStream(_location + ze.getName());
streamCopy(zin, fout);
zin.closeEntry();
fout.close();
} }
zin.close();
} catch(Exception e) {
Log.e("Decompress", "unzip", e);
}
return null;
}
protected void onProgressUpdate(Integer... progress) {
bar1.setProgress(per);
}
protected void onPostExecute(Integer... result) {
Log.i("UnZip" ,"Completed. Total size: "+result);
}
private void _dirChecker(String dir) {
File f = new File(_location + dir);
if(!f.isDirectory()) {
f.mkdirs();
}
}
}
}