Example usage for android.app ProgressDialog incrementProgressBy

List of usage examples for android.app ProgressDialog incrementProgressBy

Introduction

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

Prototype

public void incrementProgressBy(int diff) 

Source Link

Document

Increments the current progress value.

Usage

From source file:de.da_sense.moses.client.AvailableFragment.java

/**
 * FIXME: The ProgressDialog doesn't show up. Handles installing APK from
 * the Server.//from   ww  w  . j av a2 s  .c o 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();
}