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.digitalarx.android.ui.activity.FileDisplayActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;//from  ww  w  .  j  a v  a 2s  .c o m
    AlertDialog.Builder builder;
    switch (id) {
    case DIALOG_SHORT_WAIT: {
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(getResources().getString(R.string.wait_a_moment));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(false);
        dialog = working_dialog;
        break;
    }
    case DIALOG_CHOOSE_UPLOAD_SOURCE: {

        String[] items = null;

        String[] allTheItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps),
                getString(R.string.actionbar_failed_instant_upload) };

        String[] commonItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps) };

        if (InstantUploadActivity.IS_ENABLED)
            items = allTheItems;
        else
            items = commonItems;

        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.actionbar_upload);
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (item == 0) {
                    // if (!mDualPane) {
                    Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
                    action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                    // } else {
                    // TODO create and handle new fragment
                    // LocalFileListFragment
                    // }
                } else if (item == 1) {
                    Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                    action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                    startActivityForResult(
                            Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                            ACTION_SELECT_CONTENT_FROM_APPS);
                } else if (item == 2 && InstantUploadActivity.IS_ENABLED) {
                    Intent action = new Intent(FileDisplayActivity.this, InstantUploadActivity.class);
                    action.putExtra(FileUploader.KEY_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivity(action);
                }
            }
        });
        dialog = builder.create();
        break;
    }
    case DIALOG_CERT_NOT_SAVED: {
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            };
        });
        dialog = builder.create();
        break;
    }
    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

private Dialog buildCreatePublicLinkDialog() {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(getString(R.string.dialog_creating_link));
    dialog.setIndeterminate(true);/*from www.  j  a v  a  2s .co  m*/
    dialog.setCancelable(false);
    return dialog;
}

From source file:com.ubuntuone.android.files.activity.FilesActivity.java

private Dialog buildCheckDirectorySizeDialog(final Bundle extras) {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(getString(R.string.dialog_checking_size_message));
    dialog.setIndeterminate(true);//from   w  w w. j  a v a2  s . c  om
    dialog.setCancelable(true);
    return dialog;
}

