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:de.jerleo.samsung.knox.firewall.MainActivity.java

private void applyRules() {

    // Get context
    final Context context = this;

    // Show progress
    final ProgressDialog progress = new ProgressDialog(this);

    // Finish message
    final Toast completed = Toast.makeText(this, getString(R.string.firewall_rules_complete),
            Toast.LENGTH_SHORT);/*from ww w .  ja  v a2 s .  c o  m*/
    progress.setIndeterminate(true);
    progress.setProgress(0);
    progress.show();

    // Handler to dismiss progress
    @SuppressLint("HandlerLeak")
    final Handler handler = new Handler() {

        @Override
        public void handleMessage(Message msg) {

            super.handleMessage(msg);
            progress.dismiss();
            completed.show();
        }
    };

    // Apply firewall rules
    new Thread(new Runnable() {

        @Override
        public void run() {

            progress.setMessage(getString(R.string.firewall_rules_create));
            Firewall.createRules(context);
            handler.sendMessage(handler.obtainMessage());
        }
    }).start();
}

From source file:jp.co.noxi.app.NXProgressDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        final ProgressDialog dialog = mProgressDialog = new ProgressDialog(getActivity());
        dialog.setProgressStyle(mStyle);
        dialog.setIndeterminate(mIndeterminate);
        if (mMax > 0) {
            dialog.setMax(mMax);/*  w  ww .j  a v  a  2  s.c o m*/
        }
        if (mProgressVal > 0) {
            dialog.setProgress(mProgressVal);
        }
        if (mSecondaryProgressVal > 0) {
            dialog.setSecondaryProgress(mSecondaryProgressVal);
        }
        if (mMessage != null) {
            dialog.setMessage(mMessage);
        }
        if (mFormat != null) {
            dialog.setProgressNumberFormat(mFormat);
        }
        return dialog;
    } else {
        final ProgressDialogGB dialog = mProgressDialogGB = new ProgressDialogGB(getActivity());
        dialog.setProgressStyle(mStyle);
        dialog.setIndeterminate(mIndeterminate);
        if (mMax > 0) {
            dialog.setMax(mMax);
        }
        if (mProgressVal > 0) {
            dialog.setProgress(mProgressVal);
        }
        if (mSecondaryProgressVal > 0) {
            dialog.setSecondaryProgress(mSecondaryProgressVal);
        }
        if (mMessage != null) {
            dialog.setMessage(mMessage);
        }
        if (mFormat != null) {
            dialog.setProgressNumberFormat(mFormat);
        }
        return dialog;
    }
}

From source file:com.esri.arcgisruntime.generateofflinemap.MainActivity.java

/**
 * Use the generate offline map job to generate an offline map.
 *///from w w w .j  a v a 2 s. c  o m
private void generateOfflineMap() {

    // create a progress dialog to show download progress
    ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setTitle("Generate Offline Map Job");
    progressDialog.setMessage("Taking map offline...");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setIndeterminate(false);
    progressDialog.setProgress(0);

    // when the button is clicked, start the offline map task job
    mTakeMapOfflineButton.setOnClickListener(v -> {
        progressDialog.show();

        // delete any offline map already in the cache
        String tempDirectoryPath = getCacheDir() + File.separator + "offlineMap";
        deleteDirectory(new File(tempDirectoryPath));

        // specify the extent, min scale, and max scale as parameters
        double minScale = mMapView.getMapScale();
        double maxScale = mMapView.getMap().getMaxScale();
        // minScale must always be larger than maxScale
        if (minScale <= maxScale) {
            minScale = maxScale + 1;
        }
        GenerateOfflineMapParameters generateOfflineMapParameters = new GenerateOfflineMapParameters(
                mDownloadArea.getGeometry(), minScale, maxScale);

        // create an offline map offlineMapTask with the map
        OfflineMapTask offlineMapTask = new OfflineMapTask(mMapView.getMap());

        // create an offline map job with the download directory path and parameters and start the job
        GenerateOfflineMapJob job = offlineMapTask.generateOfflineMap(generateOfflineMapParameters,
                tempDirectoryPath);

        // replace the current map with the result offline map when the job finishes
        job.addJobDoneListener(() -> {
            if (job.getStatus() == Job.Status.SUCCEEDED) {
                GenerateOfflineMapResult result = job.getResult();
                mMapView.setMap(result.getOfflineMap());
                mGraphicsOverlay.getGraphics().clear();
                mTakeMapOfflineButton.setEnabled(false);
                Toast.makeText(this, "Now displaying offline map.", Toast.LENGTH_LONG).show();
            } else {
                String error = "Error in generate offline map job: " + job.getError().getAdditionalMessage();
                Toast.makeText(this, error, Toast.LENGTH_LONG).show();
                Log.e(TAG, error);
            }
            progressDialog.dismiss();
        });

        // show the job's progress with the progress dialog
        job.addProgressChangedListener(() -> progressDialog.setProgress(job.getProgress()));

        // start the job
        job.start();
    });

}

