Example usage for android.app ProgressDialog ProgressDialog

List of usage examples for android.app ProgressDialog ProgressDialog

Introduction

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

Prototype

public ProgressDialog(Context context) 

Source Link

Document

Creates a Progress dialog.

Usage

From source file:com.easemob.chatuidemo.activity.GroupDetailsActivity.java

@Override
public void onClick(View v) {
    String st6 = getResources().getString(R.string.Is_unblock);
    final String st7 = getResources().getString(R.string.remove_group_of);
    switch (v.getId()) {
    case R.id.rl_switch_block_groupmsg: // ?
        if (iv_switch_block_groupmsg.getVisibility() == View.VISIBLE) {
            EMLog.d(TAG, "change to unblock group msg");
            if (progressDialog == null) {
                progressDialog = new ProgressDialog(GroupDetailsActivity.this);
                progressDialog.setCanceledOnTouchOutside(false);
            }/*from   w w  w . ja  v  a2  s .com*/
            progressDialog.setMessage(st6);
            progressDialog.show();
            new Thread(new Runnable() {
                public void run() {
                    try {
                        EMGroupManager.getInstance().unblockGroupMessage(groupId);
                        runOnUiThread(new Runnable() {
                            public void run() {
                                iv_switch_block_groupmsg.setVisibility(View.INVISIBLE);
                                iv_switch_unblock_groupmsg.setVisibility(View.VISIBLE);
                                progressDialog.dismiss();
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            public void run() {
                                progressDialog.dismiss();
                                Toast.makeText(getApplicationContext(), st7, 1).show();
                            }
                        });

                    }
                }
            }).start();

        } else {
            String st8 = getResources().getString(R.string.group_is_blocked);
            final String st9 = getResources().getString(R.string.group_of_shielding);
            EMLog.d(TAG, "change to block group msg");
            if (progressDialog == null) {
                progressDialog = new ProgressDialog(GroupDetailsActivity.this);
                progressDialog.setCanceledOnTouchOutside(false);
            }
            progressDialog.setMessage(st8);
            progressDialog.show();
            new Thread(new Runnable() {
                public void run() {
                    try {
                        EMGroupManager.getInstance().blockGroupMessage(groupId);
                        runOnUiThread(new Runnable() {
                            public void run() {
                                iv_switch_block_groupmsg.setVisibility(View.VISIBLE);
                                iv_switch_unblock_groupmsg.setVisibility(View.INVISIBLE);
                                progressDialog.dismiss();
                            }
                        });
                    } catch (Exception e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            public void run() {
                                progressDialog.dismiss();
                                Toast.makeText(getApplicationContext(), st9, 1).show();
                            }
                        });
                    }

                }
            }).start();
        }
        break;

    case R.id.clear_all_history: // ?
        String st9 = getResources().getString(R.string.sure_to_empty_this);
        Intent intent = new Intent(GroupDetailsActivity.this, AlertDialog.class);
        intent.putExtra("cancel", true);
        intent.putExtra("titleIsCancel", true);
        intent.putExtra("msg", st9);
        startActivityForResult(intent, REQUEST_CODE_CLEAR_ALL_HISTORY);
        break;

    case R.id.rl_blacklist: // ???
        startActivity(new Intent(GroupDetailsActivity.this, GroupBlacklistActivity.class).putExtra("groupId",
                groupId));
        break;

    case R.id.rl_change_group_name:
        startActivityForResult(new Intent(this, EditActivity.class).putExtra("data", group.getGroupName()),
                REQUEST_CODE_EDIT_GROUPNAME);
        break;
    default:
        break;
    }

}

From source file:com.starclub.enrique.BuyActivity.java

public void updateCredit(int credit) {

    progress = new ProgressDialog(this);
    progress.setCancelable(false);//from w ww  . ja va  2s .c  om
    progress.setMessage("Updating...");

    progress.show();

    m_nCredit = credit;

    new Thread() {
        public void run() {

            HttpParams myParams = new BasicHttpParams();

            HttpConnectionParams.setConnectionTimeout(myParams, 30000);
            HttpConnectionParams.setSoTimeout(myParams, 30000);

            DefaultHttpClient hc = new DefaultHttpClient(myParams);
            ResponseHandler<String> res = new BasicResponseHandler();

            String url = Utils.getUpdateUrl();
            HttpPost postMethod = new HttpPost(url);

            String responseBody = "";
            try {
                MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

                reqEntity.addPart("cid", new StringBody("" + MyConstants.CID));
                reqEntity.addPart("token", new StringBody("" + Utils.getUserToken()));
                reqEntity.addPart("user_id", new StringBody("" + Utils.getUserID()));

                reqEntity.addPart("credit", new StringBody("" + m_nCredit));

                postMethod.setEntity(reqEntity);
                responseBody = hc.execute(postMethod, res);

                System.out.println("update result = " + responseBody);
                JSONObject result = new JSONObject(responseBody);
                if (result != null) {
                    boolean status = result.optBoolean("status");
                    if (status) {

                        m_handler.sendEmptyMessage(1);

                        return;
                    }
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
            }

            m_handler.sendEmptyMessage(-1);
        }
    }.start();
}