Example usage for android.app ProgressDialog setMax

List of usage examples for android.app ProgressDialog setMax

Introduction

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

Prototype

public void setMax(int max) 

Source Link

Document

Sets the maximum allowed progress value.

Usage

From source file:com.slownet5.pgprootexplorer.filemanager.ui.FileManagerActivity.java

private void setupRoot() {
    if (alreadySetup()) {
        afterInitSetup(true);//from w  w w . j ava2s. co m
        return;
    }
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setIndeterminate(true);
    dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    dialog.setTitle("Setting up root");
    dialog.setCancelable(false);
    ;
    dialog.setMax(100);
    final String os = SystemUtils.getSystemArchitecture();
    Log.d(TAG, "setupRoot: architecture is: " + os);
    class Setup extends AsyncTask<Void, Integer, Boolean> {

        @Override
        protected Boolean doInBackground(Void... params) {
            new File(SharedData.CRYPTO_FM_PATH).mkdirs();
            String filename = SharedData.CRYPTO_FM_PATH + "/toybox";
            AssetManager asset = getAssets();
            try {

                InputStream stream = asset.open("toybox");

                OutputStream out = new FileOutputStream(filename);
                byte[] buffer = new byte[4096];
                int read;
                int total = 0;
                while ((read = stream.read(buffer)) != -1) {
                    total += read;
                    out.write(buffer, 0, read);
                }
                Log.d(TAG, "doInBackground: total written bytes: " + total);
                stream.close();
                out.flush();
                out.close();
            } catch (IOException ex) {
                ex.printStackTrace();
                return false;
            }
            RootUtils.initRoot(filename);

            return true;
        }

        @Override
        protected void onPreExecute() {
            dialog.setMessage("Please wait....");
            dialog.show();
        }

        @Override
        protected void onPostExecute(Boolean aBoolean) {
            dialog.dismiss();
            if (aBoolean) {
                SharedPreferences.Editor prefs = getSharedPreferences(CommonConstants.COMMON_SHARED_PEREFS_NAME,
                        Context.MODE_PRIVATE).edit();
                prefs.putBoolean(CommonConstants.ROOT_TOYBOX, true);
                prefs.apply();
                prefs.commit();
                afterInitSetup(true);

            } else {
                afterInitSetup(aBoolean);
            }
        }
    }
    new Setup().execute();
}

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);
    pd.setProgress(p);//w  w  w .  ja v a2s . c  o m
    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);
    }//  ww w .j a va2s  .  co  m
    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//  w w w  .ja  v a 2 s . c  o m
        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:com.eleybourn.bookcatalogue.utils.SimpleTaskQueueProgressFragment.java

/**
 * Create the underlying dialog//from ww w.jav a  2  s. c  om
 */
@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.microsoft.onedrive.apiexplorer.ItemFragment.java

/**
 * Copies an item onto the current destination in the copy preferences
 * @param item The item to copy//from  w w  w  .  ja  va2  s . c  o  m
 */
private void copy(final Item item) {
    final BaseApplication app = (BaseApplication) getActivity().getApplication();
    final IOneDriveClient oneDriveClient = app.getOneDriveClient();
    final ItemReference parentReference = new ItemReference();
    parentReference.id = getCopyPrefs().getString(COPY_DESTINATION_PREF_KEY, null);

    final ProgressDialog dialog = new ProgressDialog(getActivity(), ProgressDialog.STYLE_HORIZONTAL);
    dialog.setTitle("Copying item");
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setMessage("Waiting for copy to complete");

    final IProgressCallback<Item> progressCallback = new IProgressCallback<Item>() {
        @Override
        public void progress(final long current, final long max) {
            dialog.setMax((int) current);
            dialog.setMax((int) max);
        }

        @Override
        public void success(final Item item) {
            dialog.dismiss();
            final String string = getString(R.string.copy_success_message, item.name,
                    item.parentReference.path);
            Toast.makeText(getActivity(), string, Toast.LENGTH_LONG).show();
        }

        @Override
        public void failure(final ClientException error) {
            dialog.dismiss();
            new AlertDialog.Builder(getActivity()).setTitle(R.string.error_title).setMessage(error.getMessage())
                    .setNegativeButton(R.string.close, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(final DialogInterface dialog, final int which) {
                            dialog.dismiss();
                        }
                    }).create().show();
        }
    };

    final DefaultCallback<AsyncMonitor<Item>> callback = new DefaultCallback<AsyncMonitor<Item>>(
            getActivity()) {
        @Override
        public void success(final AsyncMonitor<Item> itemAsyncMonitor) {
            final int millisBetweenPoll = 1000;
            itemAsyncMonitor.pollForResult(millisBetweenPoll, progressCallback);
        }
    };
    oneDriveClient.getDrive().getItems(item.id).getCopy(item.name, parentReference).buildRequest()
            .create(callback);
    dialog.show();
}

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/*from w w  w.j  a va  2s .com*/
        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  ww.j av  a 2 s  .  c o 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:de.da_sense.moses.client.AvailableFragment.java

