Example usage for android.app ProgressDialog setOnCancelListener

List of usage examples for android.app ProgressDialog setOnCancelListener

Introduction

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

Prototype

public void setOnCancelListener(@Nullable OnCancelListener listener) 

Source Link

Document

Set a listener to be invoked when the dialog is canceled.

Usage

From source file:com.sxt.superqq.activity.LoginActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (resultCode == RESULT_OK) {
        if (requestCode == REQUEST_CODE_SETNICK) {
            SuperQQApplication.currentUserNick = data.getStringExtra("edittext");

            progressShow = true;// ww w.j av a 2s. c om
            final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
            pd.setCanceledOnTouchOutside(false);
            pd.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    progressShow = false;
                }
            });
            pd.setMessage(getString(R.string.Is_landing));
            pd.show();

            final long start = System.currentTimeMillis();
            // sdk??
            EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {

                @Override
                public void onSuccess() {

                    if (!progressShow) {
                        return;
                    }
                    // ?????
                    SuperQQApplication.getInstance().setUserName(currentUsername);
                    SuperQQApplication.getInstance().setPassword(currentPassword);

                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.setMessage(getString(R.string.list_is_for));
                        }
                    });
                    try {
                        // ** ?logout???
                        // ** manually load all local groups and
                        // conversations in case we are auto login
                        EMGroupManager.getInstance().loadAllGroups();
                        EMChatManager.getInstance().loadAllConversations();
                        //??
                        processContactsAndGroups();
                    } catch (Exception e) {
                        e.printStackTrace();
                        //?????
                        runOnUiThread(new Runnable() {
                            public void run() {
                                pd.dismiss();
                                SuperQQApplication.getInstance().logout(null);
                                Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1)
                                        .show();
                            }
                        });
                        return;
                    }
                    //?nickname ios?nick
                    boolean updatenick = EMChatManager.getInstance()
                            .updateCurrentUserNick(SuperQQApplication.currentUserNick.trim());
                    if (!updatenick) {
                        Log.e("LoginActivity", "update current user nick fail");
                    }
                    if (!LoginActivity.this.isFinishing())
                        pd.dismiss();
                    // ?
                    startActivity(new Intent(LoginActivity.this, MainActivity.class));
                    finish();
                }

                @Override
                public void onProgress(int progress, String status) {
                }

                @Override
                public void onError(final int code, final String message) {
                    if (!progressShow) {
                        return;
                    }
                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.dismiss();
                            Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });

        }
    }
}

From source file:com.fabernovel.alertevoirie.HomeActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_PROGRESS:
        ProgressDialog pd = new ProgressDialog(this);
        pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pd.setIndeterminate(true);//from   ww  w.  j  a va 2 s .  c o m
        pd.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                if (dialog_shown)
                    removeDialog(DIALOG_PROGRESS);
            }
        });
        pd.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                AVService.getInstance(HomeActivity.this).cancelTask();
                finish();
            }
        });
        pd.setMessage(getString(R.string.ui_message_loading));
        return pd;

    default:
        return super.onCreateDialog(id);
    }
}

From source file:com.nbos.phonebook.sync.authenticator.AuthenticatorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    final ProgressDialog dialog = new ProgressDialog(this);
    dialog.setMessage(getText(R.string.ui_activity_authenticating));
    dialog.setIndeterminate(true);//from  w  ww  .  j av a 2s  .  c  o  m
    dialog.setCancelable(true);
    dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        public void onCancel(DialogInterface dialog) {
            Log.i(tag, "dialog cancel has been invoked");
            if (mAuthThread != null) {
                mAuthThread.interrupt();
                finish();
            }
        }
    });
    return dialog;
}

From source file:edu.mit.mobile.android.locast.accounts.AuthenticatorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_PROGRESS:

        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setMessage(getText(R.string.login_message_authenticating));
        dialog.setIndeterminate(true);/*from  ww  w .j  a  v a2  s .  c o  m*/
        dialog.setCancelable(true);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                Log.i(TAG, "dialog cancel has been invoked");
                if (mAuthenticationTask != null) {
                    mAuthenticationTask.cancel(true);
                    mAuthenticationTask = null;
                    finish();
                }
            }
        });
        return dialog;

    case DIALOG_SET_BASE_URL:

        final EditText baseUrl = new EditText(this);
        baseUrl.setText(getString(R.string.default_api_url));
        final AlertDialog.Builder db = new AlertDialog.Builder(this);
        return db.create();

    default:
        return null;
    }
}

From source file:com.sxt.superqq.activity.LoginActivity.java

/**
 * ?// www . j  av  a 2s  . com
 */