From source file:com.owncloud.android.ui.activity.FileDisplayActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;/*  w  w w.ja v a2 s  .c o  m*/
    AlertDialog.Builder builder;
    switch (id) {
    case DIALOG_SHORT_WAIT: {
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(getResources().getString(R.string.wait_a_moment));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(false);
        dialog = working_dialog;
        break;
    }
    case DIALOG_CHOOSE_UPLOAD_SOURCE: {

        String[] items = null;

        String[] allTheItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps),
                getString(R.string.actionbar_failed_instant_upload) };

        String[] commonItems = { getString(R.string.actionbar_upload_files),
                getString(R.string.actionbar_upload_from_apps) };

        if (InstantUploadActivity.IS_ENABLED)
            items = allTheItems;
        else
            items = commonItems;

        builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.actionbar_upload);
        builder.setItems(items, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int item) {
                if (item == 0) {
                    // if (!mDualPane) {
                    Intent action = new Intent(FileDisplayActivity.this, UploadFilesActivity.class);
                    action.putExtra(UploadFilesActivity.EXTRA_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivityForResult(action, ACTION_SELECT_MULTIPLE_FILES);
                    // } else {
                    // TODO create and handle new fragment
                    // LocalFileListFragment
                    // }
                } else if (item == 1) {
                    Intent action = new Intent(Intent.ACTION_GET_CONTENT);
                    action = action.setType("*/*").addCategory(Intent.CATEGORY_OPENABLE);
                    startActivityForResult(
                            Intent.createChooser(action, getString(R.string.upload_chooser_title)),
                            ACTION_SELECT_CONTENT_FROM_APPS);
                } else if (item == 2 && InstantUploadActivity.IS_ENABLED) {
                    Intent action = new Intent(FileDisplayActivity.this, InstantUploadActivity.class);
                    action.putExtra(FileUploader.KEY_ACCOUNT, FileDisplayActivity.this.getAccount());
                    startActivity(action);
                }
            }
        });
        dialog = builder.create();
        break;
    }
    case DIALOG_SSL_VALIDATOR: {
        dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
        break;
    }
    case DIALOG_CERT_NOT_SAVED: {
        builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            };
        });
        dialog = builder.create();
        break;
    }
    default:
        dialog = null;
    }

    return dialog;
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void sendRegistrationRequest(final String email) {
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog.setMessage(getString(R.string.registration_sending_email, email));
    progressDialog.setCancelable(true);
    progressDialog.show();//from w w  w  . ja va 2  s  . co m
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.error_please_try_again);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };
    final String timestamp = "" + mWiz.getTimestamp();
    final String registrationId = mWiz.getRegistrationId();
    final String deviceId = mWiz.getDeviceId();

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "2";
            String requestSignature = Security.sha256(version + email + " " + timestamp + " " + deviceId + " "
                    + registrationId + " " + CloudConstants.REGISTRATION_EMAIL_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_REQUEST_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("email", email));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("request_signature", requestSignature));
                nameValuePairs.add(new BasicNameValuePair("install_id", mWiz.getInstallationId()));
                nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString()));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                if (statusCode == 200) {
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            mWiz.setEmail(email);
                            mWiz.save();
                            progressDialog.dismiss();
                            mWiz.proceedToNextPage();
                            showNotification();
                        }
                    });
                } else if (statusCode == 502) {

                    final HttpEntity entity = response.getEntity();
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            progressDialog.dismiss();
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);

                            boolean stringSet = false;
                            if (entity != null) {
                                @SuppressWarnings("unchecked")
                                final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue
                                        .parse(new InputStreamReader(entity.getContent()));

                                if (responseMap != null) {
                                    String result = (String) responseMap.get("result");
                                    if (result != null) {
                                        builder.setMessage(result);
                                        stringSet = true;
                                    }
                                }
                            }

                            if (!stringSet) {
                                builder.setMessage(R.string.registration_email_not_valid);
                            }

                            builder.setPositiveButton(R.string.rogerthat, null);
                            AlertDialog dialog = builder.create();
                            dialog.show();
                        }
                    });
                } else {
                    mUIHandler.post(showErrorDialog);
                }

            } catch (ClientProtocolException e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            } catch (IOException e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveCfgPart2(final String finalval, final String needToRename) {
    Intent new_intent = new Intent();
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 16);
    new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval);
    sendBroadcast(new_intent);
    final ProgressDialog prog;
    prog = new ProgressDialog(TimidityActivity.this);
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override//from  w w w  . ja  v a  2s  . com
        public void onClick(DialogInterface dialog, int which) {

            dialog.dismiss();
        }
    });
    prog.setTitle("Saving CFG");
    prog.setMessage("Saving...");
    prog.setIndeterminate(true);
    prog.setCancelable(false);
    prog.show();
    new Thread(new Runnable() {
        @Override
        public void run() {
            while (!localfinished && prog.isShowing()) {
                try {

                    Thread.sleep(25);
                } catch (InterruptedException e) {
                }
            }

            TimidityActivity.this.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(TimidityActivity.this, finalval, needToRename)) {
                            trueName = needToRename;
                        } else {
                            trueName = "Error";
                        }
                    }
                    Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                    prog.dismiss();
                    fileFrag.getDir(fileFrag.currPath);
                }
            });

        }
    }).start();
}

From source file:com.xperia64.timidityae.TimidityActivity.java

