Example usage for android.app ProgressDialog setCancelable

List of usage examples for android.app ProgressDialog setCancelable

Introduction

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

Prototype

public void setCancelable(boolean flag) 

Source Link

Document

Sets whether this dialog is cancelable with the KeyEvent#KEYCODE_BACK BACK key.

Usage

From source file:com.linroid.pushapp.ui.bind.BindActivity.java

@OnClick(R.id.btn_bind)
public void onBindBtnClicked(Button btn) {
    final ProgressDialog dialog = new ProgressDialog(this, R.style.Theme_AppCompat_Light_Dialog);
    dialog.setIndeterminate(true);/* www.j  a v  a  2s.  c  o m*/
    dialog.setMessage(getString(R.string.msg_dialog_bind));
    dialog.setCancelable(false);
    dialog.show();
    authApi.bindDevice(bindToken, queryAndBuildDeviceInfo(), new Callback<Account>() {
        @Override
        @DebugLog
        public void success(Account authInfo, Response response) {
            Device device = authInfo.getDevice();
            User user = authInfo.getUser();
            String token = authInfo.getToken();
            account.setDevice(device);
            account.setUser(user);
            account.setToken(token);
            account.saveToFile();

            dialog.dismiss();
            redirectToHome();
        }

        @Override
        @DebugLog
        public void failure(RetrofitError error) {
            Snackbar.make(switcher, error.getMessage(), Snackbar.LENGTH_SHORT).show();
            dialog.dismiss();
        }
    });
}

From source file:net.palacesoft.cngstation.client.StationActivity.java

public ProgressDialog createProgressDialog(String message) {
    ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage(message);/*from  w  w w  .  j  av a  2 s.c  o m*/
    progressDialog.setCancelable(true);
    return progressDialog;
}

From source file:com.nanosheep.bikeroute.Feedback.java

@Override
public Dialog onCreateDialog(final int id) {
    AlertDialog.Builder builder;// w w w.  j a v a  2 s  .  c om
    ProgressDialog pDialog;
    Dialog dialog;
    switch (id) {
    case R.id.send:
        pDialog = new ProgressDialog(this);
        pDialog.setCancelable(true);
        pDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pDialog.setMessage(getText(R.string.send_msg));
        pDialog.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(final DialogInterface arg0) {
                removeDialog(R.id.send);
            }
        });
        pDialog.setOnCancelListener(new OnCancelListener() {

            @Override
            public void onCancel(final DialogInterface arg0) {
                submitHandler.cancel(true);
            }

        });
        dialog = pDialog;
        break;
    case R.id.thanks:
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getText(R.string.thanks_message)).setCancelable(true)
                .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.dismiss();
                        finish();
                    }
                });
        dialog = builder.create();
        break;
    case R.id.feedback_fail:
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getText(R.string.feedback_fail_message)).setCancelable(true)
                .setPositiveButton(getString(R.string.ok), new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(final DialogInterface dialog, final int id) {
                        dialog.dismiss();
                    }
                });
        dialog = builder.create();
        break;
    default:
        dialog = null;
    }
    return dialog;
}

From source file:net.kourlas.voipms_sms.Notifications.java

/**
 * Enable SMS notifications by configuring the VoIP.ms URL callback, registering for GCM and making the appropriate
 * changes to the application preferences.
 *
 * @param activity The source activity.// w ww  . j  a va 2  s  .  c  o m
 */
public void enableNotifications(final Activity activity) {
    if (preferences.getEmail().equals("") || preferences.getPassword().equals("")
            || preferences.getDid().equals("")) {
        Utils.showInfoDialog(activity,
                applicationContext.getString(R.string.notifications_callback_username_password_did));
        return;
    }

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    progressDialog.setMessage(activity.getString(R.string.notifications_callback_progress));
    progressDialog.setCancelable(false);
    progressDialog.show();

    new AsyncTask<Boolean, Void, Boolean>() {
        @Override
        protected Boolean doInBackground(Boolean... params) {
            try {
                String url = "https://www.voip.ms/api/v1/rest.php?" + "api_username="
                        + URLEncoder.encode(preferences.getEmail(), "UTF-8") + "&" + "api_password="
                        + URLEncoder.encode(preferences.getPassword(), "UTF-8") + "&" + "method=setSMS" + "&"
                        + "did=" + URLEncoder.encode(preferences.getDid(), "UTF-8") + "&" + "enable=1" + "&"
                        + "url_callback_enable=1" + "&" + "url_callback=" + URLEncoder
                                .encode("http://voipmssms-kourlas.rhcloud.com/sms_callback?did={TO}", "UTF-8")
                        + "&" + "url_callback_retry=0";

                JSONObject result = Utils.getJson(url);
                String status = result.optString("status");
                return !(status == null || !status.equals("success"));
            } catch (Exception ex) {
                return false;
            }
        }

        @Override
        protected void onPostExecute(Boolean success) {
            progressDialog.hide();

            DialogInterface.OnClickListener gcmOnClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    gcm.registerForGcm(activity, true, true);
                }
            };

            if (!success) {
                Utils.showAlertDialog(activity, null,
                        applicationContext.getString(R.string.notifications_callback_fail),
                        applicationContext.getString(R.string.ok), gcmOnClickListener, null, null);
            } else {
                Utils.showAlertDialog(activity, null,
                        applicationContext.getString(R.string.notifications_callback_success),
                        applicationContext.getString(R.string.ok), gcmOnClickListener, null, null);
            }
        }
    }.execute();
}