From source file:li.klass.fhem.fragments.AbstractWebViewFragment.java

@SuppressLint("SetJavaScriptEnabled")
@Override/*from   w w w.  j a va2 s  .  c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = super.onCreateView(inflater, container, savedInstanceState);
    if (view != null)
        return view;

    view = inflater.inflate(R.layout.webview, container, false);
    assert view != null;

    final WebView webView = (WebView) view.findViewById(R.id.webView);

    WebSettings settings = webView.getSettings();
    settings.setUseWideViewPort(true);
    settings.setLoadWithOverviewMode(true);
    settings.setJavaScriptEnabled(true);
    settings.setBuiltInZoomControls(true);

    final ProgressDialog progressDialog = new ProgressDialog(getActivity());
    progressDialog.setMessage(getResources().getString(R.string.loading));

    webView.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int newProgress) {
            super.onProgressChanged(view, newProgress);
            if (newProgress < 100) {
                progressDialog.setProgress(newProgress);
                progressDialog.show();
            } else {
                progressDialog.hide();
            }
        }
    });

    webView.setWebViewClient(new WebViewClient() {
        @Override
        public void onReceivedSslError(WebView view, @NotNull SslErrorHandler handler, SslError error) {
            handler.proceed();
        }

        @SuppressWarnings("ConstantConditions")
        @Override
        public void onReceivedHttpAuthRequest(WebView view, @NotNull HttpAuthHandler handler, String host,
                String realm) {
            FHEMServerSpec currentServer = connectionService.getCurrentServer(getActivity());
            String url = currentServer.getUrl();
            String alternativeUrl = trimToNull(currentServer.getAlternateUrl());
            try {

                String fhemUrlHost = new URL(url).getHost();
                String alternativeUrlHost = alternativeUrl == null ? null : new URL(alternativeUrl).getHost();
                String username = currentServer.getUsername();
                String password = currentServer.getPassword();

                if (host.startsWith(fhemUrlHost)
                        || (alternativeUrlHost != null && host.startsWith(alternativeUrlHost))) {
                    handler.proceed(username, password);
                } else {
                    handler.cancel();

                    Intent intent = new Intent(Actions.SHOW_TOAST);
                    intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_authentication);
                    getActivity().sendBroadcast(intent);
                }

            } catch (MalformedURLException e) {
                Intent intent = new Intent(Actions.SHOW_TOAST);
                intent.putExtra(BundleExtraKeys.STRING_ID, R.string.error_host_connection);
                getActivity().sendBroadcast(intent);
                LOG.error("malformed URL: " + url, e);

                handler.cancel();
            }
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            super.onPageFinished(view, url);
            if ("about:blank".equalsIgnoreCase(url)) {
                Optional<String> alternativeUrl = getAlternateLoadUrl();
                if (alternativeUrl.isPresent()) {
                    webView.loadUrl(alternativeUrl.get());
                }
            } else {
                onPageLoadFinishedCallback(view, url);
            }
        }
    });

    return view;
}

From source file:com.esri.arcgisruntime.sample.editandsyncfeatures.MainActivity.java

/**
 * Create a progress dialog to show sync state
 *//*w ww .ja v a2s.c  o  m*/
private void createProgressDialog(Job job) {

    ProgressDialog syncProgressDialog = new ProgressDialog(this);
    syncProgressDialog.setTitle("Sync Geodatabase Job");
    syncProgressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    syncProgressDialog.setCanceledOnTouchOutside(false);
    syncProgressDialog.show();

    job.addProgressChangedListener(() -> syncProgressDialog.setProgress(job.getProgress()));

    job.addJobDoneListener(syncProgressDialog::dismiss);
}

From source file:com.esri.arcgisruntime.sample.exporttiles.MainActivity.java

/**
 * Show progress UI elements.//from ww  w.ja v  a2s  .c o  m
 *
 * @param exportTileCacheJob used to track progress and cancel when required
 */
private void createProgressDialog(ExportTileCacheJob exportTileCacheJob) {

    ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setTitle("Export Tile Cache Job");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel",
            (dialogInterface, i) -> exportTileCacheJob.cancel());
    progressDialog.show();

    exportTileCacheJob
            .addProgressChangedListener(() -> progressDialog.setProgress(exportTileCacheJob.getProgress()));
    exportTileCacheJob.addJobDoneListener(progressDialog::dismiss);
}

