Example usage for android.app ProgressDialog setProgress

List of usage examples for android.app ProgressDialog setProgress

Introduction

In this page you can find the example usage for android.app ProgressDialog setProgress.

Prototype

public void setProgress(int value) 

Source Link

Document

Sets the current progress.

Usage

From source file:com.yeldi.yeldibazaar.AppDetails.java

private ProgressDialog createProgressDialog(String file, int p, int max) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    pd.setMessage(getString(R.string.download_server) + ":\n " + file);
    pd.setMax(max);//  ww w.j a v  a2  s .co m
    pd.setProgress(p);
    pd.setCancelable(true);
    pd.setCanceledOnTouchOutside(false);
    pd.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            downloadHandler.cancel();
        }
    });
    pd.setButton(DialogInterface.BUTTON_NEUTRAL, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                    pd.cancel();
                }
            });
    pd.show();
    return pd;
}

From source file:com.android.gallery3d.ingest.IngestActivity.java

private void updateProgressDialog() {
    ProgressDialog dialog = getProgressDialog();
    boolean indeterminate = (mProgressState.max == 0);
    dialog.setIndeterminate(indeterminate);
    dialog.setProgressStyle(indeterminate ? ProgressDialog.STYLE_SPINNER : ProgressDialog.STYLE_HORIZONTAL);
    if (mProgressState.title != null) {
        dialog.setTitle(mProgressState.title);
    }/*  www . j  av a 2  s  .c  om*/
    if (mProgressState.message != null) {
        dialog.setMessage(mProgressState.message);
    }
    if (!indeterminate) {
        dialog.setProgress(mProgressState.current);
        dialog.setMax(mProgressState.max);
    }
    if (!dialog.isShowing()) {
        dialog.show();
    }
}

From source file:com.xperia64.timidityae.FileBrowserFragment.java

public void saveWavPart2(final int position, final String finalval, final String needToRename) {
    ((TimidityActivity) getActivity()).writeFile(path.get(position), finalval);
    final ProgressDialog prog;
    prog = new ProgressDialog(getActivity());
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override//from   w  ww .  j  av  a 2  s  .  com
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    prog.setTitle("Converting to WAV");
    prog.setMessage("Converting...");
    prog.setIndeterminate(false);
    prog.setCancelable(false);
    prog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    prog.show();
    new Thread(new Runnable() {
        @Override
        public void run() {
            while (!localfinished && prog.isShowing()) {

                prog.setMax(JNIHandler.maxTime);
                prog.setProgress(JNIHandler.currTime);
                try {
                    Thread.sleep(25);
                } catch (InterruptedException e) {
                }
            }
            if (!localfinished) {
                JNIHandler.stop();
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(getActivity(), "Conversion canceled", Toast.LENGTH_SHORT).show();
                        if (!Globals.keepWav) {
                            if (new File(finalval).exists())
                                new File(finalval).delete();
                        } else {
                            getDir(currPath);
                        }
                    }
                });

            } else {
                getActivity().runOnUiThread(new Runnable() {
                    public void run() {
                        String trueName = finalval;
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && Globals.theFold != null
                                && needToRename != null) {
                            if (Globals.renameDocumentFile(getActivity(), finalval, needToRename)) {
                                trueName = needToRename;
                            } else {
                                trueName = "Error";
                            }
                        }
                        Toast.makeText(getActivity(), "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                        prog.dismiss();
                        getDir(currPath);
                    }
                });
            }
        }
    }).start();
}

From source file:net.bytten.comicviewer.ComicViewerActivity.java

public void loadComicImage(Uri uri) {
    webview.clearView();//from   w  w  w. j a v  a2  s.c  o m
    final ProgressDialog pd = ProgressDialog.show(this, getStringAppName(), "Loading comic image...", false,
            true, new OnCancelListener() {
                public void onCancel(DialogInterface dialog) {
                    webview.stopLoading();
                    webview.requestFocus();
                }
            });
    pd.setProgress(0);
    webview.setWebViewClient(new WebViewClient() {
        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            pd.dismiss();
            webview.requestFocus();
        }
    });
    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            pd.setProgress(newProgress * 100);
        }
    });
    if ("".equals(uri.toString())) {
        failed("Couldn't identify image in post");
        webview.loadUrl("about:blank");
    } else {
        webview.loadUrl(uri.toString());
    }
}

From source file:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java

