Example usage for android.app ProgressDialog setMessage

List of usage examples for android.app ProgressDialog setMessage

Introduction

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

Prototype

@Override
    public void setMessage(CharSequence message) 

Source Link

Usage

From source file:cn.hbm.superwechat.activity.ChatActivity.java

/**
 * ???//from  w w w  .jav a 2 s  . co m
 *
 * @param username
 */
private void addUserToBlacklist(final String username) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setMessage(getString(R.string.Is_moved_into_blacklist));
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            try {
                EMContactManager.getInstance().addUserToBlackList(username, false);
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getApplicationContext(), R.string.Move_into_blacklist_success,
                                Toast.LENGTH_SHORT).show();
                    }
                });
            } catch (EaseMobException e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getApplicationContext(), R.string.Move_into_blacklist_failure,
                                Toast.LENGTH_SHORT).show();
                    }
                });
            }
        }
    }).start();
}

From source file:cn.ucai.chatuidemo.activity.ChatActivity.java

/**
 * ???/*from w  w  w.  j  a  v a2 s . c om*/
 * 
 * @param username
 */
private void addUserToBlacklist(final String username) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setMessage(getString(R.string.Is_moved_into_blacklist));
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            try {
                EMContactManager.getInstance().addUserToBlackList(username, false);
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getApplicationContext(), R.string.Move_into_blacklist_success,
                                Toast.LENGTH_LONG).show();
                    }
                });
            } catch (EaseMobException e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        Toast.makeText(getApplicationContext(), R.string.Move_into_blacklist_failure,
                                Toast.LENGTH_LONG).show();
                    }
                });
            }
        }
    }).start();
}

From source file:com.eason.marker.emchat.chatuidemo.activity.ChatActivity.java

/**
 * ???/*from   ww  w.j  a  v a  2  s. co  m*/
 * 
 * @param username
 */
private void addUserToBlacklist(final String username) {
    final ProgressDialog pd = new ProgressDialog(this);
    pd.setMessage(getString(R.string.Is_moved_into_blacklist));
    pd.setCanceledOnTouchOutside(false);
    pd.show();
    new Thread(new Runnable() {
        public void run() {
            try {
                EMContactManager.getInstance().addUserToBlackList(username, false);
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        GreenToast
                                .makeText(getApplicationContext(),
                                        getResources().getString(R.string.Move_into_blacklist_success), 0)
                                .show();
                    }
                });
            } catch (EaseMobException e) {
                e.printStackTrace();
                runOnUiThread(new Runnable() {
                    public void run() {
                        pd.dismiss();
                        GreenToast
                                .makeText(getApplicationContext(),
                                        getResources().getString(R.string.Move_into_blacklist_failure), 0)
                                .show();
                    }
                });
            }
        }
    }).start();
}

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);//w  w w  .j av a2 s.c  o m
    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.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.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
            .setMessage(getString(R.string.registration_activating_account, getString(R.string.app_name)));
    progressDialog.setCancelable(false);
    progressDialog.show();// w w w  .j  a v  a 2  s.  c om
    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();/* w ww  .  ja  v a2 s.c o  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.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  www .j a  va 2  s  . c o m
        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:nf.frex.android.FrexActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode != Activity.RESULT_OK) {
        return;/* w w  w .  j  a v  a  2 s.com*/
    }
    if (requestCode == R.id.manage_fractals && data.getAction().equals(Intent.ACTION_VIEW)) {
        final Uri imageUri = data.getData();
        if (imageUri != null) {
            File imageFile = new File(imageUri.getPath());
            String configName = FrexIO.getFilenameWithoutExt(imageFile);
            File paramFile = new File(imageFile.getParent(), configName + FrexIO.PARAM_FILE_EXT);
            try {
                FileInputStream fis = new FileInputStream(paramFile);
                try {
                    readFrexDoc(fis, configName);
                } finally {
                    fis.close();
                }
            } catch (IOException e) {
                Toast.makeText(FrexActivity.this, getString(R.string.error_msg, e.getLocalizedMessage()),
                        Toast.LENGTH_SHORT).show();
            }
        }
    } else if (requestCode == R.id.settings) {
        view.getGenerator().setNumTasks(SettingsActivity.getNumTasks(this));
    } else if (requestCode == SELECT_PICTURE_REQUEST_CODE) {
        final Uri imageUri = data.getData();
        final ColorQuantizer colorQuantizer = new ColorQuantizer();
        final ProgressDialog progressDialog = new ProgressDialog(FrexActivity.this);
        final DialogInterface.OnCancelListener cancelListener = new DialogInterface.OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                if (progressDialog.isShowing()) {
                    progressDialog.dismiss();
                }
                colorQuantizer.cancel();
            }
        };
        final ColorQuantizer.ProgressListener progressListener = new ColorQuantizer.ProgressListener() {
            @Override
            public void progress(final String msg, final int iter, final int maxIter) {
                runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        progressDialog.setMessage(msg);
                        progressDialog.setProgress(iter);
                    }
                });
            }
        };

        progressDialog.setTitle(getString(R.string.get_pal_from_img_title));
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.setCancelable(true);
        progressDialog.setOnCancelListener(cancelListener);
        progressDialog.setMax(colorQuantizer.getMaxIterCount());
        progressDialog.show();

        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                Bitmap bitmap;
                try {
                    bitmap = FrexIO.readBitmap(getContentResolver(), imageUri, 256);
                } catch (IOException e) {
                    alert("I/O error: " + e.getLocalizedMessage());
                    return;
                }
                ColorScheme colorScheme = colorQuantizer.quantize(bitmap, progressListener);
                progressDialog.dismiss();
                if (colorScheme != null) {
                    Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: Got colorScheme");
                    String colorSchemeId = "$" + imageUri.toString();
                    colorSchemes.add(colorSchemeId, colorScheme);
                    view.setColorSchemeId(colorSchemeId);
                    view.setColorScheme(colorScheme);
                    view.recomputeColors();
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            Log.d(TAG, "SELECT_PICTURE_REQUEST_CODE: showDialog(R.id.colors)");
                            showDialog(R.id.colors);
                        }
                    });

                }
            }
        });
        thread.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   www  .j ava2s.  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.owncloud.android.authentication.AuthenticatorActivity.java

/**
 * {@inheritDoc}/*from   ww w .j a  v  a2  s .c  o m*/
 */
@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;
}