From source file:com.fortysevendeg.labs.bbc.rest.android.activities.BeerActivity.java

/**
 * Delete beer on server/*from   ww w  . ja  va  2s . c o  m*/
 */
private void deleteBeer() {
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMessage(getString(R.string.connecting));
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.show();

    APIService.get().deleteBeer(beerResponseEdit.getId(),
            new ContextAwareAPIDelegate<BeerResponse>(this, BeerResponse.class) {
                @Override
                public void onResults(BeerResponse beerResponse) {
                    progressDialog.dismiss();
                    Toast.makeText(BeerActivity.this, R.string.beerDeleted, Toast.LENGTH_SHORT).show();
                    setResult(RESULT_OK);
                    finish();
                }

                @Override
                public void onError(Throwable e) {
                    progressDialog.dismiss();
                    Toast.makeText(BeerActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                }
            });
}

From source file:com.fortysevendeg.labs.bbc.rest.android.activities.BeerActivity.java

/**
 * Add beer on server/*from w w w  .jav a 2 s  .  c o m*/
 */
private void addBeer() {
    if (TextUtils.isEmpty(etAlcohol.getText().toString()) || TextUtils.isEmpty(etName.getText().toString())) {
        Toast.makeText(BeerActivity.this, R.string.fieldsEmpty, Toast.LENGTH_SHORT).show();
        return;
    }
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMessage(getString(R.string.connecting));
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.show();

    BeerRequest beerRequest = new BeerRequest();
    beerRequest.setAvb(Double.parseDouble(etAlcohol.getText().toString()));
    beerRequest.setName(etName.getText().toString());
    beerRequest.setDescription(etDescription.getText().toString());
    APIService.get().addBeer(beerRequest, new ContextAwareAPIDelegate<BeerResponse>(this, BeerResponse.class) {
        @Override
        public void onResults(BeerResponse beerResponse) {
            progressDialog.dismiss();
            Toast.makeText(BeerActivity.this, R.string.beerSaved, Toast.LENGTH_SHORT).show();
            setResult(RESULT_OK);
            finish();
        }

        @Override
        public void onError(Throwable e) {
            progressDialog.dismiss();
            Toast.makeText(BeerActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
        }
    });
}

From source file:com.fortysevendeg.labs.bbc.rest.android.activities.BeerActivity.java

/**
 * Update beer on server//from   ww  w .ja v  a 2s. c o  m
 */
private void updateBeer() {
    if (TextUtils.isEmpty(etAlcohol.getText().toString()) || TextUtils.isEmpty(etName.getText().toString())) {
        Toast.makeText(BeerActivity.this, R.string.fieldsEmpty, Toast.LENGTH_SHORT).show();
        return;
    }
    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
    progressDialog.setMessage(getString(R.string.connecting));
    progressDialog.setIndeterminate(true);
    progressDialog.setCancelable(false);
    progressDialog.show();

    BeerRequest beerRequest = new BeerRequest();
    beerRequest.setAvb(Double.parseDouble(etAlcohol.getText().toString()));
    beerRequest.setName(etName.getText().toString());
    beerRequest.setDescription(etDescription.getText().toString());
    APIService.get().updateBeer(beerResponseEdit.getId(), beerRequest,
            new ContextAwareAPIDelegate<BeerResponse>(this, BeerResponse.class) {
                @Override
                public void onResults(BeerResponse beerResponse) {
                    progressDialog.dismiss();
                    Toast.makeText(BeerActivity.this, R.string.beerSaved, Toast.LENGTH_SHORT).show();
                    setResult(RESULT_OK);
                    finish();
                }

                @Override
                public void onError(Throwable e) {
                    progressDialog.dismiss();
                    Toast.makeText(BeerActivity.this, R.string.error, Toast.LENGTH_SHORT).show();
                }
            });
}

From source file:me.kartikarora.transfersh.activities.TransferActivity.java

private void uploadFile(Uri uri) throws IOException {
    final ProgressDialog dialog = new ProgressDialog(TransferActivity.this);
    dialog.setMessage(getString(R.string.uploading_file));
    dialog.setCancelable(false);
    dialog.show();//  w ww .  ja v  a2 s.  co m
    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
    if (cursor != null) {
        cursor.moveToFirst();
        int nameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
        final String name = cursor.getString(nameIndex);
        final String mimeType = getContentResolver().getType(uri);
        Log.d(this.getClass().getSimpleName(), cursor.getString(0));
        Log.d(this.getClass().getSimpleName(), name);
        Log.d(this.getClass().getSimpleName(), mimeType);
        InputStream inputStream = getContentResolver().openInputStream(uri);
        OutputStream outputStream = openFileOutput(name, MODE_PRIVATE);
        if (inputStream != null) {
            IOUtils.copy(inputStream, outputStream);
            final File file = new File(getFilesDir(), name);
            TypedFile typedFile = new TypedFile(mimeType, file);
            TransferClient.getInterface().uploadFile(typedFile, name, new ResponseCallback() {
                @Override
                public void success(Response response) {
                    BufferedReader reader;
                    StringBuilder sb = new StringBuilder();
                    try {
                        reader = new BufferedReader(new InputStreamReader(response.getBody().in()));
                        String line;
                        try {
                            while ((line = reader.readLine()) != null) {
                                sb.append(line);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    String result = sb.toString();
                    Snackbar.make(mCoordinatorLayout, name + " " + getString(R.string.uploaded),
                            Snackbar.LENGTH_SHORT).show();

                    ContentValues values = new ContentValues();
                    values.put(FilesContract.FilesEntry.COLUMN_NAME, name);
                    values.put(FilesContract.FilesEntry.COLUMN_TYPE, mimeType);
                    values.put(FilesContract.FilesEntry.COLUMN_URL, result);
                    values.put(FilesContract.FilesEntry.COLUMN_SIZE, String.valueOf(file.getTotalSpace()));
                    getContentResolver().insert(FilesContract.BASE_CONTENT_URI, values);
                    getSupportLoaderManager().restartLoader(BuildConfig.VERSION_CODE, null,
                            TransferActivity.this);
                    FileUtils.deleteQuietly(file);
                    if (dialog.isShowing())
                        dialog.hide();
                }

                @Override
                public void failure(RetrofitError error) {
                    error.printStackTrace();
                    if (dialog.isShowing())
                        dialog.hide();
                    Snackbar.make(mCoordinatorLayout, R.string.something_went_wrong, Snackbar.LENGTH_INDEFINITE)
                            .setAction(R.string.report, new View.OnClickListener() {
                                @Override
                                public void onClick(View view) {
                                    // TODO add feedback code
                                }
                            }).show();
                }
            });
        } else
            Snackbar.make(mCoordinatorLayout, R.string.unable_to_read, Snackbar.LENGTH_SHORT).show();
    }
}

From source file:com.ota.updates.activities.MainActivity.java

private void checkForUpdate() {
    final ProgressDialog loadingDialog = new ProgressDialog(mContext);
    loadingDialog.setIndeterminate(true);
    loadingDialog.setCancelable(false);
    loadingDialog.setMessage(mContext.getResources().getString(R.string.loading));
    loadingDialog.show();/*  w  ww  .ja va2s  .c o m*/

    new DownloadJson(mContext, new AsyncResponse() {
        @Override
        public void processFinish(Boolean output) {
            if (output) {
                new ParseJson(mContext, new AsyncResponse() {
                    @Override
                    public void processFinish(Boolean output) {
                        if (output) {
                            new CheckForUpdate(mContext, new AsyncResponse() {
                                @Override
                                public void processFinish(Boolean updateAvailability) {
                                    if (DEBUGGING) {
                                        Log.d(TAG, "Update availability is " + updateAvailability);
                                    }

                                    if (updateAvailability) {
                                        loadFragment(new AvailableFragment());
                                    } else {
                                        loadFragment(new CheckFragment());
                                    }

                                    String time = Utils.getTimeNow(mContext);
                                    Preferences.setUpdateLastChecked(mContext, time);

                                    loadingDialog.cancel();
                                }
                            }).execute();
                        } else {
                            loadingDialog.cancel();
                        }
                    }
                }).execute();
            } else {
                loadingDialog.cancel();
            }
        }
    }).execute();
}

From source file:com.almarsoft.GroundhogReader.SubscribeActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    if (id == ID_DIALOG_SEARCHING) {
        ProgressDialog searchDialog = new ProgressDialog(this);
        searchDialog.setMessage("Searching matching groups...");
        searchDialog.setIndeterminate(true);
        searchDialog.setCancelable(true);
        return searchDialog;
    }//from ww  w .j  a  v a  2s .co  m

    return super.onCreateDialog(id);
}