/**
 * Create the underlying dialog/* w  ww.j av  a2 s .c o m*/
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

    ProgressDialog dialog = new ProgressDialog(getActivity());
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(false);

    int msg = getArguments().getInt("title");
    if (msg != 0)
        dialog.setMessage(getActivity().getString(msg));
    final boolean isIndet = getArguments().getBoolean("isIndeterminate");
    dialog.setIndeterminate(isIndet);
    if (isIndet) {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    }

    // We can't use "this.requestUpdateProgress()" because getDialog() will still return null
    if (!isIndet) {
        dialog.setMax(mMax);
        dialog.setProgress(mProgress);
        if (mMessage != null)
            dialog.setMessage(mMessage);
        setDialogNumberFormat(dialog);
    }

    return dialog;
}

From source file:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java

/**
 * Method, run in the UI thread, that updates the various dialog fields.
 *///from ww  w . j ava  2 s.  co  m
private void updateProgress() {
    ProgressDialog d = (ProgressDialog) getDialog();
    if (d != null) {
        synchronized (this) {
            if (mMaxChanged) {
                d.setMax(mMax);
                mMaxChanged = false;
            }
            if (mNumberFormatChanged) {
                if (Build.VERSION.SDK_INT >= 11) {
                    // Called in a separate function so we can set API attributes
                    setDialogNumberFormat(d);
                }
                mNumberFormatChanged = false;
            }
            if (mMessageChanged) {
                d.setMessage(mMessage);
                mMessageChanged = false;
            }

            if (mProgressChanged) {
                d.setProgress(mProgress);
                mProgressChanged = false;
            }

        }
    }
}

From source file:com.cellbots.logger.LoggerActivity.java

@Override
public void onPrepareDialog(int id, Dialog dialog, Bundle bundle) {
    super.onPrepareDialog(id, dialog, bundle);

    if (id != PROGRESS_ID) {
        return;/*from ww  w.  j ava2 s.co  m*/
    }

    final ProgressDialog progressDialog = (ProgressDialog) dialog;
    progressDialog.setMessage("Processing...");
    final Handler handler = new Handler() {
        @Override
        public void handleMessage(android.os.Message msg) {
            int done = msg.getData().getInt("percentageDone");
            String status = msg.getData().getString("status");
            progressDialog.setProgress(done);
            progressDialog.setMessage(status);

            if (mRemoteControl != null) {
                mRemoteControl.broadcastMessage("Zipping Progress: " + done + "%\n");
            }
        }
    };

    zipperThread = new Thread() {
        @Override
        public void run() {
            if (useZip) {
                ZipItUpRequest request = new ZipItUpRequest();
                String directoryName = application.getLoggerPathPrefix();
                request.setInputFiles(new FileListFetcher().getFilesAndDirectoriesInDir(directoryName));
                request.setOutputFile(directoryName + "/logged-data.zip");
                request.setMaxOutputFileSize(MAX_OUTPUT_ZIP_CHUNK_SIZE);
                request.setDeleteInputfiles(true);
                request.setCompressionLevel(Deflater.NO_COMPRESSION);

                try {
                    new ZipItUpProcessor(request).chunkIt(handler);
                } catch (IOException e) {
                    Log.e("Oh Crap!", "IoEx", e);
                }
            }
            // closing dialog
            progressDialog.dismiss();
            application.generateNewFilePathUniqueIdentifier();

            // TODO: Need to deal with empty directories that are created if
            // another recording
            // session is never started.
            initSensorLogFiles();

            if (mCamcorderView != null) {
                try {
                    mCamcorderView.startPreview();
                    if (mRemoteControl != null)
                        mRemoteControl.broadcastMessage("*** Packaging Finished: OK to start ***\n");
                } catch (RuntimeException e) {
                    e.printStackTrace();
                    runOnUiThread(new Runnable() {
                        // @Override
                        @Override
                        public void run() {
                            Toast.makeText(getApplicationContext(),
                                    "Camera hardware error. Please restart the application.", Toast.LENGTH_LONG)
                                    .show();
                        }
                    });
                    finish();
                    return;
                }
            }
        }
    };
    zipperThread.start();
}

From source file:uk.co.armedpineapple.cth.SDLActivity.java