/**
 * FIXME: The ProgressDialog doesn't show up. Handles installing APK from
 * the Server.//from  www  .  j a  va 2  s  .co  m
 * 
 * @param app
 *            the App to download and install
 */
protected void handleInstallApp(ExternalApplication app) {

    final ProgressDialog progressDialog = new ProgressDialog(WelcomeActivity.getInstance());

    Log.d(TAG, "progressDialog = " + progressDialog);

    final ApkDownloadManager downloader = new ApkDownloadManager(app,
            WelcomeActivity.getInstance().getApplicationContext(), // getActivity().getApplicationContext(),
            new ExecutableForObject() {
                @Override
                public void execute(final Object o) {
                    if (o instanceof Integer) {
                        WelcomeActivity.getInstance().runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                if (totalSize == -1) {
                                    totalSize = (Integer) o / 1024;
                                    progressDialog.setMax(totalSize);
                                } else {
                                    progressDialog.incrementProgressBy(
                                            ((Integer) o / 1024) - progressDialog.getProgress());
                                }
                            }
                        });
                        /*
                         * They were : Runnable runnable = new Runnable() {
                         * Integer temporary = (Integer) o / 1024;
                         * 
                         * @Override public void run() { if (totalSize ==
                         * -1) { totalSize = temporary;
                         * progressDialog.setMax(totalSize); } else {
                         * progressDialog .incrementProgressBy( temporary -
                         * progressDialog.getProgress()); } } };
                         * getActivity().runOnUiThread(runnable);
                         */
                    }
                }
            });

    progressDialog.setTitle(getString(R.string.downloadingApp));
    progressDialog.setMessage(getString(R.string.pleaseWait));
    progressDialog.setMax(0);
    progressDialog.setProgress(0);
    progressDialog.setOnCancelListener(new OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            downloader.cancel();
        }
    });

    progressDialog.setCancelable(true);
    progressDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (progressDialog.isShowing())
                progressDialog.cancel();
        }
    });
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    Observer observer = new Observer() {
        @Override
        public void update(Observable observable, Object data) {
            if (downloader.getState() == ApkDownloadManager.State.ERROR) {
                // error downloading
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorDownloading(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.ERROR_NO_CONNECTION) {
                // error with connection
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                showMessageBoxErrorNoConnection(downloader);
            } else if (downloader.getState() == ApkDownloadManager.State.FINISHED) {
                // success
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                installDownloadedApk(downloader.getDownloadedApk(), downloader.getExternalApplicationResult());
            }
        }
    };
    downloader.addObserver(observer);
    totalSize = -1;
    // progressDialog.show(); FIXME: commented out in case it throws an
    // error
    downloader.start();
}

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

public void saveWavPart2(final String finalval, final String needToRename) {
    Intent new_intent = new Intent();
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 15);
    new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval);
    sendBroadcast(new_intent);
    final ProgressDialog prog;
    prog = new ProgressDialog(TimidityActivity.this);
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override/*from www  . ja v a2  s .  c om*/
        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();
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(TimidityActivity.this, "Conversion canceled", Toast.LENGTH_SHORT).show();
                        if (!Globals.keepWav) {
                            if (new File(finalval).exists())
                                new File(finalval).delete();
                        } else {
                            fileFrag.getDir(fileFrag.currPath);
                        }
                    }
                });

            } else {
                TimidityActivity.this.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(TimidityActivity.this, finalval, needToRename)) {
                                trueName = needToRename;
                            } else {
                                trueName = "Error";
                            }
                        }
                        Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                        prog.dismiss();
                        fileFrag.getDir(fileFrag.currPath);
                    }
                });
            }
        }
    }).start();
}