public void saveWavPart2(final String finalval, final String needToRename) {
    Intent new_intent = new Intent();
    new_intent.setAction(getResources().getString(R.string.msrv_rec));
    new_intent.putExtra(getResources().getString(R.string.msrv_cmd), 15);
    new_intent.putExtra(getResources().getString(R.string.msrv_outfile), finalval);
    sendBroadcast(new_intent);
    final ProgressDialog prog;
    prog = new ProgressDialog(TimidityActivity.this);
    prog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override//from w  ww  .  ja v a  2  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();
                TimidityActivity.this.runOnUiThread(new Runnable() {
                    public void run() {
                        Toast.makeText(TimidityActivity.this, "Conversion canceled", Toast.LENGTH_SHORT).show();
                        if (!Globals.keepWav) {
                            if (new File(finalval).exists())
                                new File(finalval).delete();
                        } else {
                            fileFrag.getDir(fileFrag.currPath);
                        }
                    }
                });

            } else {
                TimidityActivity.this.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(TimidityActivity.this, finalval, needToRename)) {
                                trueName = needToRename;
                            } else {
                                trueName = "Error";
                            }
                        }
                        Toast.makeText(TimidityActivity.this, "Wrote " + trueName, Toast.LENGTH_SHORT).show();
                        prog.dismiss();
                        fileFrag.getDir(fileFrag.currPath);
                    }
                });
            }
        }
    }).start();
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void registerWithAccessToken(final String accessToken) {
    final String timestamp = "" + mWiz.getTimestamp();
    final String deviceId = mWiz.getDeviceId();
    final String registrationId = mWiz.getRegistrationId();
    final String installId = mWiz.getInstallationId();
    // Make call to Rogerthat webfarm
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog//  w  w  w . ja  v a 2  s . com
            .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name)));
    progressDialog.setCancelable(false);
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.registration_facebook_error);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "1";
            String signature = Security.sha256(version + " " + installId + " " + timestamp + " " + deviceId
                    + " " + registrationId + " " + accessToken + CloudConstants.REGISTRATION_MAIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_FACEBOOK_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(8);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("signature", signature));
                nameValuePairs.add(new BasicNameValuePair("install_id", installId));
                nameValuePairs.add(new BasicNameValuePair("access_token", accessToken));
                nameValuePairs.add(new BasicNameValuePair("language", Locale.getDefault().getLanguage()));
                nameValuePairs.add(new BasicNameValuePair("country", Locale.getDefault().getCountry()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);

                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();

                if (entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }

                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) JSONValue
                        .parse(new InputStreamReader(entity.getContent()));

                if (statusCode != 200 || responseMap == null) {
                    if (statusCode == 500 && responseMap != null) {
                        final String errorMessage = (String) responseMap.get("error");
                        if (errorMessage != null) {
                            mUIHandler.post(new SafeRunnable() {
                                @Override
                                protected void safeRun() throws Exception {
                                    T.UI();
                                    progressDialog.dismiss();
                                    AlertDialog.Builder builder = new AlertDialog.Builder(
                                            RegistrationActivity2.this);
                                    builder.setMessage(errorMessage);
                                    builder.setPositiveButton(R.string.rogerthat, null);
                                    AlertDialog dialog = builder.create();
                                    dialog.show();
                                }
                            });
                            return;
                        }
                    }
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                JSONObject account = (JSONObject) responseMap.get("account");
                final String email = (String) responseMap.get("email");
                mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set");
                final RegistrationInfo info = new RegistrationInfo(email,
                        new Credentials((String) account.get("account"), (String) account.get("password")));
                mUIHandler.post(new SafeRunnable() {
                    @Override
                    protected void safeRun() throws Exception {
                        T.UI();
                        mWiz.setEmail(email);
                        mWiz.save();
                        hideNotification();
                        tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection,
                                email, getString(R.string.app_name)) + " ", info);
                    }
                });

            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });
}

From source file:com.mobicage.rogerthat.registration.RegistrationActivity2.java

