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:io.github.tjg1.nori.APISettingsActivity.java

@Override
public void editService(final long rowId, final String name, final String url, final String username,
        final String passphrase) {
    // Show progress dialog during the service type detection process.
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setIndeterminate(true);/*w w  w.  jav  a2s.  c  o m*/
    dialog.setCancelable(false);
    dialog.setMessage(getString(R.string.dialog_message_detectingApiType));
    dialog.show();

    // Register broadcast receiver to get results from the background service type detection service.
    registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            // Get result code from received intent.
            int resultCode = intent.getIntExtra(ServiceTypeDetectionService.RESULT_CODE, -1);
            if (resultCode == ServiceTypeDetectionService.RESULT_OK) {
                // Add a new service to the database on a background thread.
                // This is so database I/O doesn't block the UI thread.
                SearchClient.Settings.APIType apiType = SearchClient.Settings.APIType.values()[intent
                        .getIntExtra(ServiceTypeDetectionService.API_TYPE, 0)];
                final SearchClient.Settings settings = new SearchClient.Settings(apiType, name, url, username,
                        passphrase);
                new Thread(new Runnable() {
                    @Override
                    public void run() {
                        APISettingsDatabase database = new APISettingsDatabase(APISettingsActivity.this);
                        if (rowId == ROW_ID_INSERT) {
                            database.insert(settings);
                        } else {
                            database.update(rowId, settings);
                        }
                        database.close();
                    }
                }).start();
            } else if (resultCode == ServiceTypeDetectionService.RESULT_FAIL_INVALID_URL) {
                Toast.makeText(APISettingsActivity.this, R.string.toast_error_serviceUriInvalid,
                        Toast.LENGTH_LONG).show();
            } else if (resultCode == ServiceTypeDetectionService.RESULT_FAIL_NETWORK) {
                Toast.makeText(APISettingsActivity.this, R.string.toast_error_noNetwork, Toast.LENGTH_LONG)
                        .show();
            } else if (resultCode == ServiceTypeDetectionService.RESULT_FAIL_NO_API) {
                Toast.makeText(APISettingsActivity.this, R.string.toast_error_noServiceAtGivenUri,
                        Toast.LENGTH_LONG).show();
            }

            // Unregister the broadcast receiver.
            unregisterReceiver(this);
            // Dismiss progress dialog.
            dialog.dismiss();
        }
    }, new IntentFilter(ServiceTypeDetectionService.ACTION_DONE));

    // Start the background service type detection service.
    Intent serviceIntent = new Intent(this, ServiceTypeDetectionService.class);
    serviceIntent.putExtra(ServiceTypeDetectionService.ENDPOINT_URL, url);
    startService(serviceIntent);
}

From source file:de.gebatzens.sia.SetupActivity.java

public void startDownloadingSchool() {
    final ProgressDialog d = new ProgressDialog(this);
    d.setTitle(SIAApp.SIA_APP.school.name);
    d.setMessage(getString(R.string.downloading_image));
    d.setCancelable(false);
    d.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    d.show();// w  w w  .  j  av a2s  .c  om

    new Thread() {
        @Override
        public void run() {
            if (!School.downloadImage(SIAApp.SIA_APP.school.image)) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        Snackbar.make(getWindow().getDecorView().findViewById(R.id.coordinator_layout),
                                getString(R.string.download_error), Snackbar.LENGTH_LONG).show();
                    }
                });
            }

            //workaround for a bug that causes an endless loading screen
            Subst.GGPlans subst = SIAApp.SIA_APP.api.getPlans(false);
            subst.save();
            SIAApp.SIA_APP.school.fragments.getByType(FragmentData.FragmentType.PLAN).get(0).setData(subst);

            if (d.isShowing())
                d.dismiss();
            Intent i = new Intent(SetupActivity.this, MainActivity.class);
            //i.putExtra("reload", true);
            startActivity(i);
            finish();

        }
    }.start();
}

From source file:com.bestjoy.app.haierwarrantycard.ui.SettingsPreferenceActivity.java

@Override
public Dialog onCreateDialog(int id) {
    switch (id) {
    //add by chenkai, 20131201, add network check
    case DIALOG_DATA_NOT_CONNECTED:
        return ComConnectivityManager.getInstance().onCreateNoNetworkDialog(this);
    case DIALOG_PROGRESS:
        ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setMessage(getString(R.string.msg_progressdialog_wait));
        progressDialog.setCancelable(false);
        return progressDialog;
    }/*www  .  j a  v  a2  s . c o m*/
    return super.onCreateDialog(id);
}

From source file:com.gmail.charleszq.picorner.ui.MainSlideMenuActivity.java

/**
 * When first time this activity starts, load default photo list, now it's
 * flickr interesting photos./*w  ww . j  av  a 2s . c o  m*/
 */
void loadDefaultPhotoList() {
    MessageBus.reset();
    mCommand = getDefaultCommand();
    final ProgressDialog dialog = ProgressDialog.show(this, "", getString(R.string.loading_photos)); //$NON-NLS-1$
    dialog.setCancelable(true);
    mCommand.setCommndDoneListener(new ICommandDoneListener<MediaObjectCollection>() {

        @Override
        public void onCommandDone(ICommand<MediaObjectCollection> command, MediaObjectCollection t) {
            MainSlideMenuActivity.this.onCommandDone(command, t);
            if (dialog != null && dialog.isShowing()) {
                try {
                    dialog.dismiss();
                } catch (Exception ex) {

                }
            }
        }
    });
    mCommand.execute();
}

From source file:com.androidquery.simplefeed.base.BaseActivity.java