private void installFiles(final SharedPreferences preferences) {
    final ProgressDialog dialog = new ProgressDialog(this);
    final UnzipTask unzipTask = new UnzipTask(app.configuration.getCthPath() + "/scripts/", this) {

        @Override/*ww  w .ja  va2 s  .c  o  m*/
        protected void onPreExecute() {
            super.onPreExecute();
            dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
            dialog.setMessage(getString(R.string.preparing_game_files_dialog));
            dialog.setIndeterminate(false);
            dialog.setCancelable(false);
            dialog.show();
        }

        @Override
        protected void onProgressUpdate(Integer... values) {
            super.onProgressUpdate(values);
            dialog.setProgress(values[0]);
            dialog.setMax(values[1]);
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<String> result) {
            super.onPostExecute(result);
            Exception error;
            if ((error = result.getError()) != null) {
                Log.d(LOG_TAG, "Error copying files.");
                BugSenseHandler.sendException(error);
            }

            Editor edit = preferences.edit();
            edit.putBoolean("scripts_copied", true);
            edit.putInt("last_version", currentVersion);
            edit.commit();
            dialog.hide();
            loadApplication();
        }

    };

    AsyncTask<String, Void, AsyncTaskResult<File>> copyTask = new

    AsyncTask<String, Void, AsyncTaskResult<File>>() {

        @Override
        protected AsyncTaskResult<File> doInBackground(String... params) {

            try {
                Files.copyAsset(SDLActivity.this, params[0], params[1]);
            } catch (IOException e) {

                return new AsyncTaskResult<File>(e);
            }
            return new AsyncTaskResult<File>(new File(params[1] + "/" + params[0]));
        }

        @Override
        protected void onPostExecute(AsyncTaskResult<File> result) {
            super.onPostExecute(result);
            File f;
            if ((f = result.getResult()) != null) {
                unzipTask.execute(f);
            } else {
                BugSenseHandler.sendException(result.getError());

            }
        }

    };

    if (Files.canAccessExternalStorage()) {

        copyTask.execute(ENGINE_ZIP_FILE, getExternalCacheDir().getAbsolutePath());
    } else {
        DialogFactory.createExternalStorageWarningDialog(this, true).show();
    }
}

From source file:id.ridon.keude.AppDetailsData.java

private void updateProgressDialog(int progress, int total) {
    if (downloadHandler != null) {
        ProgressDialog pd = getProgressDialog(downloadHandler.getRemoteAddress());
        if (total > 0) {
            pd.setIndeterminate(false);//w w w.  j  a  va 2 s.  co m
            pd.setProgress(progress);
            pd.setMax(total);
        } else {
            pd.setIndeterminate(true);
            pd.setProgress(progress);
            pd.setMax(0);
        }
        if (!pd.isShowing()) {
            Log.d(TAG, "Showing progress dialog for download.");
            pd.show();
        }
    }
}

From source file:com.lostad.app.base.util.DownloadUtil.java

public static void downFileAsyn(final Activity ctx, final String upgradeUrl, final String savedPath,
        final MyCallback<Boolean> callback) {
    final ProgressDialog xh_pDialog = new ProgressDialog(ctx);
    // ?//from  ww w  .  j a  v a  2  s  .  com
    xh_pDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    // ProgressDialog 
    xh_pDialog.setTitle("???");
    // ProgressDialog???
    xh_pDialog.setMessage("...");
    // ProgressDialog
    // xh_pDialog.setIcon(R.drawable.img2);
    // ProgressDialog ??? false ??
    xh_pDialog.setIndeterminate(false);
    // ProgressDialog ?
    // xh_pDialog.setProgress(100);
    // ProgressDialog ???
    xh_pDialog.setCancelable(true);
    // ProgressDialog
    xh_pDialog.show();

    new Thread() {
        public void run() {

            boolean downloadSuccess = true;
            FileOutputStream fileOutputStream = null;
            try {
                Looper.prepare();
                HttpClient client = new DefaultHttpClient();
                HttpGet get = new HttpGet(upgradeUrl);

                File f = new File(savedPath);
                if (!f.exists()) {
                    f.createNewFile();
                }

                HttpResponse response = client.execute(get);
                HttpEntity entity = response.getEntity();
                // ?
                Long length = entity.getContentLength();
                xh_pDialog.setMax(length.intValue());
                //
                InputStream is = entity.getContent();
                fileOutputStream = null;

                if (is != null && length > 0) {

                    fileOutputStream = new FileOutputStream(f);

                    byte[] buf = new byte[1024];
                    int ch = -1;
                    int count = 0;
                    while ((ch = is.read(buf)) != -1) {

                        if (xh_pDialog.isShowing()) {
                            fileOutputStream.write(buf, 0, ch);
                            // ?
                            count += ch;
                            xh_pDialog.setProgress(count);
                        } else {
                            downloadSuccess = false;
                            break;// ?
                        }
                    }

                } else {
                    callback.onCallback(false);
                }

                if (downloadSuccess && fileOutputStream != null) {
                    xh_pDialog.dismiss();
                    fileOutputStream.flush();
                    fileOutputStream.close();
                    callback.onCallback(true);// ?
                }
                Looper.loop();
            } catch (FileNotFoundException e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
                xh_pDialog.dismiss();
            } catch (Exception e) {
                xh_pDialog.dismiss();
                e.printStackTrace();
                callback.onCallback(false);
            } finally {
                try {
                    fileOutputStream.flush();
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    }.start();

}