private void onPinEntered() {

    final String pin = mEnterPinEditText.getText().toString();
    // Validate pin code
    if (!RegexPatterns.PIN.matcher(pin).matches()) {
        AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
        builder.setMessage(R.string.registration_invalid_pin);
        builder.setPositiveButton(R.string.rogerthat, null);
        AlertDialog dialog = builder.create();
        dialog.show();//from ww  w.j a v  a2 s  . co  m
        return;
    }
    // Make call to Rogerthat webfarm
    final ProgressDialog progressDialog = new ProgressDialog(RegistrationActivity2.this);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    progressDialog
            .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name)));
    progressDialog.setCancelable(false);
    progressDialog.show();
    final SafeRunnable showErrorDialog = new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.UI();
            progressDialog.dismiss();
            AlertDialog.Builder builder = new AlertDialog.Builder(RegistrationActivity2.this);
            builder.setMessage(R.string.registration_sending_pin_error);
            builder.setPositiveButton(R.string.rogerthat, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    };
    final String email = mWiz.getEmail();
    final String timestamp = "" + mWiz.getTimestamp();
    final String registrationId = mWiz.getRegistrationId();
    final String deviceId = mWiz.getDeviceId();

    mWorkerHandler.post(new SafeRunnable() {
        @Override
        protected void safeRun() throws Exception {
            T.REGISTRATION();
            String version = "2";
            String pinSignature = Security.sha256(version + " " + email + " " + timestamp + " " + deviceId + " "
                    + registrationId + " " + pin + CloudConstants.REGISTRATION_PIN_SIGNATURE);

            HttpPost httppost = new HttpPost(CloudConstants.REGISTRATION_PIN_URL);
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(6);
                nameValuePairs.add(new BasicNameValuePair("version", version));
                nameValuePairs.add(new BasicNameValuePair("email", email));
                nameValuePairs.add(new BasicNameValuePair("registration_time", timestamp));
                nameValuePairs.add(new BasicNameValuePair("device_id", deviceId));
                nameValuePairs.add(new BasicNameValuePair("registration_id", registrationId));
                nameValuePairs.add(new BasicNameValuePair("pin_code", pin));
                nameValuePairs.add(new BasicNameValuePair("pin_signature", pinSignature));
                nameValuePairs.add(new BasicNameValuePair("request_id", UUID.randomUUID().toString()));
                nameValuePairs.add(new BasicNameValuePair("app_id", CloudConstants.APP_ID));
                nameValuePairs.add(
                        new BasicNameValuePair("use_xmpp_kick", CloudConstants.USE_XMPP_KICK_CHANNEL + ""));
                nameValuePairs.add(new BasicNameValuePair("GCM_registration_id", mGCMRegistrationId));

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

                // Execute HTTP Post Request
                HttpResponse response = mHttpClient.execute(httppost);
                int statusCode = response.getStatusLine().getStatusCode();
                HttpEntity entity = response.getEntity();
                if (statusCode != 200 || entity == null) {
                    mUIHandler.post(showErrorDialog);
                    return;
                }
                @SuppressWarnings("unchecked")
                final Map<String, Object> responseMap = (Map<String, Object>) org.json.simple.JSONValue
                        .parse(new InputStreamReader(entity.getContent()));
                if ("success".equals(responseMap.get("result"))) {

                    JSONObject account = (JSONObject) responseMap.get("account");
                    final RegistrationInfo info = new RegistrationInfo(email,
                            new Credentials((String) account.get("account"), (String) account.get("password")));

                    mAgeAndGenderSet = (Boolean) responseMap.get("age_and_gender_set");
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            hideNotification();
                            tryConnect(progressDialog, 1, getString(R.string.registration_establish_connection,
                                    email, getString(R.string.app_name)) + " ", info);
                        }
                    });
                } else {

                    final long attempts_left = (Long) responseMap.get("attempts_left");
                    mUIHandler.post(new SafeRunnable() {
                        @Override
                        protected void safeRun() throws Exception {
                            T.UI();
                            progressDialog.dismiss();
                            if (attempts_left > 0) {
                                AlertDialog.Builder builder = new AlertDialog.Builder(
                                        RegistrationActivity2.this);
                                builder.setMessage(getString(R.string.registration_incorrect_pin, email));
                                builder.setTitle(getString(R.string.registration_incorrect_pin_dialog_title));
                                builder.setPositiveButton(R.string.rogerthat, null);
                                AlertDialog dialog = builder.create();
                                dialog.show();
                                mEnterPinEditText.setText("");
                            } else {
                                hideNotification();
                                new AlertDialog.Builder(RegistrationActivity2.this)
                                        .setMessage(getString(R.string.registration_no_attempts_left))
                                        .setCancelable(true).setPositiveButton(R.string.try_again, null)
                                        .create().show();
                                mWiz.reInit();
                                mWiz.goBackToPrevious();
                                return;
                            }
                        }
                    });

                }
            } catch (Exception e) {
                L.d(e);
                mUIHandler.post(showErrorDialog);
            }
        }
    });

}

From source file:com.owncloud.android.authentication.AuthenticatorActivity.java

/**
 * {@inheritDoc}/*from  www  .j a va2 s.c  om*/
 */
@Override
protected Dialog onCreateDialog(int id) {
    Dialog dialog = null;
    switch (id) {
    case DIALOG_LOGIN_PROGRESS: {
        // / simple progress dialog
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(getResources().getString(R.string.auth_trying_to_login));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(true);
        working_dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                // / TODO study if this is enough
                Log_OC.i(TAG, "Login canceled");
                if (mOperationThread != null) {
                    mOperationThread.interrupt();
                    finish();
                }
            }
        });
        dialog = working_dialog;
        break;
    }
    case DIALOG_OAUTH2_LOGIN_PROGRESS: {
        ProgressDialog working_dialog = new ProgressDialog(this);
        working_dialog.setMessage(String.format("Getting authorization"));
        working_dialog.setIndeterminate(true);
        working_dialog.setCancelable(true);
        working_dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                Log_OC.i(TAG, "Login canceled");
                finish();
            }
        });
        dialog = working_dialog;
        break;
    }
    case DIALOG_SSL_VALIDATOR: {
        // / TODO start to use new dialog interface, at least for this (it
        // is a FragmentDialog already)
        dialog = SslValidatorDialog.newInstance(this, mLastSslUntrustedServerResult, this);
        break;
    }
    case DIALOG_CERT_NOT_SAVED: {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage(getResources().getString(R.string.ssl_validator_not_saved));
        builder.setCancelable(false);
        builder.setPositiveButton(R.string.common_ok, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            };
        });
        dialog = builder.create();
        break;
    }
    default:
        Log_OC.e(TAG, "Incorrect dialog called with id = " + id);
    }
    return dialog;
}