From source file:org.alfresco.mobile.android.application.fragments.operations.OperationWaitingDialogFragment.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    setRetainInstance(true);/*from  w w w  .  ja va2s  .c  om*/
    if (getArguments() != null) {
        operationType = getArguments().getInt(PARAM_TYPEID);
        intentId = getArguments().getString(PARAM_INTENTID);
        iconId = getArguments().getInt(PARAM_ICONID);
        title = getArguments().getString(PARAM_TITLEID);
        message = getArguments().getString(PARAM_MESSAGEID);
        parent = getArguments().getParcelable(PARAM_NODEID);
        nbItems = getArguments().getInt(PARAM_SIZE);
    }

    ProgressDialog dialog = new ProgressDialog(getActivity());
    if (iconId == 0) {
        iconId = R.drawable.ic_alfresco_logo;
    }
    dialog.setIcon(iconId);
    dialog.setTitle(title);
    if (message == null) {
        message = getString(R.string.waiting_operations);
    }
    dialog.setMessage(message);
    boolean indeterminate = true;
    if (nbItems > 0) {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgress(0);
        dialog.setMax(nbItems);
        indeterminate = false;
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });

    getActivity().getLoaderManager().restartLoader(this.hashCode(), null, this);

    return dialog;
}

From source file:org.alfresco.mobile.android.ui.operation.OperationWaitingDialogFragment.java

public Dialog onCreateDialog(final Bundle savedInstanceState) {
    if (getArguments() != null) {
        operationType = getArguments().getInt(ARGUMENT_TYPEID);
        intentId = getArguments().getString(ARGUMENT_INTENTID);
        iconId = getArguments().getInt(ARGUMENT_ICONID);
        title = getArguments().getString(ARGUMENT_TITLEID);
        message = getArguments().getString(ARGUMENT_MESSAGEID);
        parent = getArguments().getParcelable(ARGUMENT_NODEID);
        nbItems = getArguments().getInt(ARGUMENT_SIZE);
        operationId = getArguments().getString(ARGUMENT_OPERATIONID);
    }/*from   w w  w.j  av a 2  s.  c  o m*/

    ProgressDialog dialog = new ProgressDialog(getActivity());
    if (iconId == 0) {
        iconId = R.drawable.ic_application_logo;
    }
    dialog.setIcon(iconId);
    dialog.setTitle(title);
    if (message == null) {
        message = getString(R.string.waiting_operations);
    }
    dialog.setMessage(message);
    boolean indeterminate = true;
    if (nbItems > 0) {
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        dialog.setProgress(0);
        dialog.setMax(nbItems);
        indeterminate = false;
    } else {
        dialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    }
    dialog.setIndeterminate(indeterminate);
    dialog.setCancelable(false);
    dialog.setButton(DialogInterface.BUTTON_NEGATIVE, getString(R.string.cancel),
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (operationId != null) {
                        Operator.with(getActivity()).cancel(operationId);
                    }
                    dialog.dismiss();
                }
            });

    getActivity().getLoaderManager().restartLoader(this.hashCode(), null, this);

    return dialog;
}

From source file:com.esri.arcgisruntime.generateofflinemapoverrides.MainActivity.java

/**
 * Shows a progress dialog for the given job.
 *
 * @param job to track progress from//from   ww  w.j a va  2 s.  c  o  m
 */
private void showProgressDialog(Job job) {
    // create a progress dialog to show download progress
    ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setTitle("Generate Offline Map Job");
    progressDialog.setMessage("Taking map offline...");
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setIndeterminate(false);
    progressDialog.setProgress(0);
    progressDialog.setCanceledOnTouchOutside(false);
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", (dialog, which) -> job.cancel());
    progressDialog.show();

    // show the job's progress with the progress dialog
    job.addProgressChangedListener(() -> progressDialog.setProgress(job.getProgress()));

    // dismiss dialog when job is done
    job.addJobDoneListener(progressDialog::dismiss);
}

From source file:com.softminds.matrixcalculator.OperationFragments.InverseFragment.java

public void RunAndGetDeterminantWithAdjoint(final int i, final ProgressDialog progressDialog) {
    Runnable runnable = new Runnable() {
        @Override/*from  w w w. j a  v a2s. com*/
        public void run() {
            Message message = new Message();
            Bundle bundle = new Bundle();
            float detr = (float) SquareList.get(i).getDeterminant(progressDialog);
            if (detr == 0.0f) {
                myHandler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        Toast.makeText(getContext(), R.string.NoInverse, Toast.LENGTH_SHORT).show();
                    }
                }, 0);
                progressDialog.dismiss();
            } else {
                progressDialog.setProgress(0);
                bundle.putFloat("DETERMINANT", detr);
                MatrixV2 res = SquareList.get(i).getAdjoint(progressDialog);
                bundle.putAll(res.getDataBundled());
                message.setData(bundle);
                myHandler.sendMessage(message);
            }

        }
    };
    Thread thread = new Thread(runnable);
    thread.start();
}