private void setLoginClickListener() {
    findViewById(R.id.btnLogin).setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!CommonUtils.isNetWorkConnected(LoginActivity.this)) {
                Toast.makeText(LoginActivity.this, R.string.network_isnot_available, Toast.LENGTH_SHORT).show();
                return;
            }
            currentUsername = usernameEditText.getText().toString().trim();
            currentPassword = passwordEditText.getText().toString().trim();

            /*
             * ????
             */
            if (TextUtils.isEmpty(currentUsername)) {
                Toast.makeText(LoginActivity.this, R.string.User_name_cannot_be_empty, Toast.LENGTH_SHORT)
                        .show();
                return;
            }
            if (TextUtils.isEmpty(currentPassword)) {
                Toast.makeText(LoginActivity.this, R.string.Password_cannot_be_empty, Toast.LENGTH_SHORT)
                        .show();
                return;
            }

            //?
            progressShow = true;
            final ProgressDialog pd = new ProgressDialog(LoginActivity.this);
            pd.setCanceledOnTouchOutside(false);
            pd.setOnCancelListener(new OnCancelListener() {

                @Override
                public void onCancel(DialogInterface dialog) {
                    progressShow = false;
                }
            });
            pd.setMessage(getString(R.string.Is_landing));
            pd.show();

            final long start = System.currentTimeMillis();
            // sdk??
            EMChatManager.getInstance().login(currentUsername, currentPassword, new EMCallBack() {
                @Override
                public void onSuccess() {

                    if (!progressShow) {
                        return;
                    }

                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.setMessage(getString(R.string.list_is_for));
                        }
                    });
                    try {

                        //?
                        boolean isSuccess = loginAppServer(currentUsername, currentPassword);
                        if (!isSuccess) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(LoginActivity.this, "", 2000).show();
                                    return;
                                }
                            });
                        }
                        final String userName = SuperQQApplication.getInstance().getUserName();
                        //?
                        isSuccess = NetUtils.downloadAvatar(LoginActivity.this, userName);

                        if (SuperQQApplication.getInstance().getContacts().size() == 0) {
                            //,20userName??
                            new DownloadContactsTask(LoginActivity.this, userName, 0, 20)
                                    .execute(I.SERVER_ROOT);
                        }
                        if (!isSuccess) {
                            runOnUiThread(new Runnable() {
                                @Override
                                public void run() {
                                    Toast.makeText(LoginActivity.this, userName + "?", 3000)
                                            .show();
                                }
                            });
                        }
                        // ** ?logout???
                        // ** manually load all local groups and
                        // conversations in case we are auto login
                        EMGroupManager.getInstance().loadAllGroups();
                        EMChatManager.getInstance().loadAllConversations();
                        //??
                        processContactsAndGroups();
                    } catch (Exception e) {
                        e.printStackTrace();
                        //?????
                        runOnUiThread(new Runnable() {
                            public void run() {
                                pd.dismiss();
                                SuperQQApplication.getInstance().logout(null);
                                Toast.makeText(getApplicationContext(), R.string.login_failure_failed, 1)
                                        .show();
                            }
                        });
                        return;
                    }
                    //?nickname ios?nick
                    boolean updatenick = EMChatManager.getInstance()
                            .updateCurrentUserNick(SuperQQApplication.currentUserNick.trim());
                    if (!updatenick) {
                        Log.e("LoginActivity", "update current user nick fail");
                    }
                    if (!LoginActivity.this.isFinishing())
                        pd.dismiss();
                    // ?
                    startActivity(new Intent(LoginActivity.this, MainActivity.class));
                    finish();
                }

                @Override
                public void onProgress(int progress, String status) {
                }

                @Override
                public void onError(final int code, final String message) {
                    if (!progressShow) {
                        return;
                    }
                    runOnUiThread(new Runnable() {
                        public void run() {
                            pd.dismiss();
                            Toast.makeText(getApplicationContext(), getString(R.string.Login_failed) + message,
                                    Toast.LENGTH_SHORT).show();
                        }
                    });
                }
            });
            //                Intent intent = new Intent(LoginActivity.this, com.sxt.superqq.activity.AlertDialogActivity.class);
            //                intent.putExtra("editTextShow", true);
            //                intent.putExtra("titleIsCancel", true);
            //                intent.putExtra("msg", getResources().getString(R.string.please_set_the_current));
            //                intent.putExtra("edit_text", currentUsername);
            //                startActivityForResult(intent, REQUEST_CODE_SETNICK);
        }
    });
}

From source file:tm.veriloft.mapsplayground.MapsActivity.java

