Example usage for android.app ProgressDialog setButton

List of usage examples for android.app ProgressDialog setButton

Introduction

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

Prototype

public void setButton(int whichButton, CharSequence text, Message msg) 

Source Link

Document

Set a message to be sent when a button is pressed.

Usage

From source file:org.mobisocial.corral.BackgroundableDownloadDialogFragment.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    ProgressDialog d = new ProgressDialog(getActivity());
    d.setTitle("Fetching file");
    d.setMessage("Preparing to download...");
    d.setIndeterminate(true);/* w ww  .ja  v  a  2  s  .c om*/
    d.setCancelable(true);
    d.setButton(DialogInterface.BUTTON_POSITIVE, "Background", mBackgroundListener);
    d.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", mCancelListener);
    return d;
}

From source file:tv.loilo.promise.samples.progress.SampleProgressSpinnerDialogFragment.java

@NonNull
@Override//  www . j  av a 2 s .  c  om
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final ProgressDialog progressDialog = new ProgressDialog(getContext(), getTheme());
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage("Loading...");
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {

        }
    });
    return progressDialog;
}

From source file:tv.loilo.promise.samples.progress.SampleProgressBarDialogFragment.java

@NonNull
@Override/*  ww w.  j a  va  2  s  . c  om*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final ProgressDialog progressDialog = new ProgressDialog(getContext(), getTheme());
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMax(100);
    progressDialog.setMessage("Loading...");
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    });
    return progressDialog;
}

From source file:com.esri.arcgisruntime.sample.generateofflinemapwithlocalbasemap.ProgressDialogFragment.java

@NonNull
@Override/*w ww . j a va  2s  .  c om*/
public Dialog onCreateDialog(@Nullable Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    // create a dialog to show progress
    final ProgressDialog progressDialog = new ProgressDialog(getActivity());
    progressDialog.setTitle(mTitle);
    progressDialog.setMessage(mMessage);
    progressDialog.setIndeterminate(false);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMax(100);
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, mCancel, (dialog, which) -> onDismiss(dialog));
    return progressDialog;
}

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

/**
 * Show progress UI elements.//  w  w w  .  j a  v a2 s . 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: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  ww  w .jav a2 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:tm.veriloft.mapsplayground.MapsActivity.java

private void fetchAndDrawRoute(final LatLng... latLngs) {
    final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(SERVER_PORT);

    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Loading..");
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override//from   w w w  .  j  av a2s  .c  o m
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            asyncHttpClient.cancelRequests(MapsActivity.this, true);
            showCenteredToast("Drawing route got cancelled");
        }
    });

    final RequestParams requestParams = new RequestParams();

    for (LatLng latLng : latLngs) {
        requestParams.add("loc", latLng.latitude + "," + latLng.longitude);
        l("Added latLng to request, " + latLng);
    }

    asyncHttpClient.get(this, SERVER, requestParams, new JsonHttpResponseHandler() {
        @Override
        public void onStart() {
            progressDialog.show();
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                ArrayList<LatLng> route = MapUtils.decodePoly(response.getString("route_geometry"));
                PolylineOptions routeOptions = new PolylineOptions();

                for (int i = 0; i < route.size(); i++) {
                    routeOptions.add(route.get(i));
                    l("Returned point " + route.get(i));
                    if (returnedPointsMarkers)
                        addedMarkers.add(mMap.addMarker(new MarkerOptions().position(route.get(i))
                                .title("#" + i + " point of #" + drawnRoutes.size())));
                }

                routeOptions.width(ROUTE_WIDTH).color(ROUTE_COLOR);
                drawnRoutes.add(mMap.addPolyline(routeOptions));

                List<LatLng> points = routeOptions.getPoints();

                if (focusAfterRouteDraw)
                    focusTo(points.get(0), 13);

                if (endMarkerRouteDraw) {
                    LatLng trueEndPoint = MapUtils.findTrueEndPoint(latLngs[latLngs.length - 1], route.get(0),
                            route.get(route.size() - 1));
                    addedMarkers.add(mMap.addMarker(
                            new MarkerOptions().position(trueEndPoint).title("End of #" + drawnRoutes.size())));
                }

                if (requestedPointMarkerRouteDraw)
                    addedMarkers.add(mMap.addMarker(new MarkerOptions().position(latLngs[latLngs.length - 1])
                            .title("Requested point of #" + drawnRoutes.size())));

            } catch (JSONException exception) {
                exception.printStackTrace();
                showCenteredToast("Exception while parsing! Error: " + exception.getLocalizedMessage());
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
            showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            showCenteredToast("Network error! Server returned non-json response, response: " + responseString
                    + ", Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFinish() {
            progressDialog.dismiss();
        }
    });
}

From source file:syncthing.android.ui.login.LoginPresenter.java

void showLoading() {
    dialogPresenter.showDialog(context -> {
        ProgressDialog loadingProgress = new ProgressDialog(context);
        loadingProgress.setMessage(context.getString(R.string.fetching_api_key_dots));
        loadingProgress.setCancelable(false);
        loadingProgress.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(android.R.string.cancel),
                (dialog, which) -> {/*  ww  w  .  j  av  a2s.c om*/
                    cancelLogin();
                    dialog.dismiss();
                });
        return loadingProgress;
    });
}

From source file:org.thialfihar.android.apg.ui.dialog.ProgressDialogFragment.java

/**
 * Creates dialog//from   w  w  w.  j a  v  a2 s.  c  o m
 */
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    final Activity activity = getActivity();

    ProgressDialog dialog = new ProgressDialog(activity);
    dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);

    String message = getArguments().getString(ARG_MESSAGE);
    int style = getArguments().getInt(ARG_STYLE);
    boolean cancelable = getArguments().getBoolean(ARG_CANCELABLE);

    dialog.setMessage(message);
    dialog.setProgressStyle(style);

    if (cancelable) {
        dialog.setButton(DialogInterface.BUTTON_NEGATIVE, activity.getString(R.string.progress_cancel),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                });
    }

    // Disable the back button
    OnKeyListener keyListener = new OnKeyListener() {

        @Override
        public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_BACK) {
                return true;
            }
            return false;
        }

    };
    dialog.setOnKeyListener(keyListener);

    return dialog;
}

From source file:me.panpf.tool4a.app.ProgressDialogFragment.java

/**
 * ?//from  w  w w  .java  2  s.  c  om
 *
 * @param progressDialog ?
 */
private void applyParams(ProgressDialog progressDialog) {
    if (builder == null)
        throw new IllegalArgumentException("builder null ?setBuilder()Builder");

    progressDialog.setTitle(builder.title);
    progressDialog.setMessage(builder.message != null ? builder.message
            : (Locale.CHINA.equals(Locale.getDefault()) ? MESSAGE_DEFAULT_CHINA : MESSAGE_DEFAULT_OTHER));
    if (builder.confirmButtonName != null) {
        progressDialog.setButton(AlertDialog.BUTTON_POSITIVE, builder.confirmButtonName,
                builder.confirmButtonClickListener);
    }
    if (builder.cancelButtonName != null) {
        progressDialog.setButton(AlertDialog.BUTTON_NEGATIVE, builder.cancelButtonName,
                builder.cancelButtonClickListener);
    }
    if (builder.neutralButtonName != null) {
        progressDialog.setButton(AlertDialog.BUTTON_NEUTRAL, builder.neutralButtonName,
                builder.neutralButtonClickListener);
    }
    progressDialog.setOnKeyListener(builder.onKeyListener);
    progressDialog.setOnShowListener(builder.onShowListener);
    setCancelable(builder.cancelable);
}