public ProgressDialog makeProgressDialog(String message) {

    ProgressDialog dialog = new ProgressDialog(this);
    dialog.setIndeterminate(true);//w  w w.ja  v a  2 s.  c o m
    dialog.setCancelable(true);
    dialog.setInverseBackgroundForced(false);
    dialog.setCanceledOnTouchOutside(true);
    dialog.setMessage(message);

    return dialog;

}

From source file:com.pansapiens.occyd.NewPost.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_POSTING: {
        ProgressDialog dialog = new ProgressDialog(this);
        dialog.setTitle("Posting ...");
        dialog.setMessage("Posting ...");
        dialog.setIndeterminate(true);//w w  w.j av  a  2s.c  o  m
        dialog.setCancelable(false);
        return dialog;
    }
    }
    return null;
}

From source file:net.kourlas.voipms_sms.gcm.Gcm.java

/**
 * Registers for Google Cloud Messaging. Sends the registration token to the application servers.
 *
 * @param activity     The activity that initiated the registration.
 * @param showFeedback If true, shows a dialog at the end of the registration process indicating the success or
 *                     failure of the process.
 * @param force        If true, retrieves a new registration token even if one is already stored.
 *//*from w w  w  . j  a  v  a2s.c o m*/
public void registerForGcm(final Activity activity, final boolean showFeedback, boolean force) {
    if (!preferences.getNotificationsEnabled()) {
        return;
    }
    if (preferences.getDid().equals("")) {
        // Do not show an error; this method should never be called unless a DID is set
        return;
    }
    if (!checkPlayServices(activity, showFeedback)) {
        return;
    }

    final ProgressDialog progressDialog = new ProgressDialog(activity);
    if (showFeedback) {
        progressDialog.setMessage(applicationContext.getString(R.string.notifications_gcm_progress));
        progressDialog.setCancelable(false);
        progressDialog.show();
    }

    final InstanceID instanceIdObj = InstanceID.getInstance(applicationContext);
    final String instanceId = instanceIdObj.getId();
    if (preferences.getGcmToken().equals("") || !instanceId.equals(preferences.getGcmInstanceId()) || force) {
        new AsyncTask<Boolean, Void, Boolean>() {
            @Override
            protected Boolean doInBackground(Boolean... params) {
                try {
                    String token = instanceIdObj.getToken(
                            applicationContext.getString(R.string.notifications_gcm_sender_id),
                            GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

                    String registrationBackendUrl = "https://voipmssms-kourlas.rhcloud.com/register?" + "did="
                            + URLEncoder.encode(preferences.getDid(), "UTF-8") + "&" + "reg_id="
                            + URLEncoder.encode(token, "UTF-8");
                    JSONObject result = Utils.getJson(registrationBackendUrl);
                    String status = result.optString("status");
                    if (status == null || !status.equals("success")) {
                        return false;
                    }

                    preferences.setGcmInstanceId(instanceId);
                    preferences.setGcmToken(token);

                    return true;
                } catch (Exception ex) {
                    return false;
                }
            }

            @Override
            protected void onPostExecute(Boolean success) {
                if (showFeedback) {
                    progressDialog.hide();
                    if (!success) {
                        Utils.showInfoDialog(activity,
                                applicationContext.getResources().getString(R.string.notifications_gcm_fail));
                    } else {
                        Utils.showInfoDialog(activity, applicationContext.getResources()
                                .getString(R.string.notifications_gcm_success));
                    }
                }
            }
        }.execute();
    } else if (showFeedback) {
        Utils.showInfoDialog(activity,
                applicationContext.getResources().getString(R.string.notifications_gcm_success));
    }
}

From source file:com.ame.armymax.SettingsActivity.java

private ProgressDialog getProgressDialog() {

    ProgressDialog progress = null;//from ww  w  . jav  a2s  . c o  m

    if (progress == null) {
        ProgressDialog dialog = new ProgressDialog(this);
        dialog.setIndeterminate(true);
        dialog.setCancelable(true);
        dialog.setInverseBackgroundForced(false);
        dialog.setCanceledOnTouchOutside(true);
        progress = dialog;
    }
    return progress;
}

From source file:com.listapp.ListappActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    super.onCreateDialog(id);

    switch (id) {
    case ERR_DIALOG:
        AlertDialog errDialog = new AlertDialog.Builder(this)
                // See
                // http://code.google.com/p/android/issues/detail?id=6489
                .setMessage("").setCancelable(false).setNeutralButton("OK", new OnClickListener() {
                    @Override//from   w w  w.  jav a  2s  .  c  o m
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();
                    }
                }).create();
        return errDialog;

    case LOADING_DIALOG:
        ProgressDialog progressDialog = new ProgressDialog(mContext);
        progressDialog.setMessage("Loading...");
        progressDialog.setCancelable(true);
        progressDialog.setCanceledOnTouchOutside(false);
        // Listen for back button or cancel button in dialog itself
        progressDialog.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (taskInProgress != null) {
                    // TODO why doesn't this stop the HTTP request?
                    taskInProgress.cancel(true);
                }
            }
        });
        return progressDialog;

    default:
        return null;
    }
}

From source file:it.feio.android.omninotes.utils.SpinnerDialog.java

@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    ProgressDialog dialog = new ProgressDialog(getActivity());
    //      this.setStyle(STYLE_NO_TITLE, getTheme()); // You can use styles or
    //                                       // inflate a view
    //      dialog.setMessage("Spinning.."); // set your messages if not inflated
    // from XML/*www .  jav a  2 s  . c  om*/
    //      dialog.setView(new Spinner(getActivity(), STYLE_NO_TITLE));
    dialog.setCancelable(false);

    return dialog;
}