private void fetchAndDrawRoute(final LatLng... latLngs) {
    final AsyncHttpClient asyncHttpClient = new AsyncHttpClient(SERVER_PORT);

    final ProgressDialog progressDialog = new ProgressDialog(this);
    progressDialog.setMessage("Loading..");
    progressDialog.setButton(DialogInterface.BUTTON_NEGATIVE, "Cancel", new DialogInterface.OnClickListener() {
        @Override/* w  w w. j av a2 s  .c om*/
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
        }
    });

    progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            asyncHttpClient.cancelRequests(MapsActivity.this, true);
            showCenteredToast("Drawing route got cancelled");
        }
    });

    final RequestParams requestParams = new RequestParams();

    for (LatLng latLng : latLngs) {
        requestParams.add("loc", latLng.latitude + "," + latLng.longitude);
        l("Added latLng to request, " + latLng);
    }

    asyncHttpClient.get(this, SERVER, requestParams, new JsonHttpResponseHandler() {
        @Override
        public void onStart() {
            progressDialog.show();
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
            try {
                ArrayList<LatLng> route = MapUtils.decodePoly(response.getString("route_geometry"));
                PolylineOptions routeOptions = new PolylineOptions();

                for (int i = 0; i < route.size(); i++) {
                    routeOptions.add(route.get(i));
                    l("Returned point " + route.get(i));
                    if (returnedPointsMarkers)
                        addedMarkers.add(mMap.addMarker(new MarkerOptions().position(route.get(i))
                                .title("#" + i + " point of #" + drawnRoutes.size())));
                }

                routeOptions.width(ROUTE_WIDTH).color(ROUTE_COLOR);
                drawnRoutes.add(mMap.addPolyline(routeOptions));

                List<LatLng> points = routeOptions.getPoints();

                if (focusAfterRouteDraw)
                    focusTo(points.get(0), 13);

                if (endMarkerRouteDraw) {
                    LatLng trueEndPoint = MapUtils.findTrueEndPoint(latLngs[latLngs.length - 1], route.get(0),
                            route.get(route.size() - 1));
                    addedMarkers.add(mMap.addMarker(
                            new MarkerOptions().position(trueEndPoint).title("End of #" + drawnRoutes.size())));
                }

                if (requestedPointMarkerRouteDraw)
                    addedMarkers.add(mMap.addMarker(new MarkerOptions().position(latLngs[latLngs.length - 1])
                            .title("Requested point of #" + drawnRoutes.size())));

            } catch (JSONException exception) {
                exception.printStackTrace();
                showCenteredToast("Exception while parsing! Error: " + exception.getLocalizedMessage());
            }
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONArray errorResponse) {
            showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            showCenteredToast("Network error! Server returned non-json response, response: " + responseString
                    + ", Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
            showCenteredToast("Network error! Error: " + throwable.getLocalizedMessage());
        }

        @Override
        public void onFinish() {
            progressDialog.dismiss();
        }
    });
}

From source file:com.fabernovel.alertevoirie.NewsActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_PROGRESS:
        ProgressDialog pd = new ProgressDialog(this);
        pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);
        pd.setIndeterminate(true);/*from  w  ww .j  av a2s  . com*/
        pd.setOnDismissListener(new OnDismissListener() {
            @Override
            public void onDismiss(DialogInterface dialog) {
                removeDialog(DIALOG_PROGRESS);
            }
        });

        pd.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                AVService.getInstance(NewsActivity.this).cancelTask();
                finish();
            }
        });

        pd.setMessage(getString(R.string.ui_message_loading));
        return pd;

    default:
        return super.onCreateDialog(id);
    }
}

From source file:edu.mit.mobile.android.locast.accounts.AbsLocastAuthenticatorActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_PROGRESS:

        final ProgressDialog dialog = new ProgressDialog(this);
        dialog.setMessage(getText(R.string.login_message_authenticating));
        dialog.setIndeterminate(true);/*from w w w . j av a  2  s .c om*/
        dialog.setCancelable(true);
        dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
            public void onCancel(DialogInterface dialog) {
                if (BuildConfig.DEBUG) {
                    Log.i(TAG, "dialog cancel has been invoked");
                }
                if (mAuthenticationTask != null) {
                    mAuthenticationTask.cancel(true);
                    mAuthenticationTask = null;
                    finish();
                }
            }
        });
        return dialog;

    default:
        return null;
    }
}

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

@Override
public Dialog onCreateDialog(final int id) {
    AlertDialog.Builder builder;/*from 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:com.xabber.android.ui.activity.ContactList.java

@Override
protected Dialog onCreateDialog(int id) {
    super.onCreateDialog(id);
    switch (id) {
    case DIALOG_CLOSE_APPLICATION_ID:
        ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setMessage(getString(R.string.application_state_closing));
        progressDialog.setOnCancelListener(new OnCancelListener() {
            @Override//from   www  . jav a2s  . c o m
            public void onCancel(DialogInterface dialog) {
                finish();
            }
        });
        progressDialog.setIndeterminate(true);
        return progressDialog;
    default:
        